Просмотр исходного кода

more code cleaning in SimulationManager and HolonObject

I. Dix 7 лет назад
Родитель
Сommit
945f18a702

+ 7 - 7
src/classes/HolonObject.java

@@ -75,11 +75,11 @@ public class HolonObject extends AbstractCpsObject {
      */
     public void setState() {
         if (getCurrentEnergy() > 0) {
-            setState(3);
+            setState(PRODUCER);
             stateColor = Color.lightGray;
         } else {
             if (getCurrentEnergy() == 0) {
-                setState(0);
+                setState(NO_ENERGY);
                 stateColor = Color.WHITE;
             } else {
                 if (checkIfPartiallySupplied(0)) {
@@ -211,23 +211,23 @@ public class HolonObject extends AbstractCpsObject {
     public void setState(int state) {
         this.state = state;
         switch (state) {
-            case 0:
+            case NO_ENERGY:
                 stateColor = Color.WHITE;
                 break;
 
-            case 1:
+            case NOT_SUPPLIED:
                 stateColor = new Color(230, 120, 100);
                 break;
 
-            case 2:
+            case SUPPLIED:
                 stateColor = Color.GREEN;
                 break;
 
-            case 3:
+            case PRODUCER:
                 stateColor = Color.lightGray;
                 break;
 
-            case 4:
+            case PARTIALLY_SUPPLIED:
                 stateColor = Color.YELLOW;
         }
     }

+ 14 - 12
src/ui/controller/SimulationManager.java

@@ -51,6 +51,8 @@ public class SimulationManager {
         for (SubNet singleSubNet : subNets) {
             float production = calculateEnergy("prod", singleSubNet, timeStep);
             float consumption = calculateEnergy("cons", singleSubNet, timeStep);
+            float wastedEnergy = production - consumption;
+
             float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
             setFlowSimulation(singleSubNet);
             for (HolonObject hl : singleSubNet.getObjects()) {
@@ -62,29 +64,29 @@ public class SimulationManager {
                             // 0 = no energy, 1 = not supplied, 2 = supplied, 3
                             // = producer, 4 = partially supplied
                             if ((production + consumption) >= 0) {
-                                hl.setState(2);
+                                hl.setState(HolonObject.SUPPLIED);
                             }
                             if ((production + consumption) < 0) {
                                 if ((production + minConsumption) >= 0) {
-                                    hl.setState(4);
+                                    hl.setState(HolonObject.PARTIALLY_SUPPLIED);
                                 } else if (hl.checkIfPartiallySupplied(timeStep)) {
-                                    hl.setState(4);
+                                    hl.setState(HolonObject.PARTIALLY_SUPPLIED);
                                 } else {
-                                    hl.setState(1);
+                                    hl.setState(HolonObject.NOT_SUPPLIED);
                                 }
                             }
                             break;
                         }
-                        hl.setState(1);
+                        hl.setState(HolonObject.NOT_SUPPLIED);
                     }
                     if (hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)) {
-                        hl.setState(4);
+                        hl.setState(HolonObject.PARTIALLY_SUPPLIED);
                     }
                 }
             }
         }
         canvas.repaint();
-        //printNet();
+//        printNetToConsole();
         flexPane.recalculate();
     }
 
@@ -308,17 +310,17 @@ public class SimulationManager {
             if (type.equals("prod")) {
                 if (hl.getCurrentEnergyAtTimeStep(x) > 0) {
                     energy = energy + hl.getCurrentEnergyAtTimeStep(x);
-                    hl.setState(3);
+                    hl.setState(HolonObject.PRODUCER);
                 }
             }
             if (type.equals("cons")) {
                 if (hl.getCurrentEnergyAtTimeStep(x) < 0) {
                     energy = energy + hl.getCurrentEnergyAtTimeStep(x);
-                    hl.setState(1);
+                    hl.setState(HolonObject.NOT_SUPPLIED);
                 }
             }
             if (hl.getCurrentEnergyAtTimeStep(x) == 0) {
-                hl.setState(0);
+                hl.setState(HolonObject.NO_ENERGY);
             }
         }
         return energy;
@@ -483,7 +485,7 @@ public class SimulationManager {
     /**
      * Prints the Components auf all subnets.
      */
-    public void printNet() {
+    public void printNetToConsole() {
         for (int i = 0; i < subNets.size(); i++) {
             System.out.println("SUBNET NR:" + i);
             System.out.println("  Objects:");
@@ -555,7 +557,7 @@ public class SimulationManager {
     }
 
     /**
-     * checks wether a given object is connected to an object inside the upperNode.
+     * checks whether a given object is connected to an object inside the upperNode.
      * if yes, the state for the edge is changed in "connected" or "not connected"
      *
      * @param cps

+ 1 - 1
src/ui/view/GUI.java

@@ -271,7 +271,7 @@ public class GUI<E> implements CategoryListener {
     private void initialize() {
         frmCyberPhysical = new JFrame();
         frmCyberPhysical.setTitle("Cyber Physical Systems Model");
-        frmCyberPhysical.setBounds(100, 100, 1000, 800);
+        frmCyberPhysical.setBounds(100, -1080, 1000, 800);
         frmCyberPhysical.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frmCyberPhysical.setExtendedState(JFrame.MAXIMIZED_BOTH);
         frmCyberPhysical.addWindowListener(new java.awt.event.WindowAdapter() {

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

@@ -248,8 +248,8 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                     }
                     // Look if the uppernode is open in a Tab
                     for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-                        if (tabbedPane.getComponentAt(i) == null) {
-                        } else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+                        if (tabbedPane.getComponentAt(i) != null
+                                && ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
                                 .getComponent(0)).upperNode.getId() == cps.getId()) {
                             ((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
                             break;
@@ -518,7 +518,6 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
             try {
                 controller.autoSave();
             } catch (IOException ex) {
-                // TODO Auto-generated catch block
                 ex.printStackTrace();
             }
         }
@@ -609,7 +608,6 @@ public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMoti
                 }
                 repaint();
             } catch (Exception eex) {
-
             }
         }