Tom Troppmann 6 роки тому
батько
коміт
2811c20a92

+ 20 - 19
src/classes/HolonElement.java

@@ -3,9 +3,11 @@ package classes;
 import com.google.gson.annotations.Expose;
 
 import ui.model.Model;
+import ui.view.IndexTranslator;
 import ui.view.UnitGraph;
 
 import java.awt.*;
+import java.awt.geom.Point2D;
 import java.util.Iterator;
 import java.util.LinkedList;
 
@@ -26,7 +28,7 @@ public class HolonElement implements IGraphedElement{
      * the Y component from a Point is the percentage
      * currently saved in int -> TODO serelized float point class
      * */
-    private LinkedList<Point> testGraphPoints;
+    private LinkedList<Point2D.Double> testGraphPoints;
     /** Name of the object, e.g. House, 1 */
     @Expose
     private String objName;
@@ -65,7 +67,7 @@ public class HolonElement implements IGraphedElement{
      * beginning, it starts with all values at energyPerElement.
      * If switched to flexible, this represents the maximum of usable energy
      */
-    private float[] availableEnergyPerElementAt;
+    private float[] curveSample;
     
     @Expose
     private int localPeriod;
@@ -120,8 +122,8 @@ public class HolonElement implements IGraphedElement{
         setEnergyPerElement(element.getEnergyPerElement());
         setActive(element.isActive());
         setAvailableEnergyPerElementAt(element.getEnergyPerElement());
-        for (int i = 0; i < availableEnergyPerElementAt.length; i++) {
-            availableEnergyPerElementAt[i] = element.getAvailableEnergyAt(i);
+        for (int i = 0; i < curveSample.length; i++) {
+            curveSample[i] = element.getAvailableEnergyAt(i);
         }
         setGraphPoints(new LinkedList<>());
         setTestGraphPoints(new LinkedList<>());
@@ -129,8 +131,8 @@ public class HolonElement implements IGraphedElement{
             this.graphPoints.add(new Point((int) p.getX(), (int) p.getY()));
         }
         System.out.println("hei");
-        for (Point p : element.getTestGraphPoints()) {
-            this.testGraphPoints.add(new Point((int) p.getX(), (int) p.getY()));
+        for (Point2D.Double p : element.getTestGraphPoints()) {
+            this.testGraphPoints.add(new Point2D.Double(p.getX(), p.getY()));
         }
         setSaving(null);
         setId(IdCounterElem.nextId());
@@ -153,9 +155,9 @@ public class HolonElement implements IGraphedElement{
      * @param energy the value
      */
     public void setAvailableEnergyPerElementAt(float energy) {
-        this.availableEnergyPerElementAt = new float[100];
-        for (int i = 0; i < availableEnergyPerElementAt.length; i++) {
-            this.availableEnergyPerElementAt[i] = energy;
+        this.curveSample = new float[100];
+        for (int i = 0; i < curveSample.length; i++) {
+            this.curveSample[i] = energy;
         }
     }
 
@@ -163,7 +165,7 @@ public class HolonElement implements IGraphedElement{
      * Get the energyPerElement currently(at given time step) available
      */
     public float getAvailableEnergyAt(int timestep) {
-        return this.availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, timestep)];
+        return this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
     }
 
     
@@ -174,10 +176,9 @@ public class HolonElement implements IGraphedElement{
      */
     public float testFunctiongetAvailableEnergyAt(int timestep) {
 		if(getTestGraphPoints()==null)return 0;
-    	this.getTestGraphPoints().iterator();
-		for(Iterator<Point> iterator = getTestGraphPoints().iterator(); iterator.hasNext();)
+		for(Point2D.Double p : getTestGraphPoints())
 		{
-			System.out.println(iterator.next());
+			System.out.println(p);
 		}
     	return 0;
     }
@@ -188,7 +189,7 @@ public class HolonElement implements IGraphedElement{
      * @param energyPerElement float
      */
     public void setAvailableEnergyPerElementAt(int pos, float energyPerElement) {
-        this.availableEnergyPerElementAt[pos] = energyPerElement;
+        this.curveSample[pos] = energyPerElement;
     }
 
     /**
@@ -303,7 +304,7 @@ public class HolonElement implements IGraphedElement{
         if (flexible) {
             return ((float) amount) * energyPerElement;
         } else {
-            return ((float) amount) * availableEnergyPerElementAt[UnitGraph.getEffectiveIndex(this, timestep)];
+            return ((float) amount) * curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
         }
     }
 
@@ -441,15 +442,15 @@ public class HolonElement implements IGraphedElement{
 	public void initTestGraphPoints(int percentage)
 	{
 		testGraphPoints.clear();
-		testGraphPoints.add(new Point(0,percentage));
-		testGraphPoints.add(new Point(100,percentage));
+		testGraphPoints.add(new Point2D.Double(0,percentage));
+		testGraphPoints.add(new Point2D.Double(100,percentage));
 	}
-	public LinkedList<Point> getTestGraphPoints() {
+	public LinkedList<Point2D.Double> getTestGraphPoints() {
 		return testGraphPoints;
 	}
 
 
-	public void setTestGraphPoints(LinkedList<Point> testGraphPoints) {
+	public void setTestGraphPoints(LinkedList<Point2D.Double> testGraphPoints) {
 		this.testGraphPoints = testGraphPoints;
 	}
 }

+ 2 - 1
src/classes/HolonSwitch.java

@@ -6,6 +6,7 @@ import java.util.LinkedList;
 import com.google.gson.annotations.Expose;
 
 import ui.controller.SingletonControl;
+import ui.view.IndexTranslator;
 import ui.view.UnitGraph;
 
 /**
@@ -133,7 +134,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 		if (manualMode) {
 			return this.manualActive;
 		} else {
-			return activeAt[UnitGraph.getEffectiveIndex(this, timeStep)];
+			return activeAt[IndexTranslator.getEffectiveIndex(this, timeStep)];
 		}
 	}
 

+ 16 - 1
src/ui/controller/ClipboardController.java

@@ -10,6 +10,7 @@ import ui.model.Model;
 
 import java.awt.*;
 import java.awt.datatransfer.*;
+import java.awt.geom.Point2D;
 import java.io.IOException;
 import java.util.*;
 import java.util.List;
@@ -284,9 +285,23 @@ public class ClipboardController {
                 ele.setGraphPoints(graphpoint);
                 break;
             case TESTELEMENT:
+            	LinkedList<Point2D.Double> graphpointTEST = new LinkedList<>();
+                for (String k : keys) {
+                    if (!k.equals("ID")) {
+                        p = object.get(k).getAsString();
+                        mid = p.indexOf(':');
+                        double x1 = Double.parseDouble(p.substring(0, mid));
+                        double y1 = Integer.parseInt(p.substring(mid + 1, p.length()));
+                        graphpointTEST.add(new Point2D.Double(x1, y1));
+                    } else
+                        // else its an ID
+                        sav = object.get(k).getAsInt();
+
+                }  
+                
                 sav = eleIDMap.get(sav);
                 HolonElement ele1 = eleDispatch.get(sav);
-                ele1.setTestGraphPoints(graphpoint);
+                ele1.setTestGraphPoints(graphpointTEST);
                 break;
             default:
                 break;

+ 15 - 1
src/ui/controller/LoadController.java

@@ -15,6 +15,7 @@ import org.apache.commons.compress.utils.IOUtils;
 import ui.model.Model;
 
 import java.awt.*;
+import java.awt.geom.Point2D;
 import java.io.*;
 import java.nio.file.Files;
 import java.nio.file.StandardCopyOption;
@@ -402,8 +403,21 @@ public class LoadController {
                 ele.setGraphPoints(graphpoint);//TODO?
                 break;
             case TESTELEMENT:
+            	LinkedList<Point2D.Double> graphpointTEST = new LinkedList<>();
+                for (String k : keys) {
+                    if (!k.equals("ID")) {
+                        p = object.get(k).getAsString();
+                        mid = p.indexOf(':');
+                        double x1 = Double.parseDouble(p.substring(0, mid));
+                        double y1 = Integer.parseInt(p.substring(mid + 1, p.length()));
+                        graphpointTEST.add(new Point2D.Double(x1, y1));
+                    } else
+                        // else its an ID
+                        sav = object.get(k).getAsInt();
+
+                }  
                 HolonElement ele1 = eleDispatch.get(sav);
-                ele1.setTestGraphPoints(graphpoint);
+                ele1.setTestGraphPoints(graphpointTEST);
                 break;
             default:
                 break;

+ 18 - 1
src/ui/controller/SaveController.java

@@ -11,6 +11,7 @@ import org.apache.commons.compress.utils.IOUtils;
 import ui.model.Model;
 
 import java.awt.*;
+import java.awt.geom.Point2D;
 import java.io.*;
 import java.util.*;
 import java.util.List;
@@ -269,7 +270,7 @@ public class SaveController {
             if (!ele.getGraphPoints().isEmpty())
                 unitgraphToJson(GRAPHTYPE.ELEMENT, file, ele.getId(), ele.getGraphPoints());
             if (!ele.getTestGraphPoints().isEmpty())
-                unitgraphToJson(GRAPHTYPE.TESTELEMENT, file, ele.getId(), ele.getTestGraphPoints());
+            	unitgraphTESTToJson(file, ele.getId(), ele.getTestGraphPoints());
             temp = new JsonObject();
         }
 
@@ -305,6 +306,22 @@ public class SaveController {
 
         file.add(key, model.getGson().toJsonTree(temp));
     }
+    /**
+     * Put the UnitGraphs of Switches or Elements into Json
+     */
+    void unitgraphTESTToJson(JsonObject file, int id, LinkedList<Point2D.Double> graph) {
+
+        JsonObject temp = new JsonObject();
+        String key = null;
+        // forall points add them
+        for (int i = 0; i < graph.size(); i++) {
+            temp.add("" + i, new JsonPrimitive(graph.get(i).x + ":" + graph.get(i).y));
+        }
+        key = "ELETESTUNITGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
+        // add id of element so it can be found again
+        temp.add("ID", new JsonPrimitive(id));
+        file.add(key, model.getGson().toJsonTree(temp));
+    }
 
     /**
      * Canvas-Edge, Connections, Node-Edge and Old-Edges to json

+ 4 - 32
src/ui/view/GUI.java

@@ -323,33 +323,6 @@ public class GUI implements CategoryListener {
 		updCon = new UpdateController(model, controller);
 	}
 
-	// /**
-	// * Adds a Popup.
-	// *
-	// * @param component Component
-	// * @param popup PopupMenu
-	// */
-	// private static void addPopup(Component component, final JPopupMenu popup)
-	// {
-	// component.addMouseListener(new MouseAdapter() {
-	// public void mousePressed(MouseEvent e) {
-	// if (e.isPopupTrigger()) {
-	// showMenu(e);
-	// }
-	// }
-	//
-	// public void mouseReleased(MouseEvent e) {
-	// if (e.isPopupTrigger()) {
-	// showMenu(e);
-	// }
-	// }
-	//
-	// private void showMenu(MouseEvent e) {
-	// popup.show(e.getComponent(), e.getX(), e.getY());
-	// }
-	//
-	// });
-	// }
 
 	/**
 	 * Initialize the contents of the frame.
@@ -1197,7 +1170,6 @@ public class GUI implements CategoryListener {
 
 		/** Add local Graph length Textfield an Label */
 		unitGraphLocalPeriod.setPreferredSize(new Dimension(30, 20));//TODO
-		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
 		
 		c.gridwidth=GridBagConstraints.NORTHWEST;
 		gbl.setConstraints(unitGraphLocalPeriodLbl, c);
@@ -3107,14 +3079,14 @@ public class GUI implements CategoryListener {
 	}
 	private void repaintGraphAux(ArrayList<HolonElement> o){//TODO: 
 		unitGraph.repaintWithNewElement((ArrayList<HolonElement>)o);
-		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
-		unitGraphStretchMode.setSelected(unitGraph.isStretching());
+//		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
+//		unitGraphStretchMode.setSelected(unitGraph.isStretching());
 	}
 	
 	private void repaintGraphAux(HolonSwitch o){//TODO: 
 		unitGraph.repaintWithNewSwitch(o);
-		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
-		unitGraphStretchMode.setSelected(unitGraph.isStretching());
+//		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
+//		unitGraphStretchMode.setSelected(unitGraph.isStretching());
 	}
 
 	public void updateIterations() {

+ 250 - 269
src/ui/view/UnitGraph.java

@@ -40,8 +40,6 @@ 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 double width = -1;
     private double height = -1;
     private boolean isElement = false;
@@ -85,196 +83,198 @@ 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);
-        g2.setRenderingHints(rh);
-        g2.setStroke(new BasicStroke(0));
-
-        graphCurve.reset();
-
-        border = (int) recSize.getX() >> 1;
-        // Draw the Vertical Lines
-        g2.setColor(Color.BLACK);
-        for (int i = border; i < this.getWidth() - border; i += border * 2) {
-            g2.drawLine(i, border, i, this.getHeight() - border);
-        }
-        g2.drawLine(this.getWidth() - border, border, this.getWidth() - border, this.getHeight() - border);
-
-        for (int i = border; i < this.getHeight() - border; i += border * 2) {
-            g2.drawLine(border, i, this.getWidth() - border, i);
-        }
-        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 (current != null) {
-                // Draw the Lines
-                g2.setStroke(new BasicStroke(2));
-                g2.setColor(Color.BLACK);
-                for (int i = 0; i < pointList.size() - 1; i++) {
-                    c = buildCurve(pointList.get(i), pointList.get(i + 1));
-                    c.setCurve((x1 * scaleX) + border, (y1 * scaleY) + border, (ctrlx1 * scaleX) + border,
-                            (ctrly1 * scaleY) + border, (ctrlx2 * scaleX) + border, (ctrly2 * scaleY) + border,
-                            (x2 * scaleX) + border, (y2 * scaleY) + border);
-                    graphCurve.append(c, true);
-                }
-                g2.draw(graphCurve);
-
-                // Draw the Points
-                g2.setColor(Color.BLUE);
-                for (Point aPointList : pointList) {
-                    g2.fillOval((int) (aPointList.getX() * scaleX - recSize.getX() / 2) + border,
-                            (int) (aPointList.getY() * scaleY - recSize.getY() / 2) + border,
-                            (int) recSize.getX(), (int) recSize.getY());
-                }
-
-                // Iteration Value
-                //TODO: added function getGraphIterations see if it works
-                textWidth = g.getFontMetrics().stringWidth("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration())/*arrayOfFloats[effectiveX]*/) + 2;
-                if (textWidth
-                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
-                        + border <= this.getWidth()) {
-                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
-                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
-                                    + 2 + border,
-                            this.getHeight() - 10);
-                } else {
-                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
-                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
-                                    + border - textWidth,
-                            this.getHeight() - 10);
-                }
-
-            }
-            // drag Information
-            if (tempP != null && pointDrag) {
-                dragInformation = "" + convertToValueY(getYValueAt((int) tempP.getX()));
-                textWidth = g.getFontMetrics().stringWidth("" + convertToValueY(getYValueAt((int) tempP.getX()))) + 2;
-                if (textWidth + (tempP.getX() * scaleX) + 10 + border <= this.getWidth()) {
-                    g2.drawString(dragInformation, (int) (tempP.getX() * scaleX) + 10 + border,
-                            (int) (tempP.getY() * scaleY) + 10);
-                } else {
-                    g2.drawString(dragInformation, (int) (tempP.getX() * scaleX) - textWidth,
-                            (int) (tempP.getY() * scaleY) + 10);
-                }
-            }
-
-			/*
-             * // Actual Iteration Point Visualization g2.setColor(Color.RED);
-			 * if (arrayOfFloats != null) { for (int i = 0; i <
-			 * arrayOfFloats.length; i++) { g2.fillOval((int) (i * width /
-			 * (model.getIterations() - 1) * scaleX - recSize.getX() /
-			 * 2)+border, (int) (convertToCanvasY((int) arrayOfFloats[i]) *
-			 * scaleY - recSize.getY() / 2)+border, (int) recSize.getX(), (int)
-			 * recSize.getY()); } }
-			 */
-
-        } else if (isSwitch) {
-            if (/*arrayOfBooleans*/current != null) {//Technically this test should be unnecessary
-                // array fillen
-                fillArrayofBooleans();
-
-                // Draw the Lines
-                g2.setStroke(new BasicStroke(2));
-                g2.setColor(Color.BLACK);
-                for (int i = 0; i < pointList.size() - 1; i++) {
-                    // Left out of bounce
-                    if ((i == 1 || i == 2) && pointList.get(i).getX() < 0) {
-                        line = new Line2D.Double(border, pointList.get(i).getY() * scaleY, border,
-                                pointList.get(i + 1).getY() * scaleY);
-                    }
-                    // Right out of bounce
-                    else if (i == pointList.size() - 4 && pointList.get(pointList.size() - 3).getX() > width) {
-                        line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
-                                pointList.get(i).getY() * scaleY, this.getWidth() - border,
-                                pointList.get(i + 1).getY() * scaleY);
-                    } else if (i == pointList.size() - 3 && pointList.get(pointList.size() - 3).getX() > width) {
-                        line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
-                                this.getWidth() - border, pointList.get(i + 1).getY() * scaleY);
-                    } else if (i == pointList.size() - 2 && pointList.get(pointList.size() - 2).getX() > width) {
-                        line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
-                                pointList.get(i + 1).getX() * scaleX + border, pointList.get(i + 1).getY() * scaleY);
-                    } else {
-                        line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
-                                pointList.get(i).getY() * scaleY, pointList.get(i + 1).getX() * scaleX + border,
-                                pointList.get(i + 1).getY() * scaleY);
-                    }
-                    graphCurve.append(line, true);
-                }
-                g2.draw(graphCurve);
-
-				/*
-				 * // Draw the Points g2.setColor(Color.BLUE); for (int i = 0; i
-				 * < pointList.size() - 0; i++) { g2.fillOval((int)
-				 * (pointList.get(i).getX() * scaleX - recSize.getX() / 2) +
-				 * border, (int) (pointList.get(i).getY() * scaleY -
-				 * recSize.getY() / 2), (int) recSize.getX(), (int)
-				 * recSize.getY()); }
-				 */
-
-                // Iteration Value
-                g2.setColor(Color.BLUE);
-                textWidth = g.getFontMetrics().stringWidth("" + ((HolonSwitch)current).getState(model.getCurIteration())/*arrayOfBooleans[effectiveX]*/) + 2;
-                if (textWidth
-                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
-                        + border <= this.getWidth()) {
-                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
-                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
-                                    + 2 + border,
-                            this.getHeight() - 10);
-                } else {
-                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
-                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
-                                    + border - textWidth,
-                            this.getHeight() - 10);
-                }
-
-            }
-            // When the switch graph is dragged
-            if (tempP != null && pointDrag)
-
-            {
-                try {
-                    int i;
-                    for (i = 0; (i * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
-                            + border < getMousePosition().getX()); i++) {
-                    }
-                    dragInformation = "" + i;
-                    textWidth = g.getFontMetrics().stringWidth("" + convertToValueY(getYValueAt((int) tempP.getX())))
-                            + 2;
-                    if (textWidth + (tempP.getX() * scaleX) + 10 + border <= this.getWidth()) {
-                        g2.drawString(dragInformation, (int) (getMousePosition().getX()) + 10 + border,
-                                (int) (getMousePosition().getY() * scaleY) + 10);
-                    } else {
-                        g2.drawString(dragInformation, (int) (getMousePosition().getX()) - textWidth,
-                                (int) (getMousePosition().getY() * scaleY) + 10);
-                    }
-                } catch (Exception e) {
-                }
-            }
-        }
-
-        // Iteration Line TODO: repeat
-        g2.setColor(Color.BLUE);
-        g2.setStroke(new BasicStroke(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
-        controller.calculateStateForTimeStep(model.getCurIteration());
+//        
+//        System.out.println("paint");
+//        g2 = (Graphics2D) g;
+//        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+//        g2.setRenderingHints(rh);
+//        g2.setStroke(new BasicStroke(0));
+//
+//        graphCurve.reset();
+//
+//        border = (int) recSize.getX() >> 1;
+//        // Draw the Vertical Lines
+//        g2.setColor(Color.BLACK);
+//        for (int i = border; i < this.getWidth() - border; i += border * 2) {
+//            g2.drawLine(i, border, i, this.getHeight() - border);
+//        }
+//        g2.drawLine(this.getWidth() - border, border, this.getWidth() - border, this.getHeight() - border);
+//
+//        for (int i = border; i < this.getHeight() - border; i += border * 2) {
+//            g2.drawLine(border, i, this.getWidth() - border, i);
+//        }
+//        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
+//            generateSampleCurves();
+//
+//            if (current != null) {
+//                // Draw the Lines
+//                g2.setStroke(new BasicStroke(2));
+//                g2.setColor(Color.BLACK);
+//                for (int i = 0; i < pointList.size() - 1; i++) {
+//                    c = buildCurve(pointList.get(i), pointList.get(i + 1));
+//                    c.setCurve((x1 * scaleX) + border, (y1 * scaleY) + border, (ctrlx1 * scaleX) + border,
+//                            (ctrly1 * scaleY) + border, (ctrlx2 * scaleX) + border, (ctrly2 * scaleY) + border,
+//                            (x2 * scaleX) + border, (y2 * scaleY) + border);
+//                    graphCurve.append(c, true);
+//                }
+//                g2.draw(graphCurve);
+//
+//                // Draw the Points
+//                g2.setColor(Color.BLUE);
+//                for (Point aPointList : pointList) {
+//                    g2.fillOval((int) (aPointList.getX() * scaleX - recSize.getX() / 2) + border,
+//                            (int) (aPointList.getY() * scaleY - recSize.getY() / 2) + border,
+//                            (int) recSize.getX(), (int) recSize.getY());
+//                }
+//
+//                // Iteration Value
+//                //TODO: added function getGraphIterations see if it works
+//                textWidth = g.getFontMetrics().stringWidth("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration())/*arrayOfFloats[effectiveX]*/) + 2;
+//                if (textWidth
+//                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
+//                        + border <= this.getWidth()) {
+//                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
+//                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
+//                                    + 2 + border,
+//                            this.getHeight() - 10);
+//                } else {
+//                    g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
+//                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
+//                                    + border - textWidth,
+//                            this.getHeight() - 10);
+//                }
+//
+//            }
+//            // drag Information
+//            if (tempP != null && pointDrag) {
+//                dragInformation = "" + convertToValueY(getYValueAt((int) tempP.getX()));
+//                textWidth = g.getFontMetrics().stringWidth("" + convertToValueY(getYValueAt((int) tempP.getX()))) + 2;
+//                if (textWidth + (tempP.getX() * scaleX) + 10 + border <= this.getWidth()) {
+//                    g2.drawString(dragInformation, (int) (tempP.getX() * scaleX) + 10 + border,
+//                            (int) (tempP.getY() * scaleY) + 10);
+//                } else {
+//                    g2.drawString(dragInformation, (int) (tempP.getX() * scaleX) - textWidth,
+//                            (int) (tempP.getY() * scaleY) + 10);
+//                }
+//            }
+//
+//			/*
+//             * // Actual Iteration Point Visualization g2.setColor(Color.RED);
+//			 * if (arrayOfFloats != null) { for (int i = 0; i <
+//			 * arrayOfFloats.length; i++) { g2.fillOval((int) (i * width /
+//			 * (model.getIterations() - 1) * scaleX - recSize.getX() /
+//			 * 2)+border, (int) (convertToCanvasY((int) arrayOfFloats[i]) *
+//			 * scaleY - recSize.getY() / 2)+border, (int) recSize.getX(), (int)
+//			 * recSize.getY()); } }
+//			 */
+//
+//        } else if (isSwitch) {
+//            if (/*arrayOfBooleans*/current != null) {//Technically this test should be unnecessary
+//                // array fillen
+//                fillArrayofBooleans();
+//
+//                // Draw the Lines
+//                g2.setStroke(new BasicStroke(2));
+//                g2.setColor(Color.BLACK);
+//                for (int i = 0; i < pointList.size() - 1; i++) {
+//                    // Left out of bounce
+//                    if ((i == 1 || i == 2) && pointList.get(i).getX() < 0) {
+//                        line = new Line2D.Double(border, pointList.get(i).getY() * scaleY, border,
+//                                pointList.get(i + 1).getY() * scaleY);
+//                    }
+//                    // Right out of bounce
+//                    else if (i == pointList.size() - 4 && pointList.get(pointList.size() - 3).getX() > width) {
+//                        line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
+//                                pointList.get(i).getY() * scaleY, this.getWidth() - border,
+//                                pointList.get(i + 1).getY() * scaleY);
+//                    } else if (i == pointList.size() - 3 && pointList.get(pointList.size() - 3).getX() > width) {
+//                        line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
+//                                this.getWidth() - border, pointList.get(i + 1).getY() * scaleY);
+//                    } else if (i == pointList.size() - 2 && pointList.get(pointList.size() - 2).getX() > width) {
+//                        line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
+//                                pointList.get(i + 1).getX() * scaleX + border, pointList.get(i + 1).getY() * scaleY);
+//                    } else {
+//                        line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
+//                                pointList.get(i).getY() * scaleY, pointList.get(i + 1).getX() * scaleX + border,
+//                                pointList.get(i + 1).getY() * scaleY);
+//                    }
+//                    graphCurve.append(line, true);
+//                }
+//                g2.draw(graphCurve);
+//
+//				/*
+//				 * // Draw the Points g2.setColor(Color.BLUE); for (int i = 0; i
+//				 * < pointList.size() - 0; i++) { g2.fillOval((int)
+//				 * (pointList.get(i).getX() * scaleX - recSize.getX() / 2) +
+//				 * border, (int) (pointList.get(i).getY() * scaleY -
+//				 * recSize.getY() / 2), (int) recSize.getX(), (int)
+//				 * recSize.getY()); }
+//				 */
+//
+//                // Iteration Value
+//                g2.setColor(Color.BLUE);
+//                textWidth = g.getFontMetrics().stringWidth("" + ((HolonSwitch)current).getState(model.getCurIteration())/*arrayOfBooleans[effectiveX]*/) + 2;
+//                if (textWidth
+//                        + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
+//                        + border <= this.getWidth()) {
+//                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
+//                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
+//                                    + 2 + border,
+//                            this.getHeight() - 10);
+//                } else {
+//                    g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
+//                            (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
+//                                    + border - textWidth,
+//                            this.getHeight() - 10);
+//                }
+//
+//            }
+//            // When the switch graph is dragged
+//            if (tempP != null && pointDrag)
+//
+//            {
+//                try {
+//                    int i;
+//                    for (i = 0; (i * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
+//                            + border < getMousePosition().getX()); i++) {
+//                    }
+//                    dragInformation = "" + i;
+//                    textWidth = g.getFontMetrics().stringWidth("" + convertToValueY(getYValueAt((int) tempP.getX())))
+//                            + 2;
+//                    if (textWidth + (tempP.getX() * scaleX) + 10 + border <= this.getWidth()) {
+//                        g2.drawString(dragInformation, (int) (getMousePosition().getX()) + 10 + border,
+//                                (int) (getMousePosition().getY() * scaleY) + 10);
+//                    } else {
+//                        g2.drawString(dragInformation, (int) (getMousePosition().getX()) - textWidth,
+//                                (int) (getMousePosition().getY() * scaleY) + 10);
+//                    }
+//                } catch (Exception e) {
+//                }
+//            }
+//        }
+//
+//        // Iteration Line TODO: repeat
+//        g2.setColor(Color.BLUE);
+//        g2.setStroke(new BasicStroke(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
+//        controller.calculateStateForTimeStep(model.getCurIteration());
     }
 
     @Override
     public void mouseDragged(MouseEvent e) {
+    	System.out.println("MouseDragged");
         if (isElement) {
             elementDragged(e);
         } else if (isSwitch) {
@@ -288,6 +288,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e MouseEvent
      */
     public void elementDragged(MouseEvent e) {
+    	System.out.println("elementDragged");
         if (pointDrag && tempP != null) {
             // Out of Bounds verhindern
             int i = pointList.indexOf(tempP);
@@ -317,6 +318,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e MouseEvent
      */
     public void switchDragged(MouseEvent e) {
+    	System.out.println("switchDragged");
         if (pointDrag && tempP != null && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
             int i = pointList.indexOf(tempP);
             x = (e.getX() - border) / scaleX;
@@ -357,6 +359,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
     @Override
     public void mousePressed(MouseEvent e) {
+    	System.out.println("mousePressed");
         if (isElement) {
             elementPressed(e);
         } else if (isSwitch) {
@@ -371,6 +374,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e MouseEvent
      */
     public void elementPressed(MouseEvent e) {
+    	System.out.println("elementPressed");
         boolean added = false;
         boolean deletePoint = false;
 
@@ -429,6 +433,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e MouseEvent
      */
     public void switchPressed(MouseEvent e) {
+     	System.out.println("switchPressed");
         boolean added = false;
         boolean deletePoint = false;
 
@@ -502,6 +507,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
     @Override
     public void mouseReleased(MouseEvent e) {
+    	System.out.println("mouseReleased");
         if (pointDrag) {
             pointDrag = false;
             tempP = null;
@@ -519,6 +525,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e ComponentEvent
      */
     public void componentResized(ComponentEvent e) {
+    	System.out.println("componentResized");
         // Wenn ein anderes Element genommen wird
         if (init) {
             init = false;
@@ -558,6 +565,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * Empty the Graph.
      */
     public void empty() {
+    	System.out.println("empty");
         pointList = null;
         tempElements = null;
         current = null;
@@ -570,15 +578,16 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * Resets the Points for the Element.
      */
     public void reset() {
-        pointList.removeAll(pointList);
-        if (isSwitch) {
-            pointList.addFirst(new Point(-border, (int) (height / 6)));
-            pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
-        } else {
-            pointList.addFirst(new Point(0, 0));
-            pointList.addLast(new Point((int) ((this.getWidth() - (border * 2)) / scaleX), 0));
-        }
-        repaint();
+       	System.out.println("reset");
+//        pointList.removeAll(pointList);
+//        if (isSwitch) {
+//            pointList.addFirst(new Point(-border, (int) (height / 6)));
+//            pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
+//        } else {
+//            pointList.addFirst(new Point(0, 0));
+//            pointList.addLast(new Point((int) ((this.getWidth() - (border * 2)) / scaleX), 0));
+//        }
+//        repaint();
     }
 
     /**
@@ -588,6 +597,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return the converted number
      */
     public double convertToCanvasY(float d) {
+       	System.out.println("convertToCanvasY");
         return (height - (d * (height / maximum)));
     }
 
@@ -598,6 +608,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return the converted number
      */
     public float convertToValueY(double d) {
+    	System.out.println("convertToValueY");
         return (float) Math.round(((height - (height * (d / height))) / (height / maximum)) * 10) / 10;
     }
 
@@ -607,20 +618,21 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param selectedElement which should be visualized
      */
     public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
-    	//maybe linkedlist better?
-        //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;
-        maximum = getMaximum(selectedElement.get(selectedElement.size() - 1));
-        // First time clicked on the Element
-        if (pointList.isEmpty()) {
-            pointList.addFirst(new Point(0, 0));
-            pointList.addLast(new Point((int) ((this.getWidth() - (border * 2)) / scaleX), 0));
-        }
-        repaint();
+    	System.out.println("repaintWithNewElement");
+//    	//maybe linkedlist better?
+//        //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;
+//        maximum = getMaximum(selectedElement.get(selectedElement.size() - 1));
+//        // First time clicked on the Element
+//        if (pointList.isEmpty()) {
+//            pointList.addFirst(new Point(0, 0));
+//            pointList.addLast(new Point((int) ((this.getWidth() - (border * 2)) / scaleX), 0));
+//        }
+//        repaint();
     }
 
     /**
@@ -629,18 +641,19 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param s which should be visualized
      */
     public void repaintWithNewSwitch(HolonSwitch s) {
+    	System.out.println("repaintWithNewSwitch");
     	
-        //arrayOfBooleans = s.getValueArray();
-    	current=s;
-        pointList = s.getGraphPoints();
-        isSwitch = true;
-        isElement = false;
-        // First time clicked on the Element
-        if (pointList.isEmpty()) {
-            pointList.addFirst(new Point(-border, (int) (height / 6)));
-            pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
-        }
-        repaint();
+//        //arrayOfBooleans = s.getValueArray();
+//    	current=s;
+//        pointList = s.getGraphPoints();
+//        isSwitch = true;
+//        isElement = false;
+//        // First time clicked on the Element
+//        if (pointList.isEmpty()) {
+//            pointList.addFirst(new Point(-border, (int) (height / 6)));
+//            pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
+//        }
+//        repaint();
     }
 
     /**
@@ -651,6 +664,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return the CubicCurve2D for the Graph
      */
     public CubicCurve2D buildCurve(Point p1, Point p2) {
+    	System.out.println("buildCurve");
         x1 = (int) p1.getX();
         y1 = (int) p1.getY();
         x2 = (int) p2.getX();
@@ -677,6 +691,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * Fills the Arrays with booleans.
      */
     public void fillArrayofBooleans() {
+    	System.out.println("fillArrayofBooleans");
         for (int i = 0; i < STANDARD_GRAPH_ACCURACY; i++) {
             int t = (int) getYValueAt((int) (i * width / (STANDARD_GRAPH_ACCURACY - 1)));
             if (t <= height / 2) {
@@ -691,7 +706,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * Fills the Arrays of each HolonElement.
      */
     @SuppressWarnings("unchecked")
-	public void fillArrayofValue() {
+	public void generateSampleCurves() {
+      	System.out.println("generateSampleCurves");
         for (HolonElement he : tempElements) {
             maximum = getMaximum(he);
             he.setGraphPoints((LinkedList<Point>) pointList.clone());
@@ -707,22 +723,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
             	he.setAvailableEnergyPerElementAt(i, convertToValueY(getYValueAt2((int) (i * width / (100 - 1)))));
             }
             
-            he.setTestGraphPoints(convertUnitGraphToHolonElemntPointList(pointList));
             
             System.out.println("TestgraphPoints:");
             he.testFunctiongetAvailableEnergyAt(0);
-            LinkedList<Point> testUnitGraph = this.convertHolonElementPointListToUnitGraph(he.getTestGraphPoints());
-            System.out.println("TestUnitGraph[");
-            for(Point p: testUnitGraph)
-    		{
-    			System.out.println(p);
-    		}
-            System.out.println("NochmalChecknachGraphPoint");
-            LinkedList<Point> testGraphPoint = this.convertUnitGraphToHolonElemntPointList(testUnitGraph);
-            for(Point p: testGraphPoint)
-    		{
-    			System.out.println(p);
-    		}
         }
     }
 
@@ -770,6 +773,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return y, the value at x
      */
     public float getYValueAt(int xVal) {
+     	System.out.println("getYValueAt");
         for (int i = 0; i < pointList.size() - 1; i++) {
             // get the Points
             if (xVal <= pointList.get(i + 1).getX()) {
@@ -790,6 +794,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return y value at x
      */
     public float getYValueAt2(int xVal) {
+    	System.out.println("getYValueAt2");
         for (int i = 0; i < pointList.size() - 1; i++) {
             // get the Points
             if (xVal >= pointList.get(i).getX()) {
@@ -844,6 +849,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return The Intersection Point
      */
     public float getIntersectionPoint(Line2D l1, Line2D l2) {
+     	System.out.println("getIntersectionPoint");
         if (!l1.intersectsLine(l2)) {
             return 0;// null;
         }
@@ -864,7 +870,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     } // end intersection line-line
 
     public void update(ArrayList<AbstractCpsObject> obj) {
-
+    	System.out.println("update");
         ArrayDeque<AbstractCpsObject> queue = new ArrayDeque<>();
 
         AbstractCpsObject u = null;
@@ -884,13 +890,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     }
 
     void repaintGraph(AbstractCpsObject u) {
+    	System.out.println("repaintGraph");
         ArrayList<HolonElement> list = new ArrayList<>();
 
         if (u instanceof HolonObject) {
             for (HolonElement ele : ((HolonObject) u).getElements()) {
                 list.add(ele);
                 repaintWithNewElement(list);
-                fillArrayofValue();
+                generateSampleCurves();
                 list.remove(0);
             }
         } else if (u instanceof HolonSwitch) {
@@ -900,6 +907,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     }
 
     float getMaximum(HolonElement ele) {
+    	System.out.println("getMaximum");
         if (ele.isFlexible()) {
             return ele.getFlexibleEnergyAvailablePerElement();
         } else {
@@ -912,6 +920,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param localPeriod
      */
     public void setLocalPeriod(int localPeriod){
+    	System.out.println("setLocalPeriod");
     	if(isElement)for(IGraphedElement e:tempElements)e.setLocalPeriod(localPeriod);
     	else if(isSwitch)current.setLocalPeriod(localPeriod);
     }
@@ -921,50 +930,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @return localPeriod of the current Element or Switch
      */
     public int getLocalPeriod(){
+    	System.out.println("getLocalPeriod");
     	if(current!=null)return current.getLocalPeriod();
     	else return model.getGraphIterations();//TODO: maybe rename
     }
     
     public boolean isStretching(){
+    	System.out.println("isStretching");
     	return current.isStretching();
     }
     
     public void setStretching(boolean b){
+    	System.out.println("setStretching");
     	if(isElement)for(IGraphedElement e:tempElements)e.setStretching(b);
     	else if(isSwitch)current.setStretching(b);
     }
     
-    static int lv=0;
-    
-    /**
-     * Determines the index of the internal value array
-     * of an element that should be used, since elements only save 100 values,
-     * but iterations and local period can be anything between 1 and 100000.
-     * 
-     * @param m the corresponding model.
-     * @param e the element for which the calculation should be made.
-     * @param timeStep the iteration for which the calculation should be made.
-     * @return
-     */
-    public static int getEffectiveIndex(Model m, IGraphedElement e, int timeStep){
-    	if(e.isStretching())return timeStep*100/(m==null?STANDARD_GRAPH_ACCURACY:m.getIterations());
-    	else return timeStep%e.getLocalPeriod()*100/e.getLocalPeriod();
-    }
     
-    /**
-     * Same as getEffectiveIndex(Model, IGraphedElement, int),
-     * but using the Model obtained from the singleton controller
-     * to determine the total number of iterations(for "use global").
-     */
-    public static int getEffectiveIndex(IGraphedElement e, int timeStep){
-    	return getEffectiveIndex(SingletonControl.getInstance().getControl()==null ? null : SingletonControl.getInstance().getControl().getModel(),e,timeStep);
-    }
-    
-    /**
-     * Same as getEffectiveIndex(Model, IGraphedElement),
-     * but the current iteration is also obtained from the standard model.
-     */
-    public static int getEffectiveIndex(IGraphedElement e){
-    	return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration());
-    }
+
 }