Преглед изворни кода

Display the actual state correct.

Tom Troppmann пре 5 година
родитељ
комит
e128b07212

+ 8 - 1
src/classes/HolonSwitch.java

@@ -120,11 +120,18 @@ public class HolonSwitch extends AbstractCpsObject implements LocalMode, GraphEd
 
 	}
 
+	public static String getSwitchClosedImage(){
+		return "/Images/switch-on.png";
+	}
+	
+	public static String getSwitchOpenImage(){
+		return "/Images/switch-off.png";
+	}
 	/**
 	 * Getter for the status of the Switch at a given timestep.
 	 * 
 	 * @param timeStep state at given iteration.
-	 * @return state value
+	 * @return state value (true if closed/active, false if open)
 	 */
 	public boolean getState(int timeStep) {
 		if (manualMode) {

+ 46 - 19
src/ui/controller/CalculataModel.java

@@ -5,59 +5,88 @@ import java.util.LinkedList;
 import java.util.ListIterator;
 
 import classes.AbstractCpsObject;
-import classes.CpsEdge;
 import classes.HolonObject;
 import classes.HolonSwitch;
+import ui.model.CableWithState;
+import ui.model.CableWithState.CableState;
+import ui.model.DecoratedSwitch;
+import ui.model.DecoratedSwitch.SwitchState;
 import ui.model.MinimumModel;
 import ui.model.MinimumNetwork;
 
 public class CalculataModel {
-	public static ArrayList<MinimumNetwork> calculateNetworks(MinimumModel minModel, int Iteration){
+	public static ArrayList<DecoratedSwitch> decorateSwitches(MinimumModel minModel, int iteration) {
+		ArrayList<DecoratedSwitch> aListOfDecoratedSwitches = new ArrayList<DecoratedSwitch>(); 
+		for(HolonSwitch hSwitch: minModel.getSwitchList()) {
+			aListOfDecoratedSwitches.add(new DecoratedSwitch(hSwitch, hSwitch.getState(iteration) ? SwitchState.Closed : SwitchState.Open));
+		}
+		return aListOfDecoratedSwitches;
+	}
+	public static ArrayList<MinimumNetwork> calculateNetworks(MinimumModel minModel, int Iteration, ArrayList<CableWithState> leftOver){
+		//Copy minModel ObjectList
+		ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
+		for(HolonObject holonObject: minModel.getHolonObjectList()) {
+			holonObjectList.add(holonObject);
+		}
+		//Copy minModelEdgeList
+		ArrayList<CableWithState> edgeList = new ArrayList<CableWithState>();
+		for(CableWithState cable: minModel.getEdgeList()) {
+			edgeList.add(cable);
+		}
+		
 		ArrayList<MinimumNetwork> listOfNetworks = new ArrayList<MinimumNetwork>();
-		while(!minModel.getHolonObjectList().isEmpty()) {
+		while(!holonObjectList.isEmpty()) {
 			//lookAt the first holonObject and find his neighbors
-			HolonObject lookAtObject = minModel.getHolonObjectList().get(0);
+			HolonObject lookAtObject = holonObjectList.get(0);
 			//delete out of list
-			minModel.getHolonObjectList().remove(0);
+			holonObjectList.remove(0);
 			//create a new Network
-			MinimumNetwork actualNetwork = new MinimumNetwork(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>());
+			MinimumNetwork actualNetwork = new MinimumNetwork(new ArrayList<HolonObject>(), new ArrayList<CableWithState>());
 			actualNetwork.getHolonObjectList().add(lookAtObject);
 			//create List of neighbors
 			LinkedList<AbstractCpsObject> neighbors = new LinkedList<AbstractCpsObject>();
-			populateListOfNeighbors(minModel, lookAtObject, actualNetwork, neighbors);
+			populateListOfNeighbors(edgeList, lookAtObject, actualNetwork, neighbors);
 			while(!neighbors.isEmpty()) {
 				AbstractCpsObject lookAtNeighbor = neighbors.getFirst();
 				if(lookAtNeighbor instanceof HolonObject) {
 					actualNetwork.getHolonObjectList().add((HolonObject) lookAtNeighbor);
-					minModel.getHolonObjectList().remove(lookAtNeighbor);
+					holonObjectList.remove(lookAtNeighbor);
 				}
 				//When HolonSwitch Check if closed
 				if(!(lookAtNeighbor instanceof HolonSwitch) || ((HolonSwitch)lookAtNeighbor).getState(Iteration)) {
-					populateListOfNeighbors(minModel, lookAtNeighbor, actualNetwork, neighbors);
+					populateListOfNeighbors(edgeList, lookAtNeighbor, actualNetwork, neighbors);
 				}
 				
 				neighbors.removeFirst();
 			}
 			listOfNetworks.add(actualNetwork);
 		}	
+		if(leftOver!= null) {
+			leftOver.clear();
+			for(CableWithState cable: edgeList) {
+				leftOver.add(cable);
+			}
+		}
 		return listOfNetworks;
 	}
 
-	private static void populateListOfNeighbors(MinimumModel minModel, AbstractCpsObject lookAtObject,
+	private static void populateListOfNeighbors(ArrayList<CableWithState> edgeList, AbstractCpsObject lookAtObject,
 			MinimumNetwork actualNetwork, LinkedList<AbstractCpsObject> neighbors) {
-		ListIterator<CpsEdge> iter = minModel.getEdgeList().listIterator();
+		ListIterator<CableWithState> iter = edgeList.listIterator();
 		while(iter.hasNext())
 		{
-			CpsEdge lookAtEdge = iter.next();
-			if(lookAtEdge.isConnectedTo(lookAtObject)) {
+			CableWithState lookAtEdge = iter.next();
+			if(lookAtEdge.getState() == CableState.Working && lookAtEdge.getModel().isConnectedTo(lookAtObject)) {
 				iter.remove();
 				actualNetwork.getEdgeList().add(lookAtEdge);
+				
 				//Add neighbar
 				AbstractCpsObject edgeNeighbor;
-				if(lookAtEdge.getA().equals(lookAtObject)) {
-					edgeNeighbor = lookAtEdge.getB();
+				if(lookAtEdge.getModel().getA().equals(lookAtObject)) {
+					edgeNeighbor = lookAtEdge.getModel().getB();
+					
 				}else {
-					edgeNeighbor = lookAtEdge.getA();
+					edgeNeighbor = lookAtEdge.getModel().getA();
 				}
 				if(!neighbors.contains(edgeNeighbor)) {
 					neighbors.add(edgeNeighbor);
@@ -66,7 +95,5 @@ public class CalculataModel {
 		}
 	}
 	
-	public static void calculateDecNetworkModel(MinimumNetwork actualNetwork) {
-		
-	}
+
 }

+ 335 - 269
src/ui/controller/SimulationManager.java

@@ -4,6 +4,14 @@ import classes.*;
 import classes.comparator.EnergyMinToMaxComparator;
 import classes.comparator.MinEnergyComparator;
 import classes.comparator.WeakestBattery;
+import ui.model.CableWithState;
+import ui.model.DecoratedCable;
+import ui.model.CableWithState.CableState;
+import ui.model.DecoratedNetwork;
+import ui.model.DecoratedState;
+import ui.model.DecoratedSwitch;
+import ui.model.MinimumModel;
+import ui.model.MinimumNetwork;
 import ui.model.Model;
 import ui.view.FlexiblePane;
 import ui.view.MyCanvas;
@@ -11,6 +19,8 @@ import ui.view.MyCanvas;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+
+import javax.swing.JPanel;
 
 
 /**
@@ -25,6 +35,10 @@ public class SimulationManager {
 	// private ArrayList<CpsEdge> allConnections;
 	private ArrayList<SubNet> subNets;
 	private ArrayList<CpsEdge> brokenEdges;
+	
+	private ArrayList<DecoratedNetwork> decorNetworks = new ArrayList<DecoratedNetwork>();
+	private DecoratedState decorState;
+	private MinimumModel minimumModel = null;
 	private MyCanvas canvas;
 	private int timeStep;
 	private HashMap<Integer, Float> tagTable = new HashMap<>();
@@ -60,282 +74,321 @@ public class SimulationManager {
 	/**
 	 * calculates the flow of the edges and the supply for objects.
 	 *
-	 * @param x
+	 * @param timestep
 	 *            current Iteration
 	 */
-	void calculateStateForTimeStep(int x) {
-		reset();
-		timeStep = x;
-		searchForSubNets();
-		for (SubNet singleSubNet : subNets) {
-			if(singleSubNet.getObjects().size() == 0)
-			{
-				resetConnections(singleSubNet.getBatteries().get(0),
-						new ArrayList<>(), new ArrayList<>());
-			}else
-			{
-				resetConnections(singleSubNet.getObjects().get(0),
-					new ArrayList<>(), new ArrayList<>());
-			}
-			
+	void calculateStateForTimeStep(int timestep) {
+		System.out.println("Calculate Timestep: " + timestep);
+		timeStep = timestep;
+		decorNetworks.clear();
+		ArrayList<MinimumNetwork> list =  new ArrayList<MinimumNetwork>();
+		minimumModel = new MinimumModel(model.getObjectsOnCanvas(), model.getEdgesOnCanvas());
+		//set all working:
+		for(CableWithState cable : minimumModel.getEdgeList()) {
+			cable.setState(CableState.Working);
 		}
-		for (SubNet singleSubNet : subNets) {
-			float production = calculateEnergyWithoutFlexDevices("prod",
-					singleSubNet, timeStep);
-			float consumption = calculateEnergyWithoutFlexDevices("cons",
-					singleSubNet, timeStep);
-			// surplus of energy is computed by sum, since consumption is a
-			// negative value
-			float energySurplus = production + consumption;
-			
-			
-			//float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
-
-			// --------------- use flexible devices ---------------
-			if (energySurplus != 0 && model.useFlexibleDevices()) {
-				turnOnFlexibleDevices(singleSubNet, energySurplus, x);
-
-				// if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
-				// System.out.println("The following devices were turned on in this turn: ");
-				// System.out.println(flexDevicesTurnedOnThisTurn.toString());
-				// }
-
-				// recompute after having examined/turned on all flexible
-				// devices
-				production = calculateEnergyWithFlexDevices("prod",
-						singleSubNet, timeStep);
-				consumption = calculateEnergyWithFlexDevices("cons",
-						singleSubNet, timeStep);
-				energySurplus = production + consumption;
-			}
-
-			// --------------- set flow simulation ---------------
-			setFlowSimulation(singleSubNet);
-
-			// --------------- visualise graph ---------------
-
-			/**
-			 * production of subnets, that might be partially turned on/off
-			 */
-			float currentProduction = production;
-			/**
-			 * HolonObjects that can be partially Supplied but might be fully
-			 * Supplied
-			 */
-			/*
-			ArrayList<HolonObject> partiallySuppliedList = new ArrayList<HolonObject>();
-			/**
-			 * HolonObjects that can get the spare energy
-			 */
-//			
-//			ArrayList<HolonObject> notSuppliedList = new ArrayList<HolonObject>();
-			/**
-			 * Number of HolonObjects that need to be supplied
-			 */
-//			long numberOfConsumers = singleSubNet.getObjects().stream()
-//			.filter(hl -> (hl.getState() != HolonObject.NO_ENERGY
-//					&& hl.getState() != HolonObject.PRODUCER && hl
-//					.getConnectedTo().stream()
-//					.filter(e -> (e.getFlow() > 0)).count() > 0))
-//			.count();
-			/**
-			 * energy each HolonObject receives in AlleEqualModus
-			 */
-			
-			if(energySurplus >= 0)
-			{
-				//Supply all consumer
-				for(HolonObject hO : singleSubNet.getObjects())
-				{
-					float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
-					if(neededEnergy < 0)
-					{
-						hO.setCurrentSupply(-neededEnergy);
-						currentProduction -= -neededEnergy; //Subtract the Energy from the Production
-					}
-				}
-				//Supply all Batterys with the left currentProduction
-				singleSubNet.getBatteries().sort(new WeakestBattery(x));//Sort all batteries by the Value of ther StateOfCharge/Capasity
-				for(HolonBattery hB : singleSubNet.getBatteries())
-				{
-					float energyToCollect = hB.getInAtTimeStep(x-1);
-					if(currentProduction >= energyToCollect)
-					{
-						//change StateofCharge soc = soc + energyToCollect
-						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + energyToCollect, x);
-						currentProduction -= energyToCollect;
-					}else
-					{
-						//change StateofCharge soc = soc + currentProduction
-						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + currentProduction, x);
-						currentProduction = 0;
-						//no break must be calculatet for all break; //because no more energy
-					}
-				}
-				//Over_Supply all consumer equal
-				long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();			
-				if(nOConsumer != 0)
-				{
-					//energy to seperated equal 
-					float EnergyOverSupplyPerHolonObject = currentProduction / nOConsumer;
-					for(HolonObject hO : singleSubNet.getObjects())
-					{
-						float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
-						if(neededEnergy < 0)
-						{
-							hO.setCurrentSupply(hO.getCurrentSupply() + EnergyOverSupplyPerHolonObject);
-						}
-					}
-					currentProduction = 0;
-				}
-			}
-			else
-			{
-				//Check all Battries what they can provide
-				if(energySurplus + GetOutAllBatteries(singleSubNet.getBatteries(), x) >= 0)
-				{
-					singleSubNet.getBatteries().sort(new WeakestBattery(x));//.reverse();
-					Collections.reverse(singleSubNet.getBatteries()); //most supplyed first
-					//Get the NEEDED energy
-					for(HolonBattery hB : singleSubNet.getBatteries())
-					{
-						float neededEnergyFromBattery = currentProduction + consumption; //Energy is negativ
-						float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
-						if(maxEnergyAvailable >= -neededEnergyFromBattery)
-						{
-							//change StateofCharge soc = soc - -neededEnergyFromBattery
-							hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - -neededEnergyFromBattery, x);
-							currentProduction += -neededEnergyFromBattery;
-							//no break must be calculatet for all beabreak; //When a energy can supply the last needed energy break;
-						}
-						else
-						{
-							//change StateofCharge soc = soc - maxEnergyAvailable
-							hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
-							currentProduction += maxEnergyAvailable;
-						}
-					}
-					//Supply all consumer all ar in state Supplied no one is oversupplied because 
-					//	just the energy that is needed is gained from the batteries
-					for(HolonObject hO : singleSubNet.getObjects())
-					{
-						float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
-						if(neededEnergy < 0)
-						{
-							hO.setCurrentSupply(-neededEnergy);
-							currentProduction -= -neededEnergy; //Subtract the Energy from the Production
-						}
-					}
-				}
-				else //Objects have to be partially supplied
-				{
-					//Get all Energy out of battries as possible
-					for(HolonBattery hB : singleSubNet.getBatteries())
-					{
-						float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
-						//change StateofCharge soc = soc - maxEnergyAvailable
-						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
-						currentProduction += maxEnergyAvailable;
-					}
-					//Calc
-					singleSubNet.getObjects().stream().forEach(hl -> hl.setCurrentSupply(0));
-					if(model.getFairnessModel() == fairnessAllEqual)
-					{
-						long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
-						float energyPerHolonObject = 0;
-						if (nOConsumer != 0)
-							energyPerHolonObject = currentProduction / nOConsumer;
-						for(HolonObject hO : singleSubNet.getObjects())
-						{
-							if(hO.getCurrentEnergyAtTimeStep(x) < 0) //Just Consumer need Energy 
-							{
-								hO.setCurrentSupply(energyPerHolonObject);
-								currentProduction -= energyPerHolonObject; //Subtract the Energy from the Production
-							}
-						}
-					}
-					else //(model.getFairnessModel() == fairnessMininumDemandFirst)
-					{
-						singleSubNet.getObjects().sort(new MinEnergyComparator(x));
-						//SupplyAllMinimumEnergy
-						for(HolonObject hO : singleSubNet.getObjects())
-						{
-							if(hO.checkIfPartiallySupplied(x))continue;
-							if(hO.getCurrentEnergyAtTimeStep(x) > 0)continue;
-							float minEnergy = -hO.getMinEnergy(x); //Energy from getMinEnergy is negative -> convert to positive
-							if(minEnergy <= currentProduction)
-							{
-								hO.setCurrentSupply(minEnergy);
-								currentProduction -= minEnergy;
-							}else
-							{
-								hO.setCurrentSupply(currentProduction);
-								currentProduction = 0;
-								break;
-							}
-						}
-						singleSubNet.getObjects().sort(new EnergyMinToMaxComparator(x));
-						//supplyFullytillEnd ... because its cant be fully supplied 
-						for(HolonObject hO : singleSubNet.getObjects())
-						{
-							
-							float actualSupplyEnergy = hO.getCurrentSupply();
-							float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x) - actualSupplyEnergy;
-							if(neededEnergy <= 0)continue; //Producer or No EnergyNeeded
-							if(neededEnergy <= currentProduction)
-							{
-								hO.setCurrentSupply(neededEnergy+actualSupplyEnergy);
-								currentProduction -= neededEnergy;
-							}else
-							{
-								hO.setCurrentSupply(currentProduction+actualSupplyEnergy);
-								currentProduction = 0;
-								break;
-							}
-						}
-						
-						
-					}
-				}
-				
-			}
-			//Visualize the Color
-			for(HolonObject hO : singleSubNet.getObjects())
-			{
-				float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x); // convert negative energy in positive for calculations
-				if(neededEnergy < 0)
-				{
-					hO.setState(HolonObject.PRODUCER);
-				}
-				else if(neededEnergy > 0)
-				{
-					float currentSupply = hO.getCurrentSupply() ;
-					if(currentSupply > neededEnergy)
-					{
-						hO.setState(HolonObject.OVER_SUPPLIED);
-					}else if (currentSupply ==  neededEnergy)
-					{
-						hO.setState(HolonObject.SUPPLIED);
-					}else if (currentSupply <  neededEnergy)
-					{
-						float minEnergy = -hO.getMinEnergy(x);
-						if(currentSupply >= minEnergy || hO.getSelfMadeEnergy(x)  >= minEnergy )
-						{
-							hO.setState(HolonObject.PARTIALLY_SUPPLIED);
-						}else
-						{
-							hO.setState(HolonObject.NOT_SUPPLIED);
-						}
-					}
-				}
-				else if(neededEnergy == 0)
-				{
-					hO.setState(HolonObject.NO_ENERGY);
+		ArrayList<CableWithState> leftOver = new ArrayList<CableWithState>();
+		boolean doAnotherLoop = true;
+		while(doAnotherLoop) {
+			doAnotherLoop = false;
+			list = CalculataModel.calculateNetworks(minimumModel, timestep, leftOver);
+			for(MinimumNetwork net : list) {
+				float energyOnCables = net.getHolonObjectList().stream().filter(object -> object.getEnergyAtTimeStep(timestep) > 0.0f).map(object -> object.getEnergyAtTimeStep(timestep)).reduce(0.0f, ((a,b) -> a + b));
+				//find the cable with the energy supplied from his two connected objects are the biggest, from all cables that the network give more energy than the cablecapacity. 
+				CableWithState cable = net.getEdgeList().stream().filter(aCable -> energyOnCables > aCable.getModel().getCapacity()).max((lhs,rhs) -> Float.compare(lhs.getEnergyFromConnetedAtTimestep(timestep), rhs.getEnergyFromConnetedAtTimestep(timestep))).orElse(null);
+				if(cable != null) {
+					cable.setState(CableState.Burned);
+					doAnotherLoop = true;
 				}
 			}
 		}
+		
+		for (MinimumNetwork net : list) {
+			decorNetworks.add(new DecoratedNetwork(net, timestep));
+		}
+		ArrayList<DecoratedCable> leftOverDecoratedCables = new ArrayList<DecoratedCable>();
+		
+		for(CableWithState cable: leftOver) {
+			leftOverDecoratedCables.add(new DecoratedCable(cable.getModel(), CableWithState.convertCableStateToDecoratedCableState(cable.getState()), 0.0f));
+		}
+		ArrayList<DecoratedSwitch> listOfDecoratedSwitches = CalculataModel.decorateSwitches(minimumModel, timestep);
+		decorState = new DecoratedState(decorNetworks, leftOverDecoratedCables, listOfDecoratedSwitches);
 		canvas.repaint();
-		flexPane.recalculate();
+//		for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
+//		    System.out.println(ste);
+////		}
+//		reset();
+//		timeStep = x;
+//		searchForSubNets();
+//		for (SubNet singleSubNet : subNets) {
+//			if(singleSubNet.getObjects().size() == 0)
+//			{
+//				resetConnections(singleSubNet.getBatteries().get(0),
+//						new ArrayList<>(), new ArrayList<>());
+//			}else
+//			{
+//				resetConnections(singleSubNet.getObjects().get(0),
+//					new ArrayList<>(), new ArrayList<>());
+//			}
+//			
+//		}
+//		for (SubNet singleSubNet : subNets) {
+//			float production = calculateEnergyWithoutFlexDevices("prod",
+//					singleSubNet, timeStep);
+//			float consumption = calculateEnergyWithoutFlexDevices("cons",
+//					singleSubNet, timeStep);
+//			// surplus of energy is computed by sum, since consumption is a
+//			// negative value
+//			float energySurplus = production + consumption;
+//			
+//			
+//			//float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
+//
+//			// --------------- use flexible devices ---------------
+//			if (energySurplus != 0 && model.useFlexibleDevices()) {
+//				turnOnFlexibleDevices(singleSubNet, energySurplus, x);
+//
+//				// if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
+//				// System.out.println("The following devices were turned on in this turn: ");
+//				// System.out.println(flexDevicesTurnedOnThisTurn.toString());
+//				// }
+//
+//				// recompute after having examined/turned on all flexible
+//				// devices
+//				production = calculateEnergyWithFlexDevices("prod",
+//						singleSubNet, timeStep);
+//				consumption = calculateEnergyWithFlexDevices("cons",
+//						singleSubNet, timeStep);
+//				energySurplus = production + consumption;
+//			}
+//
+//			// --------------- set flow simulation ---------------
+//			setFlowSimulation(singleSubNet);
+//
+//			// --------------- visualise graph ---------------
+//
+//			/**
+//			 * production of subnets, that might be partially turned on/off
+//			 */
+//			float currentProduction = production;
+//			/**
+//			 * HolonObjects that can be partially Supplied but might be fully
+//			 * Supplied
+//			 */
+//			/*
+//			ArrayList<HolonObject> partiallySuppliedList = new ArrayList<HolonObject>();
+//			/**
+//			 * HolonObjects that can get the spare energy
+//			 */
+////			
+////			ArrayList<HolonObject> notSuppliedList = new ArrayList<HolonObject>();
+//			/**
+//			 * Number of HolonObjects that need to be supplied
+//			 */
+////			long numberOfConsumers = singleSubNet.getObjects().stream()
+////			.filter(hl -> (hl.getState() != HolonObject.NO_ENERGY
+////					&& hl.getState() != HolonObject.PRODUCER && hl
+////					.getConnectedTo().stream()
+////					.filter(e -> (e.getFlow() > 0)).count() > 0))
+////			.count();
+//			/**
+//			 * energy each HolonObject receives in AlleEqualModus
+//			 */
+//			
+//			if(energySurplus >= 0)
+//			{
+//				//Supply all consumer
+//				for(HolonObject hO : singleSubNet.getObjects())
+//				{
+//					float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
+//					if(neededEnergy < 0)
+//					{
+//						hO.setCurrentSupply(-neededEnergy);
+//						currentProduction -= -neededEnergy; //Subtract the Energy from the Production
+//					}
+//				}
+//				//Supply all Batterys with the left currentProduction
+//				singleSubNet.getBatteries().sort(new WeakestBattery(x));//Sort all batteries by the Value of ther StateOfCharge/Capasity
+//				for(HolonBattery hB : singleSubNet.getBatteries())
+//				{
+//					float energyToCollect = hB.getInAtTimeStep(x-1);
+//					if(currentProduction >= energyToCollect)
+//					{
+//						//change StateofCharge soc = soc + energyToCollect
+//						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + energyToCollect, x);
+//						currentProduction -= energyToCollect;
+//					}else
+//					{
+//						//change StateofCharge soc = soc + currentProduction
+//						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + currentProduction, x);
+//						currentProduction = 0;
+//						//no break must be calculatet for all break; //because no more energy
+//					}
+//				}
+//				//Over_Supply all consumer equal
+//				long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();			
+//				if(nOConsumer != 0)
+//				{
+//					//energy to seperated equal 
+//					float EnergyOverSupplyPerHolonObject = currentProduction / nOConsumer;
+//					for(HolonObject hO : singleSubNet.getObjects())
+//					{
+//						float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
+//						if(neededEnergy < 0)
+//						{
+//							hO.setCurrentSupply(hO.getCurrentSupply() + EnergyOverSupplyPerHolonObject);
+//						}
+//					}
+//					currentProduction = 0;
+//				}
+//			}
+//			else
+//			{
+//				//Check all Battries what they can provide
+//				if(energySurplus + GetOutAllBatteries(singleSubNet.getBatteries(), x) >= 0)
+//				{
+//					singleSubNet.getBatteries().sort(new WeakestBattery(x));//.reverse();
+//					Collections.reverse(singleSubNet.getBatteries()); //most supplyed first
+//					//Get the NEEDED energy
+//					for(HolonBattery hB : singleSubNet.getBatteries())
+//					{
+//						float neededEnergyFromBattery = currentProduction + consumption; //Energy is negativ
+//						float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
+//						if(maxEnergyAvailable >= -neededEnergyFromBattery)
+//						{
+//							//change StateofCharge soc = soc - -neededEnergyFromBattery
+//							hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - -neededEnergyFromBattery, x);
+//							currentProduction += -neededEnergyFromBattery;
+//							//no break must be calculatet for all beabreak; //When a energy can supply the last needed energy break;
+//						}
+//						else
+//						{
+//							//change StateofCharge soc = soc - maxEnergyAvailable
+//							hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
+//							currentProduction += maxEnergyAvailable;
+//						}
+//					}
+//					//Supply all consumer all ar in state Supplied no one is oversupplied because 
+//					//	just the energy that is needed is gained from the batteries
+//					for(HolonObject hO : singleSubNet.getObjects())
+//					{
+//						float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
+//						if(neededEnergy < 0)
+//						{
+//							hO.setCurrentSupply(-neededEnergy);
+//							currentProduction -= -neededEnergy; //Subtract the Energy from the Production
+//						}
+//					}
+//				}
+//				else //Objects have to be partially supplied
+//				{
+//					//Get all Energy out of battries as possible
+//					for(HolonBattery hB : singleSubNet.getBatteries())
+//					{
+//						float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
+//						//change StateofCharge soc = soc - maxEnergyAvailable
+//						hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
+//						currentProduction += maxEnergyAvailable;
+//					}
+//					//Calc
+//					singleSubNet.getObjects().stream().forEach(hl -> hl.setCurrentSupply(0));
+//					if(model.getFairnessModel() == fairnessAllEqual)
+//					{
+//						long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
+//						float energyPerHolonObject = 0;
+//						if (nOConsumer != 0)
+//							energyPerHolonObject = currentProduction / nOConsumer;
+//						for(HolonObject hO : singleSubNet.getObjects())
+//						{
+//							if(hO.getCurrentEnergyAtTimeStep(x) < 0) //Just Consumer need Energy 
+//							{
+//								hO.setCurrentSupply(energyPerHolonObject);
+//								currentProduction -= energyPerHolonObject; //Subtract the Energy from the Production
+//							}
+//						}
+//					}
+//					else //(model.getFairnessModel() == fairnessMininumDemandFirst)
+//					{
+//						singleSubNet.getObjects().sort(new MinEnergyComparator(x));
+//						//SupplyAllMinimumEnergy
+//						for(HolonObject hO : singleSubNet.getObjects())
+//						{
+//							if(hO.checkIfPartiallySupplied(x))continue;
+//							if(hO.getCurrentEnergyAtTimeStep(x) > 0)continue;
+//							float minEnergy = -hO.getMinEnergy(x); //Energy from getMinEnergy is negative -> convert to positive
+//							if(minEnergy <= currentProduction)
+//							{
+//								hO.setCurrentSupply(minEnergy);
+//								currentProduction -= minEnergy;
+//							}else
+//							{
+//								hO.setCurrentSupply(currentProduction);
+//								currentProduction = 0;
+//								break;
+//							}
+//						}
+//						singleSubNet.getObjects().sort(new EnergyMinToMaxComparator(x));
+//						//supplyFullytillEnd ... because its cant be fully supplied 
+//						for(HolonObject hO : singleSubNet.getObjects())
+//						{
+//							
+//							float actualSupplyEnergy = hO.getCurrentSupply();
+//							float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x) - actualSupplyEnergy;
+//							if(neededEnergy <= 0)continue; //Producer or No EnergyNeeded
+//							if(neededEnergy <= currentProduction)
+//							{
+//								hO.setCurrentSupply(neededEnergy+actualSupplyEnergy);
+//								currentProduction -= neededEnergy;
+//							}else
+//							{
+//								hO.setCurrentSupply(currentProduction+actualSupplyEnergy);
+//								currentProduction = 0;
+//								break;
+//							}
+//						}
+//						
+//						
+//					}
+//				}
+//				
+//			}
+//			//Visualize the Color
+//			for(HolonObject hO : singleSubNet.getObjects())
+//			{
+//				float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x); // convert negative energy in positive for calculations
+//				if(neededEnergy < 0)
+//				{
+//					hO.setState(HolonObject.PRODUCER);
+//				}
+//				else if(neededEnergy > 0)
+//				{
+//					float currentSupply = hO.getCurrentSupply() ;
+//					if(currentSupply > neededEnergy)
+//					{
+//						hO.setState(HolonObject.OVER_SUPPLIED);
+//					}else if (currentSupply ==  neededEnergy)
+//					{
+//						hO.setState(HolonObject.SUPPLIED);
+//					}else if (currentSupply <  neededEnergy)
+//					{
+//						float minEnergy = -hO.getMinEnergy(x);
+//						if(currentSupply >= minEnergy || hO.getSelfMadeEnergy(x)  >= minEnergy )
+//						{
+//							hO.setState(HolonObject.PARTIALLY_SUPPLIED);
+//						}else
+//						{
+//							hO.setState(HolonObject.NOT_SUPPLIED);
+//						}
+//					}
+//				}
+//				else if(neededEnergy == 0)
+//				{
+//					hO.setState(HolonObject.NO_ENERGY);
+//				}
+//			}
+//		}
+//		canvas.repaint();
+//		flexPane.recalculate();
 	}
 
 	/**
@@ -975,4 +1028,17 @@ public class SimulationManager {
 		flexPane = fp;
 	}
 
+	public ArrayList<DecoratedNetwork> getDecorNetworks() {
+		return decorNetworks;
+	}
+
+	public MinimumModel getMinimumModel() {
+		return minimumModel;
+	}
+
+	public DecoratedState getDecorState() {
+		return decorState;
+	}
+
+
 }

+ 54 - 0
src/ui/model/CableWithState.java

@@ -0,0 +1,54 @@
+package ui.model;
+
+import classes.CpsEdge;
+import classes.HolonObject;
+import ui.model.DecoratedCable.DecoratedCableState;
+
+/**
+ * Intermediate to calculate/simulate the burning of Cables.
+ * When all burning is done the Cable will be represented as a DecoratedCable.
+ * @see DecoratedCable
+ */
+public class CableWithState {
+	public enum CableState{
+		Undefined, Working, Burned
+	}
+	private CableState state;
+	private CpsEdge model;
+	public CableWithState(CpsEdge model,CableState state)
+	{
+		this.model = model;
+		this.state = state;
+	}
+	public CableState getState() {
+		return state;
+	}
+	public void setState(CableState state) {
+		this.state = state;
+	}
+	public CpsEdge getModel() {
+		return model;
+	}
+	//ugly
+	public float getEnergyFromConnetedAtTimestep(int iteration) {
+		float energy = 0.0f;
+		if(model.getA() instanceof HolonObject && ((HolonObject) model.getA()).getEnergyAtTimeStep(iteration) > 0) energy += ((HolonObject) model.getA()).getEnergyAtTimeStep(iteration);
+		if(model.getB() instanceof HolonObject && ((HolonObject) model.getB()).getEnergyAtTimeStep(iteration) > 0) energy += ((HolonObject) model.getB()).getEnergyAtTimeStep(iteration);
+		return energy;
+	}
+	
+	//to be swapped with on CableState system 
+	public static DecoratedCableState convertCableStateToDecoratedCableState(CableState toConvert) {
+		switch(toConvert) {
+		case Burned:
+			return DecoratedCableState.Burned;
+		case Working:
+			return DecoratedCableState.Working;
+		case Undefined:
+			return DecoratedCableState.Burned;
+		default:
+			return DecoratedCableState.Burned;
+		
+		}
+	}
+}

+ 3 - 0
src/ui/model/Consumer.java

@@ -67,6 +67,9 @@ public class Consumer extends DecoratedHolonObject {
 		return energySelfSupplied;
 	}
 
+	public float getSupplyBarPercentage() {
+		return (getEnergyFromNetwork()+ this.getEnergySelfSupplied())/(getEnergyNeededFromNetwork()+ this.getEnergySelfSupplied());
+	}
 	public void setEnergySelfSupplied(float energySelfSupplied) {
 		this.energySelfSupplied = energySelfSupplied;
 	}

+ 26 - 0
src/ui/model/DecoratedCable.java

@@ -0,0 +1,26 @@
+package ui.model;
+
+import classes.CpsEdge;
+
+public class DecoratedCable {
+	public enum DecoratedCableState{
+		Working, Burned
+	}
+	private CpsEdge model;
+	private DecoratedCableState state;
+	private float flowEnergy;
+	public DecoratedCable(CpsEdge edge, DecoratedCableState state, float flowEnergy){
+		this.model = edge;
+		this.state = state;
+		this.flowEnergy = flowEnergy;
+	}
+	public CpsEdge getModel() {
+		return model;
+	}
+	public DecoratedCableState getState() {
+		return state;
+	}
+	public float getFlowEnergy() {
+		return flowEnergy;
+	}
+}

+ 23 - 8
src/ui/model/DecoratedNetwork.java

@@ -2,7 +2,10 @@ package ui.model;
 
 import java.util.ArrayList;
 
+import classes.CpsEdge;
 import classes.HolonObject;
+import ui.model.CableWithState.CableState;
+import ui.model.DecoratedCable.DecoratedCableState;
 import ui.model.DecoratedHolonObject.HolonObjectState;
 
 public class DecoratedNetwork {
@@ -10,9 +13,10 @@ public class DecoratedNetwork {
 	private ArrayList<Consumer> consumerList = new ArrayList<Consumer>();
 	private ArrayList<Consumer> consumerSelfSuppliedList = new ArrayList<Consumer>();
 	private ArrayList<Passiv> passivNoEnergyList = new ArrayList<Passiv>();
-	public DecoratedNetwork(MinimumNetwork mm, int Iteration){
+	private ArrayList<DecoratedCable> decoratedCableList = new ArrayList<DecoratedCable>();
+	public DecoratedNetwork(MinimumNetwork minimumNetwork, int Iteration){	
 		//Categorize
-		for(HolonObject hObject: mm.getHolonObjectList()) {
+		for(HolonObject hObject: minimumNetwork.getHolonObjectList()) {
 			float energyNeeded = hObject.getEnergyNeededFromConsumingElements(Iteration);
 			float energySelfProducing = hObject.getEnergySelfProducingFromProducingElements(Iteration);
 			if(energyNeeded < energySelfProducing) {
@@ -42,14 +46,21 @@ public class DecoratedNetwork {
 				
 			}
 		}
+		
+		
 		//Sort SupplierList according to the EnergyToSupplyNetwork maximum first.
 		//Sort ConsumerList according to the MinimumConsumingElementEnergy minimum first.
 		supplierList.sort((Supplier lhs,Supplier rhs) -> -Float.compare(lhs.getEnergyToSupplyNetwork(), rhs.getEnergyToSupplyNetwork()));
 		consumerList.sort((Consumer lhs,Consumer rhs) -> Float.compare(lhs.getMinimumConsumingElementEnergy()  , rhs.getMinimumConsumingElementEnergy()));
 		//consumerList.forEach((con) -> System.out.println(con.getMinimumConsumingElementEnergy()));
-		consumerList.forEach((con) -> System.out.println("AfterSorting" + con));
+		//consumerList.forEach((con) -> System.out.println("AfterSorting" + con));
 		//Minimum demand first:
 		float energyToSupplyInTheNetwork = supplierList.stream().map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied()).reduce( 0.0f, (a, b) -> a + b);
+		//DecoratedCables
+		for(CableWithState edge: minimumNetwork.getEdgeList()) {		
+			decoratedCableList.add(new DecoratedCable(edge.getModel(), CableWithState.convertCableStateToDecoratedCableState(edge.getState()), (edge.getState() == CableState.Working) ? energyToSupplyInTheNetwork : 0.0f));
+		}
+		
 		outerLoop:
 		for(Consumer con : consumerList)
 		{
@@ -75,7 +86,7 @@ public class DecoratedNetwork {
 			//No more Energy in the network
 			break;
 		}
-		consumerList.forEach((con) -> System.out.println("AfterSuppliing MinimumDemand" + con));
+		//consumerList.forEach((con) -> System.out.println("AfterSuppliing MinimumDemand " + con));
 		
 		//Sort ConsumerList according to the EnergyNeeded to supply fully after minimum Demand First.
 		consumerList.sort((Consumer lhs,Consumer rhs) -> Float.compare(lhs.getEnergyNeededFromNetwork()-lhs.getEnergyFromNetwork() , rhs.getEnergyNeededFromNetwork()-rhs.getEnergyFromNetwork() ));
@@ -88,7 +99,7 @@ public class DecoratedNetwork {
 				float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
 				if(energyRdyToSupply == 0.0f) continue;
 				float energyNeededForFullySupply = con.getEnergyNeededFromNetwork() - con.getEnergyFromNetwork();
-				if(energyNeededForFullySupply == 0.0f) continue;
+				if(energyNeededForFullySupply == 0.0f) continue outerLoop;
 				if(energyRdyToSupply>=energyNeededForFullySupply) {
 					supply(con, sup, energyNeededForFullySupply);
 					continue outerLoop;
@@ -100,10 +111,11 @@ public class DecoratedNetwork {
 			//No more Energy in the network
 			break;
 		}
-		consumerList.forEach((con) -> System.out.println("AfterFullySuplieing" + con));
+		//consumerList.forEach((con) -> System.out.println("AfterFullySuplieing" + con));
 		//If Energy Left Supply all equal
 		//Count EnergyLeft
 		float energyLeft = supplierList.stream().map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied()).reduce( 0.0f, (a, b) -> a + b);
+		//System.out.println("EnergyLeft: " +  energyLeft);
 		if(energyLeft > 0.0f && (consumerList.size() + consumerSelfSuppliedList.size() != 0))
 		{
 			float equalAmountOfEnergyToSupply = energyLeft / ((float)(consumerList.size() + consumerSelfSuppliedList.size()));
@@ -147,9 +159,9 @@ public class DecoratedNetwork {
 				break;
 			}
 		}
-		consumerList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
+		//consumerList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
 		
-		consumerSelfSuppliedList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
+		//consumerSelfSuppliedList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
 		
 		//CalculateStates:
 		supplierList.forEach(sup -> sup.setState(HolonObjectState.PRODUCER));
@@ -208,4 +220,7 @@ public class DecoratedNetwork {
 	public ArrayList<Passiv> getPassivNoEnergyList() {
 		return passivNoEnergyList;
 	}
+	public ArrayList<DecoratedCable> getDecoratedCableList(){
+		return decoratedCableList;
+	}
 }

+ 24 - 0
src/ui/model/DecoratedState.java

@@ -0,0 +1,24 @@
+package ui.model;
+
+import java.util.ArrayList;
+
+public class DecoratedState {
+	ArrayList<DecoratedNetwork> networkList = new ArrayList<DecoratedNetwork>();
+	ArrayList<DecoratedCable> leftOverEdges = new ArrayList<DecoratedCable>();
+	ArrayList<DecoratedSwitch> decoratedSwitches = new ArrayList<DecoratedSwitch>();
+	public DecoratedState(ArrayList<DecoratedNetwork> networkList, ArrayList<DecoratedCable> leftOverEdges, ArrayList<DecoratedSwitch> decoratedSwitches){
+		this.networkList = networkList;
+		this.leftOverEdges = leftOverEdges;
+		this.decoratedSwitches = decoratedSwitches;
+	}
+	public ArrayList<DecoratedNetwork> getNetworkList() {
+		return networkList;
+	}
+	public ArrayList<DecoratedCable> getLeftOverEdges() {
+		return leftOverEdges;
+	}
+	public ArrayList<DecoratedSwitch> getDecoratedSwitches() {
+		return decoratedSwitches;
+	}
+
+}

+ 24 - 0
src/ui/model/DecoratedSwitch.java

@@ -0,0 +1,24 @@
+package ui.model;
+
+import classes.HolonSwitch;
+
+public class DecoratedSwitch {
+	public enum SwitchState{
+		Closed, Open
+	}
+	private SwitchState state;
+	private HolonSwitch model;
+	public DecoratedSwitch(HolonSwitch hSwitch, SwitchState state){
+		this.model = hSwitch;
+		this.state = state;
+	}
+	public SwitchState getState() {
+		return state;
+	}
+
+	public HolonSwitch getModel() {
+		return model;
+	}
+
+	
+}

+ 8 - 6
src/ui/model/MinimumModel.java

@@ -7,10 +7,12 @@ import classes.CpsEdge;
 import classes.CpsNode;
 import classes.HolonObject;
 import classes.HolonSwitch;
+import ui.model.CableWithState.CableState;
+import ui.model.DecoratedCable.DecoratedCableState;
 
 public class MinimumModel {
 	private ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
-	private ArrayList<CpsEdge> edgeList = new ArrayList<CpsEdge>();
+	private ArrayList<CableWithState> cableList = new ArrayList<CableWithState>();
 	private ArrayList<CpsNode> nodeList = new ArrayList<CpsNode>();
 	private ArrayList<HolonSwitch> switchList = new ArrayList<HolonSwitch>();
 	
@@ -21,7 +23,7 @@ public class MinimumModel {
 			else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
 		}
 		for (CpsEdge edge : edgeList) {
-			this.edgeList.add(edge);
+			this.cableList.add(new CableWithState(edge, CableState.Undefined));
 		}
 	}
 	
@@ -31,11 +33,11 @@ public class MinimumModel {
 	public void setHolonObjectList(ArrayList<HolonObject> holonObjectList) {
 		this.holonObjectList = holonObjectList;
 	}
-	public ArrayList<CpsEdge> getEdgeList() {
-		return edgeList;
+	public ArrayList<CableWithState> getEdgeList() {
+		return cableList;
 	}
-	public void setEdgeList(ArrayList<CpsEdge> edgeList) {
-		this.edgeList = edgeList;
+	public void setEdgeList(ArrayList<CableWithState> cableList) {
+		this.cableList = cableList;
 	}
 	public ArrayList<CpsNode> getNodeList() {
 		return nodeList;

+ 5 - 5
src/ui/model/MinimumNetwork.java

@@ -7,15 +7,15 @@ import classes.HolonObject;
 
 public class MinimumNetwork {
 	private ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
-	private ArrayList<CpsEdge> edgeList = new ArrayList<CpsEdge>();
-	public MinimumNetwork(ArrayList<HolonObject> holonObjectList, ArrayList<CpsEdge> edgeList){
+	private ArrayList<CableWithState> edgeList = new ArrayList<CableWithState>();
+	public MinimumNetwork(ArrayList<HolonObject> holonObjectList, ArrayList<CableWithState> edgeList){
 		this.holonObjectList = holonObjectList;
 		this.edgeList = edgeList;
 	}
 	public ArrayList<HolonObject> getHolonObjectList() {
 		return holonObjectList;
 	}
-	public ArrayList<CpsEdge> getEdgeList() {
+	public ArrayList<CableWithState> getEdgeList() {
 		return edgeList;
 	}
 	public String toString()
@@ -26,8 +26,8 @@ public class MinimumNetwork {
 		}
 		objecte += "]";
 		String edges = "[";
-		for(CpsEdge edge :edgeList) {
-			edges += " " + edge;
+		for(CableWithState edge :edgeList) {
+			edges += " " + edge.getModel();
 		}
 		edges += "]";
 		return objecte + edges;

+ 1 - 10
src/ui/view/EditEdgesPopUp.java

@@ -35,16 +35,7 @@ public class EditEdgesPopUp extends JDialog {
 	 * @param args
 	 *            standard
 	 */
-//	public static void main(String[] args) {
-//		try {
-//
-//			EditEdgesPopUp dialog = new EditEdgesPopUp();
-//			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-//			dialog.setVisible(true);
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
-//	}
+
 
 	/**
 	 * Constructor.

+ 3 - 8
src/ui/view/GUI.java

@@ -2417,15 +2417,10 @@ public class GUI implements CategoryListener {
 
 		timePanel = new TimePanel(this,controller);
 		timePanel.setBorder(null);
-		((JSlider)
-				(
-						((Container)timePanel.getComponent(1))//timePanel
-						.getComponent(1)//timeSlider
-				)
-		)//TODO: This hardcoded stuff
+		timePanel.getTimeSlider()
 				.addChangeListener(changeEvent -> {
-					int i = model.getCurIteration();
-					controller.calculateStateForTimeStep(i);
+					//TimeSliderChanged event
+					controller.calculateStateForTimeStep(timePanel.getTimeSlider().getValue());
 					unitGraph.repaint();
 					if (model.getIsSimRunning()) {
 						controller.runAlgorithm(model, controller);

+ 294 - 132
src/ui/view/MyCanvas.java

@@ -6,7 +6,18 @@ import com.google.gson.JsonParseException;
 
 import ui.controller.Control;
 import ui.controller.UpdateController;
+import ui.model.CableWithState;
+import ui.model.Consumer;
+import ui.model.DecoratedCable;
+import ui.model.DecoratedHolonObject;
+import ui.model.DecoratedHolonObject.HolonObjectState;
+import ui.model.DecoratedNetwork;
+import ui.model.DecoratedSwitch;
+import ui.model.DecoratedSwitch.SwitchState;
+import ui.model.MinimumModel;
 import ui.model.Model;
+import ui.model.Passiv;
+import ui.model.Supplier;
 
 import javax.swing.*;
 
@@ -364,151 +375,302 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 	 * @param g
 	 *            Graphics
 	 */
-	public void paintComponent(Graphics g) {
-		String maxCap = null;
-		super.paintComponent(g);
-		// Rendering
-		g2 = (Graphics2D) g;
-		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
-				RenderingHints.VALUE_ANTIALIAS_ON);
-		g2.setRenderingHints(rh);
-
-		// Paint the Background
-		if (!model.getCanvasImagePath().isEmpty()) {
-			img = new ImageIcon(model.getCanvasImagePath()).getImage();
-			switch (model.getCanvasImageMode()) {
-			case BackgroundPopUp.IMAGE_PIXELS:
-				g2.drawImage(img, 0, 0, img.getWidth(null),
-						img.getHeight(null), null);
-				break;
-			case BackgroundPopUp.STRETCHED:
-				g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(),
-						null);
-				break;
-			case BackgroundPopUp.CUSTOM:
-				g2.drawImage(img, 0, 0, model.getCanvasImageWidth(),
-						model.getCanvasImageHeight(), null);
-				break;
-			default:
-				break;
-			}
+	
+	private Color getStateColor(HolonObjectState state) {
+		switch(state) {
+		case NOT_SUPPLIED:
+			return new Color(230, 120, 100);
+		case NO_ENERGY:
+			return Color.white;
+		case OVER_SUPPLIED:
+			return new Color(138, 43, 226);
+		case PARTIALLY_SUPPLIED:
+			return Color.yellow;
+		case PRODUCER:
+			return Color.lightGray;
+		case SUPPLIED:
+			return Color.green;
+		default:
+			return Color.BLACK;
 		}
-
-		// SubNet Coloring
-		int i = 0;
-		for (SubNet s : controller.getSimManager().getSubNets()) {
-
-			if (model.getSubNetColors().size() - 1 < i) {
-				controller.addSubNetColor(new Color(
-						(int) (Math.random() * 255),
-						(int) (Math.random() * 255),
-						(int) (Math.random() * 255)));
-			}
-			if (showedInformation[3]) {
-				for (HolonObject cps : s.getObjects()) {
-					cps.setBorderColor(model.getSubNetColors().get(i));
-				}
-			}
-			i++;
+	}
+	private void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject){
+		//System.out.println(decoratedHolonObject.getModel().getImage());
+		Position pos = decoratedHolonObject.getModel().getPosition();
+		Color statecolor = getStateColor(decoratedHolonObject.getState());
+		g.setColor(statecolor);
+		//System.out.println(statecolor);
+		g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
+		drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
+		
+	}
+	//if(decoratedHolonObject.getState() != HolonObjectState.PRODUCER && decoratedHolonObject.getState() != HolonObjectState.NO_ENERGY)paintSupplyBar(g, decoratedHolonObject.get, statecolor, pos);
+	private void paintConsumer(Graphics2D g, Consumer con){
+		paintCanvasObject(g, con);
+		paintSupplyBar(g,con.getSupplyBarPercentage(), getStateColor(con.getState()), con.getModel().getPosition());
+	}
+	private void drawCanvasObject(Graphics2D g, String Image, Position pos) {
+		g.drawImage(Util.loadImage(Image) , 
+				pos.x - controller.getScaleDiv2(),
+				pos.y - controller.getScaleDiv2(),
+				controller.getScale(), controller.getScale(), null);
+	}
+	
+	private void paintCable(Graphics2D g, DecoratedCable cable)
+	{
+		Position start = cable.getModel().getA().getPosition();
+		Position end =  cable.getModel().getB().getPosition();
+		float currentEnergy = cable.getFlowEnergy();
+		float capacity = cable.getModel().getCapacity(); 
+		g.setColor(Color.BLACK);
+		g.setStroke(new BasicStroke(2));
+		switch(cable.getState()) {
+		case Burned:
+			g.setColor(Color.RED);
+			g.setStroke(new BasicStroke(2));
+			break;
+		case Working:
+			g.setColor(Color.GREEN);
+			g.setStroke(new BasicStroke((currentEnergy / capacity* 3) + 1));
+			break;
 		}
-
-		// drawEdges that is being dragged
-		if (drawEdge) {
-			g2.setColor(Color.BLACK);
-			g2.setStroke(new BasicStroke(2));
-			g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
+		g.drawLine(start.x, start.y, end.x, end.y);
+		Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
+		g.drawString(currentEnergy + "/" + capacity , middle.x, middle.y);
+	}
+	private void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch)
+	{
+		drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage(): HolonSwitch.getSwitchClosedImage() , dSwitch.getModel().getPosition());
+	}
+	private void paintSupplyBar(Graphics2D g, float percentage, Color color, Position pos) {
+		// +1, -2, -1 little Ajustment for pixelperfect allignment
+		int barWidth = (int) (controller.getScale());
+		int barHeight = (int) (controller.getScale() / 5);
+		g.setColor(Color.WHITE);
+		g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) barWidth, barHeight);
+		g.setColor(color);
+		g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
+		g.setColor(Color.BLACK);
+		g.setStroke(new BasicStroke(1));
+		g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
+		g.setFont(new Font("TimesRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
+		String percentageString = (Math.round((percentage * 100))) + "%";
+		int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
+		if(percentage > 1.0f) g.setColor(Color.WHITE); //Just to see better on purple
+		g.drawString(percentageString, pos.x + 1 - stringWidth / 2, pos.y + controller.getScaleDiv2() - 1+ barHeight);
+		
+	}
+	
+	//old code
+	void drawMarker(Graphics2D g) {
+		if (sx > x && sy > y) {
+			g.drawRect(x, y, sx - x, sy - y);
+		} else if (sx < x && sy < y) {
+			g.drawRect(sx, sy, x - sx, y - sy);
+		} else if (sx >= x) {
+			g.drawRect(x, sy, sx - x, y - sy);
+		} else if (sy >= y) {
+			g.drawRect(sx, y, x - sx, sy - y);
 		}
-
-		if(model.getEdgesOnCanvas().isEmpty() && !model.getObjectsOnCanvas().isEmpty()
-				&& !model.getObjectsOnCanvas().get(0).getConnections().isEmpty()){
-			ArrayList<CpsEdge> edgesOnCanvas= model.getEdgesOnCanvas();
-			for(AbstractCpsObject cps :model.getObjectsOnCanvas())
-				for(CpsEdge e: cps.getConnections()){
-					if(!edgesOnCanvas.contains(e))
-						model.addEdgeOnCanvas(e);
-				}
+	}
+	public void paintComponent(Graphics g) {		
+		super.paintComponent(g);
+		Graphics2D g2d = (Graphics2D) g;
+		g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+				RenderingHints.VALUE_ANTIALIAS_ON));
+		//-->Old code
+		if (drawEdge) {
+			g2d.setColor(Color.BLACK);
+			g2d.setStroke(new BasicStroke(1));
+			g2d.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
 		}
-		
-		for (CpsEdge con : model.getEdgesOnCanvas()) {
-			maxCap = paintEdge(con, maxCap);
+		//<--
+		g2d.setColor(Color.BLACK);
+		for(DecoratedCable cable : controller.getSimManager().getDecorState().getLeftOverEdges()) {
+			paintCable(g2d, cable);
 		}
-
-		// Highlighted Edge
-		if (!model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty() || model.getSelectedObjectID() > 0) {
-			g2.setColor(Color.BLUE);
-			for (CpsEdge con : model.getEdgesOnCanvas()) {
-				if (con.getFlow() <= con.getCapacity()) {
-					g2.setStroke(new BasicStroke(Math.min(
-							((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
-				} else {
-					g2.setStroke(new BasicStroke(2));
-				}
-
-				maxCap = drawEdgeLine(con, maxCap);
+		for(DecoratedNetwork network : controller.getSimManager().getDecorState().getNetworkList()) {
+			//System.out.println("A Network");
+			for(DecoratedCable cable : network.getDecoratedCableList()) {
+				paintCable(g2d, cable);
 			}
-		} else if (edgeHighlight != null) {
-			g2.setColor(Color.BLUE);
-			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
-				g2.setStroke(new BasicStroke(Math.min(((edgeHighlight.getFlow()
-						/ edgeHighlight.getCapacity() * 3) + 1), 4)));
-			} else {
-				g2.setStroke(new BasicStroke(2));
+			for(Consumer con: network.getConsumerList()) {
+				paintConsumer(g2d, con);
 			}
-			g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight
-					.getA().getPosition().y,
-					edgeHighlight.getB().getPosition().x, edgeHighlight.getB()
-							.getPosition().y);
-
-			maxCap = setCapacityString(edgeHighlight, maxCap);
-
-			if (showedInformation[0]) {
-				g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
-						(edgeHighlight.getA().getPosition().x + edgeHighlight
-								.getB().getPosition().x) / 2, (edgeHighlight
-								.getA().getPosition().y + edgeHighlight.getB()
-								.getPosition().y) / 2);
+			for(Consumer con: network.getConsumerSelfSuppliedList()) {
+				paintConsumer(g2d, con);
 			}
-		}
-
-
-		/**
-		 * highlight the Object that would be replaced
-		 */
-		highlightMayBeReplaced(g2);
-		
-		// Objects
-		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
-			// Border Highlighting
-			if (showedInformation[3]) {
-				g2.setColor(cps.getBorderColor());
-				if (g2.getColor() != Color.WHITE && !(cps instanceof CpsNode)) {
-					g2.fillRect(
-							(int) (cps.getPosition().x
-									- controller.getScaleDiv2() - scalediv20 - 3),
-							(int) (cps.getPosition().y
-									- controller.getScaleDiv2() - scalediv20 - 3),
-							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
-							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
-				}
+			for(Supplier sup: network.getSupplierList()) {
+				paintCanvasObject(g2d, sup);
+			}
+			for(Passiv pas: network.getPassivNoEnergyList()) {
+				paintCanvasObject(g2d, pas);
 			}
-
-			setEdgePictureAndHighlighting(cps);
-
-			g2.drawImage(img, cps.getPosition().x - controller.getScaleDiv2(),
-					cps.getPosition().y - controller.getScaleDiv2(),
-					controller.getScale(), controller.getScale(), null);
-
-			paintSupplyBar(g, cps);
 		}
 		
-		// Dragged marker Highlighting
+		for(DecoratedSwitch dSwitch : controller.getSimManager().getDecorState().getDecoratedSwitches()) {
+			paintSwitch(g2d, dSwitch);
+		}
+		for(CpsNode node : controller.getSimManager().getMinimumModel().getNodeList()) {
+			drawCanvasObject(g2d, "/Images/node_selected.png" , node.getPosition());
+		}
+		//oldCode 
 		if (doMark) {
-			g2.setColor(Color.BLACK);
-			g2.setStroke(new BasicStroke(0));
-			drawMarker();
+			g2d.setColor(Color.BLACK);
+			g2d.setStroke(new BasicStroke(0));
+			drawMarker(g2d);
+		}
+		/*
+		 * 
+		
+		
+		for(HolonSwitch switch2 : controller.getSimManager().getMinimumModel().getSwitchList()) {
+			drawCanvasObject(g2d, switch2.getSwitchClosedImage() , switch2.getPosition());
 		}
-		// Tooltip
-		showTooltip(g);
+		 */
+//		String maxCap = null;
+//		// Rendering
+//		g2 = (Graphics2D) g;
+//		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+//				RenderingHints.VALUE_ANTIALIAS_ON);
+//		g2.setRenderingHints(rh);
+//
+//		// Paint the Background
+//		if (!model.getCanvasImagePath().isEmpty()) {
+//			img = new ImageIcon(model.getCanvasImagePath()).getImage();
+//			switch (model.getCanvasImageMode()) {
+//			case BackgroundPopUp.IMAGE_PIXELS:
+//				g2.drawImage(img, 0, 0, img.getWidth(null),
+//						img.getHeight(null), null);
+//				break;
+//			case BackgroundPopUp.STRETCHED:
+//				g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(),
+//						null);
+//				break;
+//			case BackgroundPopUp.CUSTOM:
+//				g2.drawImage(img, 0, 0, model.getCanvasImageWidth(),
+//						model.getCanvasImageHeight(), null);
+//				break;
+//			default:
+//				break;
+//			}
+//		}
+//
+//		// SubNet Coloring
+//		int i = 0;
+//		for (SubNet s : controller.getSimManager().getSubNets()) {
+//
+//			if (model.getSubNetColors().size() - 1 < i) {
+//				controller.addSubNetColor(new Color(
+//						(int) (Math.random() * 255),
+//						(int) (Math.random() * 255),
+//						(int) (Math.random() * 255)));
+//			}
+//			if (showedInformation[3]) {
+//				for (HolonObject cps : s.getObjects()) {
+//					cps.setBorderColor(model.getSubNetColors().get(i));
+//				}
+//			}
+//			i++;
+//		}
+//
+//		// drawEdges that is being dragged
+//		if (drawEdge) {
+//			g2.setColor(Color.BLACK);
+//			g2.setStroke(new BasicStroke(2));
+//			g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
+//		}
+//
+//		if(model.getEdgesOnCanvas().isEmpty() && !model.getObjectsOnCanvas().isEmpty()
+//				&& !model.getObjectsOnCanvas().get(0).getConnections().isEmpty()){
+//			ArrayList<CpsEdge> edgesOnCanvas= model.getEdgesOnCanvas();
+//			for(AbstractCpsObject cps :model.getObjectsOnCanvas())
+//				for(CpsEdge e: cps.getConnections()){
+//					if(!edgesOnCanvas.contains(e))
+//						model.addEdgeOnCanvas(e);
+//				}
+//		}
+//		
+//		for (CpsEdge con : model.getEdgesOnCanvas()) {
+//			maxCap = paintEdge(con, maxCap);
+//		}
+//
+//		// Highlighted Edge
+//		if (!model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty() || model.getSelectedObjectID() > 0) {
+//			g2.setColor(Color.BLUE);
+//			for (CpsEdge con : model.getEdgesOnCanvas()) {
+//				if (con.getFlow() <= con.getCapacity()) {
+//					g2.setStroke(new BasicStroke(Math.min(
+//							((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
+//				} else {
+//					g2.setStroke(new BasicStroke(2));
+//				}
+//
+//				maxCap = drawEdgeLine(con, maxCap);
+//			}
+//		} else if (edgeHighlight != null) {
+//			g2.setColor(Color.BLUE);
+//			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
+//				g2.setStroke(new BasicStroke(Math.min(((edgeHighlight.getFlow()
+//						/ edgeHighlight.getCapacity() * 3) + 1), 4)));
+//			} else {
+//				g2.setStroke(new BasicStroke(2));
+//			}
+//			g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight
+//					.getA().getPosition().y,
+//					edgeHighlight.getB().getPosition().x, edgeHighlight.getB()
+//							.getPosition().y);
+//
+//			maxCap = setCapacityString(edgeHighlight, maxCap);
+//
+//			if (showedInformation[0]) {
+//				g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
+//						(edgeHighlight.getA().getPosition().x + edgeHighlight
+//								.getB().getPosition().x) / 2, (edgeHighlight
+//								.getA().getPosition().y + edgeHighlight.getB()
+//								.getPosition().y) / 2);
+//			}
+//		}
+//
+//
+//		/**
+//		 * highlight the Object that would be replaced
+//		 */
+//		highlightMayBeReplaced(g2);
+//		
+//		// Objects
+//		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
+//			// Border Highlighting
+//			if (showedInformation[3]) {
+//				g2.setColor(cps.getBorderColor());
+//				if (g2.getColor() != Color.WHITE && !(cps instanceof CpsNode)) {
+//					g2.fillRect(
+//							(int) (cps.getPosition().x
+//									- controller.getScaleDiv2() - scalediv20 - 3),
+//							(int) (cps.getPosition().y
+//									- controller.getScaleDiv2() - scalediv20 - 3),
+//							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
+//							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
+//				}
+//			}
+//
+//			setEdgePictureAndHighlighting(cps);
+//
+//			g2.drawImage(img, cps.getPosition().x - controller.getScaleDiv2(),
+//					cps.getPosition().y - controller.getScaleDiv2(),
+//					controller.getScale(), controller.getScale(), null);
+//
+//			paintSupplyBar(g, cps);
+//		}
+//		
+//		// Dragged marker Highlighting
+//		if (doMark) {
+//			g2.setColor(Color.BLACK);
+//			g2.setStroke(new BasicStroke(0));
+//			drawMarker();
+//		}
+//		// Tooltip
+//		showTooltip(g);
 	}
 
 	@Override

+ 7 - 1
src/ui/view/Outliner.java

@@ -23,6 +23,7 @@ import classes.HolonObject;
 import ui.controller.CalculataModel;
 import ui.controller.Control;
 import ui.controller.UpdateController;
+import ui.model.CableWithState;
 import ui.model.Consumer;
 import ui.model.Consumer.SupplierListEntry;
 import ui.model.DecoratedHolonObject;
@@ -32,6 +33,7 @@ import ui.model.MinimumModel;
 import ui.model.MinimumNetwork;
 import ui.model.Model;
 import ui.model.Supplier;
+import ui.model.CableWithState.CableState;
 
 
 
@@ -57,7 +59,11 @@ public class Outliner extends JFrame {
 		JPanel listPanel = createOutlinerListPanel(model, controller, gui);
 		tabbedPane.addTab("List", listPanel);
 		MinimumModel mm = new MinimumModel(model.getObjectsOnCanvas(), model.getEdgesOnCanvas());
-		list = CalculataModel.calculateNetworks(mm, model.getCurIteration());
+		//set all working:
+		for(CableWithState cable : mm.getEdgeList()) {
+			cable.setState(CableState.Working);
+		}
+		list = CalculataModel.calculateNetworks(mm, model.getCurIteration(), null);
 		JPanel networkPanel = createNetworkPanel();
 		tabbedPane.addTab("Networks", networkPanel);
 		ArrayList<DecoratedNetwork> computedList = new ArrayList<DecoratedNetwork>();

+ 4 - 1
src/ui/view/TimePanel.java

@@ -104,6 +104,9 @@ public class TimePanel extends JPanel implements ActionListener{
 			@Override
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
+				System.out.println(timeSlider.getValue());
+				int test = timeSlider.getValue();
+				System.out.println(test);
 				controller.setCurIteration(timeSlider.getValue());
 				timer.setDelay(cont.getModel().getTimerSpeed());
 				if (timeSlider.getValue() >= cont.getModel().getIterations() - 1) {
@@ -373,7 +376,7 @@ public class TimePanel extends JPanel implements ActionListener{
 	}
 
 	@Override
-	public void actionPerformed(ActionEvent arg0) {//I dislike anon classes.
+	public void actionPerformed(ActionEvent arg0) {
 		updateIterationsInput();
 	}
 	/**

+ 245 - 244
src/ui/view/UpperNodeCanvas.java

@@ -342,250 +342,251 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
     public void paintComponent(Graphics g) {
         String maxCap = null;
         super.paintComponent(g);
-        ((JScrollPane) this.getParent().getParent()).setColumnHeaderView(breadCrumb);
-        // Rendering
-        g2 = (Graphics2D) g;
-        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        g2.setRenderingHints(rh);
-
-        // Paint the Background
-        if (!upperNode.getImagePath().isEmpty()) {
-            img = new ImageIcon(upperNode.getImagePath()).getImage();
-            switch (upperNode.getBackgroundMode()) {
-                case BackgroundPopUp.IMAGE_PIXELS:
-                    g2.drawImage(img, upperNode.getLeftBorder(), 0, img.getWidth(null), img.getHeight(null), null);
-                    break;
-                case BackgroundPopUp.STRETCHED:
-                    g2.drawImage(img, upperNode.getLeftBorder(), 0, model.getCanvasX(), model.getCanvasY(), null);
-                    break;
-                case BackgroundPopUp.CUSTOM:
-                    g2.drawImage(img, upperNode.getLeftBorder(), 0, upperNode.getImageWidht(), upperNode.getImageHeight(),
-                            null);
-                    break;
-                default:
-                    break;
-            }
-        }
-
-        // Draw Left Border
-        g2.setColor(new Color(230, 230, 230));
-        g2.fillRect(0, 0, upperNode.getLeftBorder(), this.getHeight());
-        g2.setColor(Color.BLACK);
-        g2.drawLine(0, 0, this.getWidth(), 0);
-
-        // Test SubNet Coloring
-        int i = 0;
-        for (SubNet s : controller.getSimManager().getSubNets()) {
-
-            if (model.getSubNetColors().size() - 1 < i) {
-                controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
-                        (int) (Math.random() * 255)));
-            }
-
-            for (HolonObject cps : s.getObjects()) {
-                cps.setBorderColor(model.getSubNetColors().get(i));
-            }
-            i++;
-        }
-
-        // drawEdges that is being dragged
-        if (drawEdge) {
-            g2.setColor(Color.BLACK);
-            g2.setStroke(new BasicStroke(2));
-
-            // If TempCps is an outside Object
-            if (!upperNode.getNodes().contains(tempCps)) {
-                int count = 0;
-                for (CpsEdge e : upperNode.getConnections()) {
-                    if (e.getA().equals(tempCps)) {
-                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
-                                + (model.getScale() + scalediv20 + 10) * count), x, y);
-                    } else if (e.getB().equals(tempCps)) {
-                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
-                                + (model.getScale() + scalediv20 + 10) * count), x, y);
-                    }
-                    count++;
-                }
-            } else {
-                g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
-            }
-        }
-        // draw Edges
-        for (CpsEdge con : upperNode.getNodeEdges()) {
-            maxCap = paintEdge(con, maxCap);
-        }
-
-        // Objects connected to upperNode
-        int count = 0;
-        for (CpsEdge e : upperNode.getConnections()) {
-            AbstractCpsObject cps;
-            if (e.getA().equals(this.upperNode)) {
-                cps = e.getB();
-            } else {
-                cps = e.getA();
-            }
-            // Show and Highlight
-            if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4]) {
-                for (CpsEdge ed : cps.getConnections()) {
-                    AbstractCpsObject obj = null;
-                    if (upperNode.getNodes().contains(ed.getA())) {
-                        obj = ed.getA();
-                    } else if (upperNode.getNodes().contains(ed.getB())) {
-                        obj = ed.getB();
-                    }
-                    if (obj != null) {
-                        if (ed.getConnected() == 0) {
-
-                            setEdgeState(ed);
-
-                            if (ed.getA().getId() == model.getSelectedObjectID()
-                                    || ed.getB().getId() == model.getSelectedObjectID() || edgeHighlight == ed)
-                                g2.setColor(Color.BLUE);
-                        } else {
-                            g2.setColor(Color.DARK_GRAY);
-                            g2.setStroke(new BasicStroke(2));
-                        }
-                        g2.drawLine(obj.getPosition().x, obj.getPosition().y, (upperNode.getLeftBorder() >> 1),
-                                (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
-                        if (showedInformation[0]) {
-
-                            maxCap = setCapacityString(ed, maxCap);
-
-                            if (ed.getConnected() == 0 || ed.getConnected() == 1) {
-                                g2.drawString(ed.getFlow() + "/" + maxCap,
-                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
-                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
-                                                + 25) / 2);
-                            } else {
-                                g2.drawString("not connected",
-                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
-                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
-                                                + 25) / 2);
-                            }
-                        }
-                    }
-                }
-            }
-
-            // Border Highlighting
-            if (showedInformation[3]) {
-                g2.setColor(cps.getBorderColor());
-                if (g2.getColor() != Color.WHITE) {
-                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
-                            (int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
-                            (int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
-                }
-            }
-
-            // node image
-            if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
-                    || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
-            	img = Util.loadImage("/Images/node_selected.png");
-            } else {
-                if (cps instanceof HolonSwitch) {
-                    if (((HolonSwitch) cps).getState(model.getCurIteration())) {
-                        ((HolonSwitch) cps).setAutoState(true);
-                    } else {
-                        ((HolonSwitch) cps).setAutoState(false);
-                    }
-                }
-                // Highlighting
-                if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
-                        || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
-                    g2.setColor(Color.BLUE);
-                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
-                } else if (cps instanceof HolonObject) {
-                    g2.setColor(((HolonObject) cps).getColor());
-
-                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
-                }
-                // draw image
-                File checkPath = new File(cps.getImage());
-                if (checkPath.exists()) {
-                    img = new ImageIcon(cps.getImage()).getImage();
-                } else {
-                	img = Util.loadImage(cps.getImage());
-                }
-            }
-            g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
-                    (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
-            count++;
-        }
-        // Highlighted Edge
-        if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
-            g2.setColor(Color.BLUE);
-            for (CpsEdge con : upperNode.getNodeEdges()) {
-                if (con.getFlow() <= con.getCapacity()) {
-                    g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
-                } else {
-                    g2.setStroke(new BasicStroke(2));
-                }
-
-                maxCap = drawEdgeLine(con, maxCap);
-            }
-        } else if (edgeHighlight != null) {
-            g2.setColor(Color.BLUE);
-            if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
-                g2.setStroke(
-                        new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
-            } else {
-                g2.setStroke(new BasicStroke(2));
-            }
-            if (upperNode.getNodeEdges().contains(edgeHighlight)) {
-                g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
-                        edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
-
-                maxCap = setCapacityString(edgeHighlight, maxCap);
-
-                if (showedInformation[0]) {
-                    g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
-                            (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
-                            (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
-                }
-            }
-        }
-
-
-        //Draw ReplaceHighlight
-        highlightMayBeReplaced(g2);
-        
-        // Objects in upper node
-        for (AbstractCpsObject cps : upperNode.getNodes()) {
-            // Border Highlighting
-            if (showedInformation[3]) {
-                g2.setColor(cps.getBorderColor());
-                if (g2.getColor() != Color.WHITE) {
-                    g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
-                            (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
-                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
-                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
-                }
-            }
-
-            setEdgePictureAndHighlighting(cps);
-
-            g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
-                    controller.getScale(), controller.getScale(), null);
-            paintSupplyBar(g2,cps);
-        }
-        
-        // Dragged marker Highlighting
-        g2.setStroke(new BasicStroke(1));
-        if (doMark) {
-            g2.setColor(Color.BLACK);
-            drawMarker();
-        }
-
-        // Border Line
-        g2.setColor(Color.BLACK);
-        g2.drawLine(upperNode.getLeftBorder(), 0, upperNode.getLeftBorder(), this.getHeight());
-
-        // Tooltip
-        showTooltip(g);
+//        ((JScrollPane) this.getParent().getParent()).setColumnHeaderView(breadCrumb);
+//        // Rendering
+//        g2 = (Graphics2D) g;
+//        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+//        g2.setRenderingHints(rh);
+//
+//        // Paint the Background
+//        if (!upperNode.getImagePath().isEmpty()) {
+//            img = new ImageIcon(upperNode.getImagePath()).getImage();
+//            switch (upperNode.getBackgroundMode()) {
+//                case BackgroundPopUp.IMAGE_PIXELS:
+//                    g2.drawImage(img, upperNode.getLeftBorder(), 0, img.getWidth(null), img.getHeight(null), null);
+//                    break;
+//                case BackgroundPopUp.STRETCHED:
+//                    g2.drawImage(img, upperNode.getLeftBorder(), 0, model.getCanvasX(), model.getCanvasY(), null);
+//                    break;
+//                case BackgroundPopUp.CUSTOM:
+//                    g2.drawImage(img, upperNode.getLeftBorder(), 0, upperNode.getImageWidht(), upperNode.getImageHeight(),
+//                            null);
+//                    break;
+//                default:
+//                    break;
+//            }
+//        }
+//
+//        // Draw Left Border
+//        g2.setColor(new Color(230, 230, 230));
+//        g2.fillRect(0, 0, upperNode.getLeftBorder(), this.getHeight());
+//        g2.setColor(Color.BLACK);
+//        g2.drawLine(0, 0, this.getWidth(), 0);
+//
+//        // Test SubNet Coloring
+//        int i = 0;
+//        for (SubNet s : controller.getSimManager().getSubNets()) {
+//
+//            if (model.getSubNetColors().size() - 1 < i) {
+//                controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
+//                        (int) (Math.random() * 255)));
+//            }
+//
+//            for (HolonObject cps : s.getObjects()) {
+//                cps.setBorderColor(model.getSubNetColors().get(i));
+//            }
+//            i++;
+//        }
+//
+//        // drawEdges that is being dragged
+//        if (drawEdge) {
+//            g2.setColor(Color.BLACK);
+//            g2.setStroke(new BasicStroke(2));
+//
+//            // If TempCps is an outside Object
+//            if (!upperNode.getNodes().contains(tempCps)) {
+//                int count = 0;
+//                for (CpsEdge e : upperNode.getConnections()) {
+//                    if (e.getA().equals(tempCps)) {
+//                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
+//                                + (model.getScale() + scalediv20 + 10) * count), x, y);
+//                    } else if (e.getB().equals(tempCps)) {
+//                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
+//                                + (model.getScale() + scalediv20 + 10) * count), x, y);
+//                    }
+//                    count++;
+//                }
+//            } else {
+//                g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
+//            }
+//        }
+//        // draw Edges
+//        for (CpsEdge con : upperNode.getNodeEdges()) {
+//            maxCap = paintEdge(con, maxCap);
+//        }
+//
+//        // Objects connected to upperNode
+//        int count = 0;
+//        for (CpsEdge e : upperNode.getConnections()) {
+//            AbstractCpsObject cps;
+//            if (e.getA().equals(this.upperNode)) {
+//                cps = e.getB();
+//            } else {
+//                cps = e.getA();
+//            }
+//            // Show and Highlight
+//            if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4]) {
+//                for (CpsEdge ed : cps.getConnections()) {
+//                    AbstractCpsObject obj = null;
+//                    if (upperNode.getNodes().contains(ed.getA())) {
+//                        obj = ed.getA();
+//                    } else if (upperNode.getNodes().contains(ed.getB())) {
+//                        obj = ed.getB();
+//                    }
+//                    if (obj != null) {
+//                        if (ed.getConnected() == 0) {
+//
+//                            setEdgeState(ed);
+//
+//                            if (ed.getA().getId() == model.getSelectedObjectID()
+//                                    || ed.getB().getId() == model.getSelectedObjectID() || edgeHighlight == ed)
+//                                g2.setColor(Color.BLUE);
+//                        } else {
+//                            g2.setColor(Color.DARK_GRAY);
+//                            g2.setStroke(new BasicStroke(2));
+//                        }
+//                        g2.drawLine(obj.getPosition().x, obj.getPosition().y, (upperNode.getLeftBorder() >> 1),
+//                                (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
+//                        if (showedInformation[0]) {
+//
+//                            maxCap = setCapacityString(ed, maxCap);
+//
+//                            if (ed.getConnected() == 0 || ed.getConnected() == 1) {
+//                                g2.drawString(ed.getFlow() + "/" + maxCap,
+//                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
+//                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
+//                                                + 25) / 2);
+//                            } else {
+//                                g2.drawString("not connected",
+//                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
+//                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
+//                                                + 25) / 2);
+//                            }
+//                        }
+//                    }
+//                }
+//            }
+//
+//            // Border Highlighting
+//            if (showedInformation[3]) {
+//                g2.setColor(cps.getBorderColor());
+//                if (g2.getColor() != Color.WHITE) {
+//                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
+//                            (int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
+//                            (int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
+//                }
+//            }
+//
+//            // node image
+//            if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
+//                    || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
+//            	img = Util.loadImage("/Images/node_selected.png");
+//            } else {
+//                if (cps instanceof HolonSwitch) {
+//                    if (((HolonSwitch) cps).getState(model.getCurIteration())) {
+//                        ((HolonSwitch) cps).setAutoState(true);
+//                    } else {
+//                        ((HolonSwitch) cps).setAutoState(false);
+//                    }
+//                }
+//                // Highlighting
+//                if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
+//                        || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
+//                    g2.setColor(Color.BLUE);
+//                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+//                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+//                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+//                } else if (cps instanceof HolonObject) {
+//                    g2.setColor(((HolonObject) cps).getColor());
+//
+//                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+//                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+//                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+//                }
+//                // draw image
+//                File checkPath = new File(cps.getImage());
+//                if (checkPath.exists()) {
+//                    img = new ImageIcon(cps.getImage()).getImage();
+//                } else {
+//                	img = Util.loadImage(cps.getImage());
+//                }
+//            }
+//            g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
+//                    (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
+//            count++;
+//        }
+//        // Highlighted Edge
+//        if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
+//            g2.setColor(Color.BLUE);
+//            for (CpsEdge con : upperNode.getNodeEdges()) {
+//                if (con.getFlow() <= con.getCapacity()) {
+//                    g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
+//                } else {
+//                    g2.setStroke(new BasicStroke(2));
+//                }
+//
+//                maxCap = drawEdgeLine(con, maxCap);
+//            }
+//        } else if (edgeHighlight != null) {
+//            g2.setColor(Color.BLUE);
+//            if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
+//                g2.setStroke(
+//                        new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
+//            } else {
+//                g2.setStroke(new BasicStroke(2));
+//            }
+//            if (upperNode.getNodeEdges().contains(edgeHighlight)) {
+//                g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
+//                        edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
+//
+//                maxCap = setCapacityString(edgeHighlight, maxCap);
+//
+//                if (showedInformation[0]) {
+//                    g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
+//                            (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
+//                            (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
+//                }
+//            }
+//        }
+//
+//
+//        //Draw ReplaceHighlight
+//        highlightMayBeReplaced(g2);
+//        
+//        // Objects in upper node
+//        for (AbstractCpsObject cps : upperNode.getNodes()) {
+//            // Border Highlighting
+//            if (showedInformation[3]) {
+//                g2.setColor(cps.getBorderColor());
+//                if (g2.getColor() != Color.WHITE) {
+//                    g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
+//                            (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
+//                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
+//                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
+//                }
+//            }
+//
+//            setEdgePictureAndHighlighting(cps);
+//
+//            g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
+//                    controller.getScale(), controller.getScale(), null);
+//            paintSupplyBar(g2,cps);
+//        }
+//        
+//        // Dragged marker Highlighting
+//        g2.setStroke(new BasicStroke(1));
+//        if (doMark) {
+//            g2.setColor(Color.BLACK);
+//            drawMarker();
+//        }
+//
+//        // Border Line
+//        g2.setColor(Color.BLACK);
+//        g2.drawLine(upperNode.getLeftBorder(), 0, upperNode.getLeftBorder(), this.getHeight());
+//
+//        // Tooltip
+//        showTooltip(g);
+        System.out.println("PaintCanvas");
     }
 
     @Override