Commit 6fd84081 authored by Claes Sjofors's avatar Claes Sjofors

Java table, support for cell selection added

parent 588f1ffd
...@@ -6062,6 +6062,9 @@ public class Dyn { ...@@ -6062,6 +6062,9 @@ public class Dyn {
int columns; int columns;
int rows; int rows;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
int[] sel_p;
int[] sel_elements;
PwrtRefId[] sel_subid;
public DynTable( Dyn dyn) { public DynTable( Dyn dyn) {
super(dyn, Dyn.mDynType1_Table, 0, 0, 0, Dyn.eDynPrio_Table); super(dyn, Dyn.mDynType1_Table, 0, 0, 0, Dyn.eDynPrio_Table);
...@@ -6274,6 +6277,9 @@ public class Dyn { ...@@ -6274,6 +6277,9 @@ public class Dyn {
cFormat = new GlowCFormat[columns]; cFormat = new GlowCFormat[columns];
for ( int i = 0; i < columns; i++) for ( int i = 0; i < columns; i++)
cFormat[i] = new GlowCFormat( format[i]); cFormat[i] = new GlowCFormat( format[i]);
sel_p = new int[columns];
sel_subid = new PwrtRefId[columns];
sel_elements = new int[columns];
for ( int i = 0; i < columns; i++) { for ( int i = 0; i < columns; i++) {
DynParsedAttrName pname = dyn.parseAttrName(attribute[i]); DynParsedAttrName pname = dyn.parseAttrName(attribute[i]);
...@@ -6374,6 +6380,32 @@ public class Dyn { ...@@ -6374,6 +6380,32 @@ public class Dyn {
} }
// Connect select array
sel_p[i] = 0;
pname = dyn.parseAttrName(sel_attribute[i]);
if ( pname == null || pname.name.equals(""))
continue;
if ( pname.type != Pwr.eType_Boolean)
continue;
switch ( pname.database) {
case GraphIfc.eDatabase_Gdh:
ret = dyn.graph.getGdh().refObjectInfo( pname.tname);
if ( ret.oddSts()) {
if ( ret.getElements() == 0)
break;
sel_p[i] = ret.id;
sel_subid[i] = ret.refid;
sel_elements[i] = ret.getElements();
if ( sel_elements[i] > elements[i])
sel_elements[i] = elements[i];
}
break;
default:
;
}
} }
object.setTableInfo(info); object.setTableInfo(info);
...@@ -6420,6 +6452,10 @@ public class Dyn { ...@@ -6420,6 +6452,10 @@ public class Dyn {
oldValueS[i] = null; oldValueS[i] = null;
break; break;
} }
if ( sel_p[i] != 0) {
dyn.graph.getGdh().unrefObjectInfo(sel_subid[i]);
sel_p[i] = 0;
}
} }
} }
...@@ -6454,7 +6490,7 @@ public class Dyn { ...@@ -6454,7 +6490,7 @@ public class Dyn {
object.setValue(new String("1"), i, j); object.setValue(new String("1"), i, j);
else else
object.setValue(new String("0"), i, j); object.setValue(new String("0"), i, j);
object.setValue(new String(sb), i, j); //object.setValue(new String(sb), i, j);
oldValueB[i][j] = val[j]; oldValueB[i][j] = val[j];
} }
} }
...@@ -6569,9 +6605,70 @@ public class Dyn { ...@@ -6569,9 +6605,70 @@ public class Dyn {
} }
} }
// Examine select array
boolean sel_found = false;
for ( int i = 0; i < columns; i++) {
if ( sel_p[i] == 0)
continue;
boolean[] val = dyn.graph.getGdh().getObjectRefInfoBooleanArray(sel_p[i], sel_elements[i]);
for ( int j = 0; j < sel_elements[i]; j++) {
if ( val[j]) {
sel_found = true;
object.setSelectedCell( i, j);
}
}
}
if ( !sel_found)
object.setSelectedCell( -1, -1);
if ( firstScan) if ( firstScan)
firstScan = false; firstScan = false;
} }
public int action( GlowArrayElem o, GlowEvent e) {
if ( !dyn.graph.isAuthorized( dyn.access))
return 1;
GrowTable object = (GrowTable)o;
switch ( e.event) {
case Glow.eEvent_MB1Click:
int column, row;
boolean value;
if ( e.type != Glow.eEventType_Table)
break;
GlowEventTable event = (GlowEventTable)e;
row = object.getSelectedCellRow();
column = object.getSelectedCellColumn();
if ( row >= 0 && sel_p[column] != 0) {
// Reset previously selected
DynParsedAttrName pname = dyn.parseAttrName(sel_attribute[column]);
if ( pname == null || pname.name.equals(""))
break;
value = false;
String aname = pname.name + "[" + row + "]";
PwrtStatus sts = dyn.graph.getGdh().setObjectInfo( aname, value);
if ( sts.evenSts()) System.out.println("Table error: " + pname.name);
}
if ( sel_p[event.column] != 0 &&
!(event.column == column && event.row == row)) {
// Set new selected, if not same as previous selected
DynParsedAttrName pname = dyn.parseAttrName(sel_attribute[event.column]);
if ( pname == null || pname.name.equals(""))
break;
value = true;
String aname = pname.name + "[" + event.row + "]";
PwrtStatus sts = dyn.graph.getGdh().setObjectInfo( aname, value);
if ( sts.evenSts())
System.out.println("Table error: " + pname.name);
else
object.setSelectedCell( event.column, event.row);
}
break;
}
return 1;
}
} }
public class DynStatusColor extends DynElem { public class DynStatusColor extends DynElem {
......
...@@ -1491,6 +1491,7 @@ public class Glow { ...@@ -1491,6 +1491,7 @@ public class Glow {
public static final int eEventType_Object = 0; public static final int eEventType_Object = 0;
public static final int eEventType_Menu = 1; public static final int eEventType_Menu = 1;
public static final int eEventType_Toolbar = 2; public static final int eEventType_Toolbar = 2;
public static final int eEventType_Table = 3;
public static final int eEvent_MB1Click = 0; public static final int eEvent_MB1Click = 0;
public static final int eEvent_MB1Up = 2; public static final int eEvent_MB1Up = 2;
......
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2015 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
package jpwr.jopg;
public class GlowEventTable extends GlowEvent {
public int column;
public int row;
public GlowEventTable() {}
}
...@@ -434,7 +434,7 @@ public class Graph implements GraphIfc, GrowApplIfc { ...@@ -434,7 +434,7 @@ public class Graph implements GraphIfc, GrowApplIfc {
int sts; int sts;
Dyn dyn = (Dyn)((GlowArrayElem)e.object).getUserData(); Dyn dyn = (Dyn)((GlowArrayElem)e.object).getUserData();
if ( dyn != null) if ( dyn != null)
sts = dyn.action((GrowNode)e.object, e); sts = dyn.action((GlowArrayElem)e.object, e);
} }
break; break;
case Glow.eEvent_MenuActivated: case Glow.eEvent_MenuActivated:
......
...@@ -439,6 +439,25 @@ public class GrowCtx implements GrowCtxIfc { ...@@ -439,6 +439,25 @@ public class GrowCtx implements GrowCtxIfc {
return 1; return 1;
} }
public int send_table_callback( GlowArrayElem object, int event,
double x, double y, int column, int row) {
/* Send a table callback */
GlowEventTable e = new GlowEventTable();
e.event = event;
e.type = Glow.eEventType_Table;
//e.x_pixel = (int)( x * mw.zoom_factor_x) - mw.offset_x;
//e.y_pixel = (int)( y * mw.zoom_factor_y) - mw.offset_y;
e.x = x;
e.y = y;
e.object_type = object.type();
e.object = object;
e.column = column;
e.row = row;
cmn.appl.eventHandler(e);
return 1;
}
public int eventHandler(GlowEvent e, double fx, double fy) { public int eventHandler(GlowEvent e, double fx, double fy) {
return eventHandler( e); return eventHandler( e);
} }
......
...@@ -51,6 +51,8 @@ public interface GrowCtxIfc { ...@@ -51,6 +51,8 @@ public interface GrowCtxIfc {
double x, double y); double x, double y);
public int send_toolbar_callback( GlowArrayElem object, int category, int idx, int type, public int send_toolbar_callback( GlowArrayElem object, int category, int idx, int type,
double x, double y); double x, double y);
public int send_table_callback( GlowArrayElem object, int event,
double x, double y, int column, int row);
public void insert(GlowArrayElem e); public void insert(GlowArrayElem e);
public void remove(GlowArrayElem e); public void remove(GlowArrayElem e);
public void pop(GlowArrayElem e); public void pop(GlowArrayElem e);
......
...@@ -81,8 +81,8 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc { ...@@ -81,8 +81,8 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc {
int[] column_adjustment = new int[Glow.TABLE_MAX_COL]; int[] column_adjustment = new int[Glow.TABLE_MAX_COL];
int value_size; int value_size;
String[] cell_value; String[] cell_value;
int selected_cell_row; int selected_cell_row = -1;
int selected_cell_column; int selected_cell_column = -1;
int select_drawtype; int select_drawtype;
int input_focus; int input_focus;
int header_text_bold; int header_text_bold;
...@@ -882,8 +882,8 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc { ...@@ -882,8 +882,8 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc {
} }
} }
//if ( row != -1 && column != -1) if ( row != -1 && column != -1)
// ((GrowCtx *)ctx)->send_table_callback( this, event, fx, fy, column, row); cmn.ctx.send_table_callback( this, event.event, fx, fy, column, row);
break; break;
} }
default: ; default: ;
...@@ -912,4 +912,26 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc { ...@@ -912,4 +912,26 @@ public class GrowTable extends GrowRect implements GrowScrollBarIfc {
public void setValue(String value, int col, int row) { public void setValue(String value, int col, int row) {
cell_value[col * rows + row] = value; cell_value[col * rows + row] = value;
} }
public void setSelectedCell( int column, int row) {
if ( selected_cell_column == column &&
selected_cell_row == row)
return;
if ( column >= columns || row >= rows)
return;
selected_cell_column = column;
selected_cell_row = row;
draw();
}
public int getSelectedCellRow() {
return selected_cell_row;
}
public int getSelectedCellColumn() {
if ( selected_cell_row == -1)
return -1;
return selected_cell_column;
}
} }
...@@ -44,6 +44,7 @@ local_java_sources := \ ...@@ -44,6 +44,7 @@ local_java_sources := \
GlowBackgroundObject.java,\ GlowBackgroundObject.java,\
GlowEventMenu.java,\ GlowEventMenu.java,\
GlowEventToolbar.java,\ GlowEventToolbar.java,\
GlowEventTable.java,\
GrowCtxIfc.java,\ GrowCtxIfc.java,\
GrowCmn.java,\ GrowCmn.java,\
GlowNodeClass.java,\ GlowNodeClass.java,\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment