Browse Source

Merge branch 'LWR_stepLimitFix' into BP_master

Ludwig Tietze 6 years ago
parent
commit
f4925e2109

+ 35 - 8
src/classes/HolonElement.java

@@ -2,7 +2,9 @@ package classes;
 
 import com.google.gson.annotations.Expose;
 
+import ui.controller.SingletonControl;
 import ui.model.Model;
+import ui.view.UnitGraph;
 
 import java.awt.*;
 import java.util.LinkedList;
@@ -13,7 +15,7 @@ import java.util.LinkedList;
  *
  * @author Gruppe14
  */
-public class HolonElement {
+public class HolonElement implements IGraphedElement{
 
     /* Points on the UnitGraph */
     private LinkedList<Point> graphPoints;
@@ -48,7 +50,7 @@ public class HolonElement {
     @Expose
     private int id;
     
-    private static final int DEFAULT_GRAPH_LENGTH=100;
+    //private static final int DEFAULT_GRAPH_LENGTH=100;
     //private int graphLength=DEFAULT_GRAPH_LENGTH; Unimplementable due to former developer's dark magic.
     
     /*
@@ -57,6 +59,11 @@ public class HolonElement {
      * If switched to flexible, this represents the maximum of usable energy
      */
     private float[] availableEnergyPerElementAt;
+    
+    @Expose
+    private int localPeriod;
+    @Expose
+    private boolean stretch;
 
     /**
      * Create a new HolonElement with a user-defined name, amount of the same
@@ -79,8 +86,7 @@ public class HolonElement {
      * same as standard constructor, but with already given id (so the counter is not increased twice)
      */
     public HolonElement(String eleName, int amount, float energy, int id, Model model){
-    	//if(model!=null)graphLength=model.getGraphIterations();
-    	//if(graphLength==0)graphLength=DEFAULT_GRAPH_LENGTH;//This would work if the used HolonElements were actually made using a proper constructor.
+    	setLocalPeriod(model.getGraphIterations());
     	setEleName(eleName);
         setAmount(amount);
         setEnergyPerElement(energy);
@@ -101,13 +107,14 @@ public class HolonElement {
     public HolonElement(HolonElement element) {
     	//graphLength=element.graphLength;//Should I add a getter?
         setEleName(element.getEleName());
+        setLocalPeriod(element.getLocalPeriod());
         setAmount(element.getAmount());
         setEnergyPerElement(element.getEnergyPerElement());
         setActive(element.isActive());
         setSign(element.getEnergyPerElement());
         setAvailableEnergyPerElementAt(element.getEnergyPerElement());
         for (int i = 0; i < availableEnergyPerElementAt.length; i++) {
-            availableEnergyPerElementAt[i] = element.getAvailableEnergyPerElementAt()[i];
+            availableEnergyPerElementAt[i] = element.getAvailableEnergyAt(i);
         }
         setGraphPoints(new LinkedList<>());
         for (Point p : element.getGraphPoints()) {
@@ -136,7 +143,7 @@ public class HolonElement {
      *
      * @return availableEnergyPerElementAt Array of Floats
      */
-    public float[] getAvailableEnergyPerElementAt() {
+    /*public float[] getAvailableEnergyPerElementAt() {
         return availableEnergyPerElementAt;
     }
 
@@ -156,7 +163,7 @@ public class HolonElement {
      * Get the energyPerElement currently available
      */
     public float getAvailableEnergyAt(int timestep) {
-        return this.availableEnergyPerElementAt[timestep%DEFAULT_GRAPH_LENGTH];//TODO:use an attribute here
+        return this.availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, timestep)];
     }
 
     /**
@@ -264,7 +271,7 @@ public class HolonElement {
         if (flexible) {
             return ((float) amount) * energyPerElement;
         } else {
-            return ((float) amount) * availableEnergyPerElementAt[x%DEFAULT_GRAPH_LENGTH];//TODO: use an attribute
+            return ((float) amount) * availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, x)];
         }
     }
 
@@ -397,4 +404,24 @@ public class HolonElement {
 
         return sb.toString();
     }
+
+	@Override
+	public void setLocalPeriod(int period) {
+		localPeriod=period;
+	}
+
+	@Override
+	public int getLocalPeriod() {
+		return localPeriod;
+	}
+
+	@Override
+	public boolean isStretching() {
+		return stretch;
+	}
+
+	@Override
+	public void setStretching(boolean stretch) {
+		this.stretch=stretch;
+	}
 }

+ 52 - 17
src/classes/HolonSwitch.java

@@ -5,13 +5,16 @@ import java.util.LinkedList;
 
 import com.google.gson.annotations.Expose;
 
+import ui.controller.SingletonControl;
+import ui.view.UnitGraph;
+
 /**
  * The class HolonSwitch represents a Switch, which can be turned on and off.
  * 
  * @author Gruppe14
  *
  */
-public class HolonSwitch extends AbstractCpsObject {
+public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 
 	/**
 	 * The class HolonSwitch represents an Object in the system, that has the
@@ -33,19 +36,25 @@ public class HolonSwitch extends AbstractCpsObject {
 	 * electricity), else false
 	 */
 	@Expose
-	boolean autoActive;
+	private boolean autoActive;
 
 	/*
 	 * true if switch has to be used manually
 	 */
 	@Expose
 	boolean manualMode;
+	
+	@Expose
+	int localPeriod;
+	
+	@Expose
+	boolean stretch;
 
 	/*
 	 * Energy at each point of the graph with 50 predefined points. At the
 	 * beginning, it starts with all values at energy
 	 */
-	boolean[] activeAt = new boolean[100];
+	boolean[] activeAt;
 	// Points on the UnitGraph
 	LinkedList<Point> graphPoints = new LinkedList<>();
 
@@ -58,6 +67,11 @@ public class HolonSwitch extends AbstractCpsObject {
 	 */
 	public HolonSwitch(String objName) {
 		super(objName);
+		activeAt=new boolean[UnitGraph.STANDARD_GRAPH_ACCURACY];
+		setLocalPeriod(SingletonControl.getInstance().getControl()==null?
+				UnitGraph.STANDARD_GRAPH_ACCURACY:
+				SingletonControl.getInstance().getControl().getModel().getGraphIterations()
+		);
 		setManualState(true);
 		setAutoState(true);
 		setActiveAt(true);
@@ -73,12 +87,14 @@ public class HolonSwitch extends AbstractCpsObject {
 	 */
 	public HolonSwitch(AbstractCpsObject obj) {
 		super(obj);
+		activeAt=new boolean[UnitGraph.STANDARD_GRAPH_ACCURACY];
 		super.setName(obj.getName());
 		setManualState(((HolonSwitch) obj).getActiveManual());
 		setAutoState(true);
+		setLocalPeriod(((IGraphedElement)obj).getLocalPeriod());
 		setActiveAt(true);
 		for (int i = 0; i < activeAt.length; i++) {
-			activeAt[i] = ((HolonSwitch) obj).getActiveAt()[i];
+			activeAt[i] = ((HolonSwitch) obj).getState(i);
 		}
 		setGraphPoints(new LinkedList<Point>());
 		for (Point p : ((HolonSwitch) obj).getGraphPoints()) {
@@ -114,7 +130,7 @@ public class HolonSwitch extends AbstractCpsObject {
 		if (manualMode) {
 			return this.manualActive;
 		} else {
-			return getActiveAt()[timeStep];
+			return activeAt[UnitGraph.getEffectiveIndex(this, timeStep)];
 		}
 	}
 
@@ -123,7 +139,7 @@ public class HolonSwitch extends AbstractCpsObject {
 	 * 
 	 * @return boolean the State
 	 */
-	public boolean getState() {
+	public boolean getState() {//TODO: not really necessary
 		if (manualMode) {
 			return this.manualActive;
 		} else {
@@ -149,7 +165,7 @@ public class HolonSwitch extends AbstractCpsObject {
 	 * @param state
 	 *            the State
 	 */
-	public void setAutoState(boolean state) {
+	public void setAutoState(boolean state) {//TODO: This should probably not be public
 		this.autoActive = state;
 		setImage();
 	}
@@ -191,14 +207,8 @@ public class HolonSwitch extends AbstractCpsObject {
 	public void setGraphPoints(LinkedList<Point> points) {
 		this.graphPoints = points;
 	}
-
-	/**
-	 * All values of the graph for the selected Switch (only auto-Mode) get the
-	 * activeAt Array.
-	 * 
-	 * @return boolean[] the States of each Iteration
-	 */
-	public boolean[] getActiveAt() {
+	
+	public boolean[] getValueArray() {//TODO: Only used in SubNet line 97. I am not entirely sure how important it is there.
 		return activeAt;
 	}
 
@@ -218,12 +228,17 @@ public class HolonSwitch extends AbstractCpsObject {
 	 *            the default value
 	 */
 	public void setActiveAt(boolean active) {
-		activeAt = new boolean[100];
+		activeAt = new boolean[100];//TODO This is necessary because of thisgson rubbish.
 		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).
 	 * 
@@ -242,4 +257,24 @@ public class HolonSwitch extends AbstractCpsObject {
 	public boolean getManualMode() {
 		return manualMode;
 	}
+
+	@Override
+	public void setLocalPeriod(int period) {
+		localPeriod=period;
+	}
+
+	@Override
+	public int getLocalPeriod() {
+		return localPeriod;
+	}
+
+	@Override
+	public boolean isStretching() {
+		return stretch;
+	}
+
+	@Override
+	public void setStretching(boolean stretch) {
+		this.stretch=stretch;
+	}
 }

+ 13 - 0
src/classes/IGraphedElement.java

@@ -0,0 +1,13 @@
+package classes;
+
+public interface IGraphedElement {
+	void setLocalPeriod(int period);
+	int getLocalPeriod();
+	
+	/**
+	 * @return Whether the given points should be stretched over the entire graph
+	 * as opposed to repeated once the period is over.
+	 */
+	boolean isStretching();
+	void setStretching(boolean stretch);
+}

+ 2 - 2
src/classes/SubNet.java

@@ -75,7 +75,7 @@ public class SubNet {
         sb.append("  Switches:");
         for (int j = 0; j < getSwitches().size(); j++) {
             HolonSwitch sw = getSwitches().get(j);
-            sb.append("    " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt()[timeStep]);
+            sb.append("    " + sw.getName() + " " + sw.getId() + " State:" + sw.getState(timeStep));
         }
 
         return sb.toString();
@@ -94,7 +94,7 @@ public class SubNet {
         }
         sb.append("\nSwitches:");
         for (HolonSwitch sw : getSwitches()) {
-            sb.append("    " + sw.getName() + "[ID:" + sw.getId()+ "]" + " State:" + sw.getActiveAt());
+            sb.append("    " + sw.getName() + "[ID:" + sw.getId()+ "]" + " State:" + sw.getValueArray());//TODO: I don't like this
         }
         sb.append("\nBatteries:");
         for (HolonBattery hB: getBatteries()) {

+ 3 - 3
src/tests/PraktikumHolonsTestClasses.java

@@ -185,10 +185,10 @@ public class PraktikumHolonsTestClasses {
 		HolonElement ele2 = new HolonElement("Fridge", 1, -50);
 		HolonElement ele3 = new HolonElement(ele2);
 
-        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[0] == -20);
-        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[2] == -20);
+        assertTrue("Array not empty", ele1.getAvailableEnergyAt(0) == -20);
+        assertTrue("Array not empty", ele1.getAvailableEnergyAt(2) == -20);
         ele1.setAvailableEnergyPerElementAt(2, -10);
-        assertTrue("Array not empty", ele1.getAvailableEnergyPerElementAt()[2] == -10);
+        assertTrue("Array not empty", ele1.getAvailableEnergyAt(2) == -10);
         assertTrue("Name not correct", ele1.getEleName().equals("TV"));
         ele1.setEleName(ele2.getEleName());
 		assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));

+ 6 - 6
src/ui/controller/HolonCanvasController.java

@@ -100,8 +100,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyPerElementAt()[tStep] > 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    if (ele.getAvailableEnergyAt(tStep) > 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
                     }
                 }
 				if (val > 0)
@@ -131,8 +131,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyPerElementAt()[tStep] < 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    if (ele.getAvailableEnergyAt(tStep) < 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
                     }
                 }
 			} else if (obj instanceof CpsUpperNode) {
@@ -148,8 +148,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyPerElementAt()[tStep] > 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyPerElementAt()[tStep] * ele.getAmount();
+                    if (ele.getAvailableEnergyAt(tStep) > 0 && ele.isActive()) {
+                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
                     }
                 }
 			} else if (obj instanceof CpsUpperNode) {

+ 1 - 1
src/ui/controller/UpdateController.java

@@ -319,7 +319,7 @@ public class UpdateController {
 					model.getPropertyTable().setCellEditable(3, 1, true);
 				} else {
 					Object[] tempActive = { Languages.getLanguage()[75],
-							((HolonSwitch) obj).getActiveAt()[model.getCurIteration()] };
+							((HolonSwitch) obj).getState(model.getCurIteration()) };
 					model.getPropertyTable().addRow(tempActive);
 					model.getPropertyTable().setCellEditable(3, 1, false);
 				}

+ 2 - 2
src/ui/view/AbstractCanvas.java

@@ -285,8 +285,8 @@ public abstract class AbstractCanvas extends JPanel {
 				|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
 			img = Util.loadImage(this, "/Images/node_selected.png");
 		} else {
-			if (cps instanceof HolonSwitch) {
-				if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
+			if (cps instanceof HolonSwitch) {//TODO. What the hell are thes ecalls doing here?
+				if (((HolonSwitch) cps).getState(model.getCurIteration())) {
 					((HolonSwitch) cps).setAutoState(true);
 				} else {
 					((HolonSwitch) cps).setAutoState(false);

+ 14 - 5
src/ui/view/GUI.java

@@ -1193,7 +1193,7 @@ public class GUI implements CategoryListener {
 							} else {
 								holonEleNamesDisplayed = ele.getEleName() + " ";
 							}
-							unitGraph.repaintWithNewElement(selectedElements);
+							repaintGraphAux(selectedElements);
 						}
 						updCon.getActualHolonElement(null, yValueElements, 2,
 								tables);
@@ -1205,7 +1205,7 @@ public class GUI implements CategoryListener {
 						updCon.getActualHolonElement(null, yValueElements, 1,
 								tables);
 						holonEleNamesDisplayed = ele.getEleName() + " ";
-						unitGraph.repaintWithNewElement(selectedElements);
+						repaintGraphAux(selectedElements);
 					}
 				} else {
 					elementGraph.setText(Languages.getLanguage()[25]);
@@ -1968,7 +1968,7 @@ public class GUI implements CategoryListener {
 				}
 				if (temp instanceof HolonSwitch) {
 					showScrollGraph();
-					unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
+					repaintGraphAux((HolonSwitch)temp);
 					unitGraph.fillArrayofBooleans();
 				}
 				// Write new data in the PropertyTable
@@ -2232,7 +2232,7 @@ public class GUI implements CategoryListener {
 						((Container)timePanel.getComponent(1))//timePanel
 						.getComponent(1)//timeSlider
 				)
-		)//TODO: This hardcoded shit
+		)//TODO: This hardcoded stuff
 				.addChangeListener(changeEvent -> {
 					int i = model.getCurIteration();
 					controller.calculateStateForTimeStep(i);
@@ -2657,7 +2657,7 @@ public class GUI implements CategoryListener {
 						openNewUpperNodeTab();
 					}
 					if (temp instanceof HolonSwitch) {
-						unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
+						repaintGraphAux((HolonSwitch)temp);
 						unitGraph.fillArrayofBooleans();
 					}
 				}
@@ -2872,4 +2872,13 @@ public class GUI implements CategoryListener {
 			contentPane.requestFocus();
 		}
 	}
+	private void repaintGraphAux(ArrayList<HolonElement> o){//TODO: 
+		unitGraph.repaintWithNewElement((ArrayList<HolonElement>)o);
+		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
+	}
+	
+	private void repaintGraphAux(HolonSwitch o){//TODO: 
+		unitGraph.repaintWithNewSwitch(o);
+		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
+	}
 }

+ 3 - 3
src/ui/view/StatisticGraph.java

@@ -165,7 +165,7 @@ public class StatisticGraph extends JPanel {
         float temp = 0;
         for (HolonElement e : obj.getElements()) {
             if (e.isActive()) {
-                temp = temp + e.getAvailableEnergyPerElementAt()[model.getCurIteration()];
+                temp = temp + e.getAvailableEnergyAt(model.getCurIteration());
             }
         }
         return temp;
@@ -354,7 +354,7 @@ public class StatisticGraph extends JPanel {
                             set.setValAt(0, model.getCurIteration());
                         }
                     } else {
-                        if (((HolonSwitch) set.getCpsObject()).getActiveAt()[model.getCurIteration()]) {
+                        if (((HolonSwitch) set.getCpsObject()).getState(model.getCurIteration())) {
                             set.setValAt(1, model.getCurIteration());
                         } else {
                             set.setValAt(0, model.getCurIteration());
@@ -693,7 +693,7 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.isActive() && ele.getAvailableEnergyPerElementAt()[tStep] < 0 ) {
+                    if (ele.isActive() && ele.getAvailableEnergyAt(tStep) < 0 ) {
                         val += ele.getOverallEnergyAtTimeStep(tStep);
                     }
                 }

+ 64 - 37
src/ui/view/UnitGraph.java

@@ -2,6 +2,7 @@ package ui.view;
 
 import classes.*;
 import ui.controller.Control;
+import ui.controller.SingletonControl;
 import ui.model.Model;
 
 import javax.swing.*;
@@ -23,6 +24,7 @@ import java.util.LinkedList;
 public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
 
     private static final long serialVersionUID = 1L;
+	public static final int STANDARD_GRAPH_ACCURACY = 100;
     private GeneralPath graphCurve = new GeneralPath();
     private float maximum = 0;
     // Information shown when a Point is Dragged
@@ -37,8 +39,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     // Scale for the Graph
     private double scaleX;
     private double scaleY;
-    private float[] arrayOfFloats = null;
-    private boolean[] arrayOfBooleans = null;
+    //private float[] arrayOfFloats = null;
+    //private boolean[] arrayOfBooleans = null;
     private double width = -1;
     private double height = -1;
     private boolean isElement = false;
@@ -52,11 +54,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     private Point tempP = null;
     private double x = 0, y = 0;
     private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
-
     private int border = 4;
     private int textWidth = 0;
     
-    private int localPeriod = 100;
+	private IGraphedElement current;
 
     /**
      * Constructor.
@@ -83,6 +84,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param g Graphics
      */
     public void paintComponent(Graphics g) {
+    	
         super.paintComponent(g);
         g2 = (Graphics2D) g;
         RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -104,11 +106,15 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         }
         g2.drawLine(border, this.getHeight() - border, this.getWidth() - border, this.getHeight() - border);
 
+        int effectiveX;
+        if(current!=null)effectiveX=getEffectiveIndex(model, current, model.getCurIteration());
+        else effectiveX=0;
+        
         if (isElement) {
             // fill array with values from the pointList in a HolonElement
             fillArrayofValue();
 
-            if (arrayOfFloats != null) {
+            if (current != null) {
                 // Draw the Lines
                 g2.setStroke(new BasicStroke(2));
                 g2.setColor(Color.BLACK);
@@ -131,17 +137,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
                 // Iteration Value
                 //TODO: added function getGraphIterations see if it works
-                textWidth = g.getFontMetrics().stringWidth("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()]) + 2;
+                textWidth = g.getFontMetrics().stringWidth("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration())/*arrayOfFloats[effectiveX]*/) + 2;
                 if (textWidth
-                        + (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1) + 2
+                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
                         + border <= this.getWidth()) {
-                    g2.drawString("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()],
-                            (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
+                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
+                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + 2 + border,
                             this.getHeight() - 10);
                 } else {
-                    g2.drawString("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()],
-                            (model.getCurIteration()%model.getGraphIterations()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
+                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
+                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + border - textWidth,
                             this.getHeight() - 10);
                 }
@@ -171,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();
 
@@ -215,17 +221,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
                 // Iteration Value
                 g2.setColor(Color.BLUE);
-                textWidth = g.getFontMetrics().stringWidth("" + arrayOfBooleans[model.getCurIteration()]) + 2;
+                textWidth = g.getFontMetrics().stringWidth("" + ((HolonSwitch)current).getState(model.getCurIteration())/*arrayOfBooleans[effectiveX]*/) + 2;
                 if (textWidth
-                        + (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1) + 2
+                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
                         + border <= this.getWidth()) {
-                    g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
-                            (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
+                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
+                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + 2 + border,
                             this.getHeight() - 10);
                 } else {
-                    g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
-                            (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
+                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
+                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                                     + border - textWidth,
                             this.getHeight() - 10);
                 }
@@ -237,7 +243,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
             {
                 try {
                     int i;
-                    for (i = 0; (i * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
+                    for (i = 0; (i * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
                             + border < getMousePosition().getX()); i++) {
                     }
                     dragInformation = "" + i;
@@ -255,11 +261,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
             }
         }
 
-        // Iteration Line
+        // Iteration Line TODO: repeat
         g2.setColor(Color.BLUE);
         g2.setStroke(new BasicStroke(1));
-        g2.drawLine(border + (model.getCurIteration()) * (this.getWidth() - border * 2) / (model.getIterations() - 1),
-                0, border + (model.getCurIteration()) * (this.getWidth() - border * 2) / (model.getIterations() - 1),
+        g2.drawLine(border + (effectiveX) * (this.getWidth() - border * 2) / /*(model.getIterations() - 1)*/100-1,
+                0, border + (effectiveX) * (this.getWidth() - border * 2) / /*(model.getIterations() - 1)*/100-1,
                 this.getHeight());
 
         // algorithmus
@@ -553,8 +559,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     public void empty() {
         pointList = null;
         tempElements = null;
-        arrayOfFloats = null;
-        arrayOfBooleans = null;
+        current = null;
         isSwitch = false;
         isElement = false;
         repaint();
@@ -601,8 +606,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param selectedElement which should be visualized
      */
     public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
-        arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getAvailableEnergyPerElementAt();
-        tempElements = selectedElement;
+        //arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getAvailableEnergyPerElementAt();
+        current = selectedElement.get(selectedElement.size()-1);
+        tempElements=selectedElement;
         pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
         isSwitch = false;
         isElement = true;
@@ -621,7 +627,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param s which should be visualized
      */
     public void repaintWithNewSwitch(HolonSwitch s) {
-        arrayOfBooleans = s.getActiveAt();
+    	current=s;
+        //arrayOfBooleans = s.getValueArray();
         pointList = s.getGraphPoints();
         isSwitch = true;
         isElement = false;
@@ -667,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);
             }
-
         }
     }
 
@@ -686,10 +692,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         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))));
+            for (int i = 0; i < STANDARD_GRAPH_ACCURACY; i++) {//!!!!!
+            	he.setAvailableEnergyPerElementAt(i, convertToValueY(getYValueAt2((int) (i * width / (100 - 1)))));
+                //he.getAvailableEnergyPerElementAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (100 - 1))));
             }
-            arrayOfFloats = he.getAvailableEnergyPerElementAt();
+            //arrayOfFloats = he.getAvailableEnergyPerElementAt();
         }
     }
 
@@ -843,7 +850,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     public void setLocalPeriod(int localPeriod){
     	//TODO: local Graph length for each HolonElelemt
-    	this.localPeriod = localPeriod;
+    	this.current.setLocalPeriod(localPeriod);
+    	
     }
     
     /**
@@ -851,6 +859,25 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return localPeriod of the current Element or Switch
      */
     public int getLocalPeriod(){
-    	return localPeriod;
+    	if(current!=null)return current.getLocalPeriod();
+    	else return model.getGraphIterations();//TODO: maybe rename
+    }
+    
+    
+    static int lv=0;
+    
+    public static int getEffectiveIndex(Model m, IGraphedElement e, int timeStep){
+    	int o;
+    	if(e.isStretching())o= timeStep*100/m.getIterations();
+    	else o= timeStep%e.getLocalPeriod()*100/e.getLocalPeriod();
+    	return o;//TODO
+    }
+    
+    public static int getEffectiveIndex(IGraphedElement e, int timeStep){
+    	return getEffectiveIndex(SingletonControl.getInstance().getControl().getModel(),e,timeStep);
+    }
+    
+    public static int getEffectiveIndex(IGraphedElement e){
+    	return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration());
     }
 }

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

@@ -478,7 +478,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
             	img = Util.loadImage(this,"/Images/node_selected.png");
             } else {
                 if (cps instanceof HolonSwitch) {
-                    if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
+                    if (((HolonSwitch) cps).getState(model.getCurIteration())) {
                         ((HolonSwitch) cps).setAutoState(true);
                     } else {
                         ((HolonSwitch) cps).setAutoState(false);