Browse Source

Fix the problem in the PropertieTable

Edgardo Palza 8 years ago
parent
commit
637eb7d1e4
1 changed files with 37 additions and 15 deletions
  1. 37 15
      src/ui/view/GUI.java

+ 37 - 15
src/ui/view/GUI.java

@@ -210,6 +210,9 @@ public class GUI<E> implements CategoryListener {
 	// Coord for all Cells with boolean values (checkbox)
 	private int yBTHIS;
 	private int xBTHIS;
+	// Coord for the Edit-Modus in the PropertieTable
+	private int yProThis;
+	private int xProThis;
 	private CpsObject temp = null;
 	private final JButton btnTest = new JButton("test");
 	private final JMenuItem mntmUndo = new JMenuItem("Undo");
@@ -843,6 +846,20 @@ public class GUI<E> implements CategoryListener {
 		/***********************
 		 * HolonElement Properties Actions
 		 **********************/
+
+		/*
+		 * Update of the mouse coord
+		 */
+		tableProperties.addMouseListener(new MouseAdapter() {
+			public void mousePressed(MouseEvent e) {
+				if (e.getClickCount() == 2) {
+					yProThis = e.getY();
+					xProThis = e.getX();
+				}
+
+			}
+		});
+
 		/*
 		 * Update any change in the Property table
 		 */
@@ -851,17 +868,21 @@ public class GUI<E> implements CategoryListener {
 			public void propertyChange(PropertyChangeEvent evt) {
 				try {
 					Object temp;
+					Object btemp;
 					Point mousePos = tableProperties.getMousePosition();
+					int selValueY = (int) Math.floor(yProThis / 16);
+					int selValueX = (int) Math.floor(xProThis / (tableProperties.getWidth() / 2));
+					temp = tableModelProperties.getValueAt(selValueY, selValueX);
 					if (getActualCps() != null) {
-						temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
-								mousePos.x / (tableProperties.getWidth() / 2));
-						if (getActualCps() instanceof HolonObject) {
-							getActualCps().setName(temp.toString());
-						} else if (getActualCps() instanceof HolonSwitch) {
-							if (mousePos.y / tableProperties.getRowHeight() == 2) {
-								Boolean bTemp = Boolean.parseBoolean(temp.toString());
-								((HolonSwitch) getActualCps()).setManualMode(bTemp);
-								if (bTemp) {
+						if (getActualCps() instanceof HolonSwitch) {
+							btemp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
+									mousePos.x / (tableProperties.getWidth() / 2));
+							if (mousePos.y / tableProperties.getRowHeight() == 0) {
+								getActualCps().setName(btemp.toString());
+							} else if (mousePos.y / tableProperties.getRowHeight() == 2) {
+								Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
+								((HolonSwitch) getActualCps()).setManualMode(bbTemp);
+								if (bbTemp) {
 									tableModelProperties.setCellEditable(3, 1, true);
 								} else {
 									tableModelProperties.setCellEditable(3, 1, false);
@@ -873,11 +894,13 @@ public class GUI<E> implements CategoryListener {
 									((HolonSwitch) getActualCps()).setManualState(bTemp);
 								}
 							}
+						} else if (getActualCps() instanceof HolonObject) {
+							getActualCps().setName(temp.toString());
 						}
 					} else {
-						temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
-								mousePos.x / (tableProperties.getWidth() / 2));
-						if (mousePos.y / tableProperties.getRowHeight() == 2) {
+
+						temp = tableModelProperties.getValueAt(selValueY, selValueX);
+						if (selValueY / tableProperties.getRowHeight() == 2) {
 							Float ftemp;
 							if (Float.parseFloat(temp.toString()) >= 0.0) {
 								ftemp = Float.parseFloat(temp.toString());
@@ -885,7 +908,7 @@ public class GUI<E> implements CategoryListener {
 								ftemp = model.getSelectedEdge().getCapacity();
 							}
 							model.getSelectedEdge().setCapacity(ftemp);
-						} else if (mousePos.y / tableProperties.getRowHeight() == 3) {
+						} else if (selValueY / tableProperties.getRowHeight() == 3) {
 							Boolean bTemp = Boolean.parseBoolean(temp.toString());
 							model.getSelectedEdge().setState(bTemp);
 						}
@@ -1005,8 +1028,7 @@ public class GUI<E> implements CategoryListener {
 					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
 							.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
 					if (selectedNode.getLevel() == 2) {
-						controller.searchCategoryObject(selectedNode.getParent().toString(),
-								selectedNode.toString());
+						controller.searchCategoryObject(selectedNode.getParent().toString(), selectedNode.toString());
 						deleteRows(tableModelHolonElementSingle);
 						deleteRows(tableModelHolonElementMulti);
 						// if (selected instanceof HolonObject && selected !=