浏览代码

#76: trigger table update after SimMan-run (one case missing, see TODO) and vice versa

I. Dix 7 年之前
父节点
当前提交
ce080c7f1d

+ 4 - 4
src/ui/controller/SimulationManager.java

@@ -63,10 +63,10 @@ public class SimulationManager {
             if (energySurplus != 0 && model.useFlexibleDevices()) {
                 turnOnFlexibleDevices(singleSubNet, energySurplus, x);
 
-                if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
-                    System.out.println("The following devices were turned on in this turn: ");
-                    System.out.println(flexDevicesTurnedOnThisTurn.toString());
-                }
+//                if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
+//                    System.out.println("The following devices were turned on in this turn: ");
+//                    System.out.println(flexDevicesTurnedOnThisTurn.toString());
+//                }
 
                 // recompute after having examined/turned on all flexible devices
                 production = calculateEnergyWithFlexDevices("prod", singleSubNet, timeStep);

+ 7 - 0
src/ui/view/AbstractCanvas.java

@@ -362,4 +362,11 @@ public abstract class AbstractCanvas extends JPanel {
 
 
     abstract void drawDeleteEdge();
+
+
+    void triggerUpdateController() {
+        updCon.paintProperties(tempCps);
+        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+        updCon.refreshTableProperties(model.getPropertyTable());
+    }
 }

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

@@ -852,9 +852,8 @@ public class GUI implements CategoryListener {
                         controller.addElementCanvasObject(tempCpsObject.getId(), ele.getEleName(), ele.getAmount(),
                                 ele.getEnergyPerElement(), ele.getId());
                     }
-                    updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-                    updCon.refreshTableProperties(model.getPropertyTable());
                     controller.calculateStateForTimeStep(model.getCurIteration());
+                    triggerUpdateController(null);
                     contentPane.updateUI();
                 }
             }
@@ -870,9 +869,8 @@ public class GUI implements CategoryListener {
                     HolonObject obj = (HolonObject) updCon.getActualCps();
                     for (HolonElement e : selectedElements) {
                         controller.deleteElementCanvas(obj.getId(), e.getId());
-                        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-                        updCon.refreshTableProperties(model.getPropertyTable());
                         controller.calculateStateForTimeStep(model.getCurIteration());
+                        triggerUpdateController(null);
                         contentPane.updateUI();
                         // Names displayed in graph are not updated
                     }
@@ -886,12 +884,11 @@ public class GUI implements CategoryListener {
                         controller.deleteElementCanvas(i, e.getId());
                     }
                 }
-                updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-                updCon.refreshTableProperties(model.getPropertyTable());
+                triggerUpdateController(null);
                 model.getEleToDelete().clear();
                 selectedElements.clear();
             }
-            updCon.refreshTableProperties(model.getPropertyTable());
+            triggerUpdateController(null);
             elementGraph.setText(Languages.getLanguage()[25]);
             holonEleNamesDisplayed = Languages.getLanguage()[25];
         });
@@ -1060,9 +1057,10 @@ public class GUI implements CategoryListener {
                                 Float ftemp = Float.parseFloat(newStuff);
                                 eleTemp.setFlexibleEnergyAvailable(ftemp);
 
+                                // if this is a flexible device and the flexibly available energy was changed,
+                                // set used energy to 0, so that it can be computed anew
                                 if (eleTemp.isFlexible()) {
                                     eleTemp.setEnergyPerElement(0);
-                                    // TODO: recalculate energy
                                 }
                             }
                             // Amount of Elements update
@@ -1076,11 +1074,12 @@ public class GUI implements CategoryListener {
                         updateElementTableAfterChange(eleTemp, selectedValueBY);
                     }
                 }
-                updCon.refreshTableProperties(model.getPropertyTable());
-                model.getSingleTable().fireTableDataChanged();
                 controller.calculateStateForTimeStep(model.getCurIteration());
+                model.getSingleTable().fireTableDataChanged();
+                triggerUpdateController(null);
                 contentPane.updateUI();
                 unitGraph.repaint();
+                triggerUpdateController(null);
             } catch (Exception e) {
             }
         });
@@ -1492,8 +1491,7 @@ public class GUI implements CategoryListener {
                     unitGraph.fillArrayofBooleans();
                 }
                 // Write new data in the PropertyTable
-                updCon.paintProperties(temp);
-                updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+                triggerUpdateController(temp);
 
                 // New Tab with NodeOfNode
                 if (doubleClick() && MouseEvent.BUTTON3 != e.getButton() && temp instanceof CpsUpperNode) {
@@ -2242,7 +2240,7 @@ public class GUI implements CategoryListener {
     /**
      * if flexibility was turned on, then active needs to be turned off, the energy currently produced/consumed
      *
-     * @param eleBTemp element that needs to be updated
+     * @param eleBTemp        element that needs to be updated
      * @param selectedValueBY the y value in the table
      */
     private void updateElementTableAfterChange(HolonElement eleBTemp, int selectedValueBY) {
@@ -2253,6 +2251,14 @@ public class GUI implements CategoryListener {
         model.getSingleTable().setValueAt(eleBTemp.getEnergyPerElement(), selectedValueBY, 2);
     }
 
+    private void triggerUpdateController(AbstractCpsObject temp) {
+        if (temp != null) {
+            updCon.paintProperties(temp);
+        }
+        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+        updCon.refreshTableProperties(model.getPropertyTable());
+    }
+
     /**
      * Custom Mouse adapter makes contentPane gain focus once mouse leaves this component
      * so copy/paste/cut and "select all" works

+ 4 - 5
src/ui/view/MyCanvas.java

@@ -109,6 +109,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                     }
                     controller.addUpperNode("NodeOfNode", null, animCps);
                     controller.calculateStateForCurrentTimeStep();
+                    triggerUpdateController();
                     repaint();
                 }
             });
@@ -163,6 +164,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                     }
 
                     controller.calculateStateForCurrentTimeStep();
+                    triggerUpdateController();
                     repaint();
                 }
             });
@@ -432,9 +434,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                     model.getPropertyTable().removeRow(i);
                 }
             }
-            updCon.paintProperties(tempCps);
-            updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-            updCon.refreshTableProperties(model.getPropertyTable());
+            triggerUpdateController();
         }
     }
 
@@ -539,8 +539,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
 
         controller.calculateStateForTimeStep(model.getCurIteration());
 
-        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-        updCon.refreshTableProperties(model.getPropertyTable());
+        triggerUpdateController();
 
         repaint();
 

+ 6 - 5
src/ui/view/UnitGraph.java

@@ -107,8 +107,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		g2.drawLine(border, this.getHeight() - border, this.getWidth() - border, this.getHeight() - border);
 
 		if (isElement) {
-			// array fillen
-			fillArrayofValue();
+            // fill array with values from the pointList in a HolonElement
+            fillArrayofValue();
 
 			if (arrayOfFloats != null) {
 				// Draw the Lines
@@ -265,7 +265,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
 		// algorithmus
 		controller.calculateStateForTimeStep(model.getCurIteration());
-	}
+        // TODO: trigger update of GUI->HolonElement-Table (like triggerUpdateController in GUI)
+    }
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
@@ -696,8 +697,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 */
 	@SuppressWarnings("unchecked")
 	public void fillArrayofValue() {
-		for (HolonElement he : tempElements) {
-			maximum = getMaximum(he);
+        for (HolonElement he : tempElements) {
+            maximum = getMaximum(he);
 			he.setGraphPoints((LinkedList<Point>) pointList.clone());
 			for (int i = 0; i < arrayOfFloats.length; i++) {
 				he.getAvailableEnergyPerElementAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (model.getIterations() - 1))));

+ 2 - 4
src/ui/view/UpperNodeCanvas.java

@@ -569,7 +569,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
 
     @Override
     public void mouseClicked(MouseEvent e) {
-        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+        triggerUpdateController();
     }
 
     @Override
@@ -731,9 +731,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
         }
 
         controller.calculateStateForTimeStep(model.getCurIteration());
-        updCon.paintProperties(tempCps);
-        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-        updCon.refreshTableProperties(model.getPropertyTable());
+        triggerUpdateController();
         repaint();
 
     }