Browse Source

New Classes

Tom Troppmann 5 years ago
parent
commit
837670141d

+ 50 - 0
src/classes/UnitGraphPoint.java

@@ -0,0 +1,50 @@
+package classes;
+
+import java.awt.geom.Point2D;
+
+/**
+ * A class for saving all points of a Object with a editable state.
+ * e.g HolonElement, HolonSwitch
+ * @author Tom Troppmann
+ *
+ */
+public class UnitGraphPoint {
+	/** Relative position in the UnitGraphCanvas */
+	public double x,y;
+	/** To determine if this point has changed to only write back points that are changed.*/
+	public boolean changed;
+	/** The displayed Position of the UnitGraphPoint*/
+	public Position displayedPosition;
+	
+	/** Default Constructor */
+	public UnitGraphPoint(double x, double y, boolean changed){
+		this.x = x;
+		this.y = y;
+		this.changed = changed;
+	}
+	/** Constructor with a Point2D.Double*/
+	public UnitGraphPoint(Point2D.Double pos, boolean changed){
+		this.x = pos.getX();
+		this.y = pos.getY();
+		this.changed = changed;
+	}
+	/** Constructor with a Point2D.Double
+	 * when changed not specified is false;
+	 * */
+	public UnitGraphPoint(Point2D.Double pos){
+		this.x = pos.getX();
+		this.y = pos.getY();
+		this.changed = false;
+	}
+	
+	public void calcDisplayedPosition(int border, int widthWithBorder, int heightWithBorder) {
+    	//Relativ to Border
+    	//1-p.y because its on the Top
+		displayedPosition =  new Position((int) (x * widthWithBorder) + border, (int) ((1-y) * heightWithBorder) + border);
+    }
+	
+	@Override
+	public String toString() {
+		return "[" + x + ":" + y + "]";
+	}
+}

+ 15 - 0
src/classes/comparator/UnitGraphPointComperator.java

@@ -0,0 +1,15 @@
+package classes.comparator;
+
+import java.util.Comparator;
+
+import classes.UnitGraphPoint;
+
+
+public class UnitGraphPointComperator implements Comparator<UnitGraphPoint>{
+
+	@Override
+	public int compare(UnitGraphPoint o1, UnitGraphPoint o2) {
+		return o1.displayedPosition.x - o2.displayedPosition.x;
+	}
+
+}

+ 35 - 35
src/classes/comparator/WeakestBattery.java

@@ -1,35 +1,35 @@
-package classes.comparator;
-
-import java.util.Comparator;
-
-import classes.HolonBattery;
-
-public class WeakestBattery implements Comparator<HolonBattery>{
-	int timeStep = 0;
-	 public WeakestBattery(int compareAtTimeStep) {
-	        timeStep = compareAtTimeStep;
-	    }
-	@Override
-	public int compare(HolonBattery o1, HolonBattery o2) {
-		//Sort Battery by the value of StateOfCharge/Capasity
-		float O1capasity = o1.getCapacity();		
-		float O2capasity = o2.getCapacity();
-		if(O1capasity == 0)
-		{
-			return 1; 
-		}
-		else if(O2capasity == 0)
-		{
-			return -1;
-		}
-		if (o1.getStateOfChargeAtTimeStep(timeStep-1) / O1capasity < o2.getStateOfChargeAtTimeStep(timeStep-1) / O2capasity)
-		{
-			return -1;
-		}else if(o1.getStateOfChargeAtTimeStep(timeStep-1) / O1capasity > o2.getStateOfChargeAtTimeStep(timeStep-1) / O2capasity)
-		{
-			return 1;
-		}
-		return 0;
-	}
-
-}
+package classes.comparator;
+
+import java.util.Comparator;
+
+import classes.HolonBattery;
+
+public class WeakestBattery implements Comparator<HolonBattery>{
+	int timeStep = 0;
+	 public WeakestBattery(int compareAtTimeStep) {
+	        timeStep = compareAtTimeStep;
+	    }
+	@Override
+	public int compare(HolonBattery o1, HolonBattery o2) {
+		//Sort Battery by the value of StateOfCharge/Capasity
+		float O1capasity = o1.getCapacity();		
+		float O2capasity = o2.getCapacity();
+		if(O1capasity == 0)
+		{
+			return 1; 
+		}
+		else if(O2capasity == 0)
+		{
+			return -1;
+		}
+		if (o1.getStateOfChargeAtTimeStep(timeStep-1) / O1capasity < o2.getStateOfChargeAtTimeStep(timeStep-1) / O2capasity)
+		{
+			return -1;
+		}else if(o1.getStateOfChargeAtTimeStep(timeStep-1) / O1capasity > o2.getStateOfChargeAtTimeStep(timeStep-1) / O2capasity)
+		{
+			return 1;
+		}
+		return 0;
+	}
+
+}

+ 29 - 0
src/interfaces/GraphEditable.java

@@ -0,0 +1,29 @@
+package interfaces;
+
+import java.awt.geom.Point2D;
+import java.util.LinkedList;
+
+/**
+ * Interface for all Elements that have a Graph to edit it state over time.
+ * @author Tom Troppmann
+ *
+ */
+public interface GraphEditable {
+
+	/**
+	 * all types of graphs
+	 */
+	public static enum Graphtype {
+		boolGraph, doubleGraph
+	}
+	/**
+	 * Determine what type the Graph have.
+	 * @return the type of the Graph
+	 */
+	Graphtype getGraphType();
+	/**
+	 * Getter for the graph.
+	 * @return The list of all graph points.
+	 */
+	LinkedList<Point2D.Double> getStateGraph();
+}

+ 41 - 0
src/ui/view/IndexTranslator.java

@@ -0,0 +1,41 @@
+package ui.view;
+
+import interfaces.IGraphedElement;
+import ui.controller.SingletonControl;
+import ui.model.Model;
+
+
+public class IndexTranslator {
+	public static int STANDARD_GRAPH_ACCURACY = 100;
+	   /**
+     * 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());
+    }
+}

+ 128 - 475
src/ui/view/UnitGraph.java

@@ -78,20 +78,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	int dotSize = 8;
 	/** The Color of a dot in the graph. */
 	Color dotColor = Color.blue;
-	
+	Color editDotColor = new Color(255, 119, 0);
 	//Intern Variables
 	//TODO: JavaDoc
 	private LinkedList<UnitGraphPoint> actualGraphPoints = new LinkedList<UnitGraphPoint>();
-	/**
-	 * This is list is sortet in the y achsis
-	 */
-	private LinkedList<Position> representativePositions = new LinkedList<Position>();
 	private Graphtype actualGraphType;
 	private GraphEditable actualElement;
-	ListIterator<Position> iter;
-	ListIterator<UnitGraphPoint> iter2;
-	Position currentPosition;
+	Position currentPosition; //outDated
+	Position editPosition;
+	boolean released = false;
 	private int widthWithBorder, heightWithBorder;
+	
+	
+	
+	
+	
+	
     /**
      * Constructor.
      *
@@ -130,259 +132,140 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
        // g2D.drawLine(0, 0,breite, höhe);
         //printDebug();
         printDebugRepresentive();
-        g2D.setColor(dotColor);
-        drawUnitGraphPoints(g2D);
-        g2D.setColor(Color.BLACK);
         drawUnitGraph(g2D);
+        g2D.setColor(dotColor);
+        if(released)
+        {
+        	drawUnitGraphPointsReleased(g2D);
+        }else
+        {
+        	 drawUnitGraphPoints(g2D);
+        }
+       
+        
         
         //generate Path --> maybe als Methode auslagern
         
         //Good Source for basic understanding for Bezier Curves
         //http://www.theappguruz.com/blog/bezier-curve-in-games
         
-        
-        Path2D.Double mypath = new Path2D.Double();
-        
-        Position punktStart = new Position(+40,40);
-        Position punktEnd = new Position(breite-180,höhe-90);
-        //Werden Bestimmt
-        //Erster Punkt bleibt in Höhe gleich aber nimmt die Hälfte der Breite zu
-        
-        
-        mypath.moveTo(punktStart.x, punktStart.y);
-        double mitte = (punktStart.x + punktEnd.x)* 0.5;
-        mypath.curveTo(mitte, punktStart.y, mitte, punktEnd.y, punktEnd.x, punktEnd.y);
-        
-        g2D.draw(mypath);
-        g2D.setColor(Color.BLUE);
-        drawDot(g2D,punktStart);
-        drawDot(g2D,punktEnd);
-//        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()); 
     }
-    
-    
     //TODO -> New Section
     
-    
+    private Path2D.Double initBezier(Position start) {
+    	//Good Source for basic understanding for Bezier Curves
+        //http://www.theappguruz.com/blog/bezier-curve-in-games
+        
+    	Path2D.Double path = new Path2D.Double();
+    	path.moveTo(start.x, start.y);
+		return path;
+    }
+    private void curveTo(Path2D.Double path, Position actual, Position target) {
+         double mitte = (actual.x + target.x)* 0.5;
+         path.curveTo(mitte, actual.y, mitte, target.y, target.x, target.y);
+    }
     private void drawDot(Graphics2D g, Position p)
     {    	
     	g.fillOval(p.x -dotSize/2, p.y-dotSize/2, dotSize, dotSize);
     }
-    private Position convertToPosition(UnitGraphPoint p) {
-    	//Relativ to Border
-    	//1-p.y because its on the Top
-    	return new Position((int) (p.x * widthWithBorder) + border, (int) ((1-p.y) * heightWithBorder) + border);
-    }
     private void drawUnitGraph(Graphics2D g) {
     	switch(actualGraphType) {
 		case boolGraph:
 			drawBoolGraph(g);
 			break;
 		case doubleGraph:
-			drawDoubleGraph(g);
+			if(released)
+				drawDoubleGraphReleased(g);
+			else
+				drawDoubleGraph(g);
 			break;
 		default:
 			throw new UnsupportedOperationException();
     	}
     }
     private void drawUnitGraphPoints(Graphics2D g) {
+    	g.setColor(Color.blue);
     	for(UnitGraphPoint p : actualGraphPoints){
-			if (p.changed) {
-				g.setColor(Color.red);
-			} else {
-				g.setColor(Color.blue);
-			}
     		drawDot(g, p.displayedPosition);
     	}
     }
+    
+    private void drawUnitGraphPointsReleased(Graphics2D g) {
+    	ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
+    	g.setColor(Color.blue);
+    	while (iter2.hasNext())
+    	{
+    		Position tempPosition = iter2.next().displayedPosition;
+    		if(tempPosition.x > editPosition.x)
+    		{
+    			iter2.previous();
+    			break;
+    		}
+    		drawDot(g, tempPosition);
+    	}
+    	g.setColor(editDotColor);
+		drawDot(g, editPosition);
+    	
+		g.setColor(Color.blue);
+    	while (iter2.hasNext())
+    	{
+    			drawDot(g, iter2.next().displayedPosition);
+    	}
+    }
+    
     private void drawBoolGraph(Graphics2D g) {
     	throw new NotImplementedException();
     }
     
-    
+    private void drawDoubleGraph(Graphics2D g) {
+    	if(actualGraphPoints.isEmpty()) throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
+    	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
+    	Position actual = iter.next().displayedPosition;
+    	Path2D.Double path = this.initBezier(actual);
+    	while (iter.hasNext())
+    	{
+    		Position target = iter.next().displayedPosition;
+    		this.curveTo(path, actual, target);
+    		actual = target;
+    	}
+    	g.draw(path);
+    }
+    private void drawDoubleGraphReleased(Graphics2D g) {
+    	if(actualGraphPoints.isEmpty()) throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
+    	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
+    	Position actual = iter.next().displayedPosition;
+    	Path2D.Double path = this.initBezier(actual);
+    	while (iter.hasNext())
+    	{
+    		Position target = iter.next().displayedPosition;
+    		if(target.x > editPosition.x)
+    		{
+    			iter.previous();
+    			break;
+    		}
+    		this.curveTo(path, actual, target);
+    		actual = target;
+    	}
+    	Position old = actual;
+    	Path2D.Double editPath = this.initBezier(actual);
+    	
+    	actual = iter.next().displayedPosition;
+    	//here actual is new Position;
+    	this.curveTo(editPath, old, editPosition);
+    	this.curveTo(editPath, editPosition, actual);
+    	path.moveTo(actual.x, actual.y);
+    	
+//		g.setColor(Color.blue);
+    	while (iter.hasNext())
+    	{
+    		Position target = iter.next().displayedPosition;
+    		this.curveTo(path, actual, target);
+    		actual = target;
+    	}
+    	g.draw(path);
+    	g.setColor(editDotColor);
+    	g.draw(editPath);
+    }
     
     
     private void updateRepresentativePositions()
@@ -392,9 +275,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	}
     }
     
-    private void drawDoubleGraph(Graphics2D g) {
-    	
-    }
     private void overrideUnitGraph(LinkedList<Point2D.Double> stateCurve) {
     	actualGraphPoints.clear();
     	for(Point2D.Double p: stateCurve){
@@ -415,14 +295,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	actualElement = element;
     	repaint();
     }
-    private void printDebug(){
-    	if(actualGraphPoints.isEmpty()) return;
-    	System.out.print("{");
-    	for(UnitGraphPoint p: actualGraphPoints){
-    		System.out.print(p);
-    	}
-    	System.out.println("}");
-    }
+
     private void printDebugRepresentive(){
     	if(this.actualGraphPoints.isEmpty()) return;
     	System.out.print("{");
@@ -432,28 +305,25 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	System.out.println("}");
     }
     
-    private boolean detectPointUnderCurser(MouseEvent mEvent) {
+    private void detectPointUnderCurserAndRemove(MouseEvent mEvent) {
 		//get mouse Position
     	Position mPosition = new Position(mEvent.getPoint());
-    	//iter = representativePositions.listIterator();
-    	iter2 = actualGraphPoints.listIterator();
+    	ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
     	while (iter2.hasNext())
     	{
-    		Position tempPosition = iter2.next().displayedPosition;
-    		if(mPosition.squareDistance(tempPosition) < clickThreshholdSquared)
+    		if(mPosition.squareDistance(iter2.next().displayedPosition) < clickThreshholdSquared)
     		{
-    			currentPosition = tempPosition;
-    			return true;
+    			iter2.remove();
+    			break;
     		}
     	}
-    	return false;
     }
     
     
-    private void updateGraphPoint(Position newPosition) {
+    private void updateEditPointPosition(Position newPosition) {
     	//make it in the bounds of the UnitGraph no Point out of the Border
     	currentPosition = setInBounds(newPosition);
-		iter2.set(generateUnitGraphPoint(currentPosition));
+    	this.editPosition = currentPosition;
 		repaint();
     }
     
@@ -467,17 +337,15 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     {
     	System.out.println("insertNewGraphPoint");
     	setInBounds(pos);
-    	iter2 = actualGraphPoints.listIterator();
+    	ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
     	while (iter2.hasNext())
     	{
     		Position tempPosition = iter2.next().displayedPosition;
     		if(pos.x <= tempPosition.x)
     		{
-    			//First previous to go back a position to make the new point before the the Position with greater X
+    			//previous to go back a position to make the new point before the the Position with greater X
     			iter2.previous();
     			iter2.add(generateUnitGraphPoint(pos));
-    			//Second Previous to select the new added Position
-    			iter2.previous();
     			break;
     		}
     	}
@@ -491,73 +359,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	@Override
     public void mouseDragged(MouseEvent e) {
     	System.out.println("MouseDragged");
-    	//System.out.println("PositionFromITERATOR= "+ currentPosition +" Index= " + iter.previousIndex() );
-    	updateGraphPoint(new Position(e.getPoint()));
-    	//printDebugRepresentive();
-//        if (isElement) {
-//            elementDragged(e);
-//        } else if (isSwitch) {
-//            switchDragged(e);
-//        }
-    }
-
-    /**
-     * When a Point of a Holon Element is dragged.
-     *
-     * @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);
-//            x = (e.getX() - border) / scaleX;
-//            y = (e.getY() - border) / scaleY;
-//            // y
-//            if (e.getY() <= border) {
-//                y = 0;
-//            } else if (this.getHeight() - border <= e.getY()) {
-//                y = (this.getHeight() - border * 2) / scaleY;
-//            }
-//            // x
-//            if (tempP == pointList.getFirst() || tempP == pointList.getLast() || pointList.get(i + 1).getX() < x + 2
-//                    || pointList.get(i - 1).getX() > x - 2 || pointList.getFirst().getX() > x - 2
-//                    || pointList.getLast().getX() < x + 2) {
-//                x = tempP.getX();
-//            }
-//            tempP.setLocation(x, y);
-//
-//            repaint();
-//        }
-    }
-
-    /**
-     * When a Point of a switch is dragged.
-     *
-     * @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;
-//
-//            if (pointList.get(i + 1).getY() == tempP.getY()) {
-//                // x
-//                if (pointList.get(i + 1).getX() <= x + 1 || pointList.get(i - 2).getX() >= x - 1) {
-//                    x = tempP.getX();
-//                }
-//                pointList.get(i - 1).setLocation(x, pointList.get(i - 1).getY());
-//            } else {
-//                // x
-//                if (pointList.get(i + 2).getX() <= x + 1 || pointList.get(i - 1).getX() >= x - 1) {
-//                    x = tempP.getX();
-//                }
-//                pointList.get(i + 1).setLocation(x, pointList.get(i + 1).getY());
-//            }
-//            tempP.setLocation(x, tempP.getY());
-//            repaint();
-//        }
+    	updateEditPointPosition(new Position(e.getPoint()));
     }
 
     @Override
@@ -566,7 +368,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
     @Override
     public void mouseClicked(MouseEvent e) {
-    	System.out.println("mouseClicked");
     }
 
     @Override
@@ -580,166 +381,18 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     @Override
     public void mousePressed(MouseEvent e) {
     	System.out.println("mousePressed");
-		if (detectPointUnderCurser(e)) {
-			//DoNothing
-		} else {
-			//create new Position
-			this.insertNewGraphPoint(new Position(e.getPoint()));
-			repaint();
-		}
-    }
-
-    /**
-     * When a point of a Holon Element is pressed.
-     *
-     * @param e MouseEvent
-     */
-    public void elementPressed(MouseEvent e) {
-    	System.out.println("elementPressed");
-//        
-//    	boolean added = false;
-//        boolean deletePoint = false;
-//
-//        int x = (int) ((e.getX() - border) / scaleX);
-//        double y = (e.getY() - border) / scaleY;
-//
-//        // Click on Point
-//        tempP = null;
-//        if (pointList != null) {
-//            // look if a point was clicked
-//            for (Point p : pointList) {
-//                if (x >= p.getX() - recSize.getX() / 2 && y >= p.getY() - recSize.getY() / 2
-//                        && x <= p.getX() + recSize.getX() / 2 && y <= p.getY() * scaleY + recSize.getY() / 2) {
-//                    if (e.getButton() == MouseEvent.BUTTON3) {//TODO: test
-//                        tempP = p;
-//                        deletePoint = true;
-//                    } else {
-//                        pointDrag = true;
-//                        tempP = p;
-//                    }
-//                }
-//            }
-//            // New Point
-//            if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
-//                    && e.getX() != this.getWidth() / scaleX) {
-//                for (int i = 0; i < pointList.size(); i++) {
-//                    // When a point already exist on this x position
-//                    if (x == pointList.get(i).getX() || x == width || x == 0) {
-//                        break;
-//                    }
-//                    if (x < pointList.get(i).getX() && !added) {
-//                        if (e.getY() <= border) {
-//                            pointList.add(i, new Point((int) (x), 0));
-//                        } else {
-//                            pointList.add(i, new Point((int) (x), (int) y));
-//                        }
-//                        added = true;
-//                        pointDrag = true;
-//                        tempP = pointList.get(i);
-//                    }
-//                }
-//            }
-//            // Delete a Point
-//            if (deletePoint && tempP.getX() != 0
-//                    && /*(*//*tempP.getX() != this.getWidth() / scaleX || */tempP != pointList.getLast())/*)*/ {
-//                pointList.remove(tempP);
-//            }
-//
-//            repaint();
-//        }
-    }
-
-    /**
-     * When a point of a Switch is pressed.
-     *
-     * @param e MouseEvent
-     */
-    public void switchPressed(MouseEvent e) {
-     	System.out.println("switchPressed");
-        boolean added = false;
-        boolean deletePoint = false;
-
-        double x = (e.getX() - border) / scaleX;
-        e.getY();
-
-        // Halbe Iterations Distanz
-        double dist = (width / (model.getIterations() - 1)) / 2;
-
-        // Click on Point
-        tempP = null;
-        if (pointList != null) {
-            for (Point p : pointList) {
-                if (x >= p.getX() - dist * 2 && x <= p.getX() + dist * 2) {
-                    if (e.getButton() == MouseEvent.BUTTON3) {
-                        tempP = p;
-                        deletePoint = true;
-                    } else {
-                        pointDrag = true;
-                        tempP = p;
-                    }
-                }
-            }
-            // New Point
-            if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
-                for (int i = 0; i < pointList.size() && !added; i++) {
-                    if (x < pointList.get(i).getX() - dist) {
-                        // double p1, p2 um location der points zu bestimmen
-                        double p1 = pointList.get(i - 1).getX();
-                        double p2 = pointList.get(i).getX();
-                        // Punkte hinzufügen, je nachdem ob true oder false
-                        if (pointList.get(i - 1).getY() != (int) (height / 6)
-                                && pointList.get(i).getY() != (int) (height / 6)) {
-                            pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) (height - height / 6)));
-                            pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) (height / 6)));
-                            pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) (height / 6)));
-                            pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) (height - height / 6)));
-                            added = true;
-                        } else if (pointList.get(i - 1).getY() == (int) (height / 6)
-                                && pointList.get(i).getY() == (int) (height / 6)) {
-                            pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) (height / 6)));
-                            pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) (height - height / 6)));
-                            pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) (height - height / 6)));
-                            pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) (height / 6)));
-                            added = true;
-                        }
-                    }
-                }
-            }
-
-            // Delete a Point
-            if (deletePoint && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
-                int i = pointList.indexOf(tempP);
-                // If Right, else if Left
-                if (tempP.getY() == (int) (height / 6) && i < pointList.size() - 1 && i > 0) {
-                    pointList.remove(i);
-                    pointList.remove(i - 1);
-                    pointList.remove(i - 2);
-                    pointList.remove(i - 3);
-                } else if (tempP.getY() == (int) (height - height / 6)) {
-                    pointList.remove(i + 2);
-                    pointList.remove(i + 1);
-                    pointList.remove(i);
-                    pointList.remove(i - 1);
-                }
-            }
-
-            repaint();
-        }
+    	detectPointUnderCurserAndRemove(e);
+		updateEditPointPosition(new Position(e.getPoint()));
+		released = true;
+		repaint();
     }
 
     @Override
     public void mouseReleased(MouseEvent e) {
     	System.out.println("mouseReleased");
-		this.actualGraphPoints.sort(new UnitGraphPointComperator());
-//    	if (pointDrag) {
-//            pointDrag = false;
-//            tempP = null;
-//        }
-//        /**
-//         * reset the dragInformation.
-//         */
-//        dragInformation = "";
-//        repaint();
+    	this.insertNewGraphPoint(editPosition);
+    	released = false;
+    	repaint();
     }
 
     /**