Jessey Widhalm 8 years ago
parent
commit
6fac0e176b
2 changed files with 59 additions and 19 deletions
  1. 40 19
      src/ui/view/GUI.java
  2. 19 0
      src/ui/view/PropertyTable.java

+ 40 - 19
src/ui/view/GUI.java

@@ -58,6 +58,7 @@ import classes.HolonSwitch;
 import classes.HolonTransformer;
 import ui.controller.Control;
 import ui.model.Model;
+import ui.view.PropertyTable;;
 
 public class GUI<E> implements CategoryListener {
 
@@ -99,7 +100,7 @@ public class GUI<E> implements CategoryListener {
 	// HolonObject with consumption/production, name and amount.
 
 	private JTable tableHolonElement = new JTable();
-	private DefaultTableModel tableModelHolonElement = new DefaultTableModel();
+	private PropertyTable tableModelHolonElement = new PropertyTable();
 	private final JPanel scrollElements = new JPanel();
 	JScrollPane tableHolonElementScrollPane = new JScrollPane();
 
@@ -164,6 +165,8 @@ public class GUI<E> implements CategoryListener {
 	private final JComboBox comboBoxAlgo = new JComboBox();
 	private int yTHIS;
 	private int xTHIS;
+	private int yBTHIS;
+	private int xBTHIS;
 
 	/**
 	 * Create the application.
@@ -262,7 +265,7 @@ public class GUI<E> implements CategoryListener {
 		 */
 
 		// Set up of the HolonElements section
-		Object[] columnNames = { "Device", "Energy", "Quantity" };
+		Object[] columnNames = { "Device", "Energy", "Quantity", "Activated" };
 		tableModelHolonElement.setColumnIdentifiers(columnNames);
 		tableHolonElement.setBorder(null);
 		tableHolonElement.setModel(tableModelHolonElement);
@@ -364,6 +367,10 @@ public class GUI<E> implements CategoryListener {
 					yTHIS = e.getY();
 					xTHIS = e.getX();
 				}
+
+				yBTHIS = e.getY();
+				xBTHIS = e.getX();
+
 			}
 		});
 
@@ -391,21 +398,33 @@ public class GUI<E> implements CategoryListener {
 			public void propertyChange(PropertyChangeEvent evt) {
 				try {
 					int yMouse = yTHIS;
-					int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 3));
+					int yBMouse = yBTHIS;
+					int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 4));
 					int selectedValueY = (int) Math.floor(yMouse / 16);
+					int selectedValueBX = (int) Math.floor(xBTHIS / (tableHolonElement.getWidth() / 4));
+					int selectedValueBY = (int) Math.floor(yBMouse / 16);
 					if (getActualCps() != null && getActualCps().getClass() == HolonObject.class) {
-						HolonElement eleTemp = getActualHolonElement((HolonObject) getActualCps(), yMouse);
-						String newStuff = tableModelHolonElement.getValueAt(selectedValueY, selectedValueX).toString();
-						if (selectedValueX == 0) {
-							eleTemp.setEleName(newStuff);
-						} else if (selectedValueX == 1) {
-							Float ftemp = Float.parseFloat(newStuff);
-							eleTemp.setEnergy(ftemp);
-						} else if (selectedValueX == 2) {
-							Integer iTemp = Integer.parseInt(newStuff);
-							eleTemp.setAmount(iTemp);
+						if (selectedValueBX == 3) {
+							HolonElement eleBTemp = getActualHolonElement((HolonObject) getActualCps(), yBMouse);
+							String newBStuff = tableModelHolonElement.getValueAt(selectedValueBY, selectedValueBX)
+									.toString();
+							Boolean bTemp = Boolean.parseBoolean(newBStuff);
+							eleBTemp.setActive(bTemp);
+						} else {
+							HolonElement eleTemp = getActualHolonElement((HolonObject) getActualCps(), yMouse);
+							String newStuff = tableModelHolonElement.getValueAt(selectedValueY, selectedValueX)
+									.toString();
+							if (selectedValueX == 0) {
+								eleTemp.setEleName(newStuff);
+							} else if (selectedValueX == 1) {
+								Float ftemp = Float.parseFloat(newStuff);
+								eleTemp.setEnergy(ftemp);
+							} else if (selectedValueX == 2) {
+								Integer iTemp = Integer.parseInt(newStuff);
+								eleTemp.setAmount(iTemp);
+							}
+							tableModelHolonElement.fireTableDataChanged();
 						}
-						tableModelHolonElement.fireTableDataChanged();
 					}
 				} catch (Exception e) {
 
@@ -501,10 +520,12 @@ public class GUI<E> implements CategoryListener {
 						CpsObject selected = controller.searchObjInCat(selectedNode.toString(),
 								selectedNode.getParent().toString());
 						deleteRows();
-//						if (selected instanceof HolonObject && selected != null) {
-//							selected = (HolonObject) selected;
-//							fillElementTable(((HolonObject) selected).getElements());
-//						}
+						// if (selected instanceof HolonObject && selected !=
+						// null) {
+						// selected = (HolonObject) selected;
+						// fillElementTable(((HolonObject)
+						// selected).getElements());
+						// }
 					}
 					for (Category cat : model.getCategories()) {
 						for (CpsObject cps : cat.getObjects()) {
@@ -929,7 +950,7 @@ public class GUI<E> implements CategoryListener {
 
 	public void fillElementTable(ArrayList<HolonElement> elements) {
 		for (HolonElement he : elements) {
-			Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount() };
+			Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount(), he.getActive() };
 			tableModelHolonElement.addRow(temp);
 		}
 	}

+ 19 - 0
src/ui/view/PropertyTable.java

@@ -0,0 +1,19 @@
+package ui.view;
+
+import java.util.Vector;
+
+import javax.swing.table.DefaultTableModel;
+
+public class PropertyTable extends DefaultTableModel {
+
+	@Override
+	public Class<?> getColumnClass(int columnIndex) {
+		Class clazz = String.class;
+		switch (columnIndex) {
+		case 3:
+			clazz = Boolean.class;
+			break;
+		}
+		return clazz;
+	}
+}