Browse Source

Fixes

Outliner
Algorithm Printing
Replacement
Template
Todos
TomTroppmann 2 years ago
parent
commit
5705fb8382

+ 0 - 369
src/holeg/addon/InformationPanel.java

@@ -1,369 +0,0 @@
-package holeg.addon;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.util.ArrayList;
-import java.util.DoubleSummaryStatistics;
-import java.util.List;
-import java.util.Locale;
-import java.util.Random;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSeparator;
-import javax.swing.JTextField;
-
-import holeg.api.AddOn;
-import holeg.model.Flexibility;
-import holeg.model.HolonElement;
-import holeg.model.Flexibility.FlexState;
-import holeg.model.HolonElement.Priority;
-import holeg.ui.controller.Control;
-
-//TODO(Tom2022-01-13): Fix information Panel
-public class InformationPanel implements AddOn {
-	Control control;
-	
-	private JPanel content = new JPanel();
-	private JScrollPane scrollPane;
-	
-	
-	//Fields
-	private int amountSwitch;
-	private int amountActiveSwitch;
-	private int amountInactiveSwitch;
-	private int amountHolonObjects;
-		private int amountConsumer;
-			private int	amountUnderSupplied;
-			private int amountPatiallySupplied;
-			private int amountFullySupplied;
-			private int amountOversupllied;
-		private int amountSupplier;
-	private DoubleSummaryStatistics partiallySuppliedStats;
-	private DoubleSummaryStatistics overSuppliedStats;
-	
-	private int amountHolonElements;
-		private int amountElementEssential;
-		private int amountElementHigh;
-		private int amountElementMedium;
-		private int amountElementLow;
-		private int amountElementActiveEssential;
-		private int amountElementActiveHigh;
-		private int amountElementActiveMedium;
-		private int amountElementActiveLow;
-		private int amountElementInactiveEssential;
-		private int amountElementInactiveHigh;
-		private int amountElementInactiveMedium;
-		private int amountElementInactiveLow;
-	private int amountActiveHolonElements;
-	private int amountInactiveHolonElements;
-	private int amountFlexibilities;
-	private int amountActiveFlexibilities;
-		private int amountEssential;
-		private int amountActiveEssential;
-		private int amountHigh;
-		private int amountActiveHigh;
-		private int amountMedium;
-		private int amountActiveMedium;
-		private int amountLow;
-		private int amountActiveLow;
-
-		private int amountConsumingFlexibilities;
-		private int amountProducingFlexibilities;
-	private int amountPassiv;
-		
-	private int amountGroupNodes;
-	private int amountHolons;
-	
-	List<IEntry> entryList = new ArrayList<IEntry>();
-
-	private int currentEntryVerticalPosition = 0;
-
-
-
-
-
-	Random r = new Random();
-
-
-
-
-	
-	
-	public InformationPanel(){
-		content.setLayout(new BorderLayout());
-		scrollPane = new JScrollPane(createMiddlePanel(),  JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-	            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
-		int size = 75;
-		scrollPane.setPreferredSize(new Dimension(16*size, 9*size));
-		content.add(scrollPane, BorderLayout.CENTER);
-		JButton button = new JButton("calculate");
-		button.addActionListener(action -> updateEntrys());
-		content.add(button, BorderLayout.SOUTH);
-	}
-	
-	public static void main(String[] args)
-	{
-	      JFrame newFrame = new JFrame("exampleWindow");
-	      InformationPanel instance = new InformationPanel();
-	      newFrame.setContentPane(instance.getPanel());
-	      newFrame.pack();
-	      newFrame.setVisible(true);
-	      newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-	}
-	
-	
-	private JPanel createMiddlePanel() {
-		JPanel middle = new JPanel();
-		middle.setLayout(new GridBagLayout());
-		
-		
-		
-
-		entryList.add(new Entry(() -> Integer.toString(amountHolonObjects), "Holon Objects", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountConsumer) + addPercentage(amountConsumer, amountHolonObjects), "\tConsumer", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountUnderSupplied) + addPercentage(amountUnderSupplied, amountConsumer), "\t\tUnsupplied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountPatiallySupplied) + addPercentage(amountPatiallySupplied, amountConsumer), "\t\tPatiallySupplied", middle));
-		entryList.add(new StatEntry(() -> StatToFancyString(partiallySuppliedStats), middle));		
-		entryList.add(new Entry(() -> Integer.toString(amountFullySupplied) + addPercentage(amountFullySupplied, amountConsumer), "\t\tFullySupplied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountOversupllied) + addPercentage(amountOversupllied, amountConsumer), "\t\tOversupllied", middle));
-		entryList.add(new StatEntry(() -> StatToFancyString(overSuppliedStats), middle));
-		entryList.add(new Entry(() -> Integer.toString(amountSupplier) + addPercentage(amountSupplier, amountHolonObjects), "\tProducers", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountPassiv) + addPercentage(amountPassiv, amountHolonObjects), "\tPassiv", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountSwitch), "Switches", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveSwitch) + addPercentage(amountActiveSwitch, amountSwitch), "\tClosed Switches", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountInactiveSwitch) + addPercentage(amountInactiveSwitch, amountSwitch), "\tOpen Switches", middle));
-		
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountHolonElements), "Holon Elements", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementLow) + addPercentage(amountElementLow, amountHolonElements), "\tLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementMedium) + addPercentage(amountElementMedium, amountHolonElements), "\tMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementHigh) + addPercentage(amountElementHigh, amountHolonElements), "\tHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementEssential) + addPercentage(amountElementEssential, amountHolonElements), "\tEssential", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountActiveHolonElements) + addPercentage(amountActiveHolonElements, amountHolonElements), "[Active] HolonElements", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveLow) + addPercentage(amountElementActiveLow, amountActiveHolonElements), "\tLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveMedium) + addPercentage(amountElementActiveMedium, amountActiveHolonElements), "\tMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveHigh) + addPercentage(amountElementActiveHigh, amountActiveHolonElements), "\tHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveEssential) + addPercentage(amountElementActiveEssential, amountActiveHolonElements), "\tEssential", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountInactiveHolonElements) + addPercentage(amountInactiveHolonElements, amountHolonElements), "[Inactive] HolonElements", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveLow) + addPercentage(amountElementInactiveLow, amountInactiveHolonElements), "\tLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveMedium) + addPercentage(amountElementInactiveMedium, amountInactiveHolonElements), "\tMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveHigh) + addPercentage(amountElementInactiveHigh, amountInactiveHolonElements), "\tHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveEssential) + addPercentage(amountElementInactiveEssential, amountInactiveHolonElements), "\tEssential", middle));
-		
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "Flexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountConsumingFlexibilities) + addPercentage(amountConsumingFlexibilities, amountFlexibilities), "\tConsuming Flexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountProducingFlexibilities) + addPercentage(amountProducingFlexibilities, amountFlexibilities), "\tProducing Flexibilities", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "Flexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountLow) + addPercentage(amountLow, amountFlexibilities), "\tLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountMedium) + addPercentage(amountMedium, amountFlexibilities), "\tMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountHigh) + addPercentage(amountHigh, amountFlexibilities), "\tHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountEssential) + addPercentage(amountEssential, amountFlexibilities), "\tEssential", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountActiveFlexibilities), "Active Flexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveLow) + addPercentage(amountActiveLow, amountActiveFlexibilities), "\tLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveMedium) + addPercentage(amountActiveMedium, amountActiveFlexibilities), "\tMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveHigh) + addPercentage(amountActiveHigh, amountActiveFlexibilities), "\tHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveEssential) + addPercentage(amountActiveEssential, amountActiveFlexibilities), "\tEssential", middle));
-		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountGroupNodes), "Group Nodes", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountHolons), "Holons", middle));
-		
-		return middle;
-	}
-
-	String addPercentage(int amountActual, int amountMaximum) {
-		return (amountMaximum > 0) ? "                " + String.format (Locale.US, "%.2f", ((float) amountActual) / ((float) amountMaximum) * 100) + "%" : "";
-	}
-	
-	
-	
-	private void addSeperator(JPanel middle) {
-		GridBagConstraints c = new GridBagConstraints();
-		c.fill = GridBagConstraints.HORIZONTAL;
-		c.gridwidth = 2;
-		c.weighty = 0.5;
-		c.weightx = 0.5;
-		c.gridx = 0;
-		c.gridy = this.currentEntryVerticalPosition++;
-		middle.add(new JSeparator(JSeparator.HORIZONTAL), c);
-	}
-
-	private GridBagConstraints createGbConstrain(int x, int y) {
-		GridBagConstraints c = new GridBagConstraints();
-		c.fill = GridBagConstraints.HORIZONTAL;
-		c.insets = new Insets(3,6, 3, 6);  
-		c.weighty = 0.5;
-		c.weightx = 0.5;
-		c.gridx = x;
-		c.gridy = y;
-		return c;
-	}
-	
-	
-	void updateEntrys() {
-		calculateValues();
-		entryList.forEach(entry -> entry.update());
-		//printInfos();
-	}
-	
-	
-	void calculateValues(){
-//		DecoratedState dState = control.getSimManager().getActualDecorState().get();
-//		amountConsumer = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumer()).reduce(0, Integer::sum);
-//		this.amountSwitch = dState.getDecoratedSwitches().size();
-//		amountActiveSwitch = (int)dState.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
-//		amountInactiveSwitch = amountSwitch - amountActiveSwitch;
-//		this.amountUnderSupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)).reduce(0, Integer::sum);
-//		this.amountPatiallySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)).reduce(0, Integer::sum);
-//		
-//		this.amountFullySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)).reduce(0, Integer::sum);
-//		this.amountOversupllied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)).reduce(0, Integer::sum);
-//		amountSupplier = dState.getNetworkList().stream().map(net -> net.getAmountOfSupplier()).reduce(0, Integer::sum);
-//		amountPassiv = dState.getNetworkList().stream().map(net -> net.getAmountOfPassiv()).reduce(0, Integer::sum);
-//		
-//		this.amountHolonObjects = amountConsumer + amountSupplier + amountPassiv;
-//		
-//		partiallySuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		overSuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		List<Flexibility> flexList = control.getModel().getAllFlexibilities();
-//		List<Flexibility> allOfferedFlex = flexList.stream().filter(flex -> flex.getState().equals(FlexState.OFFERED)).toList();
-//		amountEssential = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
-//		amountHigh = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
-//		amountMedium = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
-//		amountLow = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-//		this.amountFlexibilities = amountEssential + amountHigh + amountMedium + amountLow;
-//		
-//		List<Flexibility> flexActiveList = flexList.stream().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
-//		amountActiveEssential = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
-//		amountActiveHigh = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
-//		amountActiveMedium = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
-//		amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-//		this.amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
-//		VisualRepresentationalState visualState =control.getSimManager().getActualVisualRepresentationalState().get();
-//		amountGroupNodes = visualState.getAmountfOfGroupNodes();
-//		
-//		
-//		amountHolons = dState.getNetworkList().size();
-//		List<HolonElement> listHolonElements = control.getModel().getAllHolonElements();
-//		this.amountHolonElements = listHolonElements.size();
-//		List<HolonElement> listAcitveHolonElemnts = listHolonElements.stream().filter(ele -> ele.active).collect(Collectors.toList());
-//		this.amountActiveHolonElements = listAcitveHolonElemnts.size();
-//		this.amountInactiveHolonElements = amountHolonElements - amountActiveHolonElements;
-//		this.amountElementLow = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
-//		this.amountElementMedium= (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
-//		this.amountElementHigh = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.High).count();
-//		this.amountElementEssential = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
-//		this.amountElementActiveLow = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
-//		this.amountElementActiveMedium= (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
-//		this.amountElementActiveHigh = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.High).count();
-//		this.amountElementActiveEssential = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
-//		this.amountElementInactiveLow = amountElementLow - amountElementActiveLow;
-//		this.amountElementInactiveMedium= amountElementMedium - amountElementActiveMedium;
-//		this.amountElementInactiveHigh = amountElementHigh - amountElementActiveHigh;
-//		this.amountElementInactiveEssential = amountElementEssential - amountElementActiveEssential;
-//		
-//		
-//		
-//		//int cost = 0;
-//		int consumingFlex = 0;
-//		//float consumingFlexEnergy = 0.0f;
-//		int producingFlex = 0;
-//		//float producingFlexEnergy = 0.0f;
-//		//int maxCooldown = 0;
-//		for(Flexibility flex :allOfferedFlex) {
-////			cost += flex.cost;
-//			float energy = flex.energyReleased();
-//			if(energy < 0) {
-//				consumingFlex++;
-////				consumingFlexEnergy += -energy;
-//			}else {
-//				producingFlex++;
-////				producingFlexEnergy += energy;
-//			}
-//		}
-//		this.amountConsumingFlexibilities = consumingFlex;
-//		this.amountProducingFlexibilities = producingFlex;
-		
-	}
-	
-
-	
-	
-
-	
-	@Override
-	public JPanel getPanel() {
-		return content;
-	}
-
-	@Override
-	public void setController(Control control) {
-		this.control = control;
-		if(control != null)  updateEntrys();
-	}
-	
-	private class Entry implements IEntry{
-		public Entry( Supplier<String> getter, String label, JPanel panel) {
-			this.getter = getter;
-			//RegisterToPanel
-			label = label.replaceAll("\t", "                   ");
-			JLabel jlabel = new JLabel(label);
-			panel.add(jlabel, createGbConstrain(0, currentEntryVerticalPosition));
-			tf = new JTextField(getter.get());
-			tf.setEditable(false);
-			panel.add(tf, createGbConstrain(1, currentEntryVerticalPosition));
-			currentEntryVerticalPosition++;
-		}
-		
-		private JTextField tf; //the Textfield to update
-		private Supplier<String> getter; //Getter for the field
-		public void update() {
-			tf.setText(getter.get());
-		}
-		
-		
-		
-	}
-	private String StatToFancyString (DoubleSummaryStatistics stats) {
-		return "Min:" + stats.getMin() + " Max:" + stats.getMax() + " Average:" + stats.getAverage();
-	}
-	public  class StatEntry implements IEntry 
-	{
-		JLabel textLabel = new JLabel("Nothing");
-		private Supplier<String> updateFunction = null;
-		public StatEntry( Supplier<String> updateText, JPanel panel){
-			updateFunction = updateText;
-			panel.add(textLabel, createGbConstrain(1, currentEntryVerticalPosition));
-			currentEntryVerticalPosition++;
-		}
-		@Override
-		public void update() {
-			textLabel.setText(updateFunction.get());
-		}
-	}
-	
-	
-	private interface IEntry{
-		public void update();
-	}
-}

+ 0 - 1
src/holeg/algorithm/objective_function/GraphMetrics.java

@@ -5,7 +5,6 @@ import java.util.logging.Logger;
 
 import holeg.model.*;
 
-//TODO(Tom2022-01-13) Fix GraphMetrics
 public class GraphMetrics {
 	private static final Logger log = Logger.getLogger(GraphMetrics.class.getName());
 	

+ 0 - 1
src/holeg/algorithm/objective_function/TopologieObjectiveFunction.java

@@ -98,7 +98,6 @@ public class TopologieObjectiveFunction {
 	 * @param moreInformation if more prints should be made
 	 * @return f_g value between 0 and 100
 	 */
-	//TODO(Tom2022-01-13) Fix TopologyFitnessFunction
 	static public float getFitnessValueForState(Model model, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
 
 

+ 97 - 119
src/holeg/api/AlgorithmFrameworkFlex.java

@@ -12,14 +12,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.math.RoundingMode;
 import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Optional;
+import java.util.*;
 import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -46,17 +39,12 @@ import javax.swing.text.NumberFormatter;
 import holeg.addon.helper.EmailNotification;
 import holeg.algorithm.objective_function.ObjectiveFunctionByCarlos;
 import holeg.algorithm.objective_function.SwitchObjectiveFunction;
-import holeg.model.Flexibility;
-import holeg.model.HolonElement;
-import holeg.model.HolonObject;
-import holeg.model.HolonSwitch;
+import holeg.model.*;
 import holeg.preferences.ImagePreference;
 import holeg.model.Flexibility.FlexState;
-import holeg.model.GroupNode;
 import holeg.model.HolonSwitch.SwitchMode;
 import holeg.model.HolonSwitch.SwitchState;
 import holeg.ui.controller.Control;
-import holeg.model.Model;
 import holeg.ui.view.component.Console;
 import holeg.ui.view.image.Import;
 import holeg.utility.math.decimal.Format;
@@ -630,7 +618,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		if(rounds > 1) {
 			RunValues avgRun = avg.getAverage();
 			
-			runPrinter.println("Average.Result: " + Format.doubleFixedPlaces(2, avgRun.result) + " Average.ExecutionTime:" + avgRun.executionTime + " "  + this.stringStatFromRunValues(avg.getAverage(), "Average."));
+			runPrinter.println("Average.Result: " + Format.doubleFixedPlaces(2, avgRun.result) + " Average.ExecutionTime:" + avgRun.executionTime + " "  + avg.getAverage().stringStatFromRunValues("Average."));
 		}
 		runPrinter.println("");
 		runPrinter.closeStream();
@@ -824,122 +812,71 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 
 	
-	
-	//TODO(Tom2022-01-13) fix print
+
 	private RunValues getRunValuesFromActualState() {
 		RunValues val = new RunValues();
-		//TODO(Tom2021-12-1) what should be printed happen when only groupNode are selected
-		groupNode.ifPresent(groupnode -> {
-//			val.producer = dGroupNode.getAmountOfSupplier();
-//			val.consumer = dGroupNode.getAmountOfConsumer();
-//			val.passiv = dGroupNode.getAmountOfPassiv();
-//			val.objects = val.producer + val.consumer + val.passiv;
-//			val.unsupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-//			val.partiallySupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-//			val.supplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-//			val.overSupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-//			
-//			
-//			val.activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
-//			val.elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
-			
-		});
-//		for(DecoratedNetwork net : state.getNetworkList()) {
-//			val.consumer += net.getAmountOfConsumer();
-//			val.producer += net.getAmountOfSupplier();
-//			val.passiv += net.getAmountOfPassiv();
-//			val.unsupplied += net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-//			val.partiallySupplied += net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-//			val.supplied += net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-//			val.overSupplied += net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-//			val.elements += net.getAmountOfElements();
-//			val.activeElements += net.getAmountOfActiveElements();
-//			val.consumption += net.getTotalConsumption();
-//			val.production += net.getTotalProduction();
-//		}
-//		val.objects = val.consumer + val.producer + val.passiv;
-//		val.difference= Math.abs(val.production - val.consumption);
-//		
-//		
-//		List<Flexibility> flexList = control.getModel().getAllFlexibilities();
-//		List<Flexibility> flexActiveList = flexList.stream().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
-//
-//		val.essentialFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
-//		val.highFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
-//		val.mediumFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
-//		val.lowFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-//		val.flexebilities = val.essentialFlex + val.highFlex + val.mediumFlex + val.lowFlex;
-//		val.holon = state.getNetworkList().size();
-//		val.switches = state.getDecoratedSwitches().size();
-//		val.activeSwitches = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
-//		
-//		DoubleSummaryStatistics overStat = state.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		val.partiallyMin = filterInf(partiallyStat.getMin());
-//		val.partiallyMax = filterInf(partiallyStat.getMax());
-//		val.partiallyAverage = filterInf(partiallyStat.getAverage());
-//		
-//		val.overMin = filterInf(overStat.getMin());
-//		val.overMax = filterInf(overStat.getMax());
-//		val.overAverage = filterInf(overStat.getAverage());
 
+		GroupNode canvas = control.getModel().getCanvas();
+		List<HolonObject> holonObjectList = canvas.getAllHolonObjectsRecursive().toList();
+		Map<HolonObject.HolonObjectState, Long> stateMap = holonObjectList.stream().collect(Collectors.groupingBy(HolonObject::getState, Collectors.counting()));
+		// UPDATE SUPPLY STATE
+		val.producer = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.PRODUCER, 0L));
+		val.overSupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.OVER_SUPPLIED, 0L));
+		val.supplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.SUPPLIED, 0L));
+		val.partiallySupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.PARTIALLY_SUPPLIED, 0L));
+		val.unsupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.NOT_SUPPLIED, 0L));
+		val.passiv = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.NO_ENERGY, 0L));
+		val.consumer = val.overSupplied + val.supplied + val.partiallySupplied + val.unsupplied;
+		val.objects = val.consumer + val.producer + val.passiv;
+
+		List<HolonElement> holonElementList = canvas.getAllHolonElements().toList();
+		val.elements = holonElementList.size();
+		// UPDATE ActiveInActive
+		val.activeElements = holonElementList.stream().filter(HolonElement::isOn).count();
+		val.consumption = canvas.getTotalConsumption();
+		val.production = canvas.getTotalProduction();
+		val.difference= Math.abs(val.production - val.consumption);
+
+		List<Flexibility> activeFlex = holonElementList.stream().flatMap(ele -> ele.flexList.stream()).filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
+		Map<HolonElement.Priority, Long> priorityCounts = activeFlex.stream().collect(Collectors.groupingBy(flex -> flex.getElement().priority, Collectors.counting()));
+		val.essentialFlex = priorityCounts.getOrDefault(HolonElement.Priority.Essential, 0L);
+		val.highFlex = priorityCounts.getOrDefault(HolonElement.Priority.High, 0L);
+		val.mediumFlex = priorityCounts.getOrDefault(HolonElement.Priority.Medium, 0L);
+		val.lowFlex = priorityCounts.getOrDefault(HolonElement.Priority.Low, 0L);
+
+		val.flexebilities = activeFlex.size();
+		val.holon = control.getModel().holons.size();
+		List<HolonSwitch> switchList = canvas.getAllSwitchObjectsRecursive().toList();
+		val.switches = switchList.size();
+		val.activeSwitches = (int)switchList.stream().filter(HolonSwitch::isClosed).count();
+
+		DoubleSummaryStatistics overStat = holonObjectList.stream().filter(con -> con.getState().equals(HolonObject.HolonObjectState.OVER_SUPPLIED))
+				.mapToDouble(HolonObject::getSupplyBarPercentage).summaryStatistics();
+
+		DoubleSummaryStatistics partiallyStat = holonObjectList.stream().filter(con -> con.getState().equals(HolonObject.HolonObjectState.PARTIALLY_SUPPLIED))
+				.mapToDouble(HolonObject::getSupplyBarPercentage).summaryStatistics();
+
+		val.partiallyMin = RunValues.filterInf(partiallyStat.getMin());
+		val.partiallyMax = RunValues.filterInf(partiallyStat.getMax());
+		val.partiallyAverage = RunValues.filterInf(partiallyStat.getAverage());
+
+		val.overMin = RunValues.filterInf(overStat.getMin());
+		val.overMax = RunValues.filterInf(overStat.getMax());
+		val.overAverage = RunValues.filterInf(overStat.getAverage());
 		return val;
-		
 	}
 	
 	
-	private double filterInf(double value) {
-		if(value == Double.NEGATIVE_INFINITY || value == Double.POSITIVE_INFINITY || value == Double.NaN) {
-			return 0;
-		}else {
-			return value;
-		}
-	}
+
 	
 	private String stringStatFromRunValues(RunValues val){
-		return stringStatFromRunValues(val , "");
+		return val.stringStatFromRunValues("");
 	}
 	
-	private String stringStatFromRunValues(RunValues val, String prefix) {
-		return	prefix +"Passiv: " + percentage(val.passiv, val.objects)
-			+ " " + prefix +"Producer: " + percentage(val.producer, val.objects)
-			+ " " +	prefix +"Consumer: " + percentage(val.consumer, val.objects)
-			+ " " +	prefix +"Unsupplied: " + percentage(val.unsupplied, val.objects)
-			+ " " +	prefix +"Partially: " + percentage(val.partiallySupplied, val.objects)
-			+ " " +	prefix +"Over: " + percentage(val.overSupplied, val.objects)
-			+ " " +	prefix +"Supplied: " + percentage(val.supplied, val.objects)
-			+ " " +	prefix +"Partially.SupplyPercentage.Min: " + Format.doubleFixedPlaces(2, val.partiallyMin) 
-			+ " " +	prefix +"Partially.SupplyPercentage.Max: "+ Format.doubleFixedPlaces(2, val.partiallyMax) 
-			+ " " +	prefix +"Partially.SupplyPercentage.Average: " + Format.doubleFixedPlaces(2, val.partiallyAverage)
-			+ " " + prefix +"Over.SupplyPercentage.Min: " + Format.doubleFixedPlaces(2, val.overMin) 
-			+ " " +	prefix +"Over.SupplyPercentage.Max: "+ Format.doubleFixedPlaces(2, val.overMax) 
-			+ " " +	prefix +"Over.SupplyPercentage.Average: " + Format.doubleFixedPlaces(2, val.overAverage)
-			+ " " +	prefix +"HolonElemnts.Active:" + percentage(val.activeElements, val.elements)
-			+ " " +	prefix +"Flexibilities.Essential: " + percentage(val.essentialFlex, val.flexebilities)
-			+ " " + prefix +"Flexibilities.High: " + percentage(val.highFlex, val.flexebilities)
-			+ " " +	prefix +"Flexibilities.Medium: " + percentage(val.mediumFlex, val.flexebilities)
-			+ " " +	prefix +"Flexibilities.Low: " + percentage(val.lowFlex, val.flexebilities)
-			+ " " +	prefix +"Switches.Active:" + percentage(val.activeSwitches,val.switches)
-			+ " " +	prefix +"Holons: " + val.holon
-			+ " " + prefix +"TotalConsumption: " + val.consumption
-			+ " " + prefix +"TotalProduction: " + val.production
-			+ " " + prefix +"Difference: " + val.difference;
-		
-	}
+
 	
 	
-	private String percentage(double numerator , double denominator) {
-		if((int)denominator == 0) {
-			return "-%";
-		}
-		return  Format.doubleTwoPlaces(numerator)   + "/" + Format.doubleTwoPlaces(denominator) + " "+ Format.doubleFixedPlaces(2,(float)numerator /(float)denominator * 100) + "%";
-	}
+
 	
 
 	
@@ -1028,7 +965,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	}
 		
 	
-	private class RunValues{
+	static class RunValues{
 		public double result;
 		public double executionTime;
 		
@@ -1064,6 +1001,47 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		public double consumption;
 		public double production;
 		public double difference;
+
+		public static double filterInf(double value) {
+			if(value == Double.NEGATIVE_INFINITY || value == Double.POSITIVE_INFINITY || Double.isNaN(value)) {
+				return 0;
+			}else {
+				return value;
+			}
+		}
+		public static String percentage(double numerator , double denominator) {
+			if((int)denominator == 0) {
+				return "-%";
+			}
+			return  Format.doubleTwoPlaces(numerator)   + "/" + Format.doubleTwoPlaces(denominator) + " "+ Format.doubleFixedPlaces(2,(float)numerator /(float)denominator * 100) + "%";
+		}
+
+		public String stringStatFromRunValues(String prefix) {
+			return	prefix +"Passiv: " + percentage(passiv, objects)
+					+ " " + prefix +"Producer: " + percentage(producer, objects)
+					+ " " +	prefix +"Consumer: " + percentage(consumer, objects)
+					+ " " +	prefix +"Unsupplied: " + percentage(unsupplied, objects)
+					+ " " +	prefix +"Partially: " + percentage(partiallySupplied, objects)
+					+ " " +	prefix +"Over: " + percentage(overSupplied, objects)
+					+ " " +	prefix +"Supplied: " + percentage(supplied, objects)
+					+ " " +	prefix +"Partially.SupplyPercentage.Min: " + Format.doubleFixedPlaces(2, partiallyMin)
+					+ " " +	prefix +"Partially.SupplyPercentage.Max: "+ Format.doubleFixedPlaces(2, partiallyMax)
+					+ " " +	prefix +"Partially.SupplyPercentage.Average: " + Format.doubleFixedPlaces(2, partiallyAverage)
+					+ " " + prefix +"Over.SupplyPercentage.Min: " + Format.doubleFixedPlaces(2, overMin)
+					+ " " +	prefix +"Over.SupplyPercentage.Max: "+ Format.doubleFixedPlaces(2, overMax)
+					+ " " +	prefix +"Over.SupplyPercentage.Average: " + Format.doubleFixedPlaces(2, overAverage)
+					+ " " +	prefix +"HolonElemnts.Active:" + percentage(activeElements, elements)
+					+ " " +	prefix +"Flexibilities.Essential: " + percentage(essentialFlex, flexebilities)
+					+ " " + prefix +"Flexibilities.High: " + percentage(highFlex, flexebilities)
+					+ " " +	prefix +"Flexibilities.Medium: " + percentage(mediumFlex, flexebilities)
+					+ " " +	prefix +"Flexibilities.Low: " + percentage(lowFlex, flexebilities)
+					+ " " +	prefix +"Switches.Active:" + percentage(activeSwitches,switches)
+					+ " " +	prefix +"Holons: " + holon
+					+ " " + prefix +"TotalConsumption: " + consumption
+					+ " " + prefix +"TotalProduction: " + production
+					+ " " + prefix +"Difference: " + difference;
+
+		}
 	}
 	
 	

+ 83 - 127
src/holeg/api/TopologieAlgorithmFramework.java

@@ -33,17 +33,11 @@ import javax.swing.JSplitPane;
 import javax.swing.text.NumberFormatter;
 
 import holeg.algorithm.objective_function.TopologieObjectiveFunction;
-import holeg.model.AbstractCanvasObject;
-import holeg.model.Edge;
-import holeg.model.GroupNode;
-import holeg.model.HolonObject;
-import holeg.model.HolonSwitch;
-import holeg.model.Node;
+import holeg.model.*;
 import holeg.model.HolonSwitch.SwitchMode;
 import holeg.model.HolonSwitch.SwitchState;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
-import holeg.model.Model;
 import holeg.ui.view.component.Console;
 import holeg.ui.view.category.Category;
 
@@ -67,23 +61,23 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	
 	//access
-	private ArrayList<AccessWrapper> accessWildcards = new  ArrayList<AccessWrapper>();
-	LinkedList<List<Integer>> resetChain = new LinkedList<List<Integer>>();
+	private ArrayList<AccessWrapper> accessWildcards = new ArrayList<>();
+	LinkedList<List<Integer>> resetChain = new LinkedList<>();
 	
 	
-	private HashMap<Integer, AbstractCanvasObject> accessIntToObject = new HashMap<Integer, AbstractCanvasObject>();
-	private HashMap<AbstractCanvasObject, Integer> accessObjectToInt = new HashMap<AbstractCanvasObject, Integer>();
-	private HashMap<Integer, AbstractCanvasObject> accessIntegerToWildcard = new HashMap<Integer, AbstractCanvasObject>();
-	private HashMap<AbstractCanvasObject, GroupNode> accessGroupNode = new HashMap<AbstractCanvasObject, GroupNode>(); 
+	private final HashMap<Integer, AbstractCanvasObject> accessIntToObject = new HashMap<>();
+	private final HashMap<AbstractCanvasObject, Integer> accessObjectToInt = new HashMap<>();
+	private final HashMap<Integer, AbstractCanvasObject> accessIntegerToWildcard = new HashMap<>();
+	private final HashMap<AbstractCanvasObject, GroupNode> accessGroupNode = new HashMap<>();
 	
-	private HashSet<IndexCable> cableSet = new HashSet<IndexCable>();
-	private ArrayList<IndexCable> cableList = new ArrayList<IndexCable>();
-	private HashMap<IndexCable, Double> addedIndexCable = new HashMap<IndexCable, Double>();
+	private final HashSet<IndexCable> cableSet = new HashSet<>();
+	private final ArrayList<IndexCable> cableList = new ArrayList<>();
+	private final HashMap<IndexCable, Double> addedIndexCable = new HashMap<>();
 	private int countForAccessMap = 0;
 	private int amountOfExistingCables = 0;
-	private ArrayList<HolonSwitch> switchList = new ArrayList<HolonSwitch>();
-	private HashMap<HolonSwitch, GroupNode> accessSwitchGroupNode = new HashMap<HolonSwitch, GroupNode>(); 
-	private ArrayList<Edge> edgeList = new ArrayList<Edge>();
+	private final ArrayList<HolonSwitch> switchList = new ArrayList<>();
+	private final HashMap<HolonSwitch, GroupNode> accessSwitchGroupNode = new HashMap<>();
+	private final ArrayList<Edge> edgeList = new ArrayList<>();
 	
 	boolean algoUseElements = false, algoUseSwitches = true, algoUseFlexes = true;
 	
@@ -91,7 +85,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	private long startTime;
 	
 	
-	private RunProgressBar runProgressbar = new RunProgressBar();
+	private final RunProgressBar runProgressbar = new RunProgressBar();
 	
 	
 	
@@ -104,8 +98,8 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 
 	
 	//printing
-	private Printer runPrinter = new Printer(plottFileName());
-	protected List<Double> runList = new LinkedList<Double>();
+	private final Printer runPrinter = new Printer(plottFileName());
+	protected List<Double> runList = new LinkedList<>();
 
 	//Parameter
 	@SuppressWarnings("rawtypes")
@@ -900,112 +894,74 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		switchList.clear();
 		edgeList.clear();
 	}
-	
-	//TODO(Tom2022-01-13): Fix print
+
 	private String stringStatFromActualState() {
-//		if(groupNode != null)
-//		{
-//			//GetActualDecoratedGroupNode
-//			int amountOfSupplier = dGroupNode.getAmountOfSupplier();
-//			int amountOfConsumer = dGroupNode.getAmountOfConsumer();
-//			int amountOfPassiv = dGroupNode.getAmountOfPassiv();
-//			int amountOfObjects = amountOfSupplier + amountOfConsumer + amountOfPassiv;
-//			int unSuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-//			int partiallySuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-//			int suppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-//			int overSuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-//			
-//			
-//			int activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
-//			int elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
-//			return	"HolonObjects["
-//				+	" Producer: " + amountOfSupplier  + "/" + amountOfObjects + "("+ (float)amountOfSupplier/(float)amountOfObjects * 100 + "%)"
-//				+	" Unsupplied: " + unSuppliedConsumer  + "/" + amountOfObjects + "("+ (float)unSuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-//				+	" PartiallySupplied: " + partiallySuppliedConsumer  + "/" + amountOfObjects + "("+ (float)partiallySuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-//				+	" Supplied: " + suppliedConsumer  + "/" + amountOfObjects + "("+ (float)suppliedConsumer/(float)amountOfObjects * 100 + "%)"
-//				+	" Passiv: " + overSuppliedConsumer  + "/" + amountOfObjects + "("+ (float)overSuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-//				+  "]" + "   HolonElemnts["
-//				+	" Active: " + activeElements  + "/" + elements + "("+ (float)activeElements/(float)elements * 100 + "%)"
-//				+ "]";
-//		}
-//		int amountOfSupplier = 0, amountOfConsumer = 0, amountOfPassiv = 0, unSuppliedConsumer = 0, partiallySuppliedConsumer = 0, suppliedConsumer = 0, overSuppliedConsumer = 0;
-//		int activeElements = 0, amountOfelements = 0;
-//		int totalConsumption = 0, totalProduction = 0;
-//		for(DecoratedNetwork net : state.getNetworkList()) {
-//			amountOfConsumer += net.getAmountOfConsumer();
-//			amountOfSupplier += net.getAmountOfSupplier();
-//			amountOfPassiv += net.getAmountOfPassiv();
-//			unSuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-//			partiallySuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-//			suppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-//			overSuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-//			amountOfelements += net.getAmountOfElements();
-//			activeElements += net.getAmountOfActiveElements();
-//			totalConsumption += net.getTotalConsumption();
-//			totalProduction += net.getTotalProduction();
-//		}
-//		int amountOfObjects = amountOfSupplier + amountOfConsumer + amountOfPassiv;
-//		int difference = Math.abs(totalProduction - totalConsumption);
-//		
-//		
-//		
-//		int amountHolons = state.getNetworkList().size();
-//		int amountSwitch = state.getDecoratedSwitches().size();
-//		int amountActiveSwitch = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
-//		
-//		int addedSwitches = calculateAmountOfAddedSwitches();
-//		double addedCableMeters = addedCableMeter();
-//		double wildcardCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-//		double cableCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-//		double switchCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-//		double totalCost = wildcardCost + cableCost + switchCost;
-//		
-//		DoubleSummaryStatistics overStat = state.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
-//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
-//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-//		
-//		return	"HolonObjects["
-//			+ " Passiv: " + percentage(amountOfPassiv, amountOfObjects)
-//			+ " Producer: " + percentage(amountOfSupplier, amountOfObjects)
-//			+ " Consumer: " + percentage(amountOfConsumer, amountOfObjects)
-//			+ " Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
-//			+ " PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects) 
-//			+ " with SupplyPercentage(Min: " + partiallyStat.getMin() 
-//			+ " Max: "+ partiallyStat.getMax() 
-//			+ " Average: " +partiallyStat.getAverage() +  ")"
-//			+ " Supplied: " + percentage(suppliedConsumer, amountOfConsumer)
-//			+ " Over: " + percentage(overSuppliedConsumer, amountOfConsumer)
-//			+ " with SupplyPercentage(Min: " + overStat.getMin() 
-//			+ " Max: "+ overStat.getMax() 
-//			+ " Average: " + overStat.getAverage() +  ")"
-//			+ "]" + "   HolonElemnts["
-//			+ " Active: " + percentage(activeElements, amountOfelements)
-//			+ "]" 
-//			+ " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
-//			+ " Holons: " + amountHolons
-//			+ " totalConsumption: " + totalConsumption
-//			+ " totalProduction: " + totalProduction
-//			+ " difference: " + difference
-//			+ " Topologie["
-//			+ " addedCableMeters:" + addedCableMeters
-//			+ " addedSwitches: " + addedSwitches
-//			+ " totalCost: " + totalCost + "("
-//			+ " wildcardCost: " + wildcardCost
-//			+ " cableCost: " + cableCost
-//			+ " switchCost: " + switchCost
-//			+  ")]"
-//			;
-//		
-		return "";
-	}
-	
-	
-	private String percentage(int actual, int max) {
-		return  actual  + "/" + max + "("+ (float)actual/(float)max * 100 + "%)";
+		AlgorithmFrameworkFlex.RunValues val = new AlgorithmFrameworkFlex.RunValues();
+		GroupNode canvas = control.getModel().getCanvas();
+		List<HolonObject> holonObjectList = canvas.getAllHolonObjectsRecursive().toList();
+		Map<HolonObject.HolonObjectState, Long> stateMap = holonObjectList.stream().collect(Collectors.groupingBy(HolonObject::getState, Collectors.counting()));
+		// UPDATE SUPPLY STATE
+		val.producer = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.PRODUCER, 0L));
+		val.overSupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.OVER_SUPPLIED, 0L));
+		val.supplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.SUPPLIED, 0L));
+		val.partiallySupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.PARTIALLY_SUPPLIED, 0L));
+		val.unsupplied = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.NOT_SUPPLIED, 0L));
+		val.passiv = Math.toIntExact(stateMap.getOrDefault(HolonObject.HolonObjectState.NO_ENERGY, 0L));
+		val.consumer = val.overSupplied + val.supplied + val.partiallySupplied + val.unsupplied;
+		val.objects = val.consumer + val.producer + val.passiv;
+
+		List<HolonElement> holonElementList = canvas.getAllHolonElements().toList();
+		val.elements = holonElementList.size();
+		// UPDATE ActiveInActive
+		val.activeElements = holonElementList.stream().filter(HolonElement::isOn).count();
+		val.consumption = canvas.getTotalConsumption();
+		val.production = canvas.getTotalProduction();
+		val.difference= Math.abs(val.production - val.consumption);
+
+		List<Flexibility> activeFlex = holonElementList.stream().flatMap(ele -> ele.flexList.stream()).filter(flex -> flex.getState().equals(Flexibility.FlexState.IN_USE)).toList();
+		Map<HolonElement.Priority, Long> priorityCounts = activeFlex.stream().collect(Collectors.groupingBy(flex -> flex.getElement().priority, Collectors.counting()));
+		val.essentialFlex = priorityCounts.getOrDefault(HolonElement.Priority.Essential, 0L);
+		val.highFlex = priorityCounts.getOrDefault(HolonElement.Priority.High, 0L);
+		val.mediumFlex = priorityCounts.getOrDefault(HolonElement.Priority.Medium, 0L);
+		val.lowFlex = priorityCounts.getOrDefault(HolonElement.Priority.Low, 0L);
+
+		val.flexebilities = activeFlex.size();
+		val.holon = control.getModel().holons.size();
+		List<HolonSwitch> switchList = canvas.getAllSwitchObjectsRecursive().toList();
+		val.switches = switchList.size();
+		val.activeSwitches = (int)switchList.stream().filter(HolonSwitch::isClosed).count();
+
+		DoubleSummaryStatistics overStat = holonObjectList.stream().filter(con -> con.getState().equals(HolonObject.HolonObjectState.OVER_SUPPLIED))
+				.mapToDouble(HolonObject::getSupplyBarPercentage).summaryStatistics();
+
+		DoubleSummaryStatistics partiallyStat = holonObjectList.stream().filter(con -> con.getState().equals(HolonObject.HolonObjectState.PARTIALLY_SUPPLIED))
+				.mapToDouble(HolonObject::getSupplyBarPercentage).summaryStatistics();
+
+		val.partiallyMin = AlgorithmFrameworkFlex.RunValues.filterInf(partiallyStat.getMin());
+		val.partiallyMax = AlgorithmFrameworkFlex.RunValues.filterInf(partiallyStat.getMax());
+		val.partiallyAverage = AlgorithmFrameworkFlex.RunValues.filterInf(partiallyStat.getAverage());
+
+		val.overMin = AlgorithmFrameworkFlex.RunValues.filterInf(overStat.getMin());
+		val.overMax = AlgorithmFrameworkFlex.RunValues.filterInf(overStat.getMax());
+		val.overAverage = AlgorithmFrameworkFlex.RunValues.filterInf(overStat.getAverage());
+
+
+		int addedSwitches = calculateAmountOfAddedSwitches();
+		double addedCableMeters = addedCableMeter();
+		double wildcardCost = TopologieObjectiveFunction.calculateWildcardCost(control.getModel());
+		double cableCost = TopologieObjectiveFunction.calculateAddedCableCost(addedCableMeters);
+		double switchCost = TopologieObjectiveFunction.calculateAddedSwitchCost(addedSwitches);
+		double totalCost = wildcardCost + cableCost + switchCost;
+
+		return val.stringStatFromRunValues("")
+			+ " Topology["
+			+ " addedCableMeters:" + addedCableMeters
+			+ " addedSwitches: " + addedSwitches
+			+ " totalCost: " + totalCost + "("
+			+ " wildcardCost: " + wildcardCost
+			+ " cableCost: " + cableCost
+			+ " switchCost: " + switchCost
+			+  ")]";
 	}
 	
 

+ 1 - 4
src/holeg/model/Edge.java

@@ -104,13 +104,11 @@ public class Edge {
         return state;
     }
 
-    //TODO(Tom 2021-12-3): public -> package
     public void setState(EdgeState state) {
         this.state = state;
     }
 
-    //TODO(Tom 2021-12-3): public -> package
-    public void reset() {
+    void reset() {
         state = initState();
     }
 
@@ -125,7 +123,6 @@ public class Edge {
         return flowEnergy;
     }
 
-    //TODO(Tom 2021-12-3): public -> package
     public void setActualFlow(float energyToSupplyInTheNetwork) {
         flowEnergy = energyToSupplyInTheNetwork;
     }

+ 5 - 6
src/holeg/model/HolonElement.java

@@ -319,18 +319,17 @@ public class HolonElement implements TimelineDependent, PostDeserialize {
      * STATE
      */
 
-    //TODO(Tom2021-12-1): public -> package
-    public void calculateState(int timestep) {
-        flexList.forEach(flex -> flex.calculateState(timestep));
-        float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
+    public void calculateState(int iteration) {
+        flexList.forEach(flex -> flex.calculateState(iteration));
+        float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, iteration)];
         actualEnergy = isOn() ? energyWhenActive : 0;
     }
 
     /**
      * Get the energyPerElement currently(at given time step) available
      */
-    public float calculateExpectedEnergyAtTimeStep(int timestep) {
-        float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
+    public float calculateExpectedEnergyAtTimeStep(int iteration) {
+        float energyWhenActive = energy * this.curveSample[IndexTranslator.getEffectiveIndex(this, iteration)];
         return active ? energyWhenActive : 0;
     }
 

+ 9 - 0
src/holeg/model/HolonSwitch.java

@@ -232,6 +232,15 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
         }
     }
 
+    public boolean isOpen() {
+        return getState().isOpen();
+    }
+
+    public boolean isClosed() {
+        return getState().isClosed();
+    }
+
+
     public enum SwitchMode {
         Manual, Auto
     }

+ 11 - 3
src/holeg/preferences/ColorPreference.java

@@ -105,8 +105,16 @@ public class ColorPreference {
         public final static Color Border = new Color(171, 173, 179);
     }
 
-    public static class GUI {
-        //TODO(Tom2021-12-1) for what is this collor used
-        public static final Color PALE_RED = new Color(255, 192, 192);
+    public static class TimePanel {
+        public static final Color Invalid = new Color(255, 192, 192);
+    }
+
+    public static class UnitGraph{
+        public static final Color DotColor = Color.blue;
+        public static final Color EditDotColor = new Color(255, 119, 0);
+        public static final Color[] SeriesColorArray = { Color.blue, Color.cyan, Color.black, Color.green, Color.gray,
+                Color.magenta, Color.yellow, Color.PINK, Color.red };
+        public static final Color GlobalCurveColor = new Color(255, 30, 30);
+        public static final Color ZeroLineColor = new Color(255, 153, 153);
     }
 }

+ 1 - 1
src/holeg/preferences/ImagePreference.java

@@ -46,7 +46,7 @@ public class ImagePreference {
 			public static final String Backward = "/images/buttons/backward.png";						
 		}
 		public static class Outliner {
-			public static final String Open = "/images/buttons/open.png";						
+			public static final String Open = "/images/buttons/opened.png";
 			public static final String Closed = "/images/buttons/closed.png";						
 			public static final String Leaf = "/images/buttons/leaf.png";						
 		}

+ 6 - 0
src/holeg/ui/controller/CanvasController.java

@@ -69,8 +69,14 @@ public class CanvasController {
         //Replace edges
         for (Edge edge : control.getModel().getEdgesOnCanvas()) {
             if (edge.getA() == toBeReplaced && edge.getB() != by) {
+                if(control.doesEdgeExist(new Edge(by, edge.getB(), 0))){
+                    continue;
+                }
                 edge.setA(by);
             } else if (edge.getB() == toBeReplaced && edge.getA() != by) {
+                if(control.doesEdgeExist(new Edge(edge.getA(), by, 0))){
+                    continue;
+                }
                 edge.setB(by);
             }
         }

+ 1 - 7
src/holeg/ui/controller/Control.java

@@ -199,7 +199,7 @@ public class Control {
         return true;
     }
 
-    private boolean doesEdgeExist(Edge edge){
+    public boolean doesEdgeExist(Edge edge){
         boolean connectsToSelf = edge.getA() == edge.getB();
         return !connectsToSelf && model.getEdgesOnCanvas().stream().anyMatch(e -> (e.getA() == edge.getA() && e.getB() == edge.getB())
                 || (e.getB() == edge.getA() && e.getA() == edge.getB()));
@@ -307,11 +307,6 @@ public class Control {
         clearSelection();
     }
 
-    public void createTemplate(HolonObject cps, JFrame parentFrame) {
-        CreateTemplatePopUp t = new CreateTemplatePopUp(cps, model, parentFrame, this);
-        t.setVisible(true);
-    }
-
 
     public void guiSetEnabled(boolean state) {
         OnGuiSetEnabled.broadcast(state);
@@ -383,7 +378,6 @@ public class Control {
      */
     public void addObject(Category category, AbstractCanvasObject object) {
         int i = 0;
-        //TODO(Tom2021-12-1) remove/redo this search
         while (category.findObjectWithName(object.getName()).isPresent()) {
             if (object.getName().contains("_"))
                 object.setName(object.getName().substring(0, object.getName().indexOf('_')));

+ 115 - 15
src/holeg/ui/view/canvas/Canvas.java

@@ -3,10 +3,12 @@ package holeg.ui.view.canvas;
 import holeg.model.*;
 import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
+import holeg.ui.view.dialog.CreateTemplatePopUp;
 import holeg.utility.math.vector.Geometry;
 import holeg.utility.math.vector.Vec2i;
 
 import javax.swing.*;
+import javax.swing.text.html.Option;
 import java.awt.*;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
@@ -14,6 +16,7 @@ import java.awt.event.MouseMotionListener;
 import java.util.HashSet;
 import java.util.Optional;
 import java.util.Set;
+import java.util.logging.Filter;
 import java.util.logging.Logger;
 
 public class Canvas extends JPanel {
@@ -22,6 +25,14 @@ public class Canvas extends JPanel {
     private final CanvasMouseListener canvasMouseListener = new CanvasMouseListener();
     private GroupNode groupNode;
     private boolean enabled = true;
+    private final JPopupMenu componentPopupMenu = new JPopupMenu();
+    private final JMenuItem groupMenu = new JMenuItem("Group");
+    private final JMenuItem ungroupMenu = new JMenuItem("Ungroup");
+    private final JMenuItem deleteMenu = new JMenuItem("Delete");
+    private final JMenuItem templateMenu = new JMenuItem("Template");
+
+    private AbstractCanvasObject checkForReplacement;
+
 
 
     public Canvas(Control control, GroupNode groupNode) {
@@ -34,6 +45,34 @@ public class Canvas extends JPanel {
         this.setPreferredSize(new Dimension(GuiSettings.canvasSize.getX(), GuiSettings.canvasSize.getY()));
         this.addMouseListener(canvasMouseListener);
         this.addMouseMotionListener(canvasMouseListener);
+        initPopupMenu();
+    }
+
+    private void initPopupMenu() {
+        componentPopupMenu.add(deleteMenu);
+        componentPopupMenu.addSeparator();
+        componentPopupMenu.add(groupMenu);
+        componentPopupMenu.add(ungroupMenu);
+        componentPopupMenu.addSeparator();
+        componentPopupMenu.add(templateMenu);
+        deleteMenu.addActionListener(clicked -> {
+            control.deleteCanvasObjects(GuiSettings.getSelectedObjects());
+            control.clearSelection();
+        });
+        groupMenu.addActionListener(clicked -> {
+           control.group();
+        });
+        ungroupMenu.addActionListener(clicked -> {
+            control.ungroup();
+        });
+        templateMenu.addActionListener(clicked -> {
+            GuiSettings.getSelectedObjects().stream().findAny().ifPresent(obj -> {
+               HolonObject hObject = (HolonObject)obj;
+                CreateTemplatePopUp templateDialog = new CreateTemplatePopUp(hObject, (JFrame) SwingUtilities.getWindowAncestor(this), control);
+            });
+
+        });
+
     }
 
     public static Rectangle getBoundsOfObject(AbstractCanvasObject obj) {
@@ -69,6 +108,9 @@ public class Canvas extends JPanel {
             case BoxSelection -> Rendering.drawSelectionBox(g2d, canvasMouseListener.getRectangleOfSelectionBox());
             case EdgeCreation -> Rendering.drawNewEdgeLine(g2d, canvasMouseListener.selectedOnPressed.getPosition(), canvasMouseListener.lastPosition);
         }
+        if(canvasMouseListener.canBeReplaced){
+            Rendering.drawReplacementSymbol(g2d, canvasMouseListener.selectedOnPressed);
+        }
     }
 
 
@@ -118,11 +160,6 @@ public class Canvas extends JPanel {
         ).findAny();
     }
 
-    //TODO(Tom2022-01-17): checkForReplacement replace with getObjectAtPosition
-    public Optional<AbstractCanvasObject> checkForReplacement(int x, int y) {
-        return Optional.empty();
-    }
-
     /**
      * Microsoft Windows10 selection & dragging behavior
      */
@@ -132,6 +169,10 @@ public class Canvas extends JPanel {
         private Set<AbstractCanvasObject> selectionBeforeBoxSelection = new HashSet<>();
         private State state = State.None;
         private AbstractCanvasObject selectedOnPressed = null;
+        private boolean canBeReplaced = false;
+
+
+
 
         @Override
         public void mousePressed(MouseEvent e) {
@@ -165,7 +206,7 @@ public class Canvas extends JPanel {
             log.finest(state.toString());
             Vec2i actualPos = new Vec2i(e.getPoint());
             switch (state) {
-                case None, Selection -> {
+                case Selection -> {
                     // Not handle to small mouse dragging
                     if (!(pressedPosition.getSquaredDistance(actualPos) > GuiSettings.dragThresholdDistance)) {
                         return;
@@ -181,16 +222,17 @@ public class Canvas extends JPanel {
                     groupNode.getObjectsInThisLayer().forEach(obj -> {
                         Rectangle bounds = getBoundsOfObject(obj);
                         if (selectionBox.intersects(bounds) ^ selectionBeforeBoxSelection.contains(obj)) {
-                            control.addObjectToSelection(obj);
+                            GuiSettings.getSelectedObjects().add(obj);
                         } else {
-                            control.removeObjectFromSelection(obj);
+                            GuiSettings.getSelectedObjects().remove(obj);
                         }
                     });
                     repaint();
                 }
                 case ObjectDragging -> {
                     Vec2i delta = actualPos.subtract(lastPosition);
-                    GuiSettings.getSelectedObjects().forEach(obj -> obj.getPosition().addAssign(delta));
+                    GuiSettings.getSelectedObjects().forEach(obj -> obj.setPosition(BoundsToCanvas(obj.getPosition().add(delta))));
+                    canBeReplaced = checkForReplacement(actualPos).isPresent();
                     repaint();
                 }
                 case EdgeCreation -> repaint();
@@ -198,18 +240,36 @@ public class Canvas extends JPanel {
             lastPosition = actualPos;
         }
 
+        private Optional<AbstractCanvasObject> checkForReplacement(Vec2i pos){
+            return groupNode.getObjectsInThisLayer().filter(obj -> obj != selectedOnPressed &&
+                    getBoundsOfObject(obj).contains(pos.getX(), pos.getY())
+            ).findAny();
+        }
+
         @Override
         public void mouseReleased(MouseEvent e) {
             if (!enabled) {
                 return;
             }
-            log.finest(state.toString());
+            log.info(state.toString());
             switch (state) {
                 case None -> {
-                    if (GuiSettings.getSelectedObjects().contains(selectedOnPressed)) {
-                        control.removeObjectFromSelection(selectedOnPressed);
-                    } else {
-                        control.addObjectToSelection(selectedOnPressed);
+                    if(SwingUtilities.isRightMouseButton(e)){
+                        preparePopupMenu();
+                        componentPopupMenu.show(Canvas.this, e.getX(), e.getY());
+                    }else {
+                        if (GuiSettings.getSelectedObjects().contains(selectedOnPressed)) {
+                            control.removeObjectFromSelection(selectedOnPressed);
+                        } else {
+                            control.addObjectToSelection(selectedOnPressed);
+                        }
+                    }
+                }
+                case Selection, BoxSelection -> {
+                    control.OnSelectionChanged.broadcast();
+                    if(SwingUtilities.isRightMouseButton(e)){
+                        preparePopupMenu();
+                        componentPopupMenu.show(Canvas.this, e.getX(), e.getY());
                     }
                 }
                 case EdgeCreation -> getObjectAtPosition(lastPosition).ifPresentOrElse(obj -> {
@@ -220,15 +280,49 @@ public class Canvas extends JPanel {
                 }, () -> {
                     Node node = new Node("Node");
                     groupNode.add(node);
-                    node.setPosition(new Vec2i(lastPosition));
+                    node.setPosition(new Vec2i(BoundsToCanvas(lastPosition)));
+
                     control.addEdgeOnCanvas(new Edge(selectedOnPressed, node, GuiSettings.maxCapacityForNewCreatedEdges));
                     control.calculateStateForCurrentIteration();
                 });
+                case ObjectDragging -> {
+                    checkForReplacement(new Vec2i(e.getPoint())).ifPresent(obj -> {
+                       control.replaceCanvasObject(obj, selectedOnPressed);
+                    });
+                }
             }
+            canBeReplaced = false;
             state = State.None;
             repaint();
         }
 
+        private void preparePopupMenu(){
+            int count = GuiSettings.getSelectedObjects().size();
+            boolean isAGroupNodeSelected = GuiSettings.getSelectedObjects().stream().anyMatch(obj -> obj instanceof GroupNode);
+            switch (count){
+                case 0 -> {
+                    groupMenu.setEnabled(false);
+                    ungroupMenu.setEnabled(false);
+                    deleteMenu.setEnabled(false);
+                    templateMenu.setEnabled(false);
+                }
+                case 1 -> {
+                    deleteMenu.setEnabled(true);
+                    boolean isSelectedObjectAHolonObject = GuiSettings.getSelectedObjects().stream().anyMatch(obj -> obj instanceof HolonObject);
+                    templateMenu.setEnabled(isSelectedObjectAHolonObject);
+                    groupMenu.setEnabled(true);
+                    ungroupMenu.setEnabled(isAGroupNodeSelected);
+                }
+                default -> {
+                    deleteMenu.setEnabled(true);
+                    templateMenu.setEnabled(false);
+                    groupMenu.setEnabled(true);
+                    ungroupMenu.setEnabled(isAGroupNodeSelected);
+                }
+            }
+        }
+
+
         @Override
         public void mouseClicked(MouseEvent e) {
             boolean doubleLeftClick = e.getClickCount() % 2 == 0 && SwingUtilities.isLeftMouseButton(e);
@@ -245,6 +339,12 @@ public class Canvas extends JPanel {
                 });
             }
         }
+        private Vec2i BoundsToCanvas(Vec2i pos){
+            Vec2i position = new Vec2i(pos);
+            position.clampX(GuiSettings.getPictureScaleDiv2(), GuiSettings.canvasSize.getX() - GuiSettings.getPictureScaleDiv2());
+            position.clampY(GuiSettings.getPictureScaleDiv2(), GuiSettings.canvasSize.getY() - GuiSettings.getPictureScaleDiv2());
+            return position;
+        }
 
         Rectangle getRectangleOfSelectionBox() {
             return Geometry.createRectangleFromCorners(lastPosition, pressedPosition);

+ 35 - 167
src/holeg/ui/view/canvas/Rendering.java

@@ -15,16 +15,13 @@ class Rendering {
             RenderingHints.VALUE_ANTIALIAS_ON);
     private static final Font CanvasFont = new Font("TimesNewRoman", Font.PLAIN,
             Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10));
-    private static final Color[] colors = {ColorPreference.HolonObject.Producer, ColorPreference.HolonObject.NotSupplied,
-            ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.Supplied,
-            ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.NoEnergy};
     private static final BasicStroke OnePixelStroke = new BasicStroke(1);
     private static final BasicStroke TwoPixelStroke = new BasicStroke(2);
     private static final Dimension SupplyBarDimensions = new Dimension(GuiSettings.getPictureScale(), GuiSettings.getPictureScale() / 5);
     private static final Font SupplyBarFont = new Font("TimesNewRoman", Font.PLAIN, (int) (GuiSettings.getPictureScale() * 0.3) - 2);
 
-    private static final Dimension LeavingEdgeTunnelSize = new Dimension(20, 20);
-
+    private static final Image ReplaceSymbol = Import.loadImage(
+            ImagePreference.Canvas.ReplaceSymbol, 20, 20);
 
 
     static Graphics2D initGraphics2D(Graphics g) {
@@ -37,14 +34,15 @@ class Rendering {
     static void drawSwitchObject(Graphics2D g, HolonSwitch hS) {
         drawCanvasObject(g, hS);
     }
+
     static void drawHolonObject(Graphics2D g, HolonObject hO) {
         Vec2i pos = hO.getPosition();
-		Color stateColor = ColorPreference.HolonObject.getStateColor(hO.getState());
-		g.setColor(stateColor);
+        Color stateColor = ColorPreference.HolonObject.getStateColor(hO.getState());
+        g.setColor(stateColor);
         g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
                 GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
         drawCanvasObject(g, hO.getImagePath(), pos);
-        if(GuiSettings.showSupplyBars && hO.getActualEnergy() <= 0){
+        if (GuiSettings.showSupplyBars && hO.getActualEnergy() <= 0) {
             drawSupplyBar(g, hO.getSupplyBarPercentage(), stateColor, pos);
         }
     }
@@ -62,9 +60,6 @@ class Rendering {
     }
 
 
-
-
-
     static void drawNode(Graphics2D g, Node node) {
         Vec2i pos = node.getPosition();
         drawCanvasObject(g, ImagePreference.Canvas.Node.Unselected, pos);
@@ -96,20 +91,17 @@ class Rendering {
         Dimension size = new Dimension(16, 16);
         Image image = Import.loadImage(ImagePreference.Canvas.ExternSymbol, size.width, size.height);
         g.drawImage(image, pos.getX() + GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2() - size.height,
-                  size.width, size.height, null);
+                size.width, size.height, null);
     }
 
 
-
-
-    static void drawNewEdgeLine(Graphics2D g, Vec2i start, Vec2i end){
+    static void drawNewEdgeLine(Graphics2D g, Vec2i start, Vec2i end) {
         g.setStroke(TwoPixelStroke);
         g.setColor(ColorPreference.Edge.Working);
         g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
     }
 
 
-
     static void drawGroupNode(Graphics2D g, GroupNode groupNode) {
         Vec2i pos = groupNode.getPosition();
         g.setColor(Color.gray);
@@ -151,157 +143,33 @@ class Rendering {
 
     }
 
+    private static void drawSupplyBar(Graphics2D g, float percentage, Color color, Vec2i pos) {
+        // +1, -2, -1 little Adjustment for pixel perfect alignment
+        g.setColor(Color.WHITE);
+        g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, SupplyBarDimensions.width,
+                SupplyBarDimensions.height);
+        g.setColor(color);
+        g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
+                (int) (SupplyBarDimensions.width * (percentage < 1 ? percentage : 1.0f) - 1), SupplyBarDimensions.height);
+        g.setColor(Color.BLACK);
+        g.setStroke(new BasicStroke(1));
+        g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, SupplyBarDimensions.width - 1,
+                SupplyBarDimensions.height);
+        g.setFont(SupplyBarFont);
+        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.getX() + 1 - stringWidth / 2,
+                pos.getY() + GuiSettings.getPictureScaleDiv2() - 1 + SupplyBarDimensions.height);
+    }
 
-
-//protected void drawCanvasObjectString(Graphics2D g, Vec2i posOfCanvasObject, float energy) {
-//	g.setColor(Color.BLACK);
-//	g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (GuiSettings.getPictureScale() / 4f)));
-//	g.drawString((energy > 0) ? "+" + Float.toString(energy) : Float.toString(energy),
-//			posOfCanvasObject.getX() - GuiSettings.getPictureScaleDiv2(),
-//			posOfCanvasObject.getY() - GuiSettings.getPictureScaleDiv2() - 1);
-//}
-//
-//protected void paintConsumer(Graphics2D g, Consumer con) {
-//	paintCanvasObject(g, con);
-//	drawCanvasObjectString(g, con.getModel().getPosition(), -con.getEnergyNeededFromNetwork());
-//	if (GuiSettings.showSupplyBars) {
-//		paintSupplyBar(g, con.getSupplyBarPercentage(), ColorPreference.HolonObject.getStateColor(con.getState()),
-//				con.getModel().getPosition());
-//	}
-//}
-//
-//protected void paintSupplier(Graphics2D g, Supplier sup) {
-//	paintCanvasObject(g, sup);
-//	drawCanvasObjectString(g, sup.getModel().getPosition(), sup.getEnergyToSupplyNetwork());
-//}
-//
-//protected void drawCanvasObject(Graphics2D g, String Image, Vec2i pos) {
-//	g.drawImage(Import.loadImage(Image, GuiSettings.getPictureScale(), GuiSettings.getPictureScale()),
-//			pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(), GuiSettings.getPictureScale(),
-//			GuiSettings.getPictureScale(), null);
-//}
-//
-//protected void paintCable(Graphics2D g, Edge cable, boolean isSelected) {
-//	Vec2i start = cable.getA().getPosition();
-//	Vec2i end = cable.getB().getPosition();
-//	float currentEnergy = cable.getActualFlow();
-//	float capacity = cable.maxCapacity;
-//	boolean unlimited = cable.isUnlimitedCapacity();
-//	switch (cable.getState()) {
-//	case Burned:
-//		g.setColor(ColorPreference.Edge.Burned);
-//		g.setStroke(new BasicStroke(2));
-//		break;
-//	case Working:
-//		g.setColor(ColorPreference.Edge.Working);
-//		g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
-//		break;
-//	}
-//	if (isSelected) {
-//		g.setColor(Color.lightGray);
-//	}
-//	g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
-//	if (showConnectionInformation) {
-//		Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
-//		g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-//		g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
-//	}
-//}
-
-//protected void paintExitCable(Graphics2D g, ExitCable eCable) {
-//	Vec2i start = eCable.getStart().getPosition();
-//	Vec2i end = eCable.getFinish().getPosition();
-//	float currentEnergy;
-//	float capacity = eCable.getEdge().maxCapacity;
-//	boolean unlimited = eCable.getEdge().isUnlimitedCapacity();
-//	if(eCable.getEdge().getState() == null) {
-//		System.err.print(eCable.getEdge());
-//	}
-//	switch (eCable.getEdge().getState()) {
-//	case Burned:
-//		currentEnergy = 0.0f;
-//		g.setColor(Color.RED);
-//		g.setStroke(new BasicStroke(2));
-//		break;
-//	case Working:
-//	default:
-//		currentEnergy = eCable.getEdge().getActualFlow();
-//		g.setColor(new Color(13, 175, 28));
-//		g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
-//		break;
-//	}
-//	g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
-//	Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
-//	g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-//	g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
-//}
-
-//private void paintGroupNodeBar(Graphics2D g, DecoratedGroupNode dGroupNode, Vec2i pos) {
-//	// +1, -2, -1 little Adjustment for pixel perfect alignment
-//	int barWidth = (int) (GuiSettings.getPictureScale());
-//	int barHeight = (int) (GuiSettings.getPictureScale() / 5);
-//	g.setColor(Color.WHITE);
-//	g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, (int) barWidth,
-//			barHeight);
-//	float[] percentages = getGroupNodeBarPercentages(dGroupNode);
-//
-//	for (int i = 5; i >= 0; i--) {
-//		g.setColor(colors[i]);
-//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
-//				(int) (barWidth * percentages[i] - 1), barHeight);
-//	}
-////	g.setColor(color);
-////	g.fillRect(pos.getX() - GuiSettings.GetPictureScaleDiv2(), pos.getY() + GuiSettings.GetPictureScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
-//	g.setColor(Color.BLACK);
-//	g.setStroke(new BasicStroke(1));
-//	g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, barWidth - 1,
-//			barHeight);
-//}
-//
-///**
-// * HardCoded Stuff dont try at Home ;)
-// * 
-// * @param dGroupNode
-// * @return
-// */
-//public float[] getGroupNodeBarPercentages(DecoratedGroupNode dGroupNode) {
-//	int[] amountOfObjects = new int[6];
-//	amountOfObjects[0] = dGroupNode.getAmountOfSupplier();
-//	amountOfObjects[1] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-//	amountOfObjects[2] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-//	amountOfObjects[3] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-//	amountOfObjects[4] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-//	amountOfObjects[5] = dGroupNode.getAmountOfPassiv();
-//	int countHolonObjects = amountOfObjects[0] + amountOfObjects[1] + amountOfObjects[2] + amountOfObjects[3]
-//			+ amountOfObjects[4] + amountOfObjects[5];
-//	float[] percentages = new float[6];
-//	int count = 0;
-//	for (int i = 0; i < 6; i++) {
-//		count += amountOfObjects[i];
-//		percentages[i] = (float) count / (float) countHolonObjects;
-//	}
-//	return percentages;
-//}
-
-private static void drawSupplyBar(Graphics2D g, float percentage, Color color, Vec2i pos) {
-	// +1, -2, -1 little Adjustment for pixel perfect alignment
-	g.setColor(Color.WHITE);
-	g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, SupplyBarDimensions.width,
-            SupplyBarDimensions.height);
-	g.setColor(color);
-	g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
-			(int) (SupplyBarDimensions.width * (percentage < 1 ? percentage : 1.0f) - 1), SupplyBarDimensions.height);
-	g.setColor(Color.BLACK);
-	g.setStroke(new BasicStroke(1));
-	g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, SupplyBarDimensions.width - 1,
-            SupplyBarDimensions.height);
-	g.setFont(SupplyBarFont);
-	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
+    public static void drawReplacementSymbol(Graphics2D g, AbstractCanvasObject hoveredObject) {
+        Vec2i pos = hoveredObject.getPosition();
+        Dimension size = new Dimension(16, 16);
+        Image image = Import.loadImage(ImagePreference.Canvas.ReplaceSymbol, size.width, size.height);
+        g.drawImage(image, pos.getX() - GuiSettings.getPictureScaleDiv2() -size.width, pos.getY() - GuiSettings.getPictureScaleDiv2() - size.height,
+                size.width, size.height, null);
     }
-	g.drawString(percentageString, pos.getX() + 1 - stringWidth / 2,
-			pos.getY() + GuiSettings.getPictureScaleDiv2() - 1 + SupplyBarDimensions.height);
-}
 }

+ 33 - 99
src/holeg/ui/view/dialog/CreateTemplatePopUp.java

@@ -1,63 +1,47 @@
 package holeg.ui.view.dialog;
 
-import java.awt.BorderLayout;
-import java.awt.Choice;
-import java.io.File;
-
-import javax.swing.DefaultListModel;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.border.EmptyBorder;
-import javax.swing.filechooser.FileNameExtensionFilter;
-
 import holeg.model.HolonElement;
 import holeg.model.HolonObject;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
-import holeg.model.Model;
 import holeg.ui.view.category.Category;
 import holeg.ui.view.image.Import;
 
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import java.awt.*;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * PopUp for creating Holon Object Template.
- * 
- * @author Gruppe 07 (A.T.M-B)
  */
 public class CreateTemplatePopUp extends JDialog {
 
 	/**
 	 * Template HolonObject
 	 */
-	private HolonObject template;
+	private final HolonObject template;
 
 	/**
 	 * HolonElementList
 	 */
-	DefaultListModel<String> listModel;
+	private final DefaultListModel<String> listModel;
+	private final List<HolonElement> holonElementList = new ArrayList<>();
 
 	/**
 	 * HolonElement List
 	 */
-	JList<String> list;
+	private final JList<String> list;
 
-	/**
-	 * Category the Template should be inserted into
-	 */
-	private String category;
 
 	// Template Attributes
 
 	// PopUp Parts
-	private Control controller;
+	private final Control controller;
 
 	/**
 	 * Category Selection
@@ -67,12 +51,12 @@ public class CreateTemplatePopUp extends JDialog {
 	/**
 	 * name textfield
 	 */
-	private JTextField textField_name;
+	private final JTextField textField_name;
 
 	/**
 	 * textField for path
 	 */
-	private JTextField textField_imagePath;
+	private final JTextField textField_imagePath;
 
 	/**
 	 * Image Preview
@@ -89,10 +73,8 @@ public class CreateTemplatePopUp extends JDialog {
 	 *            true if edit
 	 * @param obj
 	 *            the object
-	 * @param model
-	 *            the categorie
 	 */
-	public CreateTemplatePopUp(HolonObject obj, Model model,
+	public CreateTemplatePopUp(HolonObject obj,
 			JFrame parentFrame, Control controller) {
 		setResizable(false);
 		/*
@@ -113,24 +95,15 @@ public class CreateTemplatePopUp extends JDialog {
 		setLocationRelativeTo(parentFrame);
 		getContentPane().setLayout(new BorderLayout());
 
-		/**
-		 * Content Panel
-		 */
 		JPanel contentPanel = new JPanel();
 		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
 		contentPanel.setLayout(null);
 
-		/**
-		 * Category Label
-		 */
 		JLabel lblCategory = new JLabel("Category:");
 		lblCategory.setBounds(12, 13, 68, 22);
 		contentPanel.add(lblCategory);
 
-		/**
-		 * Category Choice
-		 */
 		choice = new Choice();
 		choice.setBounds(86, 13, 172, 22);
 		contentPanel.add(choice);
@@ -142,111 +115,72 @@ public class CreateTemplatePopUp extends JDialog {
 		for (Category c : GuiSettings.getCategories())
 			choice.add(c.getName());
 
-		/**
-		 * Name Label
-		 */
 		JLabel lblName = new JLabel("Name:");
 		lblName.setBounds(12, 48, 56, 16);
 		contentPanel.add(lblName);
 
-		/**
-		 * Name Textfield
-		 */
 		textField_name = new JTextField();
 		textField_name.setBounds(86, 48, 172, 22);
 		contentPanel.add(textField_name);
 		textField_name.setColumns(10);
 		textField_name.setText(template.getName());
 
-		/**
-		 * Image Path Lable
-		 */
 		JLabel lblImage = new JLabel("Image:");
 		lblImage.setBounds(12, 89, 56, 16);
 		contentPanel.add(lblImage);
 
-		/**
-		 * Image Path Text Field
-		 */
 		textField_imagePath = new JTextField();
 		textField_imagePath.setBounds(86, 86, 172, 22);
 		contentPanel.add(textField_imagePath);
 		textField_imagePath.setColumns(10);
 		textField_imagePath.setText(template.getImagePath());
 
-		/**
-		 * Browse Image Button
-		 */
 		JButton btnBrowseImage = new JButton("BrowseImage");
 		btnBrowseImage.setBounds(268, 85, 117, 25);
 		contentPanel.add(btnBrowseImage);
-		btnBrowseImage.addActionListener(actionevent -> {
-			fileChooser();
-		});
+		btnBrowseImage.addActionListener(clicked -> fileChooser());
 
-		/**
-		 * Image Preview
-		 */
 		lblImagePreview = new JLabel("Image Preview");
 		lblImagePreview.setIcon(new ImageIcon(Import.loadImage(
 				template.getImagePath(), 62, 62)));
 		lblImagePreview.setBounds(298, 13, 62, 62);
 		contentPanel.add(lblImagePreview);
 
-		/**
-		 * Holon Element List
-		 */
-		listModel = new DefaultListModel<String>();
+		listModel = new DefaultListModel<>();
 
-		/**
-		 * Add Elements to List
-		 */
 		template.elementsStream().forEach(hE -> {
 			listModel.addElement(hE.getName()
-					+ ": " + hE.getEnergy() + "U");			
+					+ ": " + hE.getEnergy() + "U");
+			holonElementList.add(hE);
 		});
-		/**
-		 * Add ScrollPane to List
-		 */
+		template.clearElements();
 		JScrollPane scrollPane = new JScrollPane();
 		scrollPane.setBounds(22, 118, 236, 150);
 		contentPanel.add(scrollPane);
-		list = new JList<String>(listModel);
+		list = new JList<>(listModel);
 		scrollPane.setViewportView(list);
 
-		/**
-		 * Delete Element Button
-		 */
 		JButton btnDeleteElement = new JButton("Delete Element");
 		btnDeleteElement.setBounds(268, 228, 140, 25);
 		contentPanel.add(btnDeleteElement);
 		btnDeleteElement.addActionListener(e -> removeElement());
 
-		/**
-		 * Edit Element Button
-		 */
 		JButton btnEditElement = new JButton("Edit Element");
 		btnEditElement.setBounds(268, 190, 140, 25);
 		contentPanel.add(btnEditElement);
 		btnEditElement.addActionListener(e -> editElement());
 
-		/**
-		 * Add Element Button
-		 */
 		JButton btnAddElement = new JButton("Add Element");
 		btnAddElement.setBounds(268, 152, 140, 25);
 		contentPanel.add(btnAddElement);
 		btnAddElement.addActionListener(e -> addElement());
 
-		/**
-		 * Cancel Button
-		 */
 		JButton btnCancel = new JButton("Cancel");
 		btnCancel.setBounds(384, 277, 74, 25);
 		contentPanel.add(btnCancel);
 		btnCancel.addActionListener(e -> dispose());
 
-		/**
+		/*
 		 * Add Template Button
 		 */
 		JButton btnAddTemplate = new JButton("Add Template");
@@ -254,11 +188,11 @@ public class CreateTemplatePopUp extends JDialog {
 		contentPanel.add(btnAddTemplate);
 		btnAddTemplate.addActionListener(e -> createTemplate());
 
-		/**
+		/*
 		 * Title
 		 */
 		setTitle("Create Template Menu");
-
+		this.setVisible(true);
 	}
 
 	/**
@@ -289,11 +223,11 @@ public class CreateTemplatePopUp extends JDialog {
 	private void createTemplate() {
 		template.setName(textField_name.getText());
 		template.setImagePath(textField_imagePath.getText());
+		template.clearElements();
+		template.add(holonElementList);
 		controller.findCategoryWithName(choice
-				.getItem(choice.getSelectedIndex())).ifPresent(cat -> {
-					controller.addObject(cat, template.getName(),
-							template.elementsStream().toList(), template.getImagePath());
-				});
+				.getItem(choice.getSelectedIndex())).ifPresent(cat -> controller.addObject(cat, template.getName(),
+						template.elementsStream().toList(), template.getImagePath()));
 		this.dispose();
 	}
 
@@ -308,7 +242,7 @@ public class CreateTemplatePopUp extends JDialog {
 		if (he != null) {
 			listModel.addElement(he.getName()
 					+ ": " + he.getEnergy() + "U");
-			template.add(he);
+			holonElementList.add(he);
 		}
 	}
 
@@ -319,8 +253,8 @@ public class CreateTemplatePopUp extends JDialog {
 		int index = list.getSelectedIndex();
 		if (index == -1)
 			return;
-		//TODO(Tom2022-01-27): template.remove(index);
 		listModel.remove(index);
+		holonElementList.remove(index);
 	}
 
 	/**
@@ -338,10 +272,10 @@ public class CreateTemplatePopUp extends JDialog {
 		HolonElement he = popUp.getElement();
 		if (he != null) {
 			listModel.remove(index);
+			holonElementList.remove(index);
 			listModel.addElement(he.getName()
 					+ ": " + he.getEnergy() + "U");
-			//TODO(Tom2022-01-27): template.removeElement(index);
-			template.add(he);
+			holonElementList.add(he);
 		}
 	}
 

+ 0 - 131
src/holeg/ui/view/information/FilterableGroupNode.java

@@ -1,131 +0,0 @@
-package holeg.ui.view.information;
-
-import holeg.model.*;
-
-public class FilterableGroupNode extends GroupNode {
-    public FilterableGroupNode() {
-        super("temp");
-    }
-
-    public void add(AbstractCanvasObject object) {
-        if (object instanceof HolonObject hObject) {
-            objectList.add(hObject);
-        }else if(object instanceof HolonSwitch hSwitch) {
-            switchList.add(hSwitch);
-        }else if(object instanceof Node node) {
-            nodeList.add(node);
-        }else if(object instanceof GroupNode groupNode) {
-            groupNodeList.add(groupNode);
-        }
-    }
-
-    public void remove(AbstractCanvasObject object) {
-        if (object instanceof HolonObject hObject) {
-            objectList.remove(hObject);
-        }else if(object instanceof HolonSwitch hSwitch) {
-            switchList.remove(hSwitch);
-        }else if(object instanceof Node node) {
-            nodeList.remove(node);
-        }else if(object instanceof GroupNode groupNode) {
-            groupNodeList.remove(groupNode);
-        }
-    }
-
-
-//
-//	// Returns the amount of holons and count himself
-//	public int getAmountOfGroupNodes() {
-//		return groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(1, Integer::sum);
-//	}
-//
-//	public Stream<Flexibility> getFlexibilitiesStream(Predicate<DecoratedHolonObject> stateFilter,
-//			Predicate<HolonElement> priorityFilter) {
-//
-//		Stream<Flexibility> flexInChildGorupNode = this.groupNodeList.stream()
-//				.flatMap(groupNode -> groupNode.getFlexibilitiesStream(stateFilter, priorityFilter));
-//
-//		Stream<Flexibility> flexInThisGorupNode = objectStream().filter(stateFilter).flatMap(object -> object.getModel()
-//				.getElements().filter(priorityFilter).flatMap(ele -> ele.flexList.stream()));
-//
-//		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
-//	}
-//
-//	public Stream<DecoratedHolonObject> objectStream() {
-//		return Stream.concat(Stream.concat(this.consumerList.stream(), this.supplierList.stream()),
-//				this.passivList.stream());
-//	}
-//
-//	// Gather Informations:
-//	public int getAmountOfSupplier(Predicate<DecoratedHolonObject> stateFilter) {
-//		return (int) supplierList.stream().filter(stateFilter).count() + groupNodeList.stream()
-//				.map(groupNode -> groupNode.getAmountOfSupplier(stateFilter)).reduce(0, Integer::sum);
-//	}
-//
-//	public int getAmountOfConsumer(Predicate<DecoratedHolonObject> stateFilter) {
-//		return (int) consumerList.stream().filter(stateFilter).count() + groupNodeList.stream()
-//				.map(groupNode -> groupNode.getAmountOfConsumer(stateFilter)).reduce(0, Integer::sum);
-//	}
-//
-//	public int getAmountOfPassiv(Predicate<DecoratedHolonObject> stateFilter) {
-//		return (int) passivList.stream().filter(stateFilter).count() + groupNodeList.stream()
-//				.map(groupNode -> groupNode.getAmountOfPassiv(stateFilter)).reduce(0, Integer::sum);
-//	}
-//
-//	public int getAmountOfConsumerWithState(Predicate<DecoratedHolonObject> stateFilter, HolonObjectState state) {
-//		return ((int) consumerList.stream().filter(stateFilter).map(con -> con.getState())
-//				.filter(rightState -> (rightState == state)).count())
-//				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(stateFilter, state))
-//						.reduce(0, Integer::sum);
-//	}
-//
-//	public PriorityCounts getPriorityCounts(Predicate<DecoratedHolonObject> stateFilter) {
-//		PriorityCounts priority = new PriorityCounts();
-//		objectStream().filter(stateFilter)
-//				.forEach(object -> object.getModel().getElements().forEach(ele -> priority.count(ele)));
-//		groupNodeList.stream().forEach(groupNode -> priority.add(groupNode.getPriorityCounts(stateFilter)));
-//		return priority;
-//	}
-//
-//	public int getAmountOfElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
-//			Predicate<HolonElement> priorityFilter) {
-//		return objectStream().filter(stateFilter)
-//				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
-//				.reduce(0, Integer::sum)
-//				+ groupNodeList.stream()
-//						.map(groupNode -> groupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter))
-//						.reduce(0, Integer::sum);
-//	}
-//
-//	public int getAmountOfAktiveElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
-//			Predicate<HolonElement> priorityFilter) {
-//		return objectStream().filter(stateFilter)
-//				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
-//				.reduce(0, Integer::sum)
-//				+ groupNodeList.stream().map(
-//						groupNode -> groupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter))
-//						.reduce(0, Integer::sum);
-//	}
-//
-//	public float getConsumption(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
-//		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
-//				.filter(stateFilter)
-//				.map(con -> con.getModel().getElements()
-//						.filter(priorityFilter.and(ele -> ele.getActualEnergy() < 0))
-//						.map(ele -> -ele.getActualEnergy()).reduce(0.0f, Float::sum))
-//				.reduce(0.f, Float::sum)
-//				+ groupNodeList.stream().map(groupNode -> groupNode.getConsumption(stateFilter, priorityFilter))
-//						.reduce(0.f, Float::sum);
-//	}
-//
-//	public float getProduction(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
-//		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
-//				.filter(stateFilter)
-//				.map(con -> con.getModel().getElements()
-//						.filter(priorityFilter.and(ele -> ele.getActualEnergy() > 0))
-//						.map(ele -> ele.getActualEnergy()).reduce(0.0f, Float::sum))
-//				.reduce(0.f, Float::sum)
-//				+ groupNodeList.stream().map(groupNode -> groupNode.getProduction(stateFilter, priorityFilter))
-//						.reduce(0.f, Float::sum);
-//	}
-
-}

+ 32 - 4
src/holeg/ui/view/information/HolonInformationPanel.java

@@ -1,8 +1,6 @@
 package holeg.ui.view.information;
 
-import holeg.model.Flexibility;
-import holeg.model.HolonElement;
-import holeg.model.HolonObject;
+import holeg.model.*;
 import holeg.model.HolonObject.HolonObjectState;
 import holeg.preferences.ColorPreference;
 import holeg.preferences.ImagePreference;
@@ -92,7 +90,7 @@ public class HolonInformationPanel extends JPanel {
 	}
 	
 	public void updateCharts() {
-		FilterableGroupNode tempGroupNode = new FilterableGroupNode();
+		TempGroupNode tempGroupNode = new TempGroupNode();
 		if(GuiSettings.getSelectedObjects().isEmpty()){
 			tempGroupNode.add(control.getModel().getCanvas());
 		}else{
@@ -488,4 +486,34 @@ public class HolonInformationPanel extends JPanel {
 		chart.addSeries("No Data", 0);
 		return chart;
 	}
+
+	private static class TempGroupNode extends GroupNode {
+		public TempGroupNode() {
+			super("temp");
+		}
+
+		public void add(AbstractCanvasObject object) {
+			if (object instanceof HolonObject hObject) {
+				objectList.add(hObject);
+			}else if(object instanceof HolonSwitch hSwitch) {
+				switchList.add(hSwitch);
+			}else if(object instanceof Node node) {
+				nodeList.add(node);
+			}else if(object instanceof GroupNode groupNode) {
+				groupNodeList.add(groupNode);
+			}
+		}
+
+		public void remove(AbstractCanvasObject object) {
+			if (object instanceof HolonObject hObject) {
+				objectList.remove(hObject);
+			}else if(object instanceof HolonSwitch hSwitch) {
+				switchList.remove(hSwitch);
+			}else if(object instanceof Node node) {
+				nodeList.remove(node);
+			}else if(object instanceof GroupNode groupNode) {
+				groupNodeList.remove(groupNode);
+			}
+		}
+	}
 }

+ 0 - 1
src/holeg/ui/view/inspector/InspectorTable.java

@@ -205,7 +205,6 @@ public class InspectorTable extends JPanel {
 			}
 				break;
 			case unselected:
-				// TODO(Tom2021-12-1) maybe select only current page
 				if (rowPool.getBorrowedCount() != 0) {
 					rowPool.getBorrowedStream().forEach(row -> row.setSelected(true));
 					duplicateButton.setEnabled(true);

+ 15 - 19
src/holeg/ui/view/inspector/UnitGraph.java

@@ -27,11 +27,13 @@ import holeg.interfaces.TimelineDependent;
 import holeg.interfaces.GraphEditable.GraphType;
 import holeg.model.HolonElement;
 import holeg.model.Model;
+import holeg.preferences.ColorPreference;
 import holeg.ui.controller.Control;
 import holeg.utility.math.Maths;
 import holeg.utility.math.vector.Vec2f;
 import holeg.utility.math.vector.Vec2i;
 
+
 /**
  * This Class represents a Graph where the User can model the behavior of
  * elements and switches over time.
@@ -51,13 +53,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	private static final int dotSize = 8;
 
 	/** The Color of a dot in the graph. */
-	//TODO(Tom2022-01-25): export them to ColorPreferences
-	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 };
-	private static final Color globalCurveColor = new Color(255, 30, 30);
-	private static final Color zeroLineColor = new Color(255, 153, 153);
+
 	private final Control control;
 
 	// Intern Variables
@@ -118,7 +114,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		overrideUnitGraph(series, element.getStateGraph());
 		series.element = element;
 		series.type = element.getGraphType();
-		series.color = seriesColorArray[element.hashCode() % seriesColorArray.length];
+		series.color = ColorPreference.UnitGraph.SeriesColorArray[element.hashCode() % ColorPreference.UnitGraph.SeriesColorArray.length];
 		seriesList.add(series);
 		repaint();
 	}
@@ -187,20 +183,20 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
 		g2d.setStroke(new BasicStroke(2f));
 		drawUnitGraph(g2d);
-		g2d.setColor(dotColor);
+		g2d.setColor(ColorPreference.UnitGraph.DotColor);
 		if (editMode) {
 			drawUnitGraphPointsReleased(g2d);
 		} else {
 			drawUnitGraphPoints(g2d);
 		}
-		g2d.setColor(dotColor);
+		g2d.setColor(ColorPreference.UnitGraph.DotColor);
 		g2d.setStroke(new BasicStroke(1));
 		drawCurrentIterationLine(g2d);
 		g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[]{6}, 3));
 		Optional.ofNullable(this.globalCurve).ifPresent(curve -> {
-			g2d.setColor(globalCurveColor);
+			g2d.setColor(ColorPreference.UnitGraph.GlobalCurveColor);
 			drawDoubleGraph(g2d, curve.points);
-			g2d.setColor(zeroLineColor);
+			g2d.setColor(ColorPreference.UnitGraph.ZeroLineColor);
 			g2d.setStroke(new BasicStroke(1));
 			drawDoubleGraph(g2d, curve.zeroLinePoints);
 		});
@@ -253,7 +249,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 * @param g to draw.
 	 */
 	private void drawUnitGraphPoints(Graphics2D g) {
-		g.setColor(dotColor);
+		g.setColor(ColorPreference.UnitGraph.DotColor);
 		for (Series series : seriesList) {
 			for (UnitGraphPoint p : series.points) {
 				drawDot(g, p.displayedPosition);
@@ -272,7 +268,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 */
 	private void drawUnitGraphPointsReleased(Graphics2D g) {
 		drawUnitGraphPoints(g);
-		g.setColor(editDotColor);
+		g.setColor(ColorPreference.UnitGraph.EditDotColor);
 		drawDot(g, editPosition);
 	}
 
@@ -333,7 +329,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			}
 			Vec2i oben = new Vec2i(border + (int) (where * widthWithBorder), 0);
 			Vec2i unten = new Vec2i(border + (int) (where * widthWithBorder), 2 * border + heightWithBorder);
-			g.setColor(dotColor);
+			g.setColor(ColorPreference.UnitGraph.DotColor);
 			drawLine(g, oben, unten);
 		}
 
@@ -428,7 +424,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		}
 		g.draw(path);
 		// Draw the Points on the Corner that dont exist in Data but should be visual
-		g.setColor(dotColor);
+		g.setColor(ColorPreference.UnitGraph.DotColor);
 		for (Vec2i p : cornerPoints) {
 			drawDot(g, p);
 		}
@@ -464,7 +460,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		if (!after.isEmpty())
 			middle.add(after.getFirst());
 
-		g.setColor(editDotColor);
+		g.setColor(ColorPreference.UnitGraph.EditDotColor);
 		drawBoolGraphFromList(g, middle);
 
 	}
@@ -519,7 +515,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			actual = target;
 		}
 		g.draw(path);
-		g.setColor(dotColor);
+		g.setColor(ColorPreference.UnitGraph.DotColor);
 		for (Vec2i p : cornerPoints) {
 			drawDot(g, p);
 		}
@@ -575,7 +571,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		if (!after.isEmpty())
 			middle.add(after.getFirst());
 
-		g.setColor(editDotColor);
+		g.setColor(ColorPreference.UnitGraph.EditDotColor);
 		drawUnitGraphFromList(g, middle);
 	}
 

+ 18 - 2
src/holeg/ui/view/main/Gui.java

@@ -265,8 +265,23 @@ public class Gui extends JFrame {
 
             edgePropertiesButton.addActionListener(actionEvent -> new EditEdgesPopUp(Gui.this, control));
             alignAllButton.addActionListener(clicked -> {
-                //TODO(Tom2022-01-14): recreateTryToAlignObjects
-                log.info("Not implemented yet.");
+                getActualCanvas().getGroupNode()
+                        .getObjectsInThisLayer().forEach(obj -> {
+                            int distance = GuiSettings.getPictureScaleDiv2() * 3;
+                            Vec2i pos = obj.getPosition();
+                            // offset relative to a grid with lines every distance pixels
+                            Vec2i offset = new Vec2i(pos.getX() % distance, pos.getY() % distance);
+
+                            //align to the other Line, if it is nearer
+                            if(offset.getX() > distance/2){
+                                offset.setX(offset.getX() - distance);
+                            }
+                            if(offset.getY() > distance/2){
+                                offset.setY(offset.getY() - distance);
+                            }
+                            obj.setPosition(obj.getPosition().subtract(offset));
+                        });
+                control.OnCanvasUpdate.broadcast();
             });
             resetCategoryButton.addActionListener(clicked -> control.resetCategories());
 
@@ -323,6 +338,7 @@ public class Gui extends JFrame {
             invertSelectionButton.setAccelerator(KeyStroke.getKeyStroke('I', defaultModifier));
             groupButton.setAccelerator(KeyStroke.getKeyStroke('G', defaultModifier));
             ungroupButton.setAccelerator(KeyStroke.getKeyStroke('U', defaultModifier));
+            alignAllButton.setAccelerator(KeyStroke.getKeyStroke('L', defaultModifier));
             removeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
         }
 

+ 2 - 2
src/holeg/ui/view/main/TimePanel.java

@@ -265,10 +265,10 @@ public class TimePanel extends JPanel implements ActionListener {
 				if (futureTask != null) {
 					futureTask.cancel(true);
 				}
-				futureTask = s.schedule((Runnable) () -> updateIterationsInput(), 1, TimeUnit.SECONDS);
+				futureTask = s.schedule((Runnable) this::updateIterationsInput, 1, TimeUnit.SECONDS);
 				hint.setText(" ");
 			} catch (NumberFormatException n) {
-				iterationsField.setBackground(ColorPreference.GUI.PALE_RED);// red stings
+				iterationsField.setBackground(ColorPreference.TimePanel.Invalid);// red stings
 				hint.setText("Invalid");
 			}
 		});

+ 0 - 1
src/holeg/ui/view/window/FlexWindow.java

@@ -365,7 +365,6 @@ public class FlexWindow extends JFrame {
 	}
 	
 	public void updateSelectedPanel() {
-		//TODO(Tom2021-12-1) Update Flex Window is slow
 		//Should not remove add so many Components
 		
 		listOfAllSelectedHolonObjects.removeAllChildren();

+ 40 - 137
src/holeg/ui/view/window/Outliner.java

@@ -1,38 +1,35 @@
 package holeg.ui.view.window;
 
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.swing.ImageIcon;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTabbedPane;
-import javax.swing.JTree;
-import javax.swing.event.TreeModelEvent;
-import javax.swing.event.TreeModelListener;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import holeg.model.AbstractCanvasObject;
+import holeg.model.Holon;
+import holeg.model.HolonObject;
+import holeg.preferences.ColorPreference;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
-import holeg.model.Holon;
-import holeg.model.Model;
 import holeg.ui.view.image.Import;
 import holeg.utility.listener.WindowClosingListener;
+import holeg.utility.math.decimal.Format;
+
+import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import java.awt.*;
+import java.util.logging.Logger;
 
 public class Outliner extends JFrame {
 	private static final Logger log = Logger.getLogger(Outliner.class.getName());
-	Control control;
+	private final Control control;
 	JTabbedPane tabbedPane = new JTabbedPane();
 	JPanel listPanel = new JPanel(new BorderLayout());
 	JPanel statePanel = new JPanel(new BorderLayout());
-	Set<Holon> list;
 	Runnable update = this::update;
 
+	private static final String ConsumptionFontHTMLBracket = "<font bgcolor='#"
+			+ Integer.toHexString(ColorPreference.Energy.Consumption.getRGB()).substring(2) + "'>";
+	private static final String ProductionFontHTMLBracket = "<font bgcolor='#"
+			+ Integer.toHexString(ColorPreference.Energy.Production.getRGB()).substring(2) + "'>";
+	private static final String FontClosingBracket = "</font> ";
+
+
 	public Outliner(JFrame parentFrame, Control control) {
 		setBounds(0, 0, 400, parentFrame.getHeight());
 		this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
@@ -42,16 +39,12 @@ public class Outliner extends JFrame {
 		this.control = control;
 		update();
 		this.getContentPane().add(tabbedPane);
-		this.addWindowListener((WindowClosingListener) e -> {
-			control.OnCanvasUpdate.removeListener(update);
-		});
+		this.addWindowListener((WindowClosingListener) e -> control.OnCanvasUpdate.removeListener(update));
 		control.OnCanvasUpdate.addListener(update);
-		tabbedPane.addTab("List", listPanel);
 		tabbedPane.addTab("State", statePanel);
 	}
 
 	public void update() {
-		// tabbedPane.removeAll();
 		listPanel.removeAll();
 		statePanel.removeAll();
 		DefaultMutableTreeNode topListPanel = new DefaultMutableTreeNode();
@@ -65,50 +58,14 @@ public class Outliner extends JFrame {
 		topListPanel.add(cables);
 		DefaultMutableTreeNode topStatePanel = new DefaultMutableTreeNode();
 
-		Model model = control.getModel();
-		model.getCanvas().getAllSwitchObjectsRecursive().forEach(hS -> {
-			switches.add(new DefaultMutableTreeNode(hS.getName()));
-		});
-
-		//TODO(Tom2022-01-13): Fix Outliner
-//		for (DecoratedNetwork dNet : decoratedState.getNetworkList()) {
-//			DefaultMutableTreeNode network = new DefaultMutableTreeNode("Network");
-//			if (!dNet.getConsumerList().isEmpty() || !dNet.getConsumerSelfSuppliedList().isEmpty()) {
-//				DefaultMutableTreeNode consumer = new DefaultMutableTreeNode("ConsumerList");
-//				for (Consumer con : dNet.getConsumerList()) {
-//					DefaultMutableTreeNode consumerNode = new ColoredTreeNode(con.toString(), con.getState().toString(),
-//							ColorPreference.HolonObject.getStateColor(con.getState()));
-//					consumer.add(consumerNode);
-//					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
-//				}
-//				for (Consumer con : dNet.getConsumerSelfSuppliedList()) {
-//					DefaultMutableTreeNode consumerNode = new DefaultMutableTreeNode(con.toString() + con.getState());
-//					consumer.add(consumerNode);
-//					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
-//				}
-//				network.add(consumer);
-//			}
-//			if (!dNet.getSupplierList().isEmpty()) {
-//				DefaultMutableTreeNode supplier = new DefaultMutableTreeNode("SupplierList");
-//				for (Supplier sup : dNet.getSupplierList()) {
-//					supplier.add(new DefaultMutableTreeNode(sup.toString()));
-//					objects.add(new DefaultMutableTreeNode(sup.getModel().getName()));
-//				}
-//				network.add(supplier);
-//			}
-//			for (Passiv pas : dNet.getPassivNoEnergyList()) {
-//				objects.add(new DefaultMutableTreeNode(pas.getModel().getName()));
-//			}
-//			topStatePanel.add(network);
-//			for (Edge cable : dNet.getDecoratedCableList()) {
-//				cables.add(new DefaultMutableTreeNode(cable.toString()));
-//			}
-//		}
-//
-//		for (Edge cable : decoratedState.getLeftOverEdges()) {
-//			cables.add(new DefaultMutableTreeNode(cable.toString()));
-//		}
-
+		for (Holon dNet : control.getModel().holons) {
+			DefaultMutableTreeNode network = new DefaultMutableTreeNode("Holon");
+			for(HolonObject hObject : dNet.holonObjects){
+				DefaultMutableTreeNode holonObjectNode = createColoredTreeNodeFromHolonObject(hObject);
+				network.add(holonObjectNode);
+			}
+			topStatePanel.add(network);
+		}
 		JTree listTree = new JTree(topListPanel);
 		signIconsForTree(listTree);
 		listTree.setRootVisible(false);
@@ -127,7 +84,6 @@ public class Outliner extends JFrame {
 		statePanel.add(new JScrollPane(stateTree));
 
 		listPanel.revalidate();
-		;
 		statePanel.revalidate();
 		listPanel.repaint();
 	}
@@ -136,77 +92,24 @@ public class Outliner extends JFrame {
 		ImageIcon ClosedIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Closed, 9, 9));
 		ImageIcon OpenIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Open, 9, 9));
 		ImageIcon LeafIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Leaf, 9, 9));
-		if (ClosedIcon != null && OpenIcon != null && LeafIcon != null) {
-			DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
-			renderer.setClosedIcon(ClosedIcon);
-			renderer.setOpenIcon(OpenIcon);
-			renderer.setLeafIcon(LeafIcon);
-			t.setCellRenderer(renderer);
-		}
+		DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
+		renderer.setClosedIcon(ClosedIcon);
+		renderer.setOpenIcon(OpenIcon);
+		renderer.setLeafIcon(LeafIcon);
+		t.setCellRenderer(renderer);
 	}
 
-	class MyTreeModelListener implements TreeModelListener {
-
-		@Override
-		public void treeNodesChanged(TreeModelEvent tmE) {
-			log.info("treeNodesChanged");
-		}
-
-		@Override
-		public void treeNodesInserted(TreeModelEvent tmE) {
-			log.info("treeNodesInserted");
-		}
-
-		@Override
-		public void treeNodesRemoved(TreeModelEvent tmE) {
-			log.info("treeNodesRemoved");
-		}
-
-		@Override
-		public void treeStructureChanged(TreeModelEvent tmE) {
-			log.info("treeStructureChanged");
-		}
-
-	}
-
-	class ColoredTreeNode extends DefaultMutableTreeNode {
-		private Color color;
-
-		public ColoredTreeNode(String string, String state, Color color) {
-			// "<html>Some text <font color='red'>" + "bla" + "some text in
-			// red</font></html>"
-			// Integer.toHexString(color.getRGB()).substring(2)
-			// String c = string + "<html><font bgcolor='#132122'>" + state
-			// +"</font></html>";
-			super(("<html>" + string + "<font bgcolor='#" + Integer.toHexString(color.getRGB()).substring(2) + "'>"
-					+ state + "</font></html>"));
-			// this.color = color;
-		}
-
-		public Color getColor() {
-			return color;
-		}
-
-		public void setColor(Color color) {
-			this.color = color;
-		}
 
+	private DefaultMutableTreeNode createColoredTreeNodeFromHolonObject(HolonObject obj){
+		String context = "<html>" + obj.getName() + "<font bgcolor='#"
+				+ Integer.toHexString(ColorPreference.HolonObject.getStateColor(obj.getState()).getRGB()).substring(2) + "'>" +
+				" " + obj.getState().toString() + FontClosingBracket
+				+ ConsumptionFontHTMLBracket + Format.doubleTwoPlaces(obj.getConsumption()) + FontClosingBracket
+				+ ProductionFontHTMLBracket + Format.doubleTwoPlaces(obj.getProduction()) + FontClosingBracket
+				+ "</html>";
+		return new DefaultMutableTreeNode(context);
 	}
 
-	class AbstractCpsObjectInfo {
-		private AbstractCanvasObject aCps;
 
-		AbstractCpsObjectInfo(AbstractCanvasObject aCps) {
-			this.aCps = aCps;
-		}
 
-		@Override
-		public String toString() {
-			return aCps.getName() + " Id:" + aCps.getId();
-		}
-
-		public AbstractCanvasObject getAbstractCpsObject() {
-			return aCps;
-		}
-	}
 }