Parcourir la source

All good except switches and a bug with the text field.

the bug causes any HolonElement or HolonSwitch to adopt the previous
one's period.
Ludwig Tietze il y a 7 ans
Parent
commit
73f8821d1a
2 fichiers modifiés avec 22 ajouts et 18 suppressions
  1. 12 6
      src/classes/HolonSwitch.java
  2. 10 12
      src/ui/view/UnitGraph.java

+ 12 - 6
src/classes/HolonSwitch.java

@@ -67,11 +67,11 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 	 */
 	public HolonSwitch(String objName) {
 		super(objName);
+		activeAt=new boolean[UnitGraph.STANDARD_GRAPH_ACCURACY];
 		setLocalPeriod(SingletonControl.getInstance().getControl()==null?
-				100:
+				UnitGraph.STANDARD_GRAPH_ACCURACY:
 				SingletonControl.getInstance().getControl().getModel().getGraphIterations()
 		);
-		activeAt=new boolean[100];
 		setManualState(true);
 		setAutoState(true);
 		setActiveAt(true);
@@ -87,6 +87,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 	 */
 	public HolonSwitch(AbstractCpsObject obj) {
 		super(obj);
+		activeAt=new boolean[UnitGraph.STANDARD_GRAPH_ACCURACY];
 		super.setName(obj.getName());
 		setManualState(((HolonSwitch) obj).getActiveManual());
 		setAutoState(true);
@@ -129,7 +130,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 		if (manualMode) {
 			return this.manualActive;
 		} else {
-			return getActiveAt(UnitGraph.getEffectiveIndex(this));
+			return getActiveAt(timeStep);
 		}
 	}
 
@@ -217,7 +218,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 		return activeAt[UnitGraph.getEffectiveIndex(this, i)];
 	}
 	
-	public boolean[] getValueArray() {
+	public boolean[] getValueArray() {//TODO: Only used in SubNet line 97. I am not entirely sure how important it is there.
 		return activeAt;
 	}
 
@@ -237,12 +238,17 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 	 *            the default value
 	 */
 	public void setActiveAt(boolean active) {
-		activeAt = new boolean[100];
+		//activeAt = new boolean[100];
 		for (int i = 0; i < activeAt.length; i++) {
 			this.activeAt[i] = active;
 		}
 	}
-
+	
+	public void setActiveAt(int pos, boolean active) {
+		//activeAt = new boolean[100];
+		this.activeAt[pos] = active;
+	}
+	
 	/**
 	 * Set the overall value of the Switch (manual mode).
 	 * 

+ 10 - 12
src/ui/view/UnitGraph.java

@@ -40,7 +40,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     private double scaleX;
     private double scaleY;
     //private float[] arrayOfFloats = null;
-    private boolean[] arrayOfBooleans = null;
+    //private boolean[] arrayOfBooleans = null;
     private double width = -1;
     private double height = -1;
     private boolean isElement = false;
@@ -177,7 +177,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			 */
 
         } else if (isSwitch) {
-            if (arrayOfBooleans != null) {
+            if (/*arrayOfBooleans*/current != null) {//Technically this test should be unnecessary
                 // array fillen
                 fillArrayofBooleans();
 
@@ -221,16 +221,16 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
                 // Iteration Value
                 g2.setColor(Color.BLUE);
-                textWidth = g.getFontMetrics().stringWidth("" + arrayOfBooleans[effectiveX]) + 2;
+                textWidth = g.getFontMetrics().stringWidth("" + ((HolonSwitch)current).getActiveAt(model.getCurIteration())/*arrayOfBooleans[effectiveX]*/) + 2;
                 if (textWidth
                         + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
                         + border <= this.getWidth()) {
-                    g2.drawString("" + arrayOfBooleans[effectiveX],
+                    g2.drawString("" + ((HolonSwitch)current).getActiveAt(model.getCurIteration()),
                             (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + 2 + border,
                             this.getHeight() - 10);
                 } else {
-                    g2.drawString("" + arrayOfBooleans[effectiveX],
+                    g2.drawString("" + ((HolonSwitch)current).getActiveAt(model.getCurIteration()),
                             (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + border - textWidth,
                             this.getHeight() - 10);
@@ -560,7 +560,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         pointList = null;
         tempElements = null;
         current = null;
-        arrayOfBooleans = null;
         isSwitch = false;
         isElement = false;
         repaint();
@@ -629,7 +628,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     public void repaintWithNewSwitch(HolonSwitch s) {
     	current=s;
-        arrayOfBooleans = s.getValueArray();
+        //arrayOfBooleans = s.getValueArray();
         pointList = s.getGraphPoints();
         isSwitch = true;
         isElement = false;
@@ -675,14 +674,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * Fills the Arrays with booleans.
      */
     public void fillArrayofBooleans() {
-        for (int i = 0; i < arrayOfBooleans.length; i++) {
-            int t = (int) getYValueAt((int) (i * width / (model.getIterations() - 1)));
+        for (int i = 0; i < STANDARD_GRAPH_ACCURACY; i++) {
+            int t = (int) getYValueAt((int) (i * width / (STANDARD_GRAPH_ACCURACY - 1)));
             if (t <= height / 2) {
-                arrayOfBooleans[i] = true;
+            	((HolonSwitch)current).setActiveAt(i, true);
             } else {
-                arrayOfBooleans[i] = false;
+            	((HolonSwitch)current).setActiveAt(i, false);
             }
-
         }
     }