Переглянути джерело

Inspector v2.0

Edge case behavior for Inspector Buttons

Inspector Switch Update
TomTroppmann 2 роки тому
батько
коміт
43d7a8b102

+ 2 - 2
src/algorithm/binary/BaseLine.java

@@ -271,7 +271,7 @@ public class BaseLine implements AddOn {
 	 */
 	private void executeBaseLine() {
 		extractPositionAndAccess();
-		int actualIteration = control.getModel().getCurIteration();
+		int actualIteration = control.getModel().getCurrentIteration();
 		if(closeSwitches)setAllSwitchesClosed();
 		setHolonElemntsAktiv();
 		control.calculateStateAndVisualForCurrentTimeStep();
@@ -338,7 +338,7 @@ public class BaseLine implements AddOn {
 		objectList = new ArrayList<HolonObject>();
 		initialState = new ArrayList<Boolean>(); 
 		access= new HashMap<Integer, AccessWrapper>();
-		rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());
+		rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurrentIteration());
 		return initialState;
 	}
 	/**

+ 2 - 2
src/algorithm/example/DemoAlgo.java

@@ -283,7 +283,7 @@ public class DemoAlgo implements AddOn {
 		private void executeDemoAlgo() {
 			extractPositionAndAccess();
 			counter = 0;
-			int actualIteration = control.getModel().getCurIteration();
+			int actualIteration = control.getModel().getCurrentIteration();
 			deactivateWindrad();
 			setAllSwitchesClosed();
 			updateVisual();
@@ -341,7 +341,7 @@ public class DemoAlgo implements AddOn {
 			objectList = new ArrayList<HolonObject>();
 			initialState = new ArrayList<Boolean>(); 
 			access= new HashMap<Integer, AccessWrapper>();
-			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());
+			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurrentIteration());
 			return initialState;
 		}
 		/**

+ 2 - 2
src/algorithm/example/FlexExample.java

@@ -332,7 +332,7 @@ public class FlexExample implements AddOn {
 		 */
 		private void executeDemoAlgo(RunResult result) {
 			extractPositionAndAccess();
-			int actualIteration = control.getModel().getCurIteration();
+			int actualIteration = control.getModel().getCurrentIteration();
 			println("TimeStep:" + actualIteration);
 			control.calculateStateOnlyForCurrentTimeStep();
 			List<Priority> priorityListASC = createPriorityListASC();
@@ -466,7 +466,7 @@ public class FlexExample implements AddOn {
 			objectList = new ArrayList<HolonObject>();
 			initialState = new ArrayList<Boolean>();
 			access= new HashMap<Integer, AccessWrapper>();
-			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());			
+			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurrentIteration());			
 			resetChain.add(initialState); 
 			return initialState;
 		}

+ 3 - 3
src/api/AlgorithmFrameworkFlex.java

@@ -624,7 +624,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
 		}
 		
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
+		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurrentIteration());
 		this.extractPositionAndAccess();
 		setState(runBest.position);
 		updateVisual();
@@ -753,7 +753,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	 * @param position
 	 */
 	private void setState(List<Boolean> position) {
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
+		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurrentIteration());
 		int i = 0;
 		for(Boolean bool: position) {
 			access.get(i++).setState(bool);
@@ -773,7 +773,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		this.accessKillSwitch = new HashMap<HolonObject, AccessWrapper>();
 		access= new ArrayList<AccessWrapper>();
 		List<Boolean> initialState = new ArrayList<Boolean>();
-		rollOutNodes((dGroupNode != null)? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());			
+		rollOutNodes((dGroupNode != null)? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurrentIteration());			
 		resetChain.add(initialState);
 		if(algoUseFlexes) {			
 			for(FlexWrapper flex :control.getSimManager().getActualFlexManager().getAllFlexWrapperWithState(FlexState.OFFERED)){

+ 2 - 2
src/api/TopologieAlgorithmFramework.java

@@ -224,7 +224,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	private void toggleSwitches() {
 		List<HolonSwitch> allSwitchList = control.getModel().getAllSwitches();
 		if(allSwitchList.isEmpty()) return;
-		boolean set = allSwitchList.get(0).getState(control.getModel().getCurIteration());
+		boolean set = allSwitchList.get(0).getState(control.getModel().getCurrentIteration());
 		allSwitchList.forEach(hSwitch -> {
 			hSwitch.setManualMode(true);
 			hSwitch.setManualState(!set);
@@ -622,7 +622,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
 		}
 		
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
+		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurrentIteration());
 		setState(runBest.position);
 		for(HolonSwitch hSwitch: switchList) {
 			hSwitch.setManualMode(true);

+ 3 - 4
src/classes/AbstractCanvasObject.java

@@ -35,10 +35,6 @@ public abstract class AbstractCanvasObject {
 	/* Position with a X and Y value */
 	@Expose
 	Vector2Int position = new Vector2Int(0,0);
-	/*
-	 * Energy input and output of each object in the grid Where the Object is
-	 * Stored
-	 */
 	@Expose
 	String sav;
 	/* tags that can be used */
@@ -129,6 +125,9 @@ public abstract class AbstractCanvasObject {
 		this.image = image;
 	}
 
+	
+	
+	
 	/**
 	 * List of all existing connections.
 	 * 

+ 4 - 5
src/classes/HolonElement.java

@@ -4,8 +4,7 @@ import com.google.gson.annotations.Expose;
 import com.google.gson.annotations.SerializedName;
 
 import classes.IdCounter.CounterType;
-import interfaces.GraphEditable;
-import interfaces.LocalMode;
+import interfaces.TimelineDependent;
 import ui.controller.FlexManager;
 import ui.controller.IndexTranslator;
 
@@ -22,7 +21,7 @@ import java.util.ListIterator;
  *
  * @author Gruppe14
  */
-public class HolonElement implements LocalMode, GraphEditable{
+public class HolonElement implements TimelineDependent{
 
     /** Points of new TestGraph 
      * Represent the Graph 
@@ -311,8 +310,8 @@ public class HolonElement implements LocalMode, GraphEditable{
 	
 	//interfaces.GraphEditable
 	@Override
-	public Graphtype getGraphType() {
-		return Graphtype.doubleGraph;
+	public GraphType getGraphType() {
+		return GraphType.doubleGraph;
 	}
 
 

+ 4 - 5
src/classes/HolonSwitch.java

@@ -7,8 +7,8 @@ import java.util.LinkedList;
 import java.util.ListIterator;
 
 import com.google.gson.annotations.Expose;
-import interfaces.GraphEditable;
 import interfaces.LocalMode;
+import interfaces.TimelineDependent;
 import ui.controller.IndexTranslator;
 
 /**
@@ -17,7 +17,7 @@ import ui.controller.IndexTranslator;
  * @author Gruppe14
  *
  */
-public class HolonSwitch extends AbstractCanvasObject implements LocalMode, GraphEditable {
+public class HolonSwitch extends AbstractCanvasObject implements TimelineDependent {
 
 	/**
 	 * The class HolonSwitch represents an Object in the system, that has the
@@ -86,7 +86,6 @@ public class HolonSwitch extends AbstractCanvasObject implements LocalMode, Grap
 	 */
 	public HolonSwitch(AbstractCanvasObject obj) {
 		super(obj);
-		System.out.println("SwitchCopy?");
 		HolonSwitch copyObj = (HolonSwitch)obj;
 		setLocalPeriod(copyObj.getLocalPeriod());
 		setUseLocalPeriod(copyObj.isUsingLocalPeriod());
@@ -244,8 +243,8 @@ public class HolonSwitch extends AbstractCanvasObject implements LocalMode, Grap
 
 	//interfaces.GraphEditable
 	@Override
-	public Graphtype getGraphType() {
-		return Graphtype.boolGraph;
+	public GraphType getGraphType() {
+		return GraphType.boolGraph;
 	}
 
 	@Override

+ 1 - 1
src/classes/comparator/UnitGraphPointComperator.java

@@ -2,7 +2,7 @@ package classes.comparator;
 
 import java.util.Comparator;
 
-import classes.UnitGraphPoint;
+import ui.view.inspector.UnitGraphPoint;
 
 
 public class UnitGraphPointComperator implements Comparator<UnitGraphPoint>{

+ 5 - 3
src/interfaces/GraphEditable.java

@@ -8,19 +8,21 @@ import java.util.LinkedList;
  * @author Tom Troppmann
  *
  */
-public interface GraphEditable {
 
+
+
+public interface GraphEditable {
 	/**
 	 * all types of graphs
 	 */
-	public static enum Graphtype {
+	public static enum GraphType {
 		boolGraph, doubleGraph
 	}
 	/**
 	 * Determine what type the Graph have.
 	 * @return the type of the Graph
 	 */
-	Graphtype getGraphType();
+	GraphType getGraphType();
 	/**
 	 * Getter for the graph.
 	 * @return The list of all graph points.

+ 1 - 0
src/interfaces/GraphListener.java

@@ -4,6 +4,7 @@ import classes.AbstractCanvasObject;
 
 import java.util.ArrayList;
 
+//TODO delete
 public interface GraphListener {
 
     void repaintTree();

+ 3 - 0
src/interfaces/TimelineDependent.java

@@ -0,0 +1,3 @@
+package interfaces;
+
+public interface TimelineDependent extends GraphEditable, LocalMode {}

+ 2 - 2
src/ui/controller/ClipboardController.java

@@ -139,7 +139,7 @@ public class ClipboardController {
         // for selecting Cps
         getObjectsInDepth();
         forwardEdges(edges, json, objDispatch, upperNode);
-        this.simManager.calculateStateForTimeStep(model.getCurIteration(), true);
+        this.simManager.calculateStateForTimeStep(model.getCurrentIteration(), true);
     }
 
     /**
@@ -157,7 +157,7 @@ public class ClipboardController {
                 cvsC.bfsNodeCleaner((GroupNode) abs);
         }
         model.getSelectedObjects().clear();
-        this.simManager.calculateStateForTimeStep(model.getCurIteration(), true);
+        this.simManager.calculateStateForTimeStep(model.getCurrentIteration(), true);
 
     }
 

+ 3 - 3
src/ui/controller/Control.java

@@ -326,7 +326,7 @@ public class Control {
 	 */
 	public void addObjectCanvas(AbstractCanvasObject object) {
 		canvasController.addNewObject(object);
-		calculateStateAndVisualForTimeStep(model.getCurIteration());
+		calculateStateAndVisualForTimeStep(model.getCurrentIteration());
 		if (!(object instanceof Node)) {
 			tryAutoSave();
 		}
@@ -527,11 +527,11 @@ public class Control {
 	 * Timestep.
 	 */
 	public void calculateStateAndVisualForCurrentTimeStep() {
-		calculateStateAndVisualForTimeStep(model.getCurIteration());
+		calculateStateAndVisualForTimeStep(model.getCurrentIteration());
 	}
 
 	public void calculateStateOnlyForCurrentTimeStep() {
-		simulationManager.calculateStateForTimeStep(model.getCurIteration(), false);
+		simulationManager.calculateStateForTimeStep(model.getCurrentIteration(), false);
 	}
 
 	/**

+ 0 - 2
src/ui/controller/FlexManager.java

@@ -43,8 +43,6 @@ public class FlexManager {
 		//because when added not all flexes can see others
 		accessFlexMap.values().stream().forEach(flexWrapper -> flexWrapper.revalidateState());
 	}
-
-	
 	
 	
 	

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

@@ -22,7 +22,7 @@ public class IndexTranslator {
     		return timeStep % e.getLocalPeriod()* 100 /e.getLocalPeriod();
     	}
     	else {
-    		return timeStep * 100 / (model == null?STANDARD_GRAPH_ACCURACY:model.getIterations());
+    		return timeStep * 100 / (model == null?STANDARD_GRAPH_ACCURACY:model.getMaxIterations());
     	}
     }
 }

+ 2 - 2
src/ui/model/Model.java

@@ -337,7 +337,7 @@ public class Model {
      *
      * @return ITERATIONS
      */
-    public int getIterations() {
+    public int getMaxIterations() {
         return iterations;
     }
 
@@ -353,7 +353,7 @@ public class Model {
      *
      * @return cURiTERATION
      */
-    public int getCurIteration() {
+    public int getCurrentIteration() {
         return curIteration;
     }
 

+ 2 - 2
src/ui/view/canvas/Canvas.java

@@ -41,7 +41,7 @@ import ui.model.DecoratedHolonObject.HolonObjectState;
 import ui.model.DecoratedSwitch;
 import ui.model.ExitCable;
 import ui.model.DecoratedSwitch.SwitchState;
-import ui.view.main.UnitGraph;
+import ui.view.inspector.UnitGraph;
 import ui.model.Model;
 import ui.model.Passiv;
 import ui.model.Supplier;
@@ -717,7 +717,7 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 			if (doubleclick && tempCps != null && tempCps instanceof GroupNode) {
 				controller.getGui().openNewUpperNodeTab((GroupNode) tempCps);
 			}
-			controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
+			controller.calculateStateAndVisualForTimeStep(model.getCurrentIteration());
 
 			repaint();
 		}

+ 2 - 2
src/ui/view/canvas/GroupNodeCanvas.java

@@ -25,7 +25,7 @@ import ui.model.ExitCable;
 import ui.model.Model;
 import ui.model.Passiv;
 import ui.model.Supplier;
-import ui.view.main.UnitGraph;
+import ui.view.inspector.UnitGraph;
 import utility.ImageImport;
 import utility.Vector2Int;
 
@@ -306,7 +306,7 @@ public class GroupNodeCanvas extends Canvas {
 			if (doubleclick && tempCps != null && tempCps instanceof GroupNode) {
 				controller.getGui().openNewUpperNodeTab((GroupNode)tempCps);
 			}
-			controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
+			controller.calculateStateAndVisualForTimeStep(model.getCurrentIteration());
 			repaint();
 		}
 	}

+ 1 - 0
src/ui/view/component/TrippleCheckBox.java

@@ -46,6 +46,7 @@ public class TrippleCheckBox extends JCheckBox implements Icon, ActionListener {
 	public void setSelectionState(State selection) {
 		state = selection;
 		setSelected(state == State.selected);
+		repaint();
 	}
 
 

+ 32 - 21
src/ui/view/main/Inspector.java → src/ui/view/inspector/Inspector.java

@@ -1,9 +1,11 @@
-package ui.view.main;
+package ui.view.inspector;
 
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.event.ItemEvent;
+import java.util.List;
+import java.util.Set;
 
 import javax.swing.Box;
 import javax.swing.GrayFilter;
@@ -17,7 +19,10 @@ import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
 import javax.swing.JToolBar;
 
+import classes.HolonElement;
+import classes.HolonSwitch;
 import interfaces.GraphEditable;
+import interfaces.TimelineDependent;
 import ui.controller.Control;
 import utility.ImageImport;
 
@@ -34,20 +39,21 @@ public class Inspector extends JSplitPane {
 	private String[] comboContext = { "", "5", "10", "20", "100", "1000" };
 	private JComboBox<String> localPeriodInput = new JComboBox<String>(comboContext);
 	private JButton resetButton = new JButton("", new ImageIcon(ImageImport.loadImage("/Images/resetIcon3.png")));
-	private final ImageIcon localPeriodButtonImageEnabled = new ImageIcon(
-			ImageImport.loadImage("/Images/Graph.png"));
-	
+	private final ImageIcon localPeriodButtonImageEnabled = new ImageIcon(ImageImport.loadImage("/Images/Graph.png"));
+
 	private final ImageIcon localPeriodButtonImageDisabled = new ImageIcon(
 			GrayFilter.createDisabledImage(ImageImport.loadImage("/Images/Graph.png")));
 	private JButton localPeriodButton = new JButton("", localPeriodButtonImageEnabled);
-	
+
 	public Inspector(Control control) {
 		this.control = control;
 		table = new InspectorTable(control);
 		unitGraph = new UnitGraph(control);
+		table.OnElementSelectionChanged.addListener(this::updateUnitGraph);
 		initUI();
-		
+
 	}
+
 	private void initUI() {
 		this.setOrientation(JSplitPane.VERTICAL_SPLIT);
 		JScrollPane scrollPane = new JScrollPane(table);
@@ -55,11 +61,9 @@ public class Inspector extends JSplitPane {
 		this.setTopComponent(scrollPane);
 		this.setBottomComponent(scrollGraph);
 		this.setDividerLocation(1000);
-		
 		scrollGraph.setViewportView(unitGraph);
 		// Set up of the Properties section
 
-
 		graphLabel.setLayout(new BorderLayout(0, 10));
 		graphLabel.add(maxGraph, BorderLayout.NORTH);
 		graphLabel.add(medGraph, BorderLayout.CENTER);
@@ -96,9 +100,9 @@ public class Inspector extends JSplitPane {
 		toolBarGraph.add(resetButton);
 		scrollGraph.setRowHeaderView(graphLabel);
 		scrollGraph.setColumnHeaderView(toolBarGraph);
-		
+
 	}
-	
+
 	/**
 	 * Validate the LocalMode Input and when its valid save on the Element.
 	 * 
@@ -111,30 +115,41 @@ public class Inspector extends JSplitPane {
 			localPeriodInputValue = Integer.parseInt(text);
 		} catch (NumberFormatException e) {
 			if (bShowMessage)
-				JOptionPane.showMessageDialog(null,
-						'"' + text + '"' + " is not a valid Input. \n Use whole numbers.");
+				JOptionPane.showMessageDialog(null, '"' + text + '"' + " is not a valid Input. \n Use whole numbers.");
 			return;
 		}
 		unitGraph.setLocalPeriod(localPeriodInputValue);
 	}
-	
+
 	/**
 	 * 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) {
+	private void updateUnitGraph(Set<HolonElement> elements) {
 		// SaveOld LocalMode State.
 		if (localPeriodInput.isVisible()) {
 			// Save Old State
 			validateInput(localPeriodInput.getEditor().getItem().toString(), false);
 		}
 		// Update UnitGraph
-		unitGraph.initNewElement(element);
+		unitGraph.clearSeries();
+		for (TimelineDependent element : elements) {
+			unitGraph.addNewSeries(element);
+		}
+		
+		if(elements.isEmpty()) {
+			control.getModel().getSelectedObjects().stream().filter(obj -> obj instanceof HolonSwitch)
+			.forEach(obj -> unitGraph.addNewSeries((HolonSwitch) obj));			
+		}
+//		if (elements.isEmpty()) {
+//			this.setDividerLocation(1.0);
+//		}
 		// Load LocalMode State.
 		changeLocalPeriodButtonAppeareance(unitGraph.isUsingLocalPeriod());
-		localPeriodInput.getEditor().setItem(unitGraph.getLocalPeriod());
+		localPeriodInput.getEditor()
+				.setItem(unitGraph.isLocalPeriedDifferentInSeries() ? "-" : unitGraph.getFirstLocalPeriod());
 	}
 
 	/**
@@ -144,11 +159,7 @@ public class Inspector extends JSplitPane {
 	 */
 	private void changeLocalPeriodButtonAppeareance(boolean enabled) {
 		localPeriodInput.setVisible(enabled);
-		if (enabled) {
-			localPeriodButton.setIcon(localPeriodButtonImageEnabled);
-		} else {
-			localPeriodButton.setIcon(localPeriodButtonImageDisabled);
-		}
+		localPeriodButton.setIcon(enabled ? localPeriodButtonImageEnabled : localPeriodButtonImageDisabled);
 	}
 
 }

+ 64 - 56
src/ui/view/main/InspectorTable.java → src/ui/view/inspector/InspectorTable.java

@@ -1,4 +1,4 @@
-package ui.view.main;
+package ui.view.inspector;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -8,10 +8,13 @@ import java.math.RoundingMode;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
@@ -37,24 +40,26 @@ import ui.controller.Control;
 import ui.view.component.TrippleCheckBox;
 import ui.view.component.TrippleCheckBox.State;
 import utility.ImageImport;
+import utility.events.Action;
 import utility.events.SimpleDocumentListener;
 
 public class InspectorTable extends JPanel {
 	private List<ElementRow> elementRows = new ArrayList<ElementRow>();
 	private Control control;
 	private final int columnHeight = 20;
-
 	//UI
 	private final TrippleCheckBox selectAllCheckBox = new TrippleCheckBox();
 	private final JButton addButton = new JButton();
 	private final JButton duplicateButton = new JButton();
 	private final JButton deleteButton = new JButton();
 	private final JPanel buttonPanel = new JPanel();
-	private final NumberFormatter doubleFormatter = generateNumberFormatter();
+	private final static NumberFormatter doubleFormatter = generateNumberFormatter();
 	
 	//Colors
-	private final Color selectedColor = new Color(126, 186, 255);
-	private final Color borderColor = new Color(171, 173, 179);
+	private final static Color selectedColor = new Color(126, 186, 255);
+	private final static Color borderColor = new Color(171, 173, 179);
+	//Events
+	public Action<Set<HolonElement>> OnElementSelectionChanged = new Action<>(); 
 
 	public InspectorTable(Control control) {
 		control.OnSelectionChanged.addListener(() -> update_ui());
@@ -71,6 +76,17 @@ public class InspectorTable extends JPanel {
 		initSelectAllCheckBox();
 		initButtonPanel();
 	}
+	private static NumberFormatter generateNumberFormatter() {
+		NumberFormat doubleFormat = NumberFormat.getNumberInstance(Locale.US);
+		doubleFormat.setMinimumFractionDigits(1);
+		doubleFormat.setMaximumFractionDigits(10);
+		doubleFormat.setRoundingMode(RoundingMode.HALF_UP);
+		doubleFormat.setGroupingUsed(false);
+		NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
+		doubleFormatter.setCommitsOnValidEdit(true);
+		doubleFormatter.setValueClass(Double.class);
+		return doubleFormatter;
+	}
 
 	private void generateHeader() {
 
@@ -84,7 +100,7 @@ public class InspectorTable extends JPanel {
 	}
 
 	private void initSelectAllCheckBox() {
-		selectAllCheckBox.setBorder(generateButtonHeaderBorder());
+		selectAllCheckBox.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
 		// Pixel Perfect alignment
 		selectAllCheckBox.setBorder(BorderFactory.createEmptyBorder(2, 3, 0, 0));
 		selectAllCheckBox.addActionListener(clicked -> {
@@ -99,35 +115,19 @@ public class InspectorTable extends JPanel {
 			}
 				break;
 			case unselected:
-				for (ElementRow row : elementRows) {
-					row.setSelected(true);
+				if(!elementRows.isEmpty()) {					
+					for (ElementRow row : elementRows) {
+						row.setSelected(true);
+					}
+					duplicateButton.setEnabled(true);
+					deleteButton.setEnabled(true);
 				}
-				duplicateButton.setEnabled(true);
-				deleteButton.setEnabled(true);
 			default:
 				break;
 			}
+			updateElementSelection();
 		});
 	}
-
-	public void update_ui() {
-		System.out.println("update_ui");
-		List<HolonElement> elements = extractElements(control.getModel().getSelectedObjects());
-		// TODO Pooling
-		this.removeAll();
-		elementRows.clear();
-		generateHeader();
-		for (HolonElement element : elements) {
-			elementRows.add(new ElementRow(element));
-		}
-		this.add(buttonPanel, "span");
-		duplicateButton.setEnabled(false);
-		deleteButton.setEnabled(false);
-		selectAllCheckBox.setSelectionState(State.unselected);
-		revalidate();
-		repaint();
-	}
-
 	private JLabel generateHeaderColumnTitle(String string) {
 		JLabel columnTitleLabel = new JLabel(string);
 		columnTitleLabel.setToolTipText(string);
@@ -135,6 +135,8 @@ public class InspectorTable extends JPanel {
 		return columnTitleLabel;
 	}
 
+
+
 	private void initButtonPanel() {
 		buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
 		buttonPanel.add(Box.createRigidArea(new Dimension(2, 0)));
@@ -142,15 +144,14 @@ public class InspectorTable extends JPanel {
 		addButton.setIcon(new ImageIcon(ImageImport.loadImage("Images/plus.png", 16, 16)));
 		addButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
 		addButton.addActionListener(clicked -> {
-			System.out.println("AddButton");
 			Optional<HolonObject> last = control.getModel().getSelectedObjects().stream()
 					.filter(obj -> obj instanceof HolonObject).reduce((prev, next) -> next)
 					.map(obj -> (HolonObject) obj);
 			last.ifPresent(obj -> {
 				obj.addElement(new HolonElement(obj, "Element", 0.0f));
+				control.calculateStateAndVisualForCurrentTimeStep();
+				update_ui();
 			});
-			control.calculateStateAndVisualForCurrentTimeStep();
-			update_ui();
 		});
 		buttonPanel.add(addButton);
 
@@ -181,31 +182,32 @@ public class InspectorTable extends JPanel {
 		buttonPanel.add(deleteButton);
 	}
 
-	// Extract elements from a list of AbstractCanvasObjects
-	private List<HolonElement> extractElements(Collection<AbstractCanvasObject> toInspect) {
-		return toInspect.stream().filter(obj -> obj instanceof HolonObject).flatMap(obj -> {
-			HolonObject ho = (HolonObject) obj;
-			return ho.getElements().stream();
-		}).collect(Collectors.toList());
+	private void update_ui() {
+		Stream<HolonElement> elements = extractElements(control.getModel().getSelectedObjects());
+		// TODO Pooling
+		this.removeAll();
+		elementRows.clear();
+		generateHeader();
+		elements.forEach(element -> elementRows.add(new ElementRow(element)));
+		this.add(buttonPanel, "span");
+		boolean isAtLeastOneHolonObjectSelected = 
+				control.getModel().getSelectedObjects().stream().anyMatch(object -> object instanceof HolonObject);
+		this.addButton.setEnabled(isAtLeastOneHolonObjectSelected);
+		duplicateButton.setEnabled(false);
+		deleteButton.setEnabled(false);
+		selectAllCheckBox.setSelectionState(State.unselected);
+		revalidate();
+		repaint();
+		this.OnElementSelectionChanged.broadcast(new HashSet<HolonElement>());
 	}
 
-	private NumberFormatter generateNumberFormatter() {
-		NumberFormat doubleFormat = NumberFormat.getNumberInstance(Locale.US);
-		doubleFormat.setMinimumFractionDigits(1);
-		doubleFormat.setMaximumFractionDigits(10);
-		doubleFormat.setRoundingMode(RoundingMode.HALF_UP);
-		doubleFormat.setGroupingUsed(false);
-		NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
-		doubleFormatter.setCommitsOnValidEdit(true);
-		doubleFormatter.setValueClass(Double.class);
-		return doubleFormatter;
-	}
 
-	private Border generateButtonHeaderBorder() {
-		return BorderFactory.createEmptyBorder(2, 0, 0, 0);
+	private void updateElementSelection() {
+		Set<HolonElement> eleSet = elementRows.stream().filter(ele -> ele.isSelected()).map(row -> row.element).collect(Collectors.toSet());
+		this.OnElementSelectionChanged.broadcast(eleSet);
 	}
 
-	private void setSelectAllCheckBox() {
+	private void updateButtonAppearance() {
 		long count = elementRows.stream().filter(ele -> ele.isSelected()).count();
 		if (count == elementRows.size()) {
 			selectAllCheckBox.setSelectionState(State.selected);
@@ -216,9 +218,16 @@ public class InspectorTable extends JPanel {
 		}
 		duplicateButton.setEnabled(count != 0);
 		deleteButton.setEnabled(count != 0);
-		selectAllCheckBox.repaint();
 	}
 
+	// Extract elements from a list of AbstractCanvasObjects
+	private Stream<HolonElement> extractElements(Collection<AbstractCanvasObject> toInspect) {
+		return toInspect.stream().filter(obj -> obj instanceof HolonObject).flatMap(obj -> {
+			HolonObject ho = (HolonObject) obj;
+			return ho.getElements().stream();
+		});
+	}
+	
 	private class ElementRow {
 		HolonElement element;
 		private JCheckBox selectionBox;
@@ -256,7 +265,8 @@ public class InspectorTable extends JPanel {
 			selectionBox = new JCheckBox();
 			selectionBox.addActionListener(clicked -> {
 				setSelected(selectionBox.isSelected());
-				setSelectAllCheckBox();
+				updateButtonAppearance();
+				updateElementSelection();
 			});
 			selectedColumnPanel.setMinimumSize(new Dimension(columnHeight, columnHeight));
 			selectedColumnPanel.setPreferredSize(new Dimension(columnHeight, columnHeight));
@@ -316,8 +326,6 @@ public class InspectorTable extends JPanel {
 			});
 			cellsInRow[5] = comboBox;
 
-			// Active Delete Column
-
 			JPanel checkBoxWrapperPanel = new JPanel(new BorderLayout());
 			checkBoxWrapperPanel.setBorder(BorderFactory.createLineBorder(borderColor));
 			checkBoxWrapperPanel.setBackground(Color.white);

+ 900 - 0
src/ui/view/inspector/UnitGraph.java

@@ -0,0 +1,900 @@
+package ui.view.inspector;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.util.Optional;
+
+import javax.swing.JPanel;
+
+import classes.HolonElement;
+import interfaces.GraphEditable;
+import interfaces.GraphEditable.GraphType;
+import interfaces.LocalMode;
+import interfaces.TimelineDependent;
+import ui.controller.Control;
+import ui.model.Model;
+import utility.Vector2Int;
+
+/**
+ * This Class represents a Graph where the User can model the behavior of
+ * elements and switches over time.
+ *
+ * @author Tom Troppmann
+ */
+public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
+
+	// Normal Settings
+	private static final int border = 4;
+	private static final int clickThreshholdSquared = 25;
+
+	// Display Settings
+	/**
+	 * The size of a dot in the graph. It should be at least 1.
+	 */
+	private static final int dotSize = 8;
+
+	/** The Color of a dot in the graph. */
+	private static final Color dotColor = Color.blue;
+	private static final Color editDotColor = new Color(255, 119, 0);
+	private static final Color[] seriesColorArray = { Color.blue, Color.cyan, Color.black, Color.green, Color.gray,
+			Color.magenta, Color.yellow, Color.PINK, Color.red };
+
+	// Intern Variables
+	private class Series {
+		public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
+		public TimelineDependent element;
+		public GraphType type;
+		public Color color;
+	}
+
+	private ArrayList<Series> seriesList = new ArrayList<Series>();
+	private Vector2Int editPosition;
+	private Optional<Series> actualSeries;
+	private boolean editMode = false;
+
+	private enum EditPointType {
+		Normal, StartPoint, EndPoint
+	};
+
+	private Model model;
+	private int widthWithBorder, heightWithBorder;
+
+	private EditPointType editPointType;
+
+	/**
+	 * Constructor.
+	 *
+	 * @param model   the Model
+	 * @param control the Controller
+	 */
+	public UnitGraph(Control control) {
+		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
+		this.model = control.getModel();
+		this.setBackground(Color.WHITE);
+
+		this.addMouseListener(this);
+		this.addMouseMotionListener(this);
+		this.addComponentListener(this);
+	}
+
+	/**
+	 * When the UnitGraph should represent a new GraphEditable Element. Its Updates
+	 * the Graph and give access to the Element.
+	 * 
+	 * @param element
+	 */
+	public void addNewSeries(TimelineDependent element) {
+		Series series = new Series();
+		overrideUnitGraph(series, element.getStateGraph());
+		series.element = element;
+		series.type = element.getGraphType();
+		series.color = seriesColorArray[element.hashCode() % seriesColorArray.length];
+		seriesList.add(series);
+		repaint();
+	}
+
+	public void clearSeries() {
+		seriesList.clear();
+		repaint();
+	}
+
+	/**
+	 * Paints the Graph, the Grid, the actual Line from the currentIteration
+	 * 
+	 * @param g Graphics
+	 */
+	public void paintComponent(Graphics g) {
+		super.paintComponent(g);
+		Graphics2D g2D = (Graphics2D) g;
+		drawGrid(g2D);
+		g2D.setColor(Color.BLACK);
+		g2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
+		g2D.setStroke(new BasicStroke(2f));
+		drawUnitGraph(g2D);
+		g2D.setColor(dotColor);
+		if (editMode) {
+			drawUnitGraphPointsReleased(g2D);
+		} else {
+			drawUnitGraphPoints(g2D);
+		}
+		g2D.setColor(dotColor);
+		g2D.setStroke(new BasicStroke(1));
+		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) {
+		boolean drawSnappingHintFlag = false;
+		for (Series series : this.seriesList) {
+			g.setColor(series.color);
+			switch (series.type) {
+			case boolGraph:
+				if (editMode) {
+					drawBoolGraphInEditMode(g, series);
+					drawSnappingHintFlag = true;					
+				}
+				else
+					drawBoolGraph(g, series);
+				break;
+			case doubleGraph:
+				if (editMode)
+					drawDoubleGraphInEditMode(g, series);
+				else
+					drawDoubleGraph(g, series);
+				break;
+			default:
+				throw new UnsupportedOperationException();
+			}
+		}
+		if(drawSnappingHintFlag) {
+			drawSnappingHint(g);
+		}
+			
+	}
+
+	/**
+	 * 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 (Series series : seriesList) {
+			for (UnitGraphPoint p : series.points) {
+				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);
+		int amountOfLines = 10;
+		int width = widthWithBorder + 2 * border;
+		int height = heightWithBorder;
+		for (int i = 0; i <= amountOfLines; i++) {
+			int linehieght = (int) (((double) i / (double) amountOfLines) * (double) height) + border;
+			g2D.drawLine(0, linehieght, width, linehieght);
+		}
+	}
+
+	/**
+	 * 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.getCurrentIteration();
+		int max = model.getMaxIterations();
+		if(isLocalPeriedDifferentInSeries()){
+			for(Series series: seriesList) {
+				double where;
+				if (!series.element.isUsingLocalPeriod()) {
+					where = ((double) cur) / ((double) max);
+				} else {
+					int lPeriod = series.element.getLocalPeriod();
+					where = ((double) cur % lPeriod) / ((double) lPeriod);
+				}
+				Vector2Int oben = new Vector2Int(border + (int) (where * widthWithBorder), 0);
+				Vector2Int unten = new Vector2Int(border + (int) (where * widthWithBorder), 2 * border + heightWithBorder);
+				g.setColor(series.color);
+				drawLine(g, oben, unten);
+			}
+		}
+		else {
+			double where;
+			if (!isUsingLocalPeriod()) {
+				where = ((double) cur) / ((double) max);
+			} else {
+				int lPeriod = getFirstLocalPeriod();
+				where = ((double) cur % lPeriod) / ((double) lPeriod);
+			}
+			Vector2Int oben = new Vector2Int(border + (int) (where * widthWithBorder), 0);
+			Vector2Int unten = new Vector2Int(border + (int) (where * widthWithBorder), 2 * border + heightWithBorder);
+			g.setColor(dotColor);
+			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, Vector2Int start, Vector2Int end) {
+		Path2D.Double path = new Path2D.Double();
+		path.moveTo(start.getX(), start.getY());
+		path.lineTo(end.getX(), end.getY());
+		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(Vector2Int 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.getX(), start.getY());
+		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, Vector2Int actual, Vector2Int target) {
+		double mitte = (actual.getX() + target.getX()) * 0.5;
+		path.curveTo(mitte, actual.getY(), mitte, target.getY(), target.getX(), target.getY());
+	}
+
+	/**
+	 * 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, Vector2Int p) {
+		g.fillOval(p.getX() - dotSize / 2, p.getY() - dotSize / 2, dotSize, dotSize);
+	}
+
+	/**
+	 * 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, Series series) {
+		if (series.points.size() <= 1)
+			return;
+		LinkedList<Vector2Int> cornerPoints = new LinkedList<Vector2Int>();
+		ListIterator<UnitGraphPoint> iter = series.points.listIterator();
+		Vector2Int actual = series.points.getFirst().displayedPosition;
+		Path2D.Double path = new Path2D.Double();
+		path.moveTo(actual.getX(), actual.getY());
+		while (iter.hasNext()) {
+			Vector2Int target = iter.next().displayedPosition;
+			// BooleanConnection
+			path.lineTo(target.getX(), actual.getY()); // line to corner
+			cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); // save corner
+			path.lineTo(target.getX(), target.getY()); // line to next Point
+
+			actual = target;
+		}
+		g.draw(path);
+		// Draw the Points on the Corner that dont exist in Data but should be visual
+		g.setColor(dotColor);
+		for (Vector2Int p : cornerPoints) {
+			drawDot(g, p);
+		}
+
+	}
+
+	/**
+	 * 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, Series series) {
+		LinkedList<Vector2Int> before = new LinkedList<Vector2Int>();
+		LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
+		for (UnitGraphPoint p : series.points) {
+			if (p.displayedPosition.getX() < editPosition.getX())
+				before.add(p.displayedPosition);
+			else
+				after.add(p.displayedPosition);
+		}
+		g.setColor(series.color);
+		drawBoolGraphFromList(g, before);
+		g.setColor(series.color);
+		drawBoolGraphFromList(g, after);
+		// EditGraph
+		LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
+		if (!before.isEmpty())
+			middle.add(before.getLast());
+		middle.add(editPosition);
+		if (!after.isEmpty())
+			middle.add(after.getFirst());
+
+		g.setColor(editDotColor);
+		drawBoolGraphFromList(g, middle);
+
+	}
+
+	/**
+	 * 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
+		g.setColor(Color.RED);
+		// Threshhold Line
+		final float dash1[] = { 10.0f };
+		final BasicStroke dashed = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1,
+				0.0f);
+		g.setStroke(dashed);
+
+		int halfheight = border + heightWithBorder / 2;
+		g.drawLine(0, halfheight, widthWithBorder + 2 * border, halfheight);
+		// Threshhold Text
+		g.drawString("Snapping Threshold", 10, halfheight - 2);
+	}
+
+	/**
+	 * 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<Vector2Int> list) {
+		if (list.size() <= 1)
+			return;
+		ListIterator<Vector2Int> iter = list.listIterator();
+		LinkedList<Vector2Int> cornerPoints = new LinkedList<Vector2Int>();
+		Vector2Int actual = list.getFirst();
+		Path2D.Double path = new Path2D.Double();
+		path.moveTo(actual.getX(), actual.getY());
+		while (iter.hasNext()) {
+			Vector2Int target = iter.next();
+			// BooleanConnection
+			path.lineTo(target.getX(), actual.getY()); // line to corner
+			cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); // save corner
+			path.lineTo(target.getX(), target.getY()); // line to next Point
+			actual = target;
+		}
+		g.draw(path);
+		g.setColor(dotColor);
+		for (Vector2Int p : cornerPoints) {
+			drawDot(g, p);
+		}
+	}
+
+	/**
+	 * 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, Series series) {
+		if (series.points.isEmpty())
+			return;
+		ListIterator<UnitGraphPoint> iter = series.points.listIterator();
+		Vector2Int actual = iter.next().displayedPosition;
+		Path2D.Double path = this.initBezier(actual);
+		while (iter.hasNext()) {
+			Vector2Int target = iter.next().displayedPosition;
+			this.curveTo(path, actual, target);
+			actual = target;
+		}
+		g.draw(path);
+
+	}
+
+	/**
+	 * 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, Series series) {
+		LinkedList<Vector2Int> before = new LinkedList<Vector2Int>();
+		LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
+		for (UnitGraphPoint p : series.points) {
+			if (p.displayedPosition.getX() < editPosition.getX())
+				before.add(p.displayedPosition);
+			else
+				after.add(p.displayedPosition);
+		}
+		drawUnitGraphFromList(g, before);
+		drawUnitGraphFromList(g, after);
+		// EditGraph
+		LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
+		if (!before.isEmpty())
+			middle.add(before.getLast());
+		middle.add(editPosition);
+		if (!after.isEmpty())
+			middle.add(after.getFirst());
+
+		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<Vector2Int> list) {
+		if (list.size() <= 1)
+			return;
+		ListIterator<Vector2Int> iter = list.listIterator();
+		Vector2Int actual = list.getFirst();
+		Path2D.Double path = this.initBezier(actual);
+		while (iter.hasNext()) {
+			Vector2Int target = iter.next();
+			curveTo(path, actual, target);
+			actual = target;
+		}
+		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 (Series series : seriesList) {
+			for (UnitGraphPoint p : series.points) {
+				p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
+			}
+		}
+	}
+
+	/**
+	 * Takes a List of GraphPoints and convert it to the actual UnitGraphPoints with
+	 * displayposition in the {@link #seriesList}
+	 * 
+	 * @param stateCurve the list of GraphPoint
+	 */
+	private void overrideUnitGraph(Series series, LinkedList<Point2D.Double> stateCurve) {
+		series.points.clear();
+		for (Point2D.Double p : stateCurve) {
+			UnitGraphPoint point = new UnitGraphPoint(p);
+			point.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
+			series.points.add(point);
+		}
+	}
+
+	/**
+	 * 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;
+	}
+
+	/**
+	 * Save the actualGraphPoint List to the GraphEditable Element.
+	 */
+	private void saveGraph() {
+		for (Series series : seriesList) {
+			LinkedList<Point2D.Double> actual = series.element.getStateGraph();
+			actual.clear();
+			for (UnitGraphPoint p : series.points) {
+				actual.add(p.getPoint());
+			}
+			series.element.sampleGraph();
+		}
+	}
+
+	/**
+	 * Remove a UnitGraphPoint from the UnitGraphPoint list ({@link #seriesList}
+	 * when its near a given Position.
+	 * 
+	 * @param mPosition
+	 */
+	private void removePointNearPosition(Series series, Vector2Int mPosition) {
+		ListIterator<UnitGraphPoint> iter = series.points.listIterator();
+		while (iter.hasNext()) {
+			if (near(mPosition, iter.next().displayedPosition, series.type)) {
+				iter.remove();
+				break;
+			}
+		}
+
+	}
+
+	private void removePointsNearPosition(Vector2Int mPosition) {
+		for (Series series : seriesList) {
+			removePointNearPosition(series, mPosition);
+		}
+	}
+
+	private Optional<Series> detectSeries(Vector2Int mPosition) {
+		return seriesList.stream().min((a, b) -> {
+			float minDistanceA = a.points.stream().map(point -> point.displayedPosition.getSquaredDistance(mPosition))
+					.min(Float::compare).get();
+			float minDistanceB = b.points.stream().map(point -> point.displayedPosition.getSquaredDistance(mPosition))
+					.min(Float::compare).get();
+			return Float.compare(minDistanceA, minDistanceB);
+		});
+	}
+
+	/**
+	 * Determine if the Point is a StartPoint , EndPoint or a NormalPoint a.k.a. in
+	 * between Points.
+	 * 
+	 * @param mPosition The Position to check.
+	 */
+	private EditPointType detectStartEndPoint(Series series, Vector2Int mPosition) {
+		UnitGraphPoint first = series.points.getFirst();
+		UnitGraphPoint last = series.points.getLast();
+		if (near(mPosition, first.displayedPosition, series.type))
+			return EditPointType.StartPoint;
+		else if (near(mPosition, last.displayedPosition, series.type))
+			return EditPointType.EndPoint;
+		else
+			return EditPointType.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(Vector2Int actual, Vector2Int target, GraphType graphType) {
+		switch (graphType) {
+		case boolGraph: // Distance only with X
+			int xDis = target.getX() - actual.getX();
+			return xDis * xDis < clickThreshholdSquared;
+		case doubleGraph:
+			return actual.getSquaredDistance(target) < clickThreshholdSquared;
+		default:
+			return false;
+		}
+	}
+
+	/**
+	 * When the Mouse Drag a Point it updates each time the position.
+	 * 
+	 * @param newPosition
+	 */
+	private void updateEditPointPosition(Vector2Int newPosition, EditPointType editPointType, GraphType graphType) {
+		// make it in the bounds of the UnitGraph no Point out of the Border
+		Vector2Int currentPosition = setInBounds(newPosition);
+		if (editPointType != EditPointType.Normal) {
+			attachToBorder(currentPosition, editPointType);
+		}
+		if (graphType == GraphType.boolGraph) {
+			snapBoolean(currentPosition);
+		}
+		editPosition = currentPosition;
+	}
+
+	/**
+	 * No Point on the UnitGraph should exit the UnitGraph.
+	 * 
+	 * @param p the Position
+	 * @return the updated Position.
+	 */
+	private Vector2Int setInBounds(Vector2Int p) {
+		p.clampX(border, border + widthWithBorder);
+		p.clampY(border, border + heightWithBorder);
+		return p;
+	}
+
+	/**
+	 * For Switches the Point have to be Snap to the Top or the Bottem.
+	 * 
+	 * @param p the Position
+	 * @return the updated Position.
+	 */
+	private Vector2Int snapBoolean(Vector2Int p) {
+		if (p.getY() < border + heightWithBorder / 2) {
+			p.setY(border);
+		} else {
+			p.setY(border + heightWithBorder);
+		}
+		return p;
+	}
+
+	/**
+	 * 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 Vector2Int attachToBorder(Vector2Int p, EditPointType editPointType) {
+		switch (editPointType) {
+		case StartPoint:
+			p.setX(border);
+			break;
+		case EndPoint:
+			p.setX(border + widthWithBorder);
+			break;
+		default:
+			break;
+		}
+		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(Series series, Vector2Int pos) {
+		setInBounds(pos);
+		ListIterator<UnitGraphPoint> iter = series.points.listIterator();
+		while (iter.hasNext()) {
+			Vector2Int tempPosition = iter.next().displayedPosition;
+			if (pos.getX() <= tempPosition.getX()) {
+				// previous to go back a position to make the new point before the the Position
+				// with greater X
+				iter.previous();
+				iter.add(generateUnitGraphPoint(pos));
+				break;
+			}
+		}
+		if (!iter.hasNext()) // if behind last point
+		{
+			iter.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(Vector2Int pos) {
+		UnitGraphPoint temp = new UnitGraphPoint((double) (pos.getX() - border) / (double) widthWithBorder,
+				1 - (double) (pos.getY() - border) / (double) heightWithBorder, true);
+		temp.displayedPosition = pos;
+		return temp;
+	}
+
+	/**
+	 * Update the Point Position
+	 */
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		actualSeries.ifPresent(series -> {
+			updateEditPointPosition(new Vector2Int(e.getPoint().x, e.getPoint().y), this.editPointType, series.type);
+			repaint();
+		});
+
+	}
+
+	@Override
+	public void mouseMoved(MouseEvent e) {
+	}
+
+	@Override
+	public void mouseClicked(MouseEvent e) {
+	}
+
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+
+	@Override
+	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) {
+		Vector2Int mPosition = new Vector2Int(e.getPoint().x, e.getPoint().y);
+		actualSeries = detectSeries(mPosition);
+		actualSeries.ifPresent(series -> {
+			if (e.getButton() == MouseEvent.BUTTON3) {
+				// RightMouseButtonEvent
+				editPointType = detectStartEndPoint(series, mPosition);
+				if (editPointType == EditPointType.Normal) {
+					removePointsNearPosition(mPosition);
+					repaint();
+				}
+				editMode = false;
+
+			} else if (e.getButton() == MouseEvent.BUTTON1) {
+				// LeftMouseButtonEvent
+				editPointType = detectStartEndPoint(series, mPosition);
+				removePointsNearPosition(mPosition);
+				updateEditPointPosition(mPosition, editPointType, series.type);
+				editMode = true;
+				repaint();
+			}
+		});
+
+	}
+
+	/**
+	 * The last step to save the Changes. Its insert the Hovering Point and exit
+	 * EditMode.
+	 */
+	@Override
+	public void mouseReleased(MouseEvent e) {
+		if (editMode && actualSeries.isPresent()) {
+			for (Series series : seriesList) {
+				this.insertNewGraphPoint(series, editPosition);
+			}
+			editMode = false;
+			repaint();
+		}
+		saveGraph();
+	}
+
+	/**
+	 * When the Component is Resized.
+	 *
+	 * @param e ComponentEvent
+	 */
+	public void componentResized(ComponentEvent e) {
+		calculateWidthHeight();
+		updateRepresentativePositions();
+		repaint();
+	}
+
+	@Override
+	public void componentHidden(ComponentEvent e) {
+	}
+
+	@Override
+	public void componentMoved(ComponentEvent e) {
+
+	}
+
+	@Override
+	public void componentShown(ComponentEvent e) {
+	}
+
+	/**
+	 * Resets the graph to normal.
+	 */
+	public void reset() {
+		for (Series series : seriesList) {
+			series.element.reset();
+			overrideUnitGraph(series, series.element.getStateGraph());
+		}
+		repaint();
+	}
+
+	// LocalMode access methods...
+	// To access a element from the GUI for the LocalMode
+	public void setUseLocalPeriod(boolean state) {
+		for (Series series : seriesList) {
+			series.element.setUseLocalPeriod(state);
+		}
+	}
+
+	public void setLocalPeriod(int localLength) {
+		for (Series series : seriesList) {
+			series.element.setLocalPeriod(localLength);
+		}
+	}
+
+	public boolean isLocalPeriedDifferentInSeries() {
+		return seriesList.stream().map(series -> series.element.getLocalPeriod()).distinct().count() > 1;
+	}
+	public int getFirstLocalPeriod() {
+		int period = 0;
+		//seriesList.stream().findFirst().ifPresentOrElse(series -> return series.element.getLocalPeriod(), () -> period = LocalMode.STANDARD_GRAPH_ACCURACY);
+		return period;
+	}
+
+	public boolean isUsingLocalPeriod() {
+		return seriesList.stream().anyMatch(series -> series.element.isUsingLocalPeriod());
+	}
+
+}

+ 1 - 1
src/classes/UnitGraphPoint.java → src/ui/view/inspector/UnitGraphPoint.java

@@ -1,4 +1,4 @@
-package classes;
+package ui.view.inspector;
 
 import java.awt.Point;
 import java.awt.geom.Point2D;

+ 2 - 0
src/ui/view/main/GUI.java

@@ -91,6 +91,8 @@ import ui.view.dialog.BackgroundPopUp;
 import ui.view.dialog.CanvasResizePopUp;
 import ui.view.dialog.CreateNewDialog;
 import ui.view.dialog.CreateNewDialog.Option;
+import ui.view.inspector.Inspector;
+import ui.view.inspector.UnitGraph;
 import ui.view.dialog.EditEdgesPopUp;
 import ui.view.dialog.SearchPopUp;
 import ui.view.window.AddOnWindow;

+ 9 - 9
src/ui/view/main/TimePanel.java

@@ -122,7 +122,7 @@ public class TimePanel extends JPanel implements ActionListener{
 				timeSlider.setValue(timeSlider.getValue() + 1);
 				controller.setCurIteration(timeSlider.getValue());
 				timer.setDelay(cont.getModel().getTimerSpeed());
-				if (timeSlider.getValue() >= cont.getModel().getIterations() - 1) {
+				if (timeSlider.getValue() >= cont.getModel().getMaxIterations() - 1) {
 					running = false;
 					playBtn.setIcon(new ImageIcon(ImageImport.loadImage("/Button_Images/play.png", 30, 30)));
 					timer.stop();
@@ -136,24 +136,24 @@ public class TimePanel extends JPanel implements ActionListener{
 		// Slider
 		timeSlider.setPaintTicks(true);
 		timeSlider.setPaintLabels(true);
-		timeSlider.setMajorTickSpacing((int)Math.ceil(((double)cont.getModel().getIterations())/20));
-		timeSlider.setMinorTickSpacing((int)Math.ceil(((double)cont.getModel().getIterations())/100));
+		timeSlider.setMajorTickSpacing((int)Math.ceil(((double)cont.getModel().getMaxIterations())/20));
+		timeSlider.setMinorTickSpacing((int)Math.ceil(((double)cont.getModel().getMaxIterations())/100));
 		timeSlider.setToolTipText("Time Slider");
-		timeSlider.setMaximum(cont.getModel().getIterations() - 1);
+		timeSlider.setMaximum(cont.getModel().getMaxIterations() - 1);
 		timeSlider.setValue(0);
 		timeSlider.addChangeListener(changeEvent -> controller.setCurIteration(timeSlider.getValue()));
 
 		timeSlider.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
-				dragResetIteration = cont.getModel().getCurIteration();
+				dragResetIteration = cont.getModel().getCurrentIteration();
 			}
 		});
 
 		timeSlider.addMouseMotionListener(new MouseAdapter() {
 			@Override
 			public void mouseDragged(MouseEvent e) {
-				if (dragResetIteration != cont.getModel().getCurIteration()) {
+				if (dragResetIteration != cont.getModel().getCurrentIteration()) {
 					if (running) {
 						playBtn.doClick();
 					}
@@ -175,7 +175,7 @@ public class TimePanel extends JPanel implements ActionListener{
 		playBtn.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				if(cont.getModel().getCurIteration()==cont.getModel().getIterations()-1)timeSlider.setValue(timeSlider.getMinimum());
+				if(cont.getModel().getCurrentIteration()==cont.getModel().getMaxIterations()-1)timeSlider.setValue(timeSlider.getMinimum());
 				running = !running;
 				if (running) {
 					timer.setDelay(cont.getModel().getTimerSpeed());
@@ -296,7 +296,7 @@ public class TimePanel extends JPanel implements ActionListener{
 		hint.setForeground(Color.red);
 		hint.setText(" ");
 		iterationsField=new JTextField(6);//Considering hundreds of thousands in an extreme case
-		iterationsField.setText(""+cont.getModel().getIterations());
+		iterationsField.setText(""+cont.getModel().getMaxIterations());
 		iterationsField.setToolTipText("0-" + MAX_ITERATIONS  );
 		iterationsField.addActionListener(this);
 		ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(1);
@@ -390,7 +390,7 @@ public class TimePanel extends JPanel implements ActionListener{
 			else resetField=false;
 			if(resetField)iterationsField.setText(""+iterations);
 			controller.getModel().setIterations(Integer.parseInt(iterationsField.getText()));
-			timeSlider.setMaximum(controller.getModel().getIterations()-1);
+			timeSlider.setMaximum(controller.getModel().getMaxIterations()-1);
 			timeSlider.setLabelTable(null);//Otherwise the ticks won't update
 			timeSlider.setMajorTickSpacing((int)Math.ceil(((double)iterations)/20));
 			timeSlider.setMinorTickSpacing((int)Math.ceil(((double)iterations)/100));//Even though the final mark can't actually be reached.

+ 0 - 790
src/ui/view/main/UnitGraph.java

@@ -1,790 +0,0 @@
-package ui.view.main;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Cursor;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.event.ComponentEvent;
-import java.awt.event.ComponentListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.geom.Path2D;
-import java.awt.geom.Point2D;
-import java.util.LinkedList;
-import java.util.ListIterator;
-
-import javax.swing.JPanel;
-
-import classes.UnitGraphPoint;
-import interfaces.GraphEditable;
-import interfaces.GraphEditable.Graphtype;
-import interfaces.LocalMode;
-import ui.controller.Control;
-import ui.model.Model;
-import utility.Vector2Int;
-
-/**
- * This Class represents a Graph where the User can model the behavior of
- * elements and switches over time.
- *
- * @author Tom Troppmann
- */
-public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
-
-    private static final long serialVersionUID = 1L;
-	
-	
-	// 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;
-	Color editDotColor = new Color(255, 119, 0);
-	
-	//Intern Variables
-	private LinkedList<UnitGraphPoint> actualGraphPoints = new LinkedList<UnitGraphPoint>();
-	private Graphtype actualGraphType = Graphtype.doubleGraph;
-	private GraphEditable actualElement;
-	Vector2Int editPosition;
-	boolean editMode = false;
-	private enum pointType {Normal, StartPoint, EndPoint};
-	pointType editPoint = pointType.Normal;
-	private Model model;
-	private int widthWithBorder, heightWithBorder;
-	
-	
-	
-	
-	
-	
-	
-	
-	
-    /**
-     * Constructor.
-     *
-     * @param model   the Model
-     * @param control the Controller
-     */
-    public UnitGraph(Control control) {
-        setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
-        this.model = control.getModel();
-        this.setBackground(Color.WHITE);
-
-        this.addMouseListener(this);
-        this.addMouseMotionListener(this);
-        this.addComponentListener(this);
-    }
-    /**
-     * 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) {
-        super.paintComponent(g);
-        Graphics2D g2D = (Graphics2D) g;
-        drawGrid(g2D);
-        g2D.setColor(Color.BLACK);
-        g2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
-        g2D.setStroke(new BasicStroke(2));
-        drawUnitGraph(g2D);
-        g2D.setColor(dotColor);
-        if(editMode)
-        {
-        	drawUnitGraphPointsReleased(g2D);
-        }else
-        {
-        	 drawUnitGraphPoints(g2D);
-        }
-        g2D.setColor(dotColor);
-        g2D.setStroke(new BasicStroke(1));
-        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);
-        int amountOfLines = 10;
-        int width = widthWithBorder + 2 * border;
-        int height = heightWithBorder;
-        for(int i = 0; i<=amountOfLines; i++)
-        {
-        	int linehieght = (int) (((double)i/ (double) amountOfLines) * (double) height) + border;
-        	g2D.drawLine(0, linehieght, width, linehieght);
-        }
-	}
-    
-	 /**
-     * 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;
-    	if(!this.isUsingLocalPeriod()) {
-    		where = ((double) cur)/((double) max);
-    	}
-    	else
-    	{
-    		int lPeriod = this.getLocalPeriod();
-    		where = ((double) cur%lPeriod)/((double) lPeriod);
-    	}
-    	Vector2Int oben = new Vector2Int(border + (int)(where * widthWithBorder), 0);
-    	Vector2Int unten = new Vector2Int(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, Vector2Int start, Vector2Int end)
-    {
-    	Path2D.Double path = new Path2D.Double();
-    	path.moveTo(start.getX(), start.getY());
-    	path.lineTo(end.getX(), end.getY());
-    	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(Vector2Int 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.getX(), start.getY());
-		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, Vector2Int actual, Vector2Int target) {
-         double mitte = (actual.getX() + target.getX())* 0.5;
-         path.curveTo(mitte, actual.getY(), mitte, target.getY(), target.getX(), target.getY());
-    }
-    /**
-     * 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, Vector2Int p)
-    {    	
-    	g.fillOval(p.getX() -dotSize/2, p.getY()-dotSize/2, dotSize, dotSize);
-    }
-    
-    
-    /**
-     * 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) {
-    	if(actualGraphPoints.size() <= 1) return;
-    	LinkedList<Vector2Int> cornerPoints =  new LinkedList<Vector2Int>();
-     	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
-     	Vector2Int actual = actualGraphPoints.getFirst().displayedPosition;
-     	Path2D.Double path = new Path2D.Double();
-     	path.moveTo(actual.getX(), actual.getY());
-     	while (iter.hasNext())
-    	{
-    		Vector2Int target = iter.next().displayedPosition;
-    		//BooleanConnection
-    		path.lineTo(target.getX(), actual.getY()); //line to corner
-    		cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); //save corner
-    		path.lineTo(target.getX(), target.getY()); //line to next Point
-    		
-    		actual = target;
-    	}
-     	g.draw(path);
-     	//Draw the Points on the Corner that dont exist in Data but should be visual
-     	g.setColor(dotColor);
-     	for(Vector2Int p: cornerPoints)
-     	{
-     		drawDot(g, p);
-     	}
-     	
-    }
-    /**
-     * 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<Vector2Int> before = new LinkedList<Vector2Int>();
-     	LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
-     	for(UnitGraphPoint p: actualGraphPoints)
-     	{
-     		if(p.displayedPosition.getX() < editPosition.getX())
-     			before.add(p.displayedPosition);
-     		else
-     			after.add(p.displayedPosition);
-     	}    	
-     	g.setColor(Color.BLACK);
-     	drawBoolGraphFromList(g, before);
-     	g.setColor(Color.BLACK);
-     	drawBoolGraphFromList(g, after);
-     	//EditGraph
-     	LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
-     	if(!before.isEmpty()) middle.add(before.getLast());
-     	middle.add(editPosition);
-    	if(!after.isEmpty()) middle.add(after.getFirst());
-    	
-    	g.setColor(editDotColor);
-    	drawBoolGraphFromList(g, middle);
-    	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
-    	g.setColor(Color.RED);
-    	//Threshhold Line
-    	final float dash1[] = {10.0f};
-        final BasicStroke dashed =new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
-        g.setStroke(dashed);
-        
-        
-        int halfheight =  border + heightWithBorder / 2;
-        g.drawLine(0, halfheight , widthWithBorder + 2 * border, halfheight);
-        //Threshhold Text
-        g.drawString("Snapping Threshold", 10, halfheight - 2);
-    }
-    
-    
-    
-    /**
-     * 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<Vector2Int> list) {
-		if(list.size() <= 1) return;
-     	ListIterator<Vector2Int> iter = list.listIterator();
-      	LinkedList<Vector2Int> cornerPoints =  new LinkedList<Vector2Int>();
-     	Vector2Int actual = list.getFirst();
-     	Path2D.Double path = new Path2D.Double();
-     	path.moveTo(actual.getX(), actual.getY());
-     	while (iter.hasNext())
-    	{
-    		Vector2Int target = iter.next();
-    		//BooleanConnection
-    		path.lineTo(target.getX(), actual.getY()); //line to corner
-    		cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); //save corner
-    		path.lineTo(target.getX(), target.getY()); //line to next Point
-    		actual = target;
-    	}
-     	g.draw(path);
-    	g.setColor(dotColor);
-     	for(Vector2Int p: cornerPoints)
-     	{
-     		drawDot(g, p);
-     	}
-	}
-    
-	  /**
-     * 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()) return;//throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
-    	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
-    	Vector2Int actual = iter.next().displayedPosition;
-    	Path2D.Double path = this.initBezier(actual);
-    	while (iter.hasNext())
-    	{
-    		Vector2Int target = iter.next().displayedPosition;
-    		this.curveTo(path, actual, target);
-    		actual = target;
-    	}
-    	g.draw(path);
-    	
-    }
-    /**
-     * 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<Vector2Int> before = new LinkedList<Vector2Int>();
-     	LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
-     	for(UnitGraphPoint p: actualGraphPoints)
-     	{
-     		if(p.displayedPosition.getX() < editPosition.getX())
-     			before.add(p.displayedPosition);
-     		else
-     			after.add(p.displayedPosition);
-     	}    	
-     	drawUnitGraphFromList(g, before);
-     	drawUnitGraphFromList(g, after);
-     	//EditGraph
-     	LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
-     	if(!before.isEmpty()) middle.add(before.getLast());
-     	middle.add(editPosition);
-    	if(!after.isEmpty()) middle.add(after.getFirst());
-    	
-    	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<Vector2Int> list) {
-		if(list.size() <= 1) return;
-     	ListIterator<Vector2Int> iter = list.listIterator();
-     	Vector2Int actual = list.getFirst();
-     	Path2D.Double path = this.initBezier(actual);
-     	while (iter.hasNext())
-    	{
-    		Vector2Int target = iter.next();
-    		curveTo(path, actual, target);
-    		actual = target;
-    	}
-     	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){
-    		actualGraphPoints.add(new UnitGraphPoint(p));
-    	}
-    	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;
-    }
-    
-    /**
-     * 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(Vector2Int mPosition) {
-    	ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
-    	while (iter.hasNext())
-    	{
-    		if(near(mPosition,iter.next().displayedPosition))
-    		{
-    			iter.remove();
-    			break;
-    		}
-    	}
-    }
-    
-    
-    /**
-     * 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(Vector2Int mPosition)
-    {
-    	UnitGraphPoint first = actualGraphPoints.getFirst();
-    	UnitGraphPoint last = actualGraphPoints.getLast();
-    	if(near(mPosition, first.displayedPosition)) editPoint = pointType.StartPoint;
-    	else if(near(mPosition, last.displayedPosition))  editPoint = pointType.EndPoint;
-    	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(Vector2Int actual, Vector2Int target) {
-		switch(actualGraphType)
-		{
-		case boolGraph: //Distance only with X 
-			int xDis = target.getX() - actual.getX();
-			return xDis * xDis  < clickThreshholdSquared;
-		case doubleGraph:
-			return actual.getSquaredDistance(target) < clickThreshholdSquared;
-		default:
-			return false;
-		}	
-	}
-    
-	/**
-	 * When the Mouse Drag a Point it updates each time the position.
-	 * @param newPosition
-	 */
-    private void updateEditPointPosition(Vector2Int newPosition) {
-    	//make it in the bounds of the UnitGraph no Point out of the Border
-    	Vector2Int currentPosition = setInBounds(newPosition);
-    	if(editPoint != pointType.Normal) attachToBorder(currentPosition);
-    	if(actualGraphType == Graphtype.boolGraph) snapBoolean(currentPosition);
-    	this.editPosition = currentPosition;
-    }
-    
-    
-    /**
-     * No Point on the UnitGraph should exit the UnitGraph.
-     * @param p the Position
-	 * @return the updated Position.
-     */
-	private Vector2Int setInBounds(Vector2Int p) {
-		p.clampX(border, border + widthWithBorder);
-		p.clampY(border, border + heightWithBorder);
-		return p;
-	}
-    
-	
-	
-	/**
-	 * For Switches the Point have to be Snap to the Top or the Bottem.
-	 * @param p the Position
-	 * @return the updated Position.
-	 */
-	private Vector2Int snapBoolean(Vector2Int p)
-	{
-		if (p.getY() < border + heightWithBorder / 2) {
-			p.setY(border);
-		} else {
-			p.setY(border + heightWithBorder);
-		}
-		return p;
-	}
-	
-	
-	/**
-	 * 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 Vector2Int attachToBorder(Vector2Int p)
-	{
-		switch(editPoint)
-		{
-		case StartPoint:
-			p.setX(border);
-			break;
-		case EndPoint:
-			p.setX(border + widthWithBorder);
-			break;
-		default:
-			break;
-		}
-		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(Vector2Int pos)
-    {
-    	setInBounds(pos);
-    	ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
-    	while (iter2.hasNext())
-    	{
-    		Vector2Int tempPosition = iter2.next().displayedPosition;
-    		if(pos.getX() <= tempPosition.getX())
-    		{
-    			//previous to go back a position to make the new point before the the Position with greater X
-    			iter2.previous();
-    			iter2.add(generateUnitGraphPoint(pos));
-    			break;
-    		}
-    	}
-    	if(!iter2.hasNext()) //if behind last point
-    	{
-    		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(Vector2Int pos) {
-		UnitGraphPoint temp = new UnitGraphPoint((double) (pos.getX() - border) / (double) widthWithBorder,
-				1 - (double) (pos.getY() - border) / (double) heightWithBorder, true);
-		temp.displayedPosition = pos;
-		return temp;
-	}
-
-    /**
-     * Update the Point Position 
-     */
-	@Override
-    public void mouseDragged(MouseEvent e) {
-    	updateEditPointPosition(new Vector2Int(e.getPoint().x, e.getPoint().y));
-    	repaint();
-    }
-
-    @Override
-    public void mouseMoved(MouseEvent e) {
-    }
-
-    @Override
-    public void mouseClicked(MouseEvent e) {
-    }
-
-    @Override
-    public void mouseEntered(MouseEvent e) {
-    }
-
-    @Override
-    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) {
-		Vector2Int mPosition = new Vector2Int(e.getPoint().x, e.getPoint().y);
-		if (e.getButton() == MouseEvent.BUTTON3) {
-			// RightMouseButtonEvent
-			detectStartEndPoint(mPosition);
-			if (editPoint == pointType.Normal) {
-				removePointNearPosition(mPosition);
-				repaint();
-			}
-			editMode = false;
-
-		} else if (e.getButton() == MouseEvent.BUTTON1) {
-			// LeftMouseButtonEvent
-			detectStartEndPoint(mPosition);
-			removePointNearPosition(mPosition);
-			updateEditPointPosition(mPosition);
-			editMode = true;
-			repaint();
-		}
-	}
-
-    /**
-     * The last step to save the Changes.
-     * Its insert the Hovering Point and exit EditMode.
-     */
-    @Override
-    public void mouseReleased(MouseEvent e) {
-    	if(editMode)
-    	{
-    		this.insertNewGraphPoint(editPosition);
-    		editMode = false;
-    		repaint();
-    	}
-    	saveGraph();
-    }
-
-    /**
-     * When the Component is Resized.
-     *
-     * @param e ComponentEvent
-     */
-    public void componentResized(ComponentEvent e) {
-    	calculateWidthHeight();
-    	updateRepresentativePositions();
-        repaint();
-    }
-
-    @Override
-    public void componentHidden(ComponentEvent e) {
-    }
-
-    @Override
-    public void componentMoved(ComponentEvent e) {
-
-    }
-
-    @Override
-    public void componentShown(ComponentEvent e) {
-    }
-
-    /**
-     * Resets the graph to normal.
-     */
-    public void reset() {
-       	if(this.actualElement != null) {
-       		actualElement.reset();
-       		overrideUnitGraph(actualElement.getStateGraph());
-       		repaint();
-       	}
-       	
-    }
-
-
-    
-    //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) {
-		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;
-	}
-
-	
-    
-
-}

+ 2 - 2
src/ui/view/window/FlexWindow.java

@@ -478,7 +478,7 @@ public class FlexWindow extends JFrame {
 		Flexibility toDeleteFlex =(Flexibility) JOptionPane.showInputDialog(this, "Select to Delete Flexibility:", "Flexibility?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , allFlexes, "");
 		if(toDeleteFlex != null) {
 			toDeleteFlex.getElement().flexList.remove(toDeleteFlex);
-			controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), true);
+			controller.getSimManager().calculateStateForTimeStep(model.getCurrentIteration(), true);
 			updateSelectedPanel();
 		}
 	}
@@ -701,7 +701,7 @@ public class FlexWindow extends JFrame {
 			
 			
 			//if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem());
-			controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), true);
+			controller.getSimManager().calculateStateForTimeStep(model.getCurrentIteration(), true);
 			
 			update();
 			addDialog.dispose();

+ 2 - 2
tests/tests/PraktikumHolonsTestGlobalController.java

@@ -37,7 +37,7 @@ public class PraktikumHolonsTestGlobalController {
 		int prevScaleDiv2 = controller.getScaleDiv2();
 		int prevNumberSav = controller.getNumbersOfSaves();
 		int timer = model.getTimerSpeed();
-		int it = model.getCurIteration();
+		int it = model.getCurrentIteration();
 
 		controller.setScale(100);
 		controller.setNumberOfSaves(50);
@@ -48,7 +48,7 @@ public class PraktikumHolonsTestGlobalController {
 		assertTrue("ScaleDiv2 was not changed ", model.getScaleDiv2() != prevScaleDiv2);
 		assertTrue("Number of Saves was not changed", controller.getNumbersOfSaves() != prevNumberSav);
 		assertTrue("Timer speed was not changed", timer != model.getTimerSpeed());
-		assertTrue("Curr Iteration was not Set", it != model.getCurIteration());
+		assertTrue("Curr Iteration was not Set", it != model.getCurrentIteration());
 
 	}