Browse Source

New Feature: New UnitGraph finish.

Tom Troppmann 5 years ago
parent
commit
44503c23ac

+ 106 - 70
src/classes/HolonElement.java

@@ -3,7 +3,7 @@ package classes;
 import com.google.gson.annotations.Expose;
 
 import interfaces.GraphEditable;
-import interfaces.IGraphedElement;
+import interfaces.LocalMode;
 import ui.model.Model;
 import ui.view.IndexTranslator;
 
@@ -19,7 +19,7 @@ import java.util.ListIterator;
  *
  * @author Gruppe14
  */
-public class HolonElement implements IGraphedElement, GraphEditable{
+public class HolonElement implements LocalMode, GraphEditable{
 
     /** Points of new TestGraph 
      * Represent the Graph 
@@ -70,7 +70,7 @@ public class HolonElement implements IGraphedElement, GraphEditable{
     @Expose
     private int localPeriod;
     @Expose
-    private boolean stretch;
+    private boolean isUsingLocalPeriod;
 
     /**
      * Create a new HolonElement with a user-defined name, amount of the same
@@ -91,13 +91,11 @@ public class HolonElement implements IGraphedElement, GraphEditable{
      * same as standard constructor, but with already given id (so the counter is not increased twice)
      */
     public HolonElement(String eleName, int amount, float energy, int id, Model model){
-    	setLocalPeriod(model==null? IGraphedElement.STANDARD_GRAPH_ACCURACY : model.getGraphIterations());
-    	setStretching(IGraphedElement.STRETCH_BY_DEFAULT);
+    	setUseLocalPeriod(false);
     	setEleName(eleName);
         setAmount(amount);
         setEnergyPerElement(energy);
         setActive(true);
-        System.out.println("heiNEW");
         setGraphPoints(new LinkedList<>());
         initGraphPoints();
         sampleGraph();
@@ -113,14 +111,13 @@ public class HolonElement implements IGraphedElement, GraphEditable{
      */
     public HolonElement(HolonElement element) {
     	setLocalPeriod(element.getLocalPeriod());
-    	setStretching(element.isStretching());
+    	setUseLocalPeriod(element.isUsingLocalPeriod());
         setEleName(element.getEleName());
         setLocalPeriod(element.getLocalPeriod());
         setAmount(element.getAmount());
         setEnergyPerElement(element.getEnergyPerElement());
         setActive(element.isActive());
         setGraphPoints(new LinkedList<>());
-        System.out.println("hei");
         for (Point2D.Double p : element.getGraphPoints()) {
             this.graphPoints.add(new Point2D.Double(p.getX(), p.getY()));
         }
@@ -140,13 +137,6 @@ public class HolonElement implements IGraphedElement, GraphEditable{
 	}
 
 
-    /**
-     * Get the energyPerElement currently(at given time step) available
-     */
-    public float getAvailableEnergyAt(int timestep) {
-    	System.out.println("getAvailableEnergyAt");
-        return amount * energyPerElement * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
-    }
 
     /**
      * Get the user-defined Name.
@@ -257,12 +247,19 @@ public class HolonElement implements IGraphedElement, GraphEditable{
      * @return energyPerElement value
      */
     public float getOverallEnergyAtTimeStep(int timestep) {
-        if (flexible) {
+    	if (flexible) {
             return ((float) amount) * energyPerElement;
         } else {
             return ((float) amount) * energyPerElement * curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
         }
     }
+    /**
+     * Get the energyPerElement currently(at given time step) available
+     */
+    public float getAvailableEnergyAt(int timestep) {
+    	System.out.println("getAvailableEnergyAt");
+    	return amount * energyPerElement * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
+    }
 
     /**
      * Get the flexibleEnergyAvailable of an element
@@ -355,42 +352,35 @@ public class HolonElement implements IGraphedElement, GraphEditable{
         return sb.toString();
     }
 
-	@Override
-	public void setLocalPeriod(int period) {
-		localPeriod=period;
-	}
-
-	@Override
-	public int getLocalPeriod() {
-		return localPeriod;
-	}
-
-	@Override
-	public boolean isStretching() {
-		return stretch;
-	}
-
-	@Override
-	public void setStretching(boolean stretch) {
-		this.stretch=stretch;
-	}
-
-	public void initGraphPoints()
+    /**
+     * Initialize the {@link HolonElement#graphPoints} List with the normal 2 Points at 100%.
+     */
+	private void initGraphPoints()
 	{
 		graphPoints.clear();
 		graphPoints.add(new Point2D.Double(0,1.0));
 		graphPoints.add(new Point2D.Double(1,1.0));
 	}
+	/**
+	 * Getter for the graphPoint List.
+	 * @return {@link HolonElement#graphPoints}
+	 */
 	public LinkedList<Point2D.Double> getGraphPoints() {
 		return graphPoints;
 	}
 
-
+	/**
+	 * Setter for the graphPoint List.
+	 * @param testGraphPoints is new  {@link HolonElement#graphPoints}
+	 */
 	public void setGraphPoints(LinkedList<Point2D.Double> testGraphPoints) {
 		this.graphPoints = testGraphPoints;
 	}
 
-
+	
+	
+	
+	//interfaces.GraphEditable
 	@Override
 	public Graphtype getGraphType() {
 		return Graphtype.doubleGraph;
@@ -403,32 +393,22 @@ public class HolonElement implements IGraphedElement, GraphEditable{
 	}
 
 	
-	private Point.Double getBezierPoint(double t, Point.Double p0, Point.Double p1,Point.Double p2,Point.Double p3) {
-    	/*
-    	 * Calculate Beziér:
-    	 * B(t) = (1-t)^3 * P0 + 3*(1-t)^2 * t * P1 + 3*(1-t)*t^2 * P2 + t^3 * P3 , 0 < t < 1
-    	 * 
-    	 * Source: //http://www.theappguruz.com/blog/bezier-curve-in-games
-    	 */
-		Point.Double bezier = new Point.Double();
-		double OneSubT =  1-t;
-		double OneSubT2 = Math.pow(OneSubT, 2);
-		double OneSubT3 = Math.pow(OneSubT, 3);
-		double t2 = Math.pow(t , 2);
-		double t3 = Math.pow(t , 3);
-	
-		bezier.x = OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x;
-		bezier.y = OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y;
-		return bezier;
-		
+	@Override
+	public void sampleGraph() {
+		curveSample = sampleGraph(100);
 	}
-	private double getYBetweenTwoPoints(double t, Point.Double start, Point.Double end) {
-		
-	    double mitte = (start.x + end.x)* 0.5;
-	    Point.Double bezier = getBezierPoint(t, start, new Point.Double(mitte, start.y), new Point.Double(mitte, end.y), end);
-		return bezier.y;
+
+	@Override
+	public void reset() {
+		initGraphPoints();
+		sampleGraph();
 	}
-	
+	/**
+	 * Generate out of the Graph Points a array of floats that represent the Curve at each sample position. The Values are in the Range [0,1]. 
+	 * e.g. 0.0 represent: "0%" , 0.34 represent: 34%  1.0 represent: "100%" 
+	 * @param sampleLength amount of samplePositions. The positions are equidistant on the Range[0,1].
+	 * @return the float array of samplepoints.
+	 */
 	private float[] sampleGraph(int sampleLength)
 	{		
 		ListIterator<Point2D.Double> iter = this.graphPoints.listIterator();
@@ -452,15 +432,71 @@ public class HolonElement implements IGraphedElement, GraphEditable{
 		return sampleCurve;
 	}
 	
+	/**
+	 * Helper method for {@link HolonElement#sampleGraph(int)}.
+	 * <p>
+	 * Its get the start and Endposition and calculate the Points in between for the Beziér Curve.
+	 * Then its get the Y Value a.k.a. the percentage from the curve at the X value t.  
+	 * @param t is in Range [0,1] and represent how much the X value is traverse along the Curve between the two Points.
+	 * @param start is the start Point of the Curve.
+	 * @param end is the end Point of the Curve.
+	 * @return the percentage from the Curve at the X Value based on t.
+	 */
+	private double getYBetweenTwoPoints(double t, Point.Double start, Point.Double end) {
+		
+		double mitte = (start.x + end.x)* 0.5;
+		Point.Double bezier = getBezierPoint(t, start, new Point.Double(mitte, start.y), new Point.Double(mitte, end.y), end);
+		return bezier.y;
+	}
+	/**
+	 * Helper method for {@link HolonElement#getYBetweenTwoPoints(double, Point.Double, Point.Double)}.
+	 * <p>
+	 * A Method for a normal Cubic Bezier Curve. A Cubic Bezier curve has four control points.
+	 * @param t is in Range [0,1] how much it traverse along the curve.
+	 * @param p0 StartPoint
+	 * @param p1 ControlPoint
+	 * @param p2 ControlPoint
+	 * @param p3 EndPoint
+	 * @return the BezierPosition at t.
+	 */
+	private Point.Double getBezierPoint(double t, Point.Double p0, Point.Double p1,Point.Double p2,Point.Double p3) {
+		/*
+		 * Calculate Beziér:
+		 * B(t) = (1-t)^3 * P0 + 3*(1-t)^2 * t * P1 + 3*(1-t)*t^2 * P2 + t^3 * P3 , 0 < t < 1
+		 * 
+		 * Source: //http://www.theappguruz.com/blog/bezier-curve-in-games
+		 */
+		Point.Double bezier = new Point.Double();
+		double OneSubT =  1-t;
+		double OneSubT2 = Math.pow(OneSubT, 2);
+		double OneSubT3 = Math.pow(OneSubT, 3);
+		double t2 = Math.pow(t , 2);
+		double t3 = Math.pow(t , 3);
+		
+		bezier.x = OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x;
+		bezier.y = OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y;
+		return bezier;
+		
+	}
+	//interfaces.LocalMode
 	@Override
-	public void sampleGraph() {
-		curveSample = sampleGraph(100);
+	public void setLocalPeriod(int period) {
+		localPeriod=period;
 	}
-
-
+	
 	@Override
-	public void reset() {
-		initGraphPoints();
-		sampleGraph();
+	public int getLocalPeriod() {
+		return localPeriod;
 	}
+	
+	@Override
+	public boolean isUsingLocalPeriod() {
+		return isUsingLocalPeriod;
+	}
+	
+	@Override
+	public void setUseLocalPeriod(boolean state) {
+		this.isUsingLocalPeriod=state;
+	}
+	
 }

+ 52 - 54
src/classes/HolonSwitch.java

@@ -8,7 +8,7 @@ import java.util.ListIterator;
 
 import com.google.gson.annotations.Expose;
 import interfaces.GraphEditable;
-import interfaces.IGraphedElement;
+import interfaces.LocalMode;
 import ui.controller.SingletonControl;
 import ui.view.IndexTranslator;
 import ui.view.UnitGraph;
@@ -19,7 +19,7 @@ import ui.view.UnitGraph;
  * @author Gruppe14
  *
  */
-public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, GraphEditable {
+public class HolonSwitch extends AbstractCpsObject implements LocalMode, GraphEditable {
 
 	/**
 	 * The class HolonSwitch represents an Object in the system, that has the
@@ -51,7 +51,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	int localPeriod;
 	
 	@Expose
-	boolean stretch;
+	boolean localPeriodActive;
 
 	/*
 	 * Energy at each point of the graph with 50 predefined points. At the
@@ -70,12 +70,8 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	 */
 	public HolonSwitch(String objName) {
 		super(objName);
-		setStretching(IGraphedElement.STRETCH_BY_DEFAULT);
-		activeAt=new boolean[IGraphedElement.STANDARD_GRAPH_ACCURACY];
-		setLocalPeriod(SingletonControl.getInstance().getControl()==null?
-				IGraphedElement.STANDARD_GRAPH_ACCURACY:
-				SingletonControl.getInstance().getControl().getModel().getGraphIterations()
-		);
+		setUseLocalPeriod(false);
+		activeAt=new boolean[LocalMode.STANDARD_GRAPH_ACCURACY];
 		setManualState(true);
 		setAutoState(true);
 		setManualMode(false);
@@ -95,12 +91,11 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 		System.out.println("SwitchCopy?");
 		HolonSwitch copyObj = (HolonSwitch)obj;
 		setLocalPeriod(copyObj.getLocalPeriod());
-		setStretching(copyObj.isStretching());
-		activeAt=new boolean[IGraphedElement.STANDARD_GRAPH_ACCURACY];
+		setUseLocalPeriod(copyObj.isUsingLocalPeriod());
+		activeAt=new boolean[LocalMode.STANDARD_GRAPH_ACCURACY];
 		super.setName(obj.getName());
 		setManualState(copyObj.getActiveManual());
 		setAutoState(true);
-		setLocalPeriod(((IGraphedElement)obj).getLocalPeriod());
 		setGraphPoints(new LinkedList<Point2D.Double>());
 		for (Point2D.Double p : copyObj.getGraphPoints()) {
 			this.graphPoints.add(new Point2D.Double(p.getX(),p.getY()));
@@ -139,19 +134,6 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 		}
 	}
 
-	/**
-	 * Overall status of the switch (manual or automatic mode).
-	 * 
-	 * @return boolean the State
-	 */
-	public boolean getState() {//TODO: not really necessary
-		if (manualMode) {
-			return this.manualActive;
-		} else {
-			return this.autoActive;
-		}
-
-	}
 
 	/**
 	 * Change the state of the Switch to manual.
@@ -168,7 +150,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	 * 
 	 * @param state the State
 	 */
-	public void setAutoState(boolean state) {//TODO: This should probably not be public
+	public void setAutoState(boolean state) {
 		this.autoActive = state;
 		setImage();
 	}
@@ -209,7 +191,9 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	public void setGraphPoints(LinkedList<Double> linkedList) {
 		this.graphPoints = linkedList;
 	}
-	//TODO: javadoc
+	/**
+	 * Initialize the Graph as a closed Switch.
+	 */
 	private void initGraphPoints()
 	{
 		graphPoints.clear();
@@ -225,7 +209,14 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 		return this.manualActive;
 	}
 
-
+	/**
+	 * Returns the autoActive.
+	 * 
+	 * @return boolean autoActive
+	 */
+	public boolean getAutoActive() {
+		return autoActive;
+	}
 	
 	/**
 	 * Set the overall value of the Switch (manual mode).
@@ -246,26 +237,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 		return manualMode;
 	}
 
-	@Override
-	public void setLocalPeriod(int period) {
-		localPeriod=period;
-	}
-
-	@Override
-	public int getLocalPeriod() {
-		return localPeriod;
-	}
-
-	@Override
-	public boolean isStretching() {
-		return stretch;
-	}
-
-	@Override
-	public void setStretching(boolean stretch) {
-		this.stretch=stretch;
-	}
-
+	//interfaces.GraphEditable
 	@Override
 	public Graphtype getGraphType() {
 		return Graphtype.boolGraph;
@@ -275,7 +247,22 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 	public LinkedList<Double> getStateGraph() {
 		return graphPoints;
 	}
+	
 
+	@Override
+	public void reset() {
+		initGraphPoints();
+		sampleGraph();
+	}
+	@Override
+	public void sampleGraph() {
+		activeAt = sampleGraph(100);
+	}
+	/**
+	 * Generate out of the Graph Points a array of boolean that represent the Curve("on or off"-Graph) at each sample position. The Values are in the Range [0,1].
+	 * @param sampleLength amount of samplePositions. The positions are equidistant on the Range[0,1].
+	 * @return the boolean array of samplepoints.
+	 */
 	private boolean[] sampleGraph(int sampleLength)
 	{
 		ListIterator<Point2D.Double> iter = this.graphPoints.listIterator();
@@ -294,14 +281,25 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement, G
 		}
 		return activeTriggerPos;
 	}
+	
+	//interfaces.LocalMode
 	@Override
-	public void sampleGraph() {
-		activeAt = sampleGraph(100);
+	public void setLocalPeriod(int period) {
+		localPeriod=period;
 	}
-
+	
 	@Override
-	public void reset() {
-		initGraphPoints();
-		sampleGraph();
+	public int getLocalPeriod() {
+		return localPeriod;
+	}
+	
+	@Override
+	public boolean isUsingLocalPeriod() {
+		return localPeriodActive;
+	}
+	
+	@Override
+	public void setUseLocalPeriod(boolean state) {
+		this.localPeriodActive=state;
 	}
 }

+ 6 - 10
src/interfaces/IGraphedElement.java → src/interfaces/LocalMode.java

@@ -1,8 +1,7 @@
 package interfaces;
 
-public interface IGraphedElement {
+public interface LocalMode {
 	
-	public static final boolean STRETCH_BY_DEFAULT=false;
 	public static final int STANDARD_GRAPH_ACCURACY=100;
 	/**
 	 * Sets the local period of the element. 
@@ -24,16 +23,13 @@ public interface IGraphedElement {
 	int getLocalPeriod();
 	
 	/**
-	 * @return Whether the given graph points
-	 * should be stretched(or compressed) over the entire simulation.
-	 * as opposed to repeated once the period is over.
+	 * @return true when using his own local Period.
 	 */
-	boolean isStretching();
+	boolean isUsingLocalPeriod();
 	
 	/**
-	 * Adjusts whether the element should act
-	 * as if local period was the same as the simulation's number of iterations.
-	 * @param stretch
+	 *  Determine if it should use his own LocalPeriod or use the global Period over the entire simulation.
+	 * 	Local Period is opposed to repeated once the period is over.
 	 */
-	void setStretching(boolean stretch);
+	void setUseLocalPeriod(boolean state);
 }

+ 96 - 71
src/ui/view/GUI.java

@@ -7,6 +7,8 @@ import com.google.gson.JsonObject;
 import com.google.gson.JsonParseException;
 
 import interfaces.CategoryListener;
+import interfaces.GraphEditable;
+import interfaces.LocalMode;
 
 import org.apache.commons.compress.archivers.ArchiveException;
 
@@ -17,10 +19,12 @@ import ui.model.Model;
 import ui.view.NewPopUp.Option;
 
 import javax.swing.*;
+import javax.swing.border.Border;
 import javax.swing.border.LineBorder;
 import javax.swing.event.AncestorEvent;
 import javax.swing.event.AncestorListener;
 import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.plaf.ColorUIResource;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.JTableHeader;
 import javax.swing.table.TableCellEditor;
@@ -139,7 +143,6 @@ public class GUI implements CategoryListener {
 	private final JLabel medGraph = new JLabel("50%");
 	private final JLabel minGraph = new JLabel("0%");
 	private final JLabel elementGraph = new JLabel("None ");
-	private final JLabel unitGraphLocalPeriodLbl = new JLabel("Local Period:");
 	private final ArrayList<HolonElement> selectedElements = new ArrayList<>();
 	private final JTree tree = new JTree();
 	/******************************************
@@ -184,7 +187,14 @@ public class GUI implements CategoryListener {
 		}
 
 	};
-
+	//Prechoosed local Periods
+	private String[] comboContext = {
+	         "", "5", "10", "20" ,"100", "1000"
+	};
+	private JComboBox<String> localPeriodInput = new JComboBox<String>(comboContext);
+	JButton resetButton = new JButton("", new ImageIcon(Util.loadImage("/Images/resetIcon3.png")));
+	ImageIcon localPeriodButtonImage = new ImageIcon(GrayFilter.createDisabledImage(Util.loadImage("/Images/Graph.png")));
+	private JButton localPeriodButton = new JButton("", localPeriodButtonImage);
 	private final JPanel graphLabel = new JPanel();
 	private final JScrollPane scrollProperties = new JScrollPane();
 	// In this section is the graph for the selected HolonElement of the clicked
@@ -199,7 +209,6 @@ public class GUI implements CategoryListener {
 	// HolonObject with consumption/production, name and amount.
 	private final JPanel panel = new JPanel();
 	private final JPanel panelHolonEl = new JPanel();
-	private final JComboBox comboBox = new JComboBox();
 	// Buttons
 
 	private final JButton btnAdd = new JButton("New");
@@ -223,15 +232,12 @@ public class GUI implements CategoryListener {
 	private final JMenuItem germanBtn = new JMenuItem("DE");
 	private final JMenuItem czechBtn = new JMenuItem("CZ");
 	private final JMenuItem chineseBtn = new JMenuItem("ZH");
-	// private final JComboBox comboBoxGraph = new JComboBox();
 	private final Console console = new Console();
 	private final MyCanvas canvas;
 	private final HolonCanvas holonCanvas;
 	private final UnitGraph unitGraph;
 	/** Textfield to show the period of an element */
 	private final JTextField unitGraphLocalPeriod = new JTextField(6);
-	private final JCheckBox unitGraphStretchMode=new JCheckBox();
-	private final JLabel unitGraphStretchModeLbl=new JLabel("  Use global:  ");//Some padding
 	private final JSplitPane splitPane3 = new JSplitPane();
 	private final JSlider sizeSlider = new JSlider();
 	private final JLabel lblImageSize = new JLabel(Languages.getLanguage()[94]);
@@ -1148,48 +1154,44 @@ public class GUI implements CategoryListener {
 		graphLabel.add(medGraph, BorderLayout.CENTER);
 		graphLabel.add(minGraph, BorderLayout.SOUTH);
 
-		GridBagLayout gbl=new GridBagLayout();
-		toolBarGraph.setLayout(gbl);
-		GridBagConstraints c=new GridBagConstraints();
-		c.weightx=0;
-		gbl.setConstraints(lblSelectedElement, c);
-		//TODO here
-		toolBarGraph.add(lblSelectedElement);
-		c.gridwidth=GridBagConstraints.REMAINDER;
-		gbl.setConstraints(elementGraph, c);
-		toolBarGraph.add(elementGraph/*, BorderLayout.AFTER_LINE_ENDS*/);//TODO
 		
-		//Component horizontalStrut = Box.createHorizontalStrut(20);
-		/*
-		Component horizontalStrut = Box.createHorizontalStrut(toolBarGraph
-				.getWidth() - resetGraphBtn.getWidth() - unitGraphLocalPeriod.getWidth()
-				-unitGraphLocalPeriodLbl.getWidth());
-
-		*/
-		//toolBarGraph.add(horizontalStrut);//What is this for?
-
-		/** Add local Graph length Textfield an Label */
-		unitGraphLocalPeriod.setPreferredSize(new Dimension(30, 20));//TODO
 		
-		c.gridwidth=GridBagConstraints.NORTHWEST;
-		gbl.setConstraints(unitGraphLocalPeriodLbl, c);
-		toolBarGraph.add(unitGraphLocalPeriodLbl);//TODO
-		//unitGraphLocalPeriodLbl.setHorizontalAlignment(SwingConstants.RIGHT);
-		gbl.setConstraints(unitGraphLocalPeriod, c);
-		toolBarGraph.add(unitGraphLocalPeriod);//TODO
-		gbl.setConstraints(unitGraphStretchModeLbl, c);
-		toolBarGraph.add(unitGraphStretchModeLbl);//TODO
-		//unitGraphStretchModeLbl.setHorizontalAlignment(SwingConstants.RIGHT);
-		gbl.setConstraints(unitGraphStretchMode, c);
-		toolBarGraph.add(unitGraphStretchMode);//TODO
-		//unitGraphStretchMode.setHorizontalAlignment(SwingConstants.RIGHT);
-		gbl.setConstraints(resetGraphBtn, c);
-		//resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
-		toolBarGraph.add(resetGraphBtn);//TODO
-		unitGraphStretchMode.addActionListener(e ->
-			{unitGraph.setStretching(unitGraphStretchMode.isSelected());}
-		);
+		
+		
 		toolBarGraph.setFloatable(false);
+		toolBarGraph.setAlignmentY(Component.RIGHT_ALIGNMENT);	
+		
+		
+		localPeriodButton.setToolTipText("Toggle Local/Global Mode");
+		toolBarGraph.add(localPeriodButton);
+		//ComboBox
+		localPeriodInput.setEditable(true);
+		localPeriodInput.setVisible(false);
+		localPeriodInput.setMaximumSize(new Dimension(20,23));
+		localPeriodInput.addItemListener(aListener->{
+			if(aListener.getStateChange() == ItemEvent.DESELECTED) {
+				validateInput(localPeriodInput.getEditor().getItem().toString(), true);
+			}
+			
+		});
+		
+		toolBarGraph.add(localPeriodInput);
+				
+		//localPeriodButtonFunction
+		localPeriodButton.addActionListener(actionEvent->{
+			boolean newState= !localPeriodInput.isVisible();
+			changeLocalPeriodButtonAppeareance(newState);
+			unitGraph.setUseLocalPeriod(newState);
+		});
+		
+		
+		toolBarGraph.add(Box.createHorizontalGlue());
+		resetButton.setToolTipText("Reset");
+		resetButton.addActionListener(actionEvent ->  unitGraph.reset());
+		toolBarGraph.add(resetButton);
+		
+		
+		
 		
 		
 		scrollGraph.setRowHeaderView(graphLabel);
@@ -1309,7 +1311,7 @@ public class GUI implements CategoryListener {
 							} else {
 								holonEleNamesDisplayed = ele.getEleName() + " ";
 							}
-							repaintGraphAux(selectedElements);
+							updateUnitGraph((GraphEditable)selectedElements.get(selectedElements.size()-1));
 						}
 						updCon.getActualHolonElement(null, yValueElements, 2,
 								tables);
@@ -1321,7 +1323,7 @@ public class GUI implements CategoryListener {
 						updCon.getActualHolonElement(null, yValueElements, 1,
 								tables);
 						holonEleNamesDisplayed = ele.getEleName() + " ";
-						repaintGraphAux(selectedElements);
+						updateUnitGraph((GraphEditable)selectedElements.get(selectedElements.size()-1));
 					}
 				} else {
 					elementGraph.setText(Languages.getLanguage()[25]);
@@ -1372,7 +1374,6 @@ public class GUI implements CategoryListener {
 		 */
 		model.getTableHolonElement()
 				.addPropertyChangeListener(propertyChangeEvent -> {
-					System.out.println("GUI->getTableHolonElement");
 					try {
 						int yMouse = yThis;
 						int yBMouse = yBTis;
@@ -1677,11 +1678,6 @@ public class GUI implements CategoryListener {
 		/***********************
 		 * HolonElement Graph Actions
 		 **********************/
-		/*
-		 * Reset the graph of the selected HolonElement
-		 */
-		resetGraphBtn.setBorder(new LineBorder(Color.BLACK));
-		resetGraphBtn.addActionListener(actionEvent -> unitGraph.reset());
 		
 		/*
 		 * Update Local Period of an Element Graph
@@ -2030,11 +2026,6 @@ public class GUI implements CategoryListener {
 		toolBar.setFloatable(false);
 
 		panel.add(toolBar);
-		comboBox.setMaximumSize(new Dimension(100, 20));
-		//toolBar.add(comboBox);
-		//comboBox.setModel(new DefaultComboBoxModel(comboBoxCat));
-		// Add Buttonnew DefaultComboBoxModel(comboBoxCat)
-		//TODO: Add functionalyty
 		btnAddPopUp.add(mItemNew);
 		mItemNew.addActionListener(actionEvent -> {
 			new NewPopUp(controller, frmCyberPhysical);
@@ -2148,7 +2139,7 @@ public class GUI implements CategoryListener {
 				}
 				if (temp instanceof HolonSwitch) {
 					showScrollGraph();
-					repaintGraphAux((HolonSwitch)temp);
+					updateUnitGraph((GraphEditable)temp);
 				}
 				// Write new data in the PropertyTable
 				triggerUpdateController(temp);
@@ -2551,7 +2542,6 @@ public class GUI implements CategoryListener {
 	}
 
 	private void hideScrollGraph() {
-		System.out.println("GUI->hideScrollGraph");
 		scrollGraph.setVisible(false);
 		splitGraphHolonEl.remove(scrollGraph);
 		splitGraphHolonEl.setDividerLocation(0);
@@ -2854,7 +2844,7 @@ public class GUI implements CategoryListener {
 						openNewUpperNodeTab();
 					}
 					if (temp instanceof HolonSwitch) {
-						repaintGraphAux((HolonSwitch)temp);
+						updateUnitGraph((GraphEditable)temp);
 					}
 				}
 
@@ -3076,19 +3066,54 @@ public class GUI implements CategoryListener {
 			contentPane.requestFocus();
 		}
 	}
-	private void repaintGraphAux(ArrayList<HolonElement> o){//TODO: 
-		//TODO -> just in Progress 
-		unitGraph.initNewElement(o.get(o.size()-1));
-//		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
-//		unitGraphStretchMode.setSelected(unitGraph.isStretching());
+	/**
+	 * This Method updates the UnitGraph, saves the old LocalModeState and load the new LocalModeState.
+	 * @param element The new Element to load the UnitGraph
+	 */
+	private void updateUnitGraph(GraphEditable element){
+		//SaveOld LocalMode State.
+		if(localPeriodInput.isVisible())
+		{
+			//Save Old State
+			validateInput(localPeriodInput.getEditor().getItem().toString(), false);
+		}
+		//Update UnitGraph
+		unitGraph.initNewElement(element);
+		//Load LocalMode State.
+		changeLocalPeriodButtonAppeareance(unitGraph.isUsingLocalPeriod());
+		localPeriodInput.getEditor().setItem(unitGraph.getLocalPeriod());
 	}
 	
-	private void repaintGraphAux(HolonSwitch o){//TODO: 
-		unitGraph.initNewElement(o);
-//		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
-//		unitGraphStretchMode.setSelected(unitGraph.isStretching());
+	/**
+	 * Displayed the actual LocalModeState.
+	 * @param enabled
+	 */
+	private void changeLocalPeriodButtonAppeareance(boolean enabled) {
+		localPeriodInput.setVisible(enabled);
+		if(enabled)
+		{
+			localPeriodButtonImage.setImage(Util.loadImage("/Images/Graph.png"));
+		}else {
+			localPeriodButtonImage.setImage(GrayFilter.createDisabledImage(Util.loadImage("/Images/Graph.png")));
+		}
 	}
-
+	/**
+	 * Validate the LocalMode Input and when its valid save on the Element.
+	 * @param text the inputText to validate. 
+	 * @param bShowMessage when true, open a MessageDialog when text invalid.
+	 */
+	private void validateInput(String text, boolean bShowMessage) {
+		int localPeriodInputValue;
+		try {
+		      localPeriodInputValue = Integer.parseInt(text);
+		} catch (NumberFormatException e) {
+			if(bShowMessage)
+				JOptionPane.showMessageDialog(contentPane, '"' +text + '"'+ " is not a valid Input. \n Use whole numbers.");
+			return;
+		}
+		unitGraph.setLocalPeriod(localPeriodInputValue);
+	}
+	
 	public void updateIterations() {
 		this.statSplitPane.updateIterations();
 	}

+ 6 - 6
src/ui/view/IndexTranslator.java

@@ -1,6 +1,6 @@
 package ui.view;
 
-import interfaces.IGraphedElement;
+import interfaces.LocalMode;
 import ui.controller.SingletonControl;
 import ui.model.Model;
 
@@ -17,9 +17,9 @@ public class IndexTranslator {
      * @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();
+    public static int getEffectiveIndex(Model m, LocalMode e, int timeStep){
+    	if(e.isUsingLocalPeriod())return timeStep%e.getLocalPeriod()*100/e.getLocalPeriod();
+    	else return timeStep*100/(m==null?STANDARD_GRAPH_ACCURACY:m.getIterations());
     }
     
     /**
@@ -27,7 +27,7 @@ public class IndexTranslator {
      * 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){
+    public static int getEffectiveIndex(LocalMode e, int timeStep){
     	return getEffectiveIndex(SingletonControl.getInstance().getControl()==null ? null : SingletonControl.getInstance().getControl().getModel(),e,timeStep);
     }
     
@@ -35,7 +35,7 @@ public class IndexTranslator {
      * Same as getEffectiveIndex(Model, IGraphedElement),
      * but the current iteration is also obtained from the standard model.
      */
-    public static int getEffectiveIndex(IGraphedElement e){
+    public static int getEffectiveIndex(LocalMode e){
     	return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration());
     }
 }

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

@@ -454,7 +454,7 @@ public class StatisticGraph extends JPanel {
                 case TrackedDataSet.AMOUNT_BROKEN_EDGES:
                     for (SubNet sub : controller.getSimManager().getSubNets()) {
                         for (HolonSwitch s : sub.getSwitches()) {
-                            if (s.getState()) {
+                            if (s.getManualMode()?s.getActiveManual():s.getAutoActive()) {
                                 val++;
                             }
                         }

+ 285 - 125
src/ui/view/UnitGraph.java

@@ -4,7 +4,7 @@ import classes.*;
 import classes.comparator.UnitGraphPointComperator;
 import interfaces.GraphEditable;
 import interfaces.GraphEditable.Graphtype;
-import interfaces.IGraphedElement;
+import interfaces.LocalMode;
 import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 import ui.controller.Control;
 import ui.controller.SingletonControl;
@@ -82,10 +82,23 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         this.addMouseMotionListener(this);
         this.addComponentListener(this);
     }
-
     /**
-     * Paints all Components on the Canvas.
-     *
+     * When the UnitGraph should represent a new GraphEditable Element.
+     * Its Updates the Graph and give access to the Element.
+     * @param element
+     */
+    public void initNewElement(GraphEditable element)
+    {
+    	overrideUnitGraph(element.getStateGraph());
+    	actualGraphType = element.getGraphType();
+    	actualElement = element;
+    	repaint();
+    }
+    
+    
+    
+    /**
+     * Paints the Graph, the Grid, the actual Line fro the currentIteration
      * @param g Graphics
      */
     public void paintComponent(Graphics g) {
@@ -109,6 +122,60 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         drawCurrentIterartionLine(g2D);
     }
 
+    // Draw Methods only to let the User see the changes. Nothing its saved here or changed.
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Methods draws the UnitGraph whether its a boolGraph or a doubleGraph.
+     * @param g to draw.
+     */
+    private void drawUnitGraph(Graphics2D g) {
+    	switch(actualGraphType) {
+    	case boolGraph:
+    		if(editMode)
+    			drawBoolGraphInEditMode(g);
+    		else
+    			drawBoolGraph(g);
+    		break;
+    	case doubleGraph:
+    		if(editMode)
+    			drawDoubleGraphInEditMode(g);
+    		else
+    			drawDoubleGraph(g);
+    		break;
+    	default:
+    		throw new UnsupportedOperationException();
+    	}
+    }
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Methods draws the UnitGraphPoints of the UnitGraph.
+     * @param g to draw.
+     */
+    private void drawUnitGraphPoints(Graphics2D g) {
+    	g.setColor(dotColor);
+    	for(UnitGraphPoint p : actualGraphPoints){
+    		drawDot(g, p.displayedPosition);
+    	}
+    }
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Methods draws the UnitGraphPoints of the UnitGraph when its in EditMode.
+     * @param g to draw.
+     */
+    private void drawUnitGraphPointsReleased(Graphics2D g) {
+    	drawUnitGraphPoints(g);
+    	g.setColor(editDotColor);
+    	drawDot(g, editPosition);
+    }
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Methods draws the Grid on the Canvas.
+     * @param g2D to draw.
+     */
 	private void drawGrid(Graphics2D g2D) {
         g2D.setStroke(new BasicStroke(1));
         g2D.setColor(Color.lightGray);
@@ -122,16 +189,39 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
         }
 	}
     
+	 /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws the CurrentIterationLine.
+     * @param g2D to draw.
+     */
     private void drawCurrentIterartionLine(Graphics2D g)
     {
     	int cur = model.getCurIteration();
     	int max = model.getIterations();
-    	double where = ((double) cur)/((double) max - 1);
+    	double where;
+    	if(!this.isUsingLocalPeriod()) {
+    		where = ((double) cur)/((double) max);
+    	}
+    	else
+    	{
+    		int lPeriod = this.getLocalPeriod();
+    		where = ((double) cur%lPeriod)/((double) lPeriod);
+    	}
     	Position oben = new Position(border + (int)(where * widthWithBorder), 0);
     	Position unten = new Position(border + (int)(where * widthWithBorder), 2 * border + heightWithBorder);
     	drawLine(g,oben,unten);
+    	
     }
     
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws a line between two Positions on the Canvas.
+     * @param g2D to draw.
+     * @param start the Position of one end of the line to draw. 
+     * @param end the other Ends Position of the Line to draw.
+     */
     private void drawLine(Graphics2D g, Position start, Position end)
     {
     	Path2D.Double path = new Path2D.Double();
@@ -140,6 +230,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	g.draw(path);
     }
     
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * Initialize a Cubic BezierCurve.
+     * @param start The Position to start the Curve.
+     */
     private Path2D.Double initBezier(Position start) {
     	//Good Source for basic understanding for Bezier Curves
         //http://www.theappguruz.com/blog/bezier-curve-in-games
@@ -147,56 +243,38 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	path.moveTo(start.x, start.y);
 		return path;
     }
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * Calculate the Path of a the Cubic BezierCurve with the special controlPoints to make the wanted behavior.
+     * @param path the path of the Bezier.
+     * @param actaul the actual Position of the Path.
+     * @param target the end Position of the Curve.
+     */
     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);
     }
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * Draws a Dot at a Position.
+     * @param g to draw.
+     * @param p the position of the Dot.
+     */
     private void drawDot(Graphics2D g, Position p)
     {    	
     	g.fillOval(p.x -dotSize/2, p.y-dotSize/2, dotSize, dotSize);
     }
-    private void drawUnitGraph(Graphics2D g) {
-    	switch(actualGraphType) {
-		case boolGraph:
-			if(editMode)
-				drawBoolGraphWithEditPosition(g);
-			else
-				drawBoolGraph(g);
-			break;
-		case doubleGraph:
-			if(editMode)
-				drawDoubleGraphWithEditPosition(g);
-			else
-				drawDoubleGraph(g);
-			break;
-		default:
-			throw new UnsupportedOperationException();
-    	}
-    }
-    private void drawUnitGraphPoints(Graphics2D g) {
-    	g.setColor(dotColor);
-    	for(UnitGraphPoint p : actualGraphPoints){
-    		drawDot(g, p.displayedPosition);
-    	}
-    }
     
-	private void saveGraph() {
-		LinkedList<Point2D.Double> actual = actualElement.getStateGraph();
-		actual.clear();
-		for(UnitGraphPoint p: actualGraphPoints)
-		{
-			actual.add(p.getPoint());
-		}
-		actualElement.sampleGraph();
-	}
-    private void drawUnitGraphPointsReleased(Graphics2D g) {
-    	drawUnitGraphPoints(g);
-    	g.setColor(editDotColor);
-		drawDot(g, editPosition);
-    }
     
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws the UnitGraph as BoolGraph.
+     * @param g2D to draw.
+     */
     private void drawBoolGraph(Graphics2D g) {
-    	System.out.println("DoImplement");
     	if(actualGraphPoints.size() <= 1) return;
     	LinkedList<Position> cornerPoints =  new LinkedList<Position>();
      	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
@@ -222,8 +300,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      	}
      	
     }
-    
-    private void drawBoolGraphWithEditPosition(Graphics2D g) {
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws the UnitGraph as BoolGraph in EditMode.
+     * @param g2D to draw.
+     */
+    private void drawBoolGraphInEditMode(Graphics2D g) {
     	LinkedList<Position> before = new LinkedList<Position>();
      	LinkedList<Position> after = new LinkedList<Position>();
      	for(UnitGraphPoint p: actualGraphPoints)
@@ -248,6 +331,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	drawSnappingHint(g);
     }
     
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws a red Hint to signal the User the snapping of the hovered Point under the Cursor in EditMode.
+     * @param g2D to draw.
+     */
     private void drawSnappingHint(Graphics2D g)
     {
     	//ColorHint
@@ -266,7 +355,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     
     
     
-    
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws a partial Graph from a Position List as BoolGraph.
+     * @param g2D to draw.
+     * @param list the PositionList to draw a BoolGraph
+     */
 	private void drawBoolGraphFromList(Graphics2D g, LinkedList<Position> list) {
 		if(list.size() <= 1) return;
      	ListIterator<Position> iter = list.listIterator();
@@ -291,7 +386,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      	}
 	}
     
-    
+	  /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws the UnitGraph as DoubleGraph.
+     * @param g2D to draw.
+     */
     private void drawDoubleGraph(Graphics2D g) {
     	if(actualGraphPoints.isEmpty()) throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
     	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
@@ -306,7 +406,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	g.draw(path);
     	
     }
-    private void drawDoubleGraphWithEditPosition(Graphics2D g) {
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws the UnitGraph as DoubleGraph in EditMode.
+     * @param g2D to draw.
+     */
+    private void drawDoubleGraphInEditMode(Graphics2D g) {
      	LinkedList<Position> before = new LinkedList<Position>();
      	LinkedList<Position> after = new LinkedList<Position>();
      	for(UnitGraphPoint p: actualGraphPoints)
@@ -327,7 +433,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	g.setColor(editDotColor);
     	drawUnitGraphFromList(g, middle);
     }
-
+    
+    /**
+     * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
+     * <p>
+     * This Method draws a partial Graph from a Position List as DoubleGraph.
+     * @param g2D to draw.
+     * @param list the PositionList to draw a DoubleGraph
+     */
 	private void drawUnitGraphFromList(Graphics2D g, LinkedList<Position> list) {
 		if(list.size() <= 1) return;
      	ListIterator<Position> iter = list.listIterator();
@@ -342,15 +455,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      	g.draw(path);
 	}
   
-    
-    
+    //Under the hood functions to calculate and function the 
+    /**
+     * A unitgraphpoint have a x and y position to store the data of a graph point.
+     * Also it have a displayposition to store the Position of the GraphPoints on the Canvas. 
+     * e.g. when the canvas has 500 width and 200 height a GraphPoint with the X=0.5 and Y=1.0 should have a displayposition of (250,3) when border is 3.
+     */
     private void updateRepresentativePositions()
     {
     	for(UnitGraphPoint p : actualGraphPoints) {
     		p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
     	}
     }
-    
+    /**
+     * Takes a List of GraphPoints and convert it to the actual UnitGraphPoints with displayposition in the {@link #actualGraphPoints}
+     * @param stateCurve the list of GraphPoint
+     */
     private void overrideUnitGraph(LinkedList<Point2D.Double> stateCurve) {
     	actualGraphPoints.clear();
     	for(Point2D.Double p: stateCurve){
@@ -358,21 +478,32 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	}
     	updateRepresentativePositions();
     }
+    
+    /**
+     * When the PanelSize Change the width and height to calculate the drawings have to be adjusted.
+     */
     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();
+    /**
+     * Save the actualGraphPoint List to the GraphEditable Element.
+     */
+    private void saveGraph() {
+    	LinkedList<Point2D.Double> actual = actualElement.getStateGraph();
+    	actual.clear();
+    	for(UnitGraphPoint p: actualGraphPoints)
+    	{
+    		actual.add(p.getPoint());
+    	}
+    	actualElement.sampleGraph();
     }
-    
-    
+    /**
+     * Remove a UnitGraphPoint from the UnitGraphPoint list ({@link #actualGraphPoints} when its near a given Position.
+     * @param mPosition
+     */
     private void removePointNearPosition(Position mPosition) {
     	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
     	while (iter.hasNext())
@@ -385,6 +516,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	}
     }
     
+    
+    /**
+     * Determine if the Point is a StartPoint , EndPoint or a NormalPoint a.k.a. in between Points.
+     * @param mPosition The Position to check.
+     */
     private void  detectStartEndPoint(Position mPosition)
     {
     	UnitGraphPoint first = actualGraphPoints.getFirst();
@@ -394,6 +530,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	else editPoint = pointType.Normal;
     }
 
+    /**
+     * Determine if a Point is near the Cursor (depends on Mode what near means). To detect if it should grab the Point or create a new Point. 
+     * @param actual
+     * @param target
+     * @return
+     */
 	private boolean near(Position actual, Position target) {
 		switch(actualGraphType)
 		{
@@ -407,6 +549,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		}	
 	}
     
+	/**
+	 * When the Mouse Drag a Point it updates each time the position.
+	 * @param newPosition
+	 */
     private void updateEditPointPosition(Position newPosition) {
     	//make it in the bounds of the UnitGraph no Point out of the Border
     	Position currentPosition = setInBounds(newPosition);
@@ -415,6 +561,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     	this.editPosition = currentPosition;
     }
     
+    
+    /**
+     * No Point on the UnitGraph should exit the UnitGraph.
+     * @param p the Position
+	 * @return the updated Position.
+     */
 	private Position setInBounds(Position p) {
 		p.clampX(border, border + widthWithBorder);
 		p.clampY(border, border + heightWithBorder);
@@ -422,6 +574,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	}
     
 	
+	
+	/**
+	 * For Switches the Point have to be Snap to the Top or the Bottem.
+	 * @param p the Position
+	 * @return the updated Position.
+	 */
 	private Position snapBoolean(Position p)
 	{
 		if (p.y < border + heightWithBorder / 2) {
@@ -433,55 +591,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	}
 	
 	
-	private Point.Double getBezierPoint(double t, Point.Double p0, Point.Double p1,Point.Double p2,Point.Double p3) {
-    	/*
-    	 * Calculate Beziér:
-    	 * B(t) = (1-t)^3 * P0 + 3*(1-t)^2 * t * P1 + 3*(1-t)*t^2 * P2 + t^3 * P3 , 0 < t < 1
-    	 * 
-    	 * Source: //http://www.theappguruz.com/blog/bezier-curve-in-games
-    	 */
-		Point.Double bezier = new Point.Double();
-		double OneSubT =  1-t;
-		double OneSubT2 = Math.pow(OneSubT, 2);
-		double OneSubT3 = Math.pow(OneSubT, 3);
-		double t2 = Math.pow(t , 2);
-		double t3 = Math.pow(t , 3);
-	
-		bezier.x = OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x;
-		bezier.y = OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y;
-		return bezier;
-		
-	}
-	private double getYBetweenTwoPoints(double t, Point.Double start, Point.Double end) {
-		
-	    double mitte = (start.x + end.x)* 0.5;
-	    Point.Double bezier = getBezierPoint(t, start, new Point.Double(mitte, start.y), new Point.Double(mitte, end.y), end);
-		return bezier.y;
-	}
-	
-	private float[] sampleGraph(int sampleLength)
-	{		
-		ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
-		Point.Double before = iter.next().getPoint();
-		Point.Double after = iter.next().getPoint();
-		float [] sampleCurve = new float[sampleLength];	
-		for(int i = 0; i<sampleLength ; i++)
-		{
-			double graphX = (double)i / (double) (sampleLength - 1); //from 0.0 to 1.0
-			if(graphX > after.x)
-			{
-				before = after;
-				after = iter.next().getPoint();
-			}
-			//inverseLerp(valueBetween, min, max) (valueBetween - min) / (max - min)
-			// e.g. old.x = 0.4, actual.x = 0.8 and graphX = 0.6 then t is 0.5
-			double t = (after.x -before.x > 0)? (graphX - before.x) / (after.x -before.x) : 0.0;			
-			sampleCurve[i] = (float) getYBetweenTwoPoints(t, before, after);
-		}
-		return sampleCurve;
-	}
-	
-	
+	/**
+	 * The First Point has to be at 0(LeftSide) and Last Point has to be at 1(RightSide).  
+	 * @param p the Position
+	 * @return the updated Position.
+	 */
 	private Position attachToBorder(Position p)
 	{
 		switch(editPoint)
@@ -497,9 +611,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		}
 		return p;
 	}
+	/**
+	 * Insert a Position in the UnitGraphList at the right order.
+	 * Its sorted based on the xValues.
+	 * @param pos The new UnitGraphPoints Position
+	 */
     private void insertNewGraphPoint(Position pos)
     {
-    	System.out.println("insertNewGraphPoint");
     	setInBounds(pos);
     	ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
     	while (iter2.hasNext())
@@ -518,7 +636,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     		iter2.add(generateUnitGraphPoint(pos));
     	}
     }
-
+    /**
+     * Generate a UnitGraphPoint from a normal Position in the UnitGraph.
+     * @param pos the normal pos with xValues from 0..Width and yValues from 0..Height
+     * @return a UnitGraphPoint
+     */
 	private UnitGraphPoint generateUnitGraphPoint(Position pos) {
 		UnitGraphPoint temp = new UnitGraphPoint((double) (pos.x - border) / (double) widthWithBorder,
 				1 - (double) (pos.y - border) / (double) heightWithBorder, true);
@@ -526,10 +648,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		return temp;
 	}
 
-    
+    /**
+     * Update the Point Position 
+     */
 	@Override
     public void mouseDragged(MouseEvent e) {
-    	System.out.println("MouseDragged");
     	updateEditPointPosition(new Position(e.getPoint()));
     	repaint();
     }
@@ -550,9 +673,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     public void mouseExited(MouseEvent e) {
     }
 
+    /**
+     * The First Step.
+     * When LeftMouseButton its checks if a point is to grab under the cursor or create a new Point. Then enter EditMode.
+     * When RightMouseButton its delete a point if its under the Curser.
+     */
     @Override
     public void mousePressed(MouseEvent e) {
-		System.out.println("mousePressed");
 		Position mPosition = new Position(e.getPoint());
 		if (e.getButton() == MouseEvent.BUTTON3) {
 			// RightMouseButtonEvent
@@ -573,9 +700,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		}
 	}
 
+    /**
+     * The last step to save the Changes.
+     * Its insert the Hovering Point and exit EditMode.
+     */
     @Override
     public void mouseReleased(MouseEvent e) {
-    	System.out.println("mouseReleased");
     	if(editMode)
     	{
     		this.insertNewGraphPoint(editPosition);
@@ -591,7 +721,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
      * @param e ComponentEvent
      */
     public void componentResized(ComponentEvent e) {
-    	System.out.println("componentResized");
     	calculateWidthHeight();
     	updateRepresentativePositions();
         repaint();
@@ -610,8 +739,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
     public void componentShown(ComponentEvent e) {
     }
 
+    /**
+     * Resets the graph to normal.
+     */
     public void reset() {
-       	System.out.println("reset");
        	if(this.actualElement != null) {
        		actualElement.reset();
        		overrideUnitGraph(actualElement.getStateGraph());
@@ -620,23 +751,52 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
        	
     }
 
-    public void update(ArrayList<AbstractCpsObject> obj) {
-    	System.out.println("update");
-    }
 
-	public void setStretching(boolean selected) {
-		System.out.println("setStretching");
+    
+    //LocalMode access methods...
+    //To access a element from the GUI for the LocalMode
+	public void setUseLocalPeriod(boolean state) {
+		if(this.actualElement != null) {
+			((LocalMode) actualElement).setUseLocalPeriod(state);
+       	}
 	}
 
 	public void setLocalPeriod(int localLength) {
-		System.out.println("setLocalPeriod");
+		if(this.actualElement != null) {
+			((LocalMode) actualElement).setLocalPeriod(localLength);
+       	}
+	}
+	
+	public int getLocalPeriod() {
+		if(this.actualElement != null) {
+			return ((LocalMode) actualElement).getLocalPeriod();
+       	}
+		return -1;
+	}
+	
+	public boolean isUsingLocalPeriod() {
+		if(this.actualElement != null) {
+			return ((LocalMode) actualElement).isUsingLocalPeriod();
+       	}
+		return false;
 	}
 
+	
+	/**
+	 * @deprecated
+	 * @param cps
+	 */
 	public void repaintGraph(AbstractCpsObject cps) {
-		// TODO Auto-generated method stub
 		System.out.println("repaintGraph");
 	}
    
+	/**
+	 * @deprecated
+	 * @param obj
+	 */
+	public void update(ArrayList<AbstractCpsObject> obj) {
+		System.out.println("update");
+	}
     
 
 }