Browse Source

GraphEditor

Tom Troppmann 6 years ago
parent
commit
16053844e9
5 changed files with 391 additions and 130 deletions
  1. 12 5
      src/classes/HolonElement.java
  2. 7 0
      src/classes/HolonSwitch.java
  3. 67 7
      src/classes/Position.java
  4. 5 1
      src/ui/view/GUI.java
  5. 300 117
      src/ui/view/UnitGraph.java

+ 12 - 5
src/classes/HolonElement.java

@@ -10,6 +10,7 @@ import ui.view.UnitGraph;
 
 import java.awt.*;
 import java.awt.geom.Point2D;
+import java.awt.geom.Point2D.Double;
 import java.util.LinkedList;
 
 /**
@@ -25,8 +26,8 @@ public class HolonElement implements IGraphedElement, GraphEditable{
     
     /** Points of new TestGraph 
      * Represent the Graph 
-     * the X component from a Point is period
-     * the Y component from a Point is the percentage
+     * the X component from a Point is period from 0..1
+     * the Y component from a Point is the percentage from 0..1
      * currently saved in int -> TODO serelized float point class
      * */
     private LinkedList<Point2D.Double> testGraphPoints;
@@ -103,7 +104,7 @@ public class HolonElement implements IGraphedElement, GraphEditable{
         setGraphPoints(new LinkedList<>());
         System.out.println("heiNEW");
         setTestGraphPoints(new LinkedList<>());
-        initTestGraphPoints(100);
+        initTestGraphPoints(1);
         setId(id);
         setFlexibleEnergyAvailable(0);
         setFlexible(false);
@@ -444,7 +445,7 @@ public class HolonElement implements IGraphedElement, GraphEditable{
 	{
 		testGraphPoints.clear();
 		testGraphPoints.add(new Point2D.Double(0,percentage));
-		testGraphPoints.add(new Point2D.Double(100,percentage));
+		testGraphPoints.add(new Point2D.Double(1,percentage));
 	}
 	public LinkedList<Point2D.Double> getTestGraphPoints() {
 		return testGraphPoints;
@@ -458,6 +459,12 @@ public class HolonElement implements IGraphedElement, GraphEditable{
 
 	@Override
 	public Graphtype getGraphType() {
-		return Graphtype.floatGraph;
+		return Graphtype.doubleGraph;
+	}
+
+
+	@Override
+	public LinkedList<Double> getStateGraph() {
+		return getTestGraphPoints();
 	}
 }

+ 7 - 0
src/classes/HolonSwitch.java

@@ -1,6 +1,7 @@
 package classes;
 
 import java.awt.Point;
+import java.awt.geom.Point2D.Double;
 import java.util.LinkedList;
 
 import com.google.gson.annotations.Expose;
@@ -282,4 +283,10 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	public Graphtype getGraphType() {
 		return Graphtype.boolGraph;
 	}
+
+	@Override
+	public LinkedList<Double> getStateGraph() {
+		// TODO no Double List
+		return null;
+	}
 }

+ 67 - 7
src/classes/Position.java

@@ -1,5 +1,7 @@
 package classes;
 
+import java.awt.Point;
+
 /**
  * Coordinates of an Object on the canvas with a (int) x-coord and a (int).
  * y-coord
@@ -8,22 +10,28 @@ package classes;
  *
  */
 public class Position {
-	public int x;
-	public int y;
+	/** Coordinate*/
+	public int x,y;
 
 	/**
 	 * Constructor with an positive x and y coord on the canvas.
 	 * 
-	 * @param x
-	 *            int
-	 * @param y
-	 *            int
+	 * @param x Coord
+	 * @param y Coord
 	 */
 	public Position(int x, int y) {
 		this.x = x;
 		this.y = y;
 	}
-
+	/**
+	 * Convert a Point to a Position;
+	 * @param p Point
+	 */
+	public Position(Point p)
+	{
+		this.x = (int)p.getX();
+		this.y = (int)p.getY();
+	}
 	/**
 	 * Default constructor without defined position.
 	 */
@@ -31,4 +39,56 @@ public class Position {
 		this.x = -1;
 		this.y = -1;
 	}
+	/**
+	 * Return the Distance squared to a other Position.
+	 * Faster then Distance because no Sqrt() needed.
+	 * @param other the other Position.
+	 * @return squared distance to the Position
+	 */
+	public double squareDistance(Position other)
+	{
+		//The Distance in X
+		double xDis = x - other.x;
+		//The Distance in Y
+		double yDis = y - other.y;
+		return xDis * xDis + yDis * yDis;	
+	}
+	/**
+	 * Return the Distance to a other Position.
+	 * @param other the other Position.
+	 * @return distance to the Position.
+	 */
+	public double Distance(Position other)
+	{
+		return Math.sqrt(squareDistance(other));
+	}
+	
+	/**
+	 * Clamp the X Value two a upper or lower bound
+	 * @param min lower bound
+	 * @param max upper bound
+	 */
+	public void clampX(int min, int max)
+	{
+		if(x < min) x = min;
+		if(x > max) x = max;
+	}
+	/**
+	 * Clamp the Y Value two a upper or lower bound
+	 * @param min lower bound
+	 * @param max upper bound
+	 */
+	public void clampY(int min, int max)
+	{
+		if(y < min) y = min;
+		if(y > max) y = max;
+	}
+	/**
+	 * Returns a String that represents the value of this Position.
+	 * @return a string representation of this Position.
+	 */
+	@Override
+	public String toString() {
+		return "Position[x=" + x + ",y="+ y +"]";
+	}
 }

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

@@ -1372,6 +1372,7 @@ public class GUI implements CategoryListener {
 		 */
 		model.getTableHolonElement()
 				.addPropertyChangeListener(propertyChangeEvent -> {
+					System.out.println("GUI->getTableHolonElement");
 					try {
 						int yMouse = yThis;
 						int yBMouse = yBTis;
@@ -2487,7 +2488,7 @@ public class GUI implements CategoryListener {
 		splitGraphHolonEl.setBorder(null);
 		panelHolonEl.setBorder(null);
 		canvasSP.setBorder(null);
-
+		hideScrollGraph();
 		tableHolonElementScrollPane.setBorder(null);
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
@@ -2551,6 +2552,7 @@ public class GUI implements CategoryListener {
 	}
 
 	private void hideScrollGraph() {
+		System.out.println("GUI->hideScrollGraph");
 		scrollGraph.setVisible(false);
 		unitGraph.empty();
 		splitGraphHolonEl.remove(scrollGraph);
@@ -3079,6 +3081,8 @@ public class GUI implements CategoryListener {
 	}
 	private void repaintGraphAux(ArrayList<HolonElement> o){//TODO: 
 		unitGraph.repaintWithNewElement((ArrayList<HolonElement>)o);
+		//TODO -> just in Progress 
+		unitGraph.initNewElement(o.get(o.size()-1));
 //		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
 //		unitGraphStretchMode.setSelected(unitGraph.isStretching());
 	}

+ 300 - 117
src/ui/view/UnitGraph.java

@@ -1,7 +1,11 @@
 package ui.view;
 
 import classes.*;
+import classes.comparator.UnitGraphPointComperator;
+import interfaces.GraphEditable;
+import interfaces.GraphEditable.Graphtype;
 import interfaces.IGraphedElement;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 import ui.controller.Control;
 import ui.controller.SingletonControl;
 import ui.model.Model;
@@ -13,10 +17,12 @@ import java.awt.geom.CubicCurve2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Line2D;
 import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.ListIterator;
 
 /**
  * This Class represents a Graph where the User can model the behavior of
@@ -55,16 +61,37 @@ 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 IGraphedElement current;
 	
 	//NEW ERA
+	// Normal Settings
+	private int border = 4;
+	private int clickThreshholdSquared = 25;
+	// Display Settings
+	/**
+	 * The size of a dot in the graph.
+	 * It should be at least 1.
+	 * */
 	int dotSize = 8;
+	/** The Color of a dot in the graph. */
+	Color dotColor = Color.blue;
 	
-	
-
+	//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;
+	private int widthWithBorder, heightWithBorder;
     /**
      * Constructor.
      *
@@ -92,15 +119,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     public void paintComponent(Graphics g) {
         super.paintComponent(g);
         
-        System.out.println("paint");
+        //System.out.println("paint");
         Graphics2D g2D = (Graphics2D) g;
         g2D.setColor(Color.BLACK);
         int höhe = this.getHeight();
         int breite = this.getWidth();
-        int punktGröße = 8;
+        
         g2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
         g2D.setStroke(new BasicStroke(2));
        // g2D.drawLine(0, 0,breite, höhe);
+        //printDebug();
+        printDebugRepresentive();
+        g2D.setColor(dotColor);
+        drawUnitGraphPoints(g2D);
+        g2D.setColor(Color.BLACK);
+        drawUnitGraph(g2D);
+        
         //generate Path --> maybe als Methode auslagern
         
         //Good Source for basic understanding for Bezier Curves
@@ -309,19 +343,162 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 //        controller.calculateStateForTimeStep(model.getCurIteration()); 
     }
     
+    
+    //TODO -> New Section
+    
+    
     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);
+			break;
+		default:
+			throw new UnsupportedOperationException();
+    	}
+    }
+    private void drawUnitGraphPoints(Graphics2D g) {
+    	for(UnitGraphPoint p : actualGraphPoints){
+			if (p.changed) {
+				g.setColor(Color.red);
+			} else {
+				g.setColor(Color.blue);
+			}
+    		drawDot(g, p.displayedPosition);
+    	}
+    }
+    private void drawBoolGraph(Graphics2D g) {
+    	throw new NotImplementedException();
+    }
+    
+    
+    
+    
+    private void updateRepresentativePositions()
+    {
+    	for(UnitGraphPoint p : actualGraphPoints) {
+    		p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
+    	}
+    }
+    
+    private void drawDoubleGraph(Graphics2D g) {
+    	
+    }
+    private void overrideUnitGraph(LinkedList<Point2D.Double> stateCurve) {
+    	actualGraphPoints.clear();
+    	for(Point2D.Double p: stateCurve){
+    		actualGraphPoints.add(new UnitGraphPoint(p));
+    	}
+    	updateRepresentativePositions();
+    }
+    private void calculateWidthHeight()
+    {
+    	widthWithBorder = this.getWidth() - 2 * border;
+    	heightWithBorder = this.getHeight() - 2 * border;
+    }
+    
+    public void initNewElement(GraphEditable element)
+    {
+    	overrideUnitGraph(element.getStateGraph());
+    	actualGraphType = element.getGraphType();
+    	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("{");
+    	for(UnitGraphPoint p: actualGraphPoints){
+    		System.out.print(p.displayedPosition);
+    	}
+    	System.out.println("}");
+    }
+    
+    private boolean detectPointUnderCurser(MouseEvent mEvent) {
+		//get mouse Position
+    	Position mPosition = new Position(mEvent.getPoint());
+    	//iter = representativePositions.listIterator();
+    	iter2 = actualGraphPoints.listIterator();
+    	while (iter2.hasNext())
+    	{
+    		Position tempPosition = iter2.next().displayedPosition;
+    		if(mPosition.squareDistance(tempPosition) < clickThreshholdSquared)
+    		{
+    			currentPosition = tempPosition;
+    			return true;
+    		}
+    	}
+    	return false;
+    }
+    
+    
+    private void updateGraphPoint(Position newPosition) {
+    	//make it in the bounds of the UnitGraph no Point out of the Border
+    	currentPosition = setInBounds(newPosition);
+		iter2.set(generateUnitGraphPoint(currentPosition));
+		repaint();
+    }
+    
+	private Position setInBounds(Position p) {
+		p.clampX(border, border + widthWithBorder);
+		p.clampY(border, border + heightWithBorder);
+		return p;
+	}
+    
+    private void insertNewGraphPoint(Position pos)
+    {
+    	System.out.println("insertNewGraphPoint");
+    	setInBounds(pos);
+    	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
+    			iter2.previous();
+    			iter2.add(generateUnitGraphPoint(pos));
+    			//Second Previous to select the new added Position
+    			iter2.previous();
+    			break;
+    		}
+    	}
+    }
+    private UnitGraphPoint generateUnitGraphPoint(Position pos) {
+    	UnitGraphPoint temp = new UnitGraphPoint((double)(pos.x - border)/(double)widthWithBorder,(double)(pos.y - border)/(double)heightWithBorder,true);
+		temp.displayedPosition = pos;
+    	return temp;
+	}
 
-    @Override
+	@Override
     public void mouseDragged(MouseEvent e) {
     	System.out.println("MouseDragged");
-        if (isElement) {
-            elementDragged(e);
-        } else if (isSwitch) {
-            switchDragged(e);
-        }
+    	//System.out.println("PositionFromITERATOR= "+ currentPosition +" Index= " + iter.previousIndex() );
+    	updateGraphPoint(new Position(e.getPoint()));
+    	//printDebugRepresentive();
+//        if (isElement) {
+//            elementDragged(e);
+//        } else if (isSwitch) {
+//            switchDragged(e);
+//        }
     }
 
     /**
@@ -331,27 +508,27 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     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();
-        }
+//        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();
+//        }
     }
 
     /**
@@ -361,26 +538,26 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     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();
-        }
+//        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();
+//        }
     }
 
     @Override
@@ -389,6 +566,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
     @Override
     public void mouseClicked(MouseEvent e) {
+    	System.out.println("mouseClicked");
     }
 
     @Override
@@ -402,12 +580,13 @@ 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) {
-            switchPressed(e);
-        }
-
+		if (detectPointUnderCurser(e)) {
+			//DoNothing
+		} else {
+			//create new Position
+			this.insertNewGraphPoint(new Position(e.getPoint()));
+			repaint();
+		}
     }
 
     /**
@@ -417,56 +596,57 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     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();
-        }
+//        
+//    	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();
+//        }
     }
 
     /**
@@ -550,15 +730,16 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     @Override
     public void mouseReleased(MouseEvent e) {
     	System.out.println("mouseReleased");
-        if (pointDrag) {
-            pointDrag = false;
-            tempP = null;
-        }
-        /**
-         * reset the dragInformation.
-         */
-        dragInformation = "";
-        repaint();
+		this.actualGraphPoints.sort(new UnitGraphPointComperator());
+//    	if (pointDrag) {
+//            pointDrag = false;
+//            tempP = null;
+//        }
+//        /**
+//         * reset the dragInformation.
+//         */
+//        dragInformation = "";
+//        repaint();
     }
 
     /**
@@ -568,6 +749,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      */
     public void componentResized(ComponentEvent e) {
     	System.out.println("componentResized");
+    	calculateWidthHeight();
+    	updateRepresentativePositions();
         // Wenn ein anderes Element genommen wird
     	/*
         if (init) {