Browse Source

Beginning Refactor Gui

Improves Save/Load
TomTroppmann 2 years ago
parent
commit
cd75e6c350

+ 1 - 3
build.gradle

@@ -13,17 +13,15 @@ java {
     toolchain.languageVersion.set(JavaLanguageVersion.of(17))
 }
 application {
-    mainClass = 'holeg.ui.view.main.Main'
+    mainClass = 'holeg.ui.view.Main'
 }
 
 repositories {
-    // maven { url "https://artifactory.cronapp.io/public-release/" }
     mavenCentral()
 }
 
 dependencies {
     implementation 'com.google.code.gson:gson:2.8.9'
-    // implementation 'com.google.code.gson:gson-extras:2.8.5'
     implementation 'org.apache.commons:commons-email:1.5'
     implementation 'org.wso2.orbit.org.apache.commons:commons-compress:1.18.0.wso2v1'
     implementation 'org.knowm.xchart:xchart:3.8.1'

+ 4 - 15
src/holeg/adapter/ModelDeserializer.java

@@ -3,40 +3,29 @@ package holeg.adapter;
 import com.google.gson.*;
 import com.google.gson.reflect.TypeToken;
 import holeg.model.*;
-import holeg.ui.controller.Control;
 import holeg.ui.model.IdCounter;
 
 import java.lang.reflect.Type;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.function.Function;
 import java.util.logging.Logger;
 import java.util.stream.Collectors;
 
 public class ModelDeserializer implements JsonDeserializer<Model> {
     private static final Logger log = Logger.getLogger(ModelDeserializer.class.getName());
-    private final static Type edgeSetType = new TypeToken<HashSet<Edge>>() {
-    }.getType();
-    private final Control control;
+    private final static Type edgeSetType = TypeToken.getParameterized(HashSet.class, Edge.class).getType();
     private final EdgeDeserializer edgeDeserializer = new EdgeDeserializer();
     private final Gson gson = new GsonBuilder().registerTypeAdapter(Edge.class, edgeDeserializer).create();
 
-
-    public ModelDeserializer(Control control) {
-        this.control = control;
-    }
-
     @Override
     public Model deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
         log.info("ModelDeserializer");
         final JsonObject jsonObj = json.getAsJsonObject();
-        Model model = control.getModel();
-        model.clear();
+        Model model = new Model();
         GroupNode canvas = context.deserialize(jsonObj.getAsJsonObject("canvas"), GroupNode.class);
-        Map<Integer, AbstractCanvasObject> idMap = canvas.getAllObjectsRecursive()
-                .collect(Collectors.toMap(AbstractCanvasObject::getId, Function.identity()));
         model.setCanvas(canvas);
-        edgeDeserializer.idMap = idMap;
+        edgeDeserializer.idMap = canvas.getAllObjectsRecursive()
+                .collect(Collectors.toMap(AbstractCanvasObject::getId, Function.identity()));
         //TODO(Tom2022-01-27): COMBINE methods sampleGraph and updateReference in Interface
         model.getAllHolonElements().forEach(HolonElement::sampleGraph);
         model.getCanvas().getAllSwitchObjectsRecursive().forEach(HolonSwitch::sampleGraph);

+ 38 - 43
src/holeg/addon/helper/EmailNotification.java

@@ -14,6 +14,7 @@ import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.JTextField;
 
+import holeg.preferences.PreferenceKeys;
 import org.apache.commons.mail.*;
 
 import holeg.preferences.ImagePreference;
@@ -21,11 +22,9 @@ import holeg.ui.view.image.Import;
 
 
 public class EmailNotification {
-	private static Preferences _prefs;
-	private static EmailSmtpInformation _info = new EmailSmtpInformation();
-	
-	
-	
+	private static final Preferences prefs = Preferences.userNodeForPackage(EmailNotification.class);
+	private static final EmailSmtpInformation info = new EmailSmtpInformation();
+
 	public static class EmailSmtpInformation{
 		public String Hostname;
 		public int Port;
@@ -68,22 +67,22 @@ public class EmailNotification {
 		JPanel infoPanel = new JPanel();
 		GridLayout infoLayout= new GridLayout(0,2);
 		infoPanel.add(new JLabel("SMTP Hostname:"));
-		JTextField hostnameTextField = new JTextField(_info.Hostname);
+		JTextField hostnameTextField = new JTextField(info.Hostname);
 		infoPanel.add(hostnameTextField);
 		infoPanel.add(new JLabel("Port:"));
-		JTextField portTextField = new JTextField(Integer.toString(_info.Port));
+		JTextField portTextField = new JTextField(Integer.toString(info.Port));
 		infoPanel.add(portTextField);
 		infoPanel.add(new JLabel("Username:"));
-		JTextField usernameTextField = new JTextField(_info.Username);
+		JTextField usernameTextField = new JTextField(info.Username);
 		infoPanel.add(usernameTextField);
 		infoPanel.add(new JLabel("Password:"));
-		JPasswordField  passwordTextField = new JPasswordField (_info.Password);
+		JPasswordField  passwordTextField = new JPasswordField (info.Password);
 		infoPanel.add(passwordTextField);
 		infoPanel.add(new JLabel("From Email:"));
-		JTextField fromEmailTextField = new JTextField(_info.FromEmail);
+		JTextField fromEmailTextField = new JTextField(info.FromEmail);
 		infoPanel.add(fromEmailTextField);
 		infoPanel.add(new JLabel("To Email:"));
-		JTextField toEmailTextField = new JTextField(_info.ToEmail);
+		JTextField toEmailTextField = new JTextField(info.ToEmail);
 		infoPanel.add(toEmailTextField);
 		infoPanel.setLayout(infoLayout);
 		panel.add(infoPanel, BorderLayout.CENTER);
@@ -92,19 +91,17 @@ public class EmailNotification {
 		controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
 		controlPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
 		JButton cancelButton = new JButton("Cancel");
-		cancelButton.addActionListener(event -> {
-			frame.dispose();
-		});
+		cancelButton.addActionListener(event -> frame.dispose());
 		controlPanel.add(cancelButton);
 		JButton applyButton = new JButton("Apply and Close");
 		applyButton.addActionListener(event -> {
 			// parse Textfields
-			_info.Hostname = hostnameTextField.getText();
-			_info.Port = Integer.valueOf(portTextField.getText());
-			_info.Username = usernameTextField.getText();
-			_info.Password =  String.valueOf(passwordTextField.getPassword());
-			_info.FromEmail = fromEmailTextField.getText();
-			_info.ToEmail = toEmailTextField.getText();
+			info.Hostname = hostnameTextField.getText();
+			info.Port = Integer.parseInt(portTextField.getText());
+			info.Username = usernameTextField.getText();
+			info.Password =  String.valueOf(passwordTextField.getPassword());
+			info.FromEmail = fromEmailTextField.getText();
+			info.ToEmail = toEmailTextField.getText();
 			// Save Preferences
 			savePreferences();
 			frame.dispose();
@@ -114,14 +111,14 @@ public class EmailNotification {
 		JButton testButton = new JButton("Send Test-Email");
 		testButton.addActionListener(event -> {
 			// parse Textfields
-			EmailSmtpInformation testinfo = new EmailSmtpInformation();
-			testinfo.Hostname = hostnameTextField.getText();
-			testinfo.Port = Integer.valueOf(portTextField.getText());
-			testinfo.Username = usernameTextField.getText();
-			testinfo.Password = String.valueOf(passwordTextField.getPassword());
-			testinfo.FromEmail = fromEmailTextField.getText();
-			testinfo.ToEmail = toEmailTextField.getText();
-			sendEmail(testinfo, "Holeg Notification Test", "Success.");
+			EmailSmtpInformation testInfo = new EmailSmtpInformation();
+			testInfo.Hostname = hostnameTextField.getText();
+			testInfo.Port = Integer.parseInt(portTextField.getText());
+			testInfo.Username = usernameTextField.getText();
+			testInfo.Password = String.valueOf(passwordTextField.getPassword());
+			testInfo.FromEmail = fromEmailTextField.getText();
+			testInfo.ToEmail = toEmailTextField.getText();
+			sendEmail(testInfo, "Holeg Notification Test", "Success.");
 		});
 		controlPanel.add(testButton);
 		
@@ -133,7 +130,7 @@ public class EmailNotification {
 	}
 	public static void sendEmail(String subject, String message) {
 		loadPreferences();
-		sendEmail(_info, subject, message);
+		sendEmail(info, subject, message);
 	}
 
 	public static void sendEmail(EmailSmtpInformation info, String subject, String message) {
@@ -154,23 +151,21 @@ public class EmailNotification {
 	}
 	
 	private static void savePreferences() {
-		_prefs = Preferences.userRoot().node("EmailNotification");
-		_prefs.put("Hostname", _info.Hostname);
-		_prefs.putInt("Port", _info.Port);
-		_prefs.put("Username", _info.Username);
-		_prefs.put("Password", _info.Password);
-		_prefs.put("FromEmail", _info.FromEmail);
-		_prefs.put("ToEmail", _info.ToEmail);
+		prefs.put(PreferenceKeys.EmailNotification.Hostname, info.Hostname);
+		prefs.putInt(PreferenceKeys.EmailNotification.Port, info.Port);
+		prefs.put(PreferenceKeys.EmailNotification.Username, info.Username);
+		prefs.put(PreferenceKeys.EmailNotification.Password, info.Password);
+		prefs.put(PreferenceKeys.EmailNotification.FromEmail, info.FromEmail);
+		prefs.put(PreferenceKeys.EmailNotification.ToEmail, info.ToEmail);
 	}
 	
 	private static void loadPreferences() {
-		_prefs = Preferences.userRoot().node("EmailNotification");
-		_info.Hostname = _prefs.get("Hostname", "");
-		_info.Port = _prefs.getInt("Port", 465);
-		_info.Username = _prefs.get("Username", "");
-		_info.Password = _prefs.get("Password", "");
-		_info.FromEmail= _prefs.get("FromEmail", "");
-		_info.ToEmail = _prefs.get("ToEmail", "");
+		info.Hostname = prefs.get(PreferenceKeys.EmailNotification.Hostname, "");
+		info.Port = prefs.getInt(PreferenceKeys.EmailNotification.Port, 465);
+		info.Username = prefs.get(PreferenceKeys.EmailNotification.Username, "");
+		info.Password = prefs.get(PreferenceKeys.EmailNotification.Password, "");
+		info.FromEmail= prefs.get(PreferenceKeys.EmailNotification.FromEmail, "");
+		info.ToEmail = prefs.get(PreferenceKeys.EmailNotification.ToEmail, "");
 	}
 	
 	

+ 1 - 1
src/holeg/api/TopologieAlgorithmFramework.java

@@ -45,7 +45,7 @@ import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
 import holeg.model.Model;
 import holeg.ui.view.component.Console;
-import holeg.ui.view.main.Category;
+import holeg.ui.view.category.Category;
 
 public abstract class TopologieAlgorithmFramework implements AddOn{
 	//Algo

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

@@ -14,15 +14,12 @@ import java.util.logging.Logger;
 
 /**
  * The class "HolonElement" represents any possible element that can be added to
- * a CpsObject (such as TV (consumer) or any energyPerElement source/producer).
+ * a HolonObject.
  *
  * @author Gruppe14
  */
 public class HolonElement implements TimelineDependent {
     private static final Logger log = Logger.getLogger(HolonElement.class.getName());
-    /*
-     * MODEL
-     */
     /**
      * Owner of the Element
      */

+ 1 - 72
src/holeg/model/Model.java

@@ -22,14 +22,7 @@ public class Model {
     /** the amount of iterations */
     private int currentIteration = 0;
     private int maxIterations = 100;
-    /**
-     * the Fairness model in use
-     */
-    private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
-    /*
-     * Array of all CpsObjects in our canvas. It is set by default as an empty
-     * list.
-     */
+
     private Set<Edge> edgesOnCanvas = new HashSet<>();
 
     public Model() {
@@ -40,56 +33,26 @@ public class Model {
         return canvas;
     }
 
-    /**
-     * Get all Edges on the Canvas.
-     *
-     * @return the edgesOnCanvas
-     */
     public Set<Edge> getEdgesOnCanvas() {
         return edgesOnCanvas;
     }
 
-    /**
-     * Adds an Edge to The Canvas.
-     *
-     * @param edge the edgesOnCanvas to add
-     */
     public void addEdgeOnCanvas(Edge edge) {
         this.edgesOnCanvas.add(edge);
     }
 
-    /**
-     * Remove an edge from the Canvas.
-     *
-     * @param edge the edge to remove
-     */
     public void removeEdgesOnCanvas(Edge edge) {
         this.edgesOnCanvas.remove(edge);
     }
 
-    /**
-     * Returns the maximum iterations.
-     *
-     * @return iterations
-     */
     public int getMaxIterations() {
         return maxIterations;
     }
 
-    /**
-     * Returns the current iteration.
-     *
-     * @return current iteration
-     */
     public int getCurrentIteration() {
         return currentIteration;
     }
 
-    /**
-     * sets the current Iteration.
-     *
-     * @param value the current Iteration
-     */
     public void setCurrentIteration(int value) {
         this.currentIteration = value;
     }
@@ -115,27 +78,10 @@ public class Model {
         this.getEdgesOnCanvas().forEach(Edge::reset);
     }
 
-    /**
-     * @param iterations the number of steps for this simulation
-     */
     public void setIterations(int iterations) {
         this.maxIterations = iterations;
     }
 
-    /**
-     * @return the fairnessModel
-     */
-    public FairnessModel getFairnessModel() {
-        return fairnessModel;
-    }
-
-    /**
-     * @param fairnessModel the fairnessModel to set
-     */
-    public void setFairnessModel(FairnessModel fairnessModel) {
-        this.fairnessModel = fairnessModel;
-    }
-
     public void clear() {
         this.edgesOnCanvas.clear();
         canvas.clear();
@@ -149,23 +95,6 @@ public class Model {
         this.edgesOnCanvas = edgesOnCanvas;
     }
 
-    /**
-     * All implemented FairnessModels:<br>
-     * {@link FairnessModel#MininumDemandFirst}<br>
-     * {@link FairnessModel#AllEqual}
-     */
-    public enum FairnessModel {
-        /**
-         * One Element of each HolonObject will be powered first, starting with the
-         * smallest Demand. If ale HolonObjects have an active Element, the
-         * simulation will try to fully supply as many HolonObjects as possible.
-         */
-        MininumDemandFirst,
-        /**
-         * All HolonObjects will receive the same amount of energy.
-         */
-        AllEqual
-    }
 
 
 }

+ 15 - 0
src/holeg/preferences/PreferenceKeys.java

@@ -0,0 +1,15 @@
+package holeg.preferences;
+
+public class PreferenceKeys {
+    public static class Gui{
+        public static final String DefaultFolder = "DefaultFolder";
+    }
+    public static class EmailNotification{
+        public static final String Hostname = "Hostname";
+        public static final String Port = "Port";
+        public static final String Username = "Username";
+        public static final String Password = "Password";
+        public static final String FromEmail = "FromEmail";
+        public static final String ToEmail = "ToEmail";
+    }
+}

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

@@ -7,8 +7,9 @@ import holeg.adapter.ModelDeserializer;
 import holeg.model.*;
 import holeg.preferences.ImagePreference;
 import holeg.ui.model.GuiSettings;
+import holeg.ui.model.IdCounter;
 import holeg.ui.view.dialog.CreateTemplatePopUp;
-import holeg.ui.view.main.Category;
+import holeg.ui.view.category.Category;
 import holeg.utility.events.Action;
 import holeg.utility.events.Event;
 import holeg.utility.math.vector.Vec2i;
@@ -438,11 +439,13 @@ public class Control {
             Gson gson = initGson();
             Model model = gson.fromJson(reader, Model.class);
             reader.close();
-            //this.model = model;
+            this.model = model;
             calculateStateAndVisualForCurrentTimeStep();
         } catch (IOException e) {
             log.warning(e.getLocalizedMessage());
         }
+        clearSelection();
+        GuiSettings.setActualSaveFile(file);
     }
 
 
@@ -456,20 +459,25 @@ public class Control {
         } catch (IOException e) {
             log.warning(e.getLocalizedMessage());
         }
+        GuiSettings.setActualSaveFile(file);
     }
 
     public Gson initGson() {
         GsonBuilder builder = new GsonBuilder();
-        //new GraphAdapterBuilder().addType(AbstractCanvasObject.class).registerOn(builder);
-        //RuntimeTypeAdapterFactory.of(AbstractCanvasObject.class).registerSubtype(Group)
         builder.registerTypeAdapter(Edge.class, new EdgeSerializer());
-        builder.registerTypeAdapter(Model.class, new ModelDeserializer(this));
+        builder.registerTypeAdapter(Model.class, new ModelDeserializer());
         builder.serializeNulls();
-        //builder.excludeFieldsWithoutExposeAnnotation();
         builder.setPrettyPrinting();
-        //builder.registerTypeAdapter(AbstractCanvasObject.class, new AbstractCpsObjectAdapter());
         return builder.create();
     }
 
 
+    public void clearModel() {
+        model.clear();
+        clearSelection();
+        model.setCurrentIteration(0);
+        IdCounter.reset();
+        calculateStateAndVisualForCurrentTimeStep();
+        GuiSettings.setActualSaveFile(null);
+    }
 }

+ 1 - 0
src/holeg/ui/controller/SimulationManager.java

@@ -31,6 +31,7 @@ public class SimulationManager {
         List<Edge> edgeList = new ArrayList<>(model.getEdgesOnCanvas());
         Set<Holon> holons = getHolons(holonObjectList, edgeList, timeStep);
         holons.forEach(holon -> holon.calculate(timeStep));
+        model.holons = holons;
         log.info("Holons:" + holons.stream().map(Object::toString).collect(Collectors.joining("\n")));
         long end = System.currentTimeMillis();
         log.finer("Simulation: " + (end - start) + "ms");

+ 13 - 2
src/holeg/ui/model/GuiSettings.java

@@ -1,10 +1,13 @@
 package holeg.ui.model;
 
+import java.io.File;
 import java.util.HashSet;
+import java.util.Optional;
 import java.util.Set;
 import holeg.model.AbstractCanvasObject;
 import holeg.model.Edge;
-import holeg.ui.view.main.Category;
+import holeg.ui.view.category.Category;
+import holeg.ui.view.dialog.CreateNewDialog;
 import holeg.utility.math.vector.Vec2i;
 
 public class GuiSettings {
@@ -28,7 +31,15 @@ public class GuiSettings {
     public static int numberOfSaves = 35;
 
     public static float dragThresholdDistance = 5;
-    
+    private static File actualSaveFile = null;
+
+	public static Optional<File> getActualSaveFile(){
+		return Optional.ofNullable(actualSaveFile);
+	}
+	public static void setActualSaveFile(File file){
+		actualSaveFile = file;
+	}
+
     
     public static int getPictureScale() {
         return pictureScale;

+ 67 - 67
src/holeg/ui/view/main/Main.java → src/holeg/ui/view/Main.java

@@ -1,67 +1,67 @@
-package holeg.ui.view.main;
-
-import javax.swing.*;
-
-import holeg.ui.controller.Control;
-import holeg.ui.controller.IndexTranslator;
-import holeg.model.Model;
-
-import java.awt.*;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Locale;
-import java.util.logging.Level;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-/**
- * The main Class in this Program. The GUI is created in this Class.
- *
- * @author Gruppe14
- */
-public class Main {
-    private static final LogManager logManager = LogManager.getLogManager();
-    private static final Logger log = Logger.getLogger(Main.class.getName());
-
-    static {
-        try {
-            logManager.readConfiguration(new FileInputStream("./config/log.properties"));
-        } catch (IOException exception) {
-            log.log(Level.SEVERE, "Error in loading configuration", exception);
-        }
-    }
-
-    /**
-     * main method of this program.
-     *
-     * @param args standard
-     */
-    public static void main(String[] args) {
-        setLookAndFeel();
-        setLocale();
-        EventQueue.invokeLater(() -> {
-            Model model = new Model();
-            Control control = new Control(model);
-            GUI view = new GUI(control);
-            view.setVisible(true);
-        });
-    }
-
-    private static void setLocale() {
-        Locale.setDefault(Locale.US);
-    }
-
-    /**
-     * This method loads the System LookAndFeel. Except for Linux OS.
-     */
-    private static void setLookAndFeel() {
-        try {
-            if (!System.getProperty("os.name").startsWith("Linux")) {
-                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-            }
-        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
-                | UnsupportedLookAndFeelException e) {
-        }
-    }
-
-}
+package holeg.ui.view;
+
+import javax.swing.*;
+
+import holeg.ui.controller.Control;
+import holeg.model.Model;
+import holeg.ui.view.main.Gui;
+
+import java.awt.*;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+/**
+ * The main Class in this Program. The GUI is created in this Class.
+ *
+ * @author Gruppe14
+ */
+public class Main {
+    private static final LogManager logManager = LogManager.getLogManager();
+    private static final Logger log = Logger.getLogger(Main.class.getName());
+
+    static {
+        try {
+            logManager.readConfiguration(new FileInputStream("./config/log.properties"));
+        } catch (IOException exception) {
+            log.log(Level.SEVERE, "Error in loading configuration", exception);
+        }
+    }
+
+    /**
+     * main method of this program.
+     *
+     * @param args standard
+     */
+    public static void main(String[] args) {
+        setLookAndFeel();
+        setLocale();
+        EventQueue.invokeLater(() -> {
+            Model model = new Model();
+            Control control = new Control(model);
+            Gui view = new Gui(control);
+            view.setVisible(true);
+        });
+    }
+
+    private static void setLocale() {
+        Locale.setDefault(Locale.US);
+    }
+
+    /**
+     * This method loads the System LookAndFeel. Except for Linux OS.
+     */
+    private static void setLookAndFeel() {
+        try {
+            if (!System.getProperty("os.name").startsWith("Linux")) {
+                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+            }
+        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
+                | UnsupportedLookAndFeelException ignored) {
+        }
+    }
+
+}

+ 4 - 1
src/holeg/ui/view/canvas/Canvas.java

@@ -29,6 +29,7 @@ public class Canvas extends JPanel {
         this.groupNode = groupNode;
         control.OnGuiSetEnabled.addListener(this::setCanvasEnabled);
         control.OnSelectionChanged.addListener(this::repaint);
+        control.OnCanvasUpdate.addListener(this::repaint);
         // TODO(Tom2022-01-14): remove listener when not needed anymore
         this.addMouseListener(canvasMouseListener);
         this.addMouseMotionListener(canvasMouseListener);
@@ -60,6 +61,9 @@ public class Canvas extends JPanel {
         Graphics2D g2d = Rendering.initGraphics2D(g);
         Rendering.drawSelection(g2d);
         control.getModel().getEdgesOnCanvas().forEach(edge -> {
+            if (edge.getA().getGroupNode().isEmpty() || edge.getB().getGroupNode().isEmpty()){
+                return;
+            }
             boolean edgeAinside = edge.getA().getGroupNode().get() == groupNode;
             boolean edgeBinside = edge.getB().getGroupNode().get() == groupNode;
             //both
@@ -193,7 +197,6 @@ public class Canvas extends JPanel {
                         control.addEdgeOnCanvas(new Edge(selectedOnPressed, node, GuiSettings.maxCapacityForNewCreatedEdges));
                         control.calculateStateAndVisualForCurrentTimeStep();
                     });
-
                 }
             }
             state = State.None;

+ 6 - 0
src/holeg/ui/view/canvas/CanvasCollectionPanel.java

@@ -0,0 +1,6 @@
+package holeg.ui.view.canvas;
+
+import javax.swing.*;
+
+public class CanvasCollectionPanel extends JTabbedPane {
+}

+ 80 - 80
src/holeg/ui/view/main/Category.java → src/holeg/ui/view/category/Category.java

@@ -1,80 +1,80 @@
-package holeg.ui.view.main;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-
-import com.google.gson.annotations.Expose;
-
-import holeg.model.AbstractCanvasObject;
-
-/**
- * Class "Category" performs the functionality of listing elements into groups.
- * Each Category contains an ArrayList of CpsObjects, a name and a HashMap of
- * ObjIdx.
- * 
- * @author Gruppe14
- *
- */
-
-public class Category {
-	// objects: is a ArrayList of all Objects that belongs to the Category
-	private Set<AbstractCanvasObject> objects = new HashSet<AbstractCanvasObject>();
-	// name: is a String chosen by the User
-	private String name; 
-
-	/**
-	 * Category Constructor.
-	 * 
-	 * @param name name of the Category
-	 */
-	public Category(String name) {
-		setName(name);
-	}
-
-	/**
-	 * Getter for all CpsObjects.
-	 * 
-	 * @return the objects
-	 */
-	public Set<AbstractCanvasObject> getObjects() {
-		return objects;
-	}
-
-	/**
-	 * Set a new ArrayList of CpsObjects.
-	 * 
-	 * @param objects
-	 *            the objects to set
-	 */
-	public void setObjects(Set<AbstractCanvasObject> objects) {
-		this.objects = objects;
-	}
-
-	/**
-	 * Getter the name of the Category.
-	 * 
-	 * @return the name
-	 */
-	public String getName() {
-		return name;
-	}
-
-	/**
-	 * Set the name of the Category to a new one.
-	 * 
-	 * @param name
-	 *            the name to set
-	 */
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	
-	public Optional<AbstractCanvasObject> findObjectWithName(String name){
-		return objects.stream().filter(obj -> obj.getName().equals(name)).findFirst();
-	}
-	
-	public boolean removeObjectsWithName(String name){
-		return objects.removeIf(obj -> obj.getName().equals(name));
-	}
-}
+package holeg.ui.view.category;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+import com.google.gson.annotations.Expose;
+
+import holeg.model.AbstractCanvasObject;
+
+/**
+ * Class "Category" performs the functionality of listing elements into groups.
+ * Each Category contains an ArrayList of CpsObjects, a name and a HashMap of
+ * ObjIdx.
+ * 
+ * @author Gruppe14
+ *
+ */
+
+public class Category {
+	// objects: is a ArrayList of all Objects that belongs to the Category
+	private Set<AbstractCanvasObject> objects = new HashSet<AbstractCanvasObject>();
+	// name: is a String chosen by the User
+	private String name; 
+
+	/**
+	 * Category Constructor.
+	 * 
+	 * @param name name of the Category
+	 */
+	public Category(String name) {
+		setName(name);
+	}
+
+	/**
+	 * Getter for all CpsObjects.
+	 * 
+	 * @return the objects
+	 */
+	public Set<AbstractCanvasObject> getObjects() {
+		return objects;
+	}
+
+	/**
+	 * Set a new ArrayList of CpsObjects.
+	 * 
+	 * @param objects
+	 *            the objects to set
+	 */
+	public void setObjects(Set<AbstractCanvasObject> objects) {
+		this.objects = objects;
+	}
+
+	/**
+	 * Getter the name of the Category.
+	 * 
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * Set the name of the Category to a new one.
+	 * 
+	 * @param name
+	 *            the name to set
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	
+	public Optional<AbstractCanvasObject> findObjectWithName(String name){
+		return objects.stream().filter(obj -> obj.getName().equals(name)).findFirst();
+	}
+	
+	public boolean removeObjectsWithName(String name){
+		return objects.removeIf(obj -> obj.getName().equals(name));
+	}
+}

+ 7 - 0
src/holeg/ui/view/category/CategoryPanel.java

@@ -0,0 +1,7 @@
+package holeg.ui.view.category;
+
+import javax.swing.*;
+
+public class CategoryPanel extends JPanel {
+
+}

+ 18 - 21
src/holeg/ui/view/dialog/AboutUsPopUp.java

@@ -13,25 +13,6 @@ import java.awt.*;
  * @author Gruppe14
  */
 public class AboutUsPopUp extends JFrame {
-    /**
-     * Serial.
-     */
-    private static final long serialVersionUID = 1L;
-    private final JPanel contentPanel = new JPanel();
-    private final JPanel contentPanel2 = new JPanel();
-    private final JPanel contentPanel3 = new JPanel();
-    private JLabel titel = new JLabel("HOLEG Simulator");
-    private JLabel h1 = new JLabel("Project Management & Architect");
-    private JLabel h2 = new JLabel("Software Developers");
-    private JLabel h3 = new JLabel("Documentation");
-    private JLabel h4 = new JLabel("Additional Collaborators");
-    private JLabel description = new JLabel("A discrete-time simulator for modeling Smart Grids that follow a Holon-based model.");
-    private JLabel namesManagement = new JLabel("C. Garcia Cordero");
-    private JLabel namesDevelopersUntilV2 = new JLabel("K. Trometer, D. Rieder, T. Zheng, J. Widhalm, E. Palza, I. Dix");
-    private JLabel namesDevelopersV2_1= new JLabel("A.T. Meyer-Berg, A. Schneider, T. Troppmann and L. Tietze");
-    private JLabel namesDocumentation = new JLabel("E. Palza, C. Garcia Cordero");
-    private JLabel namesCollaborators = new JLabel("R. Egert and F. Volk");
-    private JLabel credits = new JLabel();
 
     /**
      * Constructor
@@ -40,21 +21,29 @@ public class AboutUsPopUp extends JFrame {
         super("About Us");
 
         // Set fonts
-        Font fontTitle = new Font("Titel", 2, 35);
+        Font fontTitle = new Font("Titel", Font.ITALIC, 35);
+        JLabel titel = new JLabel("HOLEG Simulator");
         titel.setFont(fontTitle);
         titel.setBounds(150, 30, 100, 20);
-        Font headerFont = new Font("Header", 2, 20);
+        Font headerFont = new Font("Header", Font.ITALIC, 20);
+        JLabel h1 = new JLabel("Project Management & Architect");
         h1.setFont(headerFont);
+        JLabel h2 = new JLabel("Software Developers");
         h2.setFont(headerFont);
+        JLabel h3 = new JLabel("Documentation");
         h3.setFont(headerFont);
+        JLabel h4 = new JLabel("Additional Collaborators");
         h4.setFont(headerFont);
 
         // Set labels
         titel.setHorizontalAlignment(JLabel.CENTER);
 
         // Set layout
+        JPanel contentPanel = new JPanel();
         contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
+        JPanel contentPanel2 = new JPanel();
         contentPanel2.setLayout(new BoxLayout(contentPanel2, BoxLayout.Y_AXIS));
+        JPanel contentPanel3 = new JPanel();
         contentPanel3.setLayout(new BoxLayout(contentPanel3, BoxLayout.Y_AXIS));
         
         this.setIconImage(Import.loadImage(ImagePreference.Logo,30,30));
@@ -65,28 +54,36 @@ public class AboutUsPopUp extends JFrame {
         contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
         contentPanel.add(titel);
         contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+        JLabel description = new JLabel("A discrete-time simulator for modeling Smart Grids that follow a Holon-based model.");
         contentPanel.add(description);
         contentPanel.add(Box.createRigidArea(new Dimension(0, 60)));
         getContentPane().add(contentPanel, BorderLayout.NORTH);
 
         contentPanel2.add(h1);
+        JLabel namesManagement = new JLabel("C. Garcia Cordero");
         contentPanel2.add(namesManagement);
         contentPanel2.add(Box.createRigidArea(new Dimension(0, 50)));
         contentPanel2.add(h2);
+        JLabel namesDevelopersUntilV2 = new JLabel("K. Trometer, D. Rieder, T. Zheng, J. Widhalm, E. Palza, I. Dix");
         contentPanel2.add(namesDevelopersUntilV2);
+        JLabel namesDevelopersV2_1 = new JLabel("A.T. Meyer-Berg, A. Schneider, T. Troppmann and L. Tietze");
         contentPanel2.add(namesDevelopersV2_1);
         contentPanel2.add(Box.createRigidArea(new Dimension(0, 50)));
         contentPanel2.add(h3);
+        JLabel namesDocumentation = new JLabel("E. Palza, C. Garcia Cordero");
         contentPanel2.add(namesDocumentation);
         contentPanel2.add(Box.createRigidArea(new Dimension(0, 50)));
         contentPanel2.add(h4);
+        JLabel namesCollaborators = new JLabel("R. Egert and F. Volk");
         contentPanel2.add(namesCollaborators);
         contentPanel2.add(Box.createRigidArea(new Dimension(0, 50)));
+        JLabel credits = new JLabel();
         contentPanel2.add(credits);
         getContentPane().add(contentPanel2, BorderLayout.CENTER);
 
         contentPanel3.add(Box.createRigidArea(new Dimension(0, 50)));
         //contentPanel3.add(namesDevelopers);
         getContentPane().add(contentPanel3, BorderLayout.SOUTH);
+        this.setVisible(true);
     }
 }

+ 2 - 3
src/holeg/ui/view/dialog/CanvasResizePopUp.java

@@ -18,7 +18,6 @@ public class CanvasResizePopUp extends JDialog {
     private final JButton btnOk = new JButton("OK");
 	private final JButton btnCancel = new JButton("Cancel");
 	JTabbedPane tabbedPane;
-	Model model;
 	Control controller;
 	Canvas canvas;
     private JPanel mainPanel = new JPanel();
@@ -28,10 +27,9 @@ public class CanvasResizePopUp extends JDialog {
     private JLabel lblHeight = new JLabel("Height:");
     private JPanel buttonPanel = new JPanel();
 
-	public CanvasResizePopUp(Model model, Control controller, Canvas canvas, JTabbedPane tabbedPane, JFrame parentFrame) {
+	public CanvasResizePopUp(Control controller, Canvas canvas, JTabbedPane tabbedPane, JFrame parentFrame) {
         super((java.awt.Frame) null, true);
 		this.tabbedPane = tabbedPane;
-		this.model = model;
 		this.controller = controller;
 		this.canvas = canvas;
 
@@ -93,6 +91,7 @@ public class CanvasResizePopUp extends JDialog {
 		// Add to ContentPane
 		getContentPane().add(mainPanel, BorderLayout.CENTER);
 		getContentPane().add(buttonPanel, BorderLayout.SOUTH);
+		this.setVisible(true);
 	}
 
 }

+ 1 - 1
src/holeg/ui/view/dialog/CreateTemplatePopUp.java

@@ -24,7 +24,7 @@ import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
 import holeg.model.Model;
-import holeg.ui.view.main.Category;
+import holeg.ui.view.category.Category;
 import holeg.ui.view.image.Import;
 
 /**

+ 42 - 87
src/holeg/ui/view/dialog/EditEdgesPopUp.java

@@ -1,25 +1,14 @@
 package holeg.ui.view.dialog;
 
-import java.awt.BorderLayout;
-import java.awt.Font;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JTextField;
-import javax.swing.border.EmptyBorder;
-
 import holeg.model.Edge;
+import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
-import holeg.ui.view.canvas.Canvas;
+import holeg.ui.view.image.Import;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import java.awt.*;
 
 /**
  * Popup for Editing Edges.
@@ -27,39 +16,29 @@ import holeg.ui.view.canvas.Canvas;
  * @author Gruppe14
  */
 public class EditEdgesPopUp extends JDialog {
-
-	private static final long serialVersionUID = 1L;
-	private final JPanel contentPanel = new JPanel();
-	private JTextField capacityField;
+	private final JTextField capacityField;
 	private float capacity;
-	private JRadioButton rdbtnChangeForAll;
-	private JRadioButton rdbtnChangeForNew;
-	private JRadioButton rdbtnChangeForAll1;
-	private Control controller;
-	private Canvas canvas;
-
-	/**
-	 * Launch the application.
-	 * 
-	 * @param args
-	 *            standard
-	 */
+	private final JRadioButton rdbtnChangeForAll;
+	private final JRadioButton rdbtnChangeForNew;
+	private final JRadioButton rdbtnChangeForAll1;
+	private final Control control;
 
 
 	/**
 	 * Constructor.
 	 */
-    public EditEdgesPopUp(JFrame parentFrame) {
+    public EditEdgesPopUp(JFrame parentFrame, Control control) {
         super((java.awt.Frame) null, true);
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle("Edit Capacities of Edges");
 		setBounds(100, 100, 400, 220);
         setLocationRelativeTo(parentFrame);
         getContentPane().setLayout(new BorderLayout());
+		JPanel contentPanel = new JPanel();
 		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
 		contentPanel.setLayout(null);
-
+		this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
 		JLabel lblMaximumCapacity = new JLabel("Maximum Capacity:");
 		lblMaximumCapacity.setFont(new Font("Tahoma", Font.PLAIN, 11));
 		lblMaximumCapacity.setBounds(10, 11, 98, 14);
@@ -84,38 +63,33 @@ public class EditEdgesPopUp extends JDialog {
 
 		JButton btnCancel = new JButton("Cancel");
 		btnCancel.setActionCommand("Cancel");
-		btnCancel.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent arg0) {
-				dispose();
-			}
-		});
+		btnCancel.addActionListener(clicked -> dispose());
+
 		btnCancel.setBounds(285, 147, 89, 23);
 		contentPanel.add(btnCancel);
 
 		JButton btnOk1 = new JButton("OK");
-		btnOk1.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e) {
-					try {
-						capacity = Float.parseFloat(capacityField.getText().toString());
-						if (capacity < 0) {
-							throw new NumberFormatException();
-						}
-						if (rdbtnChangeForAll.isSelected()) {
-							changeForExisting(capacity);
-							dispose();
-						} else if (rdbtnChangeForNew.isSelected()) {
-							changeForNew(capacity);
-							dispose();
-						} else if (rdbtnChangeForAll1.isSelected()) {
-							changeForExAndNew(capacity);
-							dispose();
-						} else {
-							JOptionPane.showMessageDialog(new JFrame(), "Please select one of the options");
-						}
-					} catch (NumberFormatException eex) {
-						JOptionPane.showMessageDialog(new JFrame(), "Please enter a number greater or equal 0 in the Field for Maximum Capacity");
+		btnOk1.addActionListener(clicked -> {
+				try {
+					capacity = Float.parseFloat(capacityField.getText());
+					if (capacity < 0) {
+						throw new NumberFormatException();
 					}
-			}
+					if (rdbtnChangeForAll.isSelected()) {
+						changeForExisting(capacity);
+						dispose();
+					} else if (rdbtnChangeForNew.isSelected()) {
+						changeForNew(capacity);
+						dispose();
+					} else if (rdbtnChangeForAll1.isSelected()) {
+						changeForExAndNew(capacity);
+						dispose();
+					} else {
+						JOptionPane.showMessageDialog(new JFrame(), "Please select one of the options");
+					}
+				} catch (NumberFormatException eex) {
+					JOptionPane.showMessageDialog(new JFrame(), "Please enter a number greater or equal 0 in the Field for Maximum Capacity");
+				}
 		});
 		btnOk1.setBounds(186, 147, 89, 23);
 		contentPanel.add(btnOk1);
@@ -124,26 +98,8 @@ public class EditEdgesPopUp extends JDialog {
 		bG.add(rdbtnChangeForAll1);
 		bG.add(rdbtnChangeForNew);
 		bG.add(rdbtnChangeForAll);
-	}
-
-	/**
-	 * Set the Canvas.
-	 * 
-	 * @param can
-	 *            the Canvas
-	 */
-	public void setCanvas(Canvas can) {
-		canvas = can;
-	}
-
-	/**
-	 * set the Controller.
-	 * 
-	 * @param cont
-	 *            the Controller
-	 */
-	public void setController(Control cont) {
-		controller = cont;
+		this.control = control;
+		this.setVisible(true);
 	}
 
 	/**
@@ -154,7 +110,7 @@ public class EditEdgesPopUp extends JDialog {
 	 */
 	public void changeForNew(float cap) {
 		GuiSettings.maxCapacityForNewCreatedEdges = cap;
-		controller.resetSimulation();
+		control.resetSimulation();
 	}
 
 	/**
@@ -170,12 +126,11 @@ public class EditEdgesPopUp extends JDialog {
 		 * controller.getSimManager().getBrokenEdges()){ edge.setCapacity(cap);
 		 * }
 		 */
-		for (Edge edge : controller.getModel().getEdgesOnCanvas()) {
+		for (Edge edge : control.getModel().getEdgesOnCanvas()) {
 			edge.maxCapacity = cap;
         }
-		controller.resetSimulation();
-		controller.calculateStateAndVisualForCurrentTimeStep();
-		canvas.repaint();
+		control.resetSimulation();
+		control.calculateStateAndVisualForCurrentTimeStep();
 	}
 
 

+ 10 - 10
src/holeg/ui/view/inspector/UnitGraph.java

@@ -26,8 +26,8 @@ import holeg.interfaces.LocalMode;
 import holeg.interfaces.TimelineDependent;
 import holeg.interfaces.GraphEditable.GraphType;
 import holeg.model.HolonElement;
-import holeg.ui.controller.Control;
 import holeg.model.Model;
+import holeg.ui.controller.Control;
 import holeg.utility.math.Maths;
 import holeg.utility.math.vector.Vec2f;
 import holeg.utility.math.vector.Vec2i;
@@ -42,7 +42,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	private static final Logger log = Logger.getLogger(UnitGraph.class.getName());
 	// Normal Settings
 	private static final int border = 4;
-	private static final int clickThreshholdSquared = 25;
+	private static final int clickThresholdSquared = 25;
 
 	// Display Settings
 	/**
@@ -58,6 +58,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			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
 	private class Series {
@@ -86,7 +87,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		Normal, StartPoint, EndPoint
 	};
 
-	private Model model;
 	private int widthWithBorder, heightWithBorder;
 
 	private EditPointType editPointType;
@@ -99,9 +99,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 */
 	public UnitGraph(Control control) {
 		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
-		this.model = control.getModel();
 		this.setBackground(Color.WHITE);
-
+		this.control = control;
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
@@ -138,7 +137,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 				Float::sum);
 		curve.minEnergy = elements.stream().map(ele -> ele.getEnergy()).filter(energy -> energy < 0).reduce(0.0f,
 				Float::sum);
-		
+		Model model = control.getModel();
 		float[] sample = new float[model.getMaxIterations()];
 		// sample energy
 		for (HolonElement element : elements) {
@@ -195,7 +194,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		}
 		g2d.setColor(dotColor);
 		g2d.setStroke(new BasicStroke(1));
-		drawCurrentIterartionLine(g2d);
+		drawCurrentIterationLine(g2d);
 		g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[]{6}, 3));
 		this.globalCurve.ifPresent(curve -> {
 			g2d.setColor(globalCurveColor);
@@ -304,7 +303,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 * 
 	 * @param g to draw.
 	 */
-	private void drawCurrentIterartionLine(Graphics2D g) {
+	private void drawCurrentIterationLine(Graphics2D g) {
+		Model model = control.getModel();
 		int cur = model.getCurrentIteration();
 		int max = model.getMaxIterations();
 		if (isLocalPeriedDifferentInSeries()) {
@@ -726,9 +726,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		switch (graphType) {
 		case boolGraph: // Distance only with X
 			int xDis = target.getX() - actual.getX();
-			return xDis * xDis < clickThreshholdSquared;
+			return xDis * xDis < clickThresholdSquared;
 		case doubleGraph:
-			return actual.getSquaredDistance(target) < clickThreshholdSquared;
+			return actual.getSquaredDistance(target) < clickThresholdSquared;
 		default:
 			return false;
 		}

+ 0 - 1315
src/holeg/ui/view/main/GUI.java

@@ -1,1315 +0,0 @@
-package holeg.ui.view.main;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Image;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
-import java.io.File;
-import java.net.URI;
-import java.util.Collection;
-import java.util.logging.Logger;
-import java.util.prefs.Preferences;
-
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.BoxLayout;
-import javax.swing.ImageIcon;
-import javax.swing.InputMap;
-import javax.swing.JButton;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
-import javax.swing.JTabbedPane;
-import javax.swing.JTextField;
-import javax.swing.JToolBar;
-import javax.swing.JTree;
-import javax.swing.KeyStroke;
-import javax.swing.SwingUtilities;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeCellRenderer;
-
-import holeg.interfaces.LocalMode;
-import holeg.model.AbstractCanvasObject;
-import holeg.model.GroupNode;
-import holeg.model.HolonObject;
-import holeg.model.HolonSwitch;
-import holeg.preferences.ColorPreference;
-import holeg.preferences.ImagePreference;
-import holeg.ui.controller.Control;
-import holeg.ui.model.GuiSettings;
-import holeg.ui.model.IdCounter;
-import holeg.model.Model;
-import holeg.model.Model.FairnessModel;
-import holeg.ui.view.canvas.Canvas;
-import holeg.ui.view.component.ButtonTabComponent;
-import holeg.ui.view.dialog.AboutUsPopUp;
-import holeg.ui.view.dialog.AddObjectPopUp;
-import holeg.ui.view.dialog.CanvasResizePopUp;
-import holeg.ui.view.dialog.CreateNewDialog;
-import holeg.ui.view.dialog.CreateNewDialog.Option;
-import holeg.ui.view.dialog.EditEdgesPopUp;
-import holeg.ui.view.information.HolonInformationPanel;
-import holeg.ui.view.inspector.Inspector;
-import holeg.ui.view.inspector.UnitGraph;
-import holeg.ui.view.window.AddOnWindow;
-import holeg.ui.view.window.FlexWindow;
-import holeg.ui.view.window.Outliner;
-import holeg.ui.view.image.Import;
-
-/**
- * Graphical User Interface.
- *
- * @author Gruppe14
- */
-public class GUI {
-	private static final Logger log = Logger.getLogger(Model.class.getName());
-	/**
-	 * Menu on the Top containing File, Edit View Help etc
-	 */
-	private final JMenuBar menuBar = new JMenuBar();
-	private final JMenu mnNewMenu = new JMenu("File");
-	private final JMenu mnNewMenuEdit = new JMenu("Edit");
-	private final JMenu mnNewMenuOptions = new JMenu("Options");
-	private final JMenu mnNewMenuView = new JMenu("View");
-	private final JMenu menuWindow = new JMenu("Window");
-
-	/** Help Menu containing helpful Informations and the AboutUs Popup */
-	private final JMenu mnHelp = new JMenu("Help");
-
-	/**
-	 * Help -> Introduction A small Introduction of the Application, SmartGrids and
-	 * Holons
-	 */
-	private final JMenuItem mntmIntroduction = new JMenuItem("Introduction");
-
-	/**
-	 * Help -> UserManual
-	 */
-	private final JMenuItem mntmUserManual = new JMenuItem("User Manual");
-
-	/** Help -> Algorithm Help Menu */
-	private final JMenuItem mntmAlgorithmHelp = new JMenuItem("Algorithm Introduction");
-
-	/** Help -> CodeDocumentation */
-	private final JMenuItem mntmCodeDoc = new JMenuItem("Code Documentation");
-
-	/** Help -> AboutUs */
-	private final JMenuItem mntmAboutUs = new JMenuItem("About Us");
-	/** checked if supplyBars should be shown */
-	private final JCheckBoxMenuItem showSupplyBarsCheckBox = new JCheckBoxMenuItem("Show supply bars.");
-	/** menu for the different fairness Models */
-	private final JMenu mnFairnessModel = new JMenu("Fairness Model");
-	/** press to supply minimum demand first */
-	private final JMenuItem mntmFairMinFirst = new JMenuItem("Minimum demand first");
-	/** press to give everyone the same energy */
-	private final JMenuItem mntmFairAlleEqual = new JMenuItem("Equal supply for everyone");
-	private final JMenuItem mntmOpen = new JMenuItem("Open");
-	private final JMenuItem mntmNew = new JMenuItem("New");
-	private final JMenuItem mntmSave = new JMenuItem("Save");
-	private final JMenuItem mntmCanvasSize = new JMenuItem("Set View Size");
-	private final JSplitPane splitPane = new JSplitPane();
-	private final JSplitPane splitPane1 = new JSplitPane();
-	// the tabbed canvas containing the different sub-net tabs of the grid (Main
-	// Grid + Nodes of Nodes)
-
-	private final JPanel myPanel = new JPanel(new BorderLayout());
-	private final JTabbedPane tabbedPaneInnerOriginal = new JTabbedPane(JTabbedPane.TOP);
-	// the main canvas where we can see the grid currently displayed
-	private final JScrollPane canvasSP = new JScrollPane();
-	private final JScrollPane scrollPane1 = new JScrollPane();
-	// private final JScrollPane holonSP = new JScrollPane();
-	// the original tabbed Pane (containing tabs for view, statistics, holon,
-	// flexibility)
-	private final JTabbedPane tabbedPaneOriginal = new JTabbedPane(JTabbedPane.TOP);
-	private final JPopupMenu popmenuEdit = new JPopupMenu();
-	private final JMenuItem editItem = new JMenuItem("Edit Object");
-
-	private final JLabel elementGraph = new JLabel("None ");
-	private final JTree categoryTree = new JTree();
-	/******************************************
-	 ************* Right Container*************
-	 ******************************************
-	 * Right Container: here comes the information about the HolonObject, such as
-	 * HolonElements Information, Properties and Consumption/Production graph.
-	 **/
-	private final Inspector inspector;
-	private final HolonInformationPanel informationPanel;
-	private final JSplitPane splitHolonElPro = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
-
-	// Prechoosed local Periods
-
-	private final JScrollPane scrollProperties = new JScrollPane();
-	// In this section is the graph for the selected HolonElement of the clicked
-
-	private final Model model;
-	private final Control control;
-
-	// In this section are all the Holonelements that correspond to the clicked
-	// HolonObject with consumption/production, name and amount.
-	private final JPanel panel = new JPanel();
-	private final JPanel panelHolonEl = new JPanel();
-	// Buttons
-
-	private final JButton btnAdd = new JButton();
-	private final JPopupMenu btnAddPopUp = new JPopupMenu("Newacac");
-	private final JMenuItem mItemNew = new JMenuItem("New..");
-	private final JMenuItem mItemCategory = new JMenuItem("Category");
-	private final JMenuItem mItemObject = new JMenuItem("Object");
-	private final JMenuItem mItemSwitch = new JMenuItem("Switch");
-	private final JButton btnDel = new JButton();
-
-	private final JToolBar toolBar = new JToolBar();
-	private final JToolBar toolBarHolonEl = new JToolBar();
-
-	// Languages
-	private Canvas canvas;
-	private final UnitGraph unitGraph;
-	/** Textfield to show the period of an element */
-	private final JTextField unitGraphLocalPeriod = new JTextField(6);
-	private final JMenuItem mntmUndo = new JMenuItem("Undo");
-	private final JMenuItem mntmRedo = new JMenuItem("Redo");
-	private final JMenuItem mntmEditEdges = new JMenuItem("Edge Properties");
-	private final JMenuItem mntmAlignAll = new JMenuItem("Align All");
-	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
-	// TODO(Tom2021-12-1) make GUI a JFRAME and remove holegJFrame
-	private JFrame holegJFrame;
-
-	// tabbedPaneOriginal or tabbedPaneSplit
-	private JTabbedPane tabTemp;
-	private String catOfObjToBeEdited;
-	private Canvas unc;
-	private JPanel contentPane;
-	// Pop up Windows
-	private AddObjectPopUp addObjectPopUP;
-	private AboutUsPopUp aboutUsPopUp;
-	// variables
-	private boolean dragging = false;
-	private String actualObjectClicked;
-	private Image img = null;
-	private AbstractCanvasObject tempCps = null;
-	// Time Stuff
-	private TimePanel timePanel;
-
-	public TimePanel getTimePanel() {
-		return timePanel;
-	}
-
-	private AbstractCanvasObject temp = null;
-	private String warningText = "Warning";
-	private String saveBeforeNew = "Do you want to save your current data?";
-	private String eraseCategory = "Do you really want to delete the Category ";
-	private String selectObjBeforeErase = "Please select a Category or an Object in the left library in order to delete something.";
-
-	private JMenuItem removeItem = new JMenuItem("Remove");
-
-	// Save / Load
-	private final JFileChooser safeLoadFileChooser = initSaveLoadFileChooser();
-
-
-	/**
-	 * Create the application.
-	 *
-	 * @param control the Controller
-	 */
-	GUI(Control control) {
-		this.control = control;
-		this.informationPanel = new HolonInformationPanel(control);
-		this.model = control.getModel();
-		inspector = new Inspector(control);
-		control.calculateStateAndVisualForCurrentTimeStep();
-		this.unitGraph = new UnitGraph(control);
-		this.canvas = new Canvas(control, model.getCanvas());
-		initialize();
-		updateCategories(GuiSettings.getCategories());
-		control.OnCategoryChanged.addListener(() -> this.updateCategoryUI(GuiSettings.getCategories()));
-		this.unc = this.canvas;
-	}
-
-	/**
-	 * Initialize the contents of the frame.
-	 */
-	private void initialize() {
-		holegJFrame = new JFrame();
-		holegJFrame.setTitle("HOLEG Simulator");
-		holegJFrame.setBounds(new Rectangle(1200, 800));
-		//Center
-		holegJFrame.setLocationRelativeTo(null);
-		holegJFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-
-		holegJFrame.addWindowListener(new java.awt.event.WindowAdapter() {
-			@Override
-			public void windowClosing(java.awt.event.WindowEvent windowEvent) {
-				if (JOptionPane.showConfirmDialog(holegJFrame, "Are you sure you want to exit?", "HOLEG",
-						JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
-					//TODO(Tom2022-01-27):
-					System.exit(0);
-				}
-			}
-		});
-
-		contentPane = (JPanel) holegJFrame.getContentPane();
-
-		int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
-		InputMap inputMap = contentPane.getInputMap(condition);
-		ActionMap actionMap = contentPane.getActionMap();
-
-		String cntrlZDown = "controlZ";
-		inputMap.put(KeyStroke.getKeyStroke("control Z"), cntrlZDown);
-		actionMap.put(cntrlZDown, new AbstractAction() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				//TODO(Tom2022-01-27): CtrlZ
-			}
-		});
-
-		String cntrlYDown = "controlY";
-		inputMap.put(KeyStroke.getKeyStroke("control Y"), cntrlYDown);
-		actionMap.put(cntrlYDown, new AbstractAction() {
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				//TODO Ctrl Y
-			}
-		});
-
-		String cntrlADown = "controlA";
-		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
-		AbstractAction controlA = new AbstractAction() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				GuiSettings.getSelectedObjects().clear();
-				//TODO(Tom2022-01-27): Ctrl A
-			}
-		};
-		actionMap.put(cntrlADown, controlA);
-
-		String delDown = "delete";
-		inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
-		actionMap.put(delDown, new AbstractAction() {
-
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				chooseTabTemp();
-				//TODO(Tom2022-01-27): delete
-				GuiSettings.getSelectedObjects().clear();
-			}
-		});
-		String cntrlCDown = "controlC";
-		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
-		AbstractAction controlC = new AbstractAction() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				chooseTabTemp();
-				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-				if (!GuiSettings.getSelectedObjects().isEmpty()) {
-					if (scrollPane.getViewport().getComponent(0)instanceof Canvas groupNodeCanvas)
-						control.copy(groupNodeCanvas.getGroupNode());
-					else
-						control.copy(null);
-					if (!GuiSettings.getClipboardObjects().isEmpty()) {
-						//TODO(Tom2022-01-14): old code changes itemPaste
-						//OLD: canvas.itemPaste.setEnabled(true);
-					}
-				}
-			}
-		};
-		actionMap.put(cntrlCDown, controlC);
-
-		String cntrlVDown = "controlV";
-		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
-		AbstractAction controlV = new AbstractAction() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				//TODO(Tom2022-01-27): Paste
-			}
-		};
-		actionMap.put(cntrlVDown, controlV);
-
-		String cntrlXDown = "controlX";
-		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
-		AbstractAction controlX = new AbstractAction() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				chooseTabTemp();
-				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-				if (!GuiSettings.getSelectedObjects().isEmpty()) {
-					if (scrollPane.getViewport().getComponent(0)instanceof Canvas groupNodeCanvas) {
-						control.cut(groupNodeCanvas.getGroupNode());
-						control.calculateStateAndVisualForCurrentTimeStep();
-						scrollPane.getViewport().getComponent(0).repaint();
-					} else {
-						control.cut(null);
-						control.calculateStateAndVisualForCurrentTimeStep();
-						log.info("canvas.repaint3");
-						canvas.repaint();
-					}
-					if (!GuiSettings.getClipboardObjects().isEmpty()) {
-						//TODO(Tom2022-01-14): old code changes itemPaste
-						//OLD: canvas.itemPaste.setEnabled(true);
-					}
-				}
-			}
-		};
-		actionMap.put(cntrlXDown, controlX);
-
-		holegJFrame.setJMenuBar(menuBar);
-
-		holegJFrame.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
-
-		menuBar.add(mnNewMenu);
-
-		mnNewMenu.add(mntmNew);
-
-		mnNewMenu.add(mntmOpen);
-
-		mnNewMenu.add(mntmSave);
-
-		menuBar.add(mnNewMenuEdit);
-
-		mnNewMenuEdit.add(mntmUndo);
-
-		mnNewMenuEdit.add(mntmRedo);
-		mnNewMenuEdit.add(mntmEditEdges);
-		mntmEditEdges.addActionListener(actionEvent -> {
-			EditEdgesPopUp edgePopUp = new EditEdgesPopUp(holegJFrame);
-			edgePopUp.setCanvas(canvas);
-			edgePopUp.setController(control);
-			edgePopUp.setVisible(true);
-		});
-
-		// Edit -> Align All
-
-		mnNewMenuEdit.add(mntmAlignAll);
-		mntmAlignAll.addActionListener(actionEvent -> {
-			// getScrollPaneFromTabbedPane().getViewport().getComponent(0) is always the
-			// active canvas
-			tryToAlignObjects();
-		});
-
-		menuBar.add(mnNewMenuOptions);
-
-		mnNewMenuOptions.add(mntmResetCategory);
-		mntmResetCategory.addActionListener(actionEvent -> {
-			control.resetCategories();
-			categoryTree.revalidate();
-			categoryTree.repaint();
-		});
-
-		/**
-		 * Add Fairness Model Option to the option Menu
-		 */
-		mnNewMenuOptions.add(mnFairnessModel);
-
-		mnFairnessModel.add(mntmFairMinFirst);
-		mntmFairMinFirst.setForeground(Color.BLUE);
-		mntmFairMinFirst
-				.setToolTipText("HolonObjects with the smallest mininum Demand will be partially supplied first.\n"
-						+ "After that as many HolonObjects as possible will get fully supplied.");
-
-		mntmFairMinFirst.addActionListener(arg0 -> {
-			control.getModel().setFairnessModel(FairnessModel.MininumDemandFirst);
-			mntmFairMinFirst.setForeground(Color.BLUE);
-			mntmFairAlleEqual.setForeground(mnFairnessModel.getForeground());
-			control.calculateStateAndVisualForCurrentTimeStep();
-			// Update UpperNodes
-			Component canvasOrUpperNodeCanvas = getScrollPaneFromTabbedPane().getViewport().getComponent(0);
-			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
-				groupNodeCanvas.repaint();
-			}
-		});
-
-		mnFairnessModel.add(mntmFairAlleEqual);
-		mntmFairAlleEqual.setToolTipText("HolonObjects will all get the same amount of energy.");
-
-		mntmFairAlleEqual.addActionListener(arg0 -> {
-			control.getModel().setFairnessModel(FairnessModel.AllEqual);
-			mntmFairAlleEqual.setForeground(Color.BLUE);
-			mntmFairMinFirst.setForeground(mnFairnessModel.getForeground());
-			control.calculateStateAndVisualForCurrentTimeStep();
-			// Update UpperNodes
-			Component canvasOrUpperNodeCanvas = getScrollPaneFromTabbedPane().getViewport().getComponent(0);
-			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
-				groupNodeCanvas.repaint();
-			}
-		});
-
-		menuBar.add(mnNewMenuView);
-
-		mnNewMenuView.add(mntmCanvasSize);
-		mntmCanvasSize.addActionListener(actionEvent -> {
-			CanvasResizePopUp popUp = new CanvasResizePopUp(model, control, canvas, this.tabbedPaneInnerOriginal,
-					holegJFrame);
-			popUp.setVisible(true);
-		});
-
-		tabbedPaneInnerOriginal.addChangeListener(change -> {
-			control.clearSelection();
-		});
-		mnNewMenuView.add(mntmCanvasSize);
-
-		/*
-		 * Adds Checkbox to turn supply bars on/off
-		 */
-		mnNewMenuView.add(showSupplyBarsCheckBox);
-		showSupplyBarsCheckBox.setSelected(true);
-		showSupplyBarsCheckBox.addActionListener(arg0 -> {
-			GuiSettings.showSupplyBars = showSupplyBarsCheckBox.isSelected();
-			log.info("canvas.repaint4");
-			canvas.repaint();
-
-			// Update UpperNodes
-			JScrollPane spane = getScrollPaneFromTabbedPane();
-			if (spane != null) {
-				Component canvasOrUpperNodeCanvas = spane.getViewport().getComponent(0);
-				if (canvasOrUpperNodeCanvas != null
-						&& canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
-					groupNodeCanvas.repaint();
-				}
-			}
-		});
-		initWindowMenu();
-
-		/**
-		 * add Help Menu and its items
-		 */
-		menuBar.add(mnHelp);
-		mnHelp.add(mntmIntroduction);
-		mnHelp.add(mntmUserManual);
-		mnHelp.add(mntmAlgorithmHelp);
-		mnHelp.add(mntmCodeDoc);
-		mnHelp.add(mntmAboutUs);
-
-		canvas.setBackground(Color.WHITE);
-		canvas.setPreferredSize(new Dimension(GuiSettings.canvasSize.getX(), GuiSettings.canvasSize.getY()));
-		/********************
-		 * RIGHT CONTAINER (INFORMATION)
-		 **********************/
-
-		panelHolonEl.setLayout(new BoxLayout(panelHolonEl, BoxLayout.X_AXIS));
-		toolBarHolonEl.setFloatable(false);
-		panelHolonEl.add(toolBarHolonEl);
-
-		/***********************
-		 * HolonElement Graph Actions
-		 **********************/
-
-		/*
-		 * Update Local Period of an Element Graph
-		 */
-		unitGraphLocalPeriod.addKeyListener(new KeyAdapter() {
-			@Override
-			public void keyReleased(KeyEvent e) {
-				try {
-					int localLength = Integer.parseInt(unitGraphLocalPeriod.getText());
-					unitGraphLocalPeriod.setBackground(Color.WHITE);
-					/**
-					 * set local graph Period
-					 */
-					if (e.getKeyCode() == KeyEvent.VK_ENTER){
-						LocalMode.Period period = new LocalMode.Period(localLength);
-						period.setInterval(localLength);
-						unitGraph.setPeriod(period);
-					}
-				} catch (NumberFormatException ex) {
-					unitGraphLocalPeriod.setBackground(ColorPreference.GUI.PALE_RED);
-				}
-
-			}
-		});
-
-		/*****************************
-		 * RIGHT CONTAINER DONE
-		 *****************************/
-
-		holegJFrame.getContentPane().setLayout(new BorderLayout(0, 0));
-		/****************
-		 * Tree Stuff
-		 ****************/
-
-		// Override Key Actions
-		inputMap = categoryTree.getInputMap();
-		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
-		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
-		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
-		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
-
-		TreeCellRenderer customRenderer = new TreeCellRenderer() {
-			@Override
-			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
-					boolean leaf, int row, boolean hasFocus) {
-				JLabel label = new JLabel();
-				Image imgR;
-				if (leaf) {
-					for (Category cat : GuiSettings.getCategories()) {
-						for (AbstractCanvasObject cps : cat.getObjects()) {
-							if (value.toString().equals(cps.getName())) {
-								imgR = Import.loadImage(cps.getImagePath(), 50, 50);
-								if (imgR != null) {
-									label.setIcon(new ImageIcon(imgR));
-								}
-								label.setText(cps.getName());
-							}
-						}
-					}
-				}
-				tree.setRowHeight(50);
-				if (hasFocus) {
-					label.setForeground(ColorPreference.Category.Focus);
-					label.setOpaque(true);
-				}
-				if (label.getText().isEmpty()) {
-					label.setText(value.toString());
-					if (!value.toString().equals("Categories")) {
-						label.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Category.Folder)));
-					}
-				}
-
-				return label;
-
-			}
-		};
-
-		categoryTree.setCellRenderer(customRenderer);
-
-		categoryTree.addMouseMotionListener(new MouseMotionAdapter() {
-
-			public void mouseDragged(MouseEvent e) {
-				checkForDragAndDrop(e);
-			}
-
-			/**
-			 * checks if an object of the current Panel could be replaced by the dragged
-			 * object
-			 * 
-			 * @param e
-			 */
-			private void checkForDragAndDrop(MouseEvent e) {
-				try {
-					/**
-					 * if no object gets dragged -> finished
-					 */
-					if (!dragging)
-						return;
-
-					/**
-					 * select the current Panel
-					 */
-					chooseTabTemp();
-					JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-					if (scrollPane == null)
-						return;
-					Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
-
-					/**
-					 * check for replacements on the canvas
-					 */
-					if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
-						if (unc.getMousePosition() == null)
-							return;
-						int x = (int) unc.getMousePosition().getX() + 16;
-						int y = (int) unc.getMousePosition().getY() + 16;
-
-						/**
-						 * check for replacement
-						 */
-						groupNodeCanvas.checkForReplacement(x, y);
-
-						/**
-						 * repaint
-						 */
-						unc.invalidate();
-						unc.repaint();
-					} else {
-						if (canvas.getMousePosition() == null)
-							return;
-						int x = (int) canvas.getMousePosition().getX() + 16;
-						int y = (int) canvas.getMousePosition().getY() + 16;
-
-						/**
-						 * check for replacement
-						 */
-						canvas.checkForReplacement(x, y);
-
-						/**
-						 * repaint
-						 */
-						log.info("canvas.repaint5");
-						canvas.repaint();
-					}
-					contentPane.updateUI();
-
-				} catch (Exception eex) {
-					eex.printStackTrace();
-				}
-			}
-		});
-
-		categoryTree.addMouseListener(new MouseAdapter() {
-
-			public void mouseReleased(MouseEvent e) {
-				try {
-					if (dragging) {
-						chooseTabTemp();
-						JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-						Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
-
-						if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
-							int x = (int) groupNodeCanvas.getMousePosition().getX() + 16;
-							int y = (int) groupNodeCanvas.getMousePosition().getY() + 16;
-
-							AbstractCanvasObject h = null;
-							if (tempCps instanceof HolonObject hO) {
-								h = new HolonObject(hO);
-							}
-							if (tempCps instanceof HolonSwitch sw) {
-								h = new HolonSwitch(sw);
-							}
-							h.setPosition(x, y);
-							control.addObjectCanvas(model.getCanvas(), h);
-
-							/**
-							 * object would be replaced
-							 */
-							groupNodeCanvas.invalidate();
-							control.calculateStateAndVisualForCurrentTimeStep();
-							groupNodeCanvas.repaint();
-						} else {
-							int x = (int) canvas.getMousePosition().getX() + 16;
-							int y = (int) canvas.getMousePosition().getY() + 16;
-
-							AbstractCanvasObject h = null;
-							if (tempCps instanceof HolonObject hO) {
-								h = new HolonObject(hO);
-							}
-							if (tempCps instanceof HolonSwitch sw) {
-								h = new HolonSwitch(sw);
-							}
-
-							h.setPosition(x, y);
-
-							/**
-							 * close UpperNodeTabs of replaced UpperNode
-							 */
-							//TODO(Tom2022-01-27):
-							control.addObjectCanvas(model.getCanvas(), h);
-							/**
-							 * no object should get replaced
-							 */
-							log.info("canvas.repaint6");
-							canvas.repaint();
-						}
-						control.calculateStateAndVisualForCurrentTimeStep();
-						contentPane.updateUI();
-						dragging = false;
-					}
-				} catch (Exception eex) {
-				}
-				holegJFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
-			}
-		});
-
-		popmenuEdit.add(editItem);
-		popmenuEdit.add(removeItem);
-		editItem.setEnabled(false);
-		editItem.addActionListener(actionEvent -> {
-		});
-		categoryTree.addMouseListener(new MouseAdapter() {
-
-			public void mousePressed(MouseEvent e) {
-				try {
-					actualObjectClicked = categoryTree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent()
-							.toString();
-					// if an Object was selected, the porperties are shown in
-					// the table
-					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) categoryTree
-							.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
-					if (SwingUtilities.isRightMouseButton(e)) {
-						for (Category cat : GuiSettings.getCategories()) {
-							for (AbstractCanvasObject cps : cat.getObjects()) {
-								if (actualObjectClicked.equals(cps.getName())
-										&& !(cps instanceof HolonSwitch)) {
-									editItem.setEnabled(true);
-									popmenuEdit.show(e.getComponent(), e.getX(), e.getY());
-									catOfObjToBeEdited = selectedNode.getParent().toString();
-									tempCps = cps;
-								}
-							}
-						}
-					} else {
-						for (Category cat : GuiSettings.getCategories()) {
-							for (AbstractCanvasObject cps : cat.getObjects()) {
-								if (actualObjectClicked.equals(cps.getName())) {
-									File checkPath = new File(cps.getImagePath());
-									if (checkPath.exists()) {
-										img = new ImageIcon(cps.getImagePath()).getImage().getScaledInstance(32, 32,
-												java.awt.Image.SCALE_SMOOTH);
-									} else {
-										img = Import.loadImage(cps.getImagePath(), 32, 32);
-									}
-									tempCps = cps;
-									dragging = true;
-									Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
-											"Image");
-									holegJFrame.setCursor(cursor);
-								}
-							}
-						}
-					}
-				} catch (Exception eex) {
-				}
-			}
-		});
-		editItem.addActionListener(actionEvent -> {
-			// Remove the selected Object object
-			// AddObjectPopUp(boolean edit, AbstractCpsObject obj, String cat, JFrame
-			// parentFrame)
-			System.out.println("Edit");
-			addObjectPopUP = new AddObjectPopUp(true, tempCps, catOfObjToBeEdited, holegJFrame);
-			addObjectPopUP.setCategory(catOfObjToBeEdited);
-			addObjectPopUP.setController(control);
-			addObjectPopUP.setVisible(true);
-		});
-		removeItem.addActionListener(actionEvent -> {
-			// Remove the selected Object object
-			log.info("catOfObjToBeEdited:" + catOfObjToBeEdited + ", tempCps:" + tempCps);
-			control.findCategoryWithName(catOfObjToBeEdited).ifPresent(cat -> {
-				cat.removeObjectsWithName(tempCps.getName());
-			});
-		});
-		scrollPane1.setViewportView(categoryTree);
-
-		scrollPane1.setColumnHeaderView(panel);
-		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-		toolBar.setAlignmentX(Component.LEFT_ALIGNMENT);
-		toolBar.setFloatable(false);
-
-		panel.add(toolBar);
-		btnAddPopUp.add(mItemNew);
-		mItemNew.addActionListener(actionEvent -> {
-			new CreateNewDialog(control, holegJFrame);
-		});
-		btnAddPopUp.addSeparator();
-		btnAddPopUp.add(mItemCategory);
-		mItemCategory.addActionListener(actionEvent -> {
-			new CreateNewDialog(control, Option.Category, holegJFrame);
-		});
-		btnAddPopUp.add(mItemObject);
-		mItemObject.addActionListener(actionEvent -> {
-			new CreateNewDialog(control, Option.Object, holegJFrame);
-		});
-		btnAddPopUp.add(mItemSwitch);
-		mItemSwitch.addActionListener(actionEvent -> {
-			new CreateNewDialog(control, Option.Switch, holegJFrame);
-		});
-		btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, -1, +20));
-		btnAdd.setIcon(new ImageIcon(Import.loadImage("images/buttons/plus.png", 16, 16)));
-		btnAdd.setToolTipText("<html><b>New</b><br>Add a new Category or Item to the library.</html>");
-		toolBar.add(btnAdd);
-		/**
-		 * Help Menu Action Listeners
-		 */
-
-		/**
-		 * URL of the telecommunication git Wiki
-		 */
-		String tkWikiWebpage = "https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons/wiki/";
-
-		/** open Introduction Web Page */
-		mntmIntroduction.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				openWebpage(tkWikiWebpage + "Introduction+V2.1");
-			}
-		});
-
-		/** open UserManual WebPage */
-		mntmUserManual.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				openWebpage(tkWikiWebpage + "User+Manual+V2.1");
-			}
-		});
-
-		/** open Algorithm Help Web Page */
-		mntmAlgorithmHelp.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				openWebpage(tkWikiWebpage + "Algorithms+V2.1");
-			}
-		});
-
-		/** open Code Documentation Web Page */
-		mntmCodeDoc.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				openWebpage(tkWikiWebpage + "Code+documentation+V2.1");
-			}
-		});
-
-		/**
-		 * Pop up - About Us with some important information about the developers,
-		 * source and programming stuff
-		 */
-		mntmAboutUs.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mousePressed(MouseEvent e) {
-				aboutUsPopUp = new AboutUsPopUp(holegJFrame);
-				aboutUsPopUp.setVisible(true);
-			}
-		});
-		// Del Button
-		btnDel.addActionListener(actionEvent -> {
-			Object nodeInfo = categoryTree.getLastSelectedPathComponent();
-			if (nodeInfo != null) {
-				DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
-				String nodeName = selectedNode.getUserObject().toString();
-				int depthOfNode = selectedNode.getLevel();
-				try {
-					switch (depthOfNode) {
-					case 1:
-						int dialogResult = JOptionPane.showConfirmDialog(holegJFrame, eraseCategory + nodeName + "?",
-								warningText, JOptionPane.YES_NO_OPTION);
-						if (dialogResult == JOptionPane.YES_OPTION) {
-							GuiSettings.getCategories().stream().filter(cat -> cat.getName() == nodeName).findAny()
-									.ifPresent(cat -> {
-										control.deleteCategory(cat);
-									});
-						}
-						break;
-					case 2:
-						DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
-						control.findCategoryWithName(parent.getUserObject().toString()).ifPresent(cat -> {
-							cat.removeObjectsWithName(nodeName);
-						});
-						break;
-
-					default:
-						JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
-					}
-				} catch (Exception e2) {
-				}
-
-			} else {
-				JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
-			}
-			categoryTree.repaint();
-		});
-		btnDel.setIcon(new ImageIcon(Import.loadImage("images/buttons/minus.png", 16, 16)));
-		btnDel.setToolTipText("<html><b>Delete</b><br>Removes a Category or a Category Item.</html>");
-		toolBar.add(btnDel);
-
-		holegJFrame.getContentPane().add(splitPane);
-
-		mntmNew.addActionListener(actionEvent -> {
-			if (model.getCanvas().getObjectsInThisLayer().findAny().isPresent()) {
-				int newWarning = JOptionPane.YES_NO_OPTION;
-				int dialogForNewWarning = JOptionPane.showConfirmDialog(holegJFrame, saveBeforeNew, warningText,
-						newWarning);
-				if (dialogForNewWarning == JOptionPane.YES_OPTION) {
-					mntmSave.doClick();
-				}
-			}
-			// Remove all but main tab
-			while (tabbedPaneInnerOriginal.getTabCount() > 1) {
-				tabbedPaneInnerOriginal.remove(1);
-			}
-			control.clearSelection();
-			model.clear();
-			control.OnSelectionChanged.broadcast();
-			GuiSettings.getSelectedEdges().clear();
-			control.getModel().setCurrentIteration(0);
-			elementGraph.setText("None");
-			log.info("canvas.repaint7");
-			canvas.repaint();
-			IdCounter.reset();
-			IdCounter.reset();
-			control.calculateStateAndVisualForCurrentTimeStep();
-		});
-
-		mntmOpen.addActionListener(clicked -> {
-			if(safeLoadFileChooser.showOpenDialog(this.holegJFrame) == JFileChooser.APPROVE_OPTION){
-				control.loadFile(safeLoadFileChooser.getSelectedFile());
-				//TODO(Tom2022-01-27): make better
-				this.canvas.setGroupNode(control.getModel().getCanvas());
-				this.canvas.repaint();
-			}
-		});
-
-
-
-
-		mntmSave.addActionListener(clicked -> {
-			log.info("Save Button Pressed");
-			if(safeLoadFileChooser.showSaveDialog(this.holegJFrame) == JFileChooser.APPROVE_OPTION){
-				String path = safeLoadFileChooser.getSelectedFile().getPath();
-				if(!path.endsWith(".json")){
-					path += ".json";
-				}
-				control.saveFile(new File(path));
-			}
-		});
-
-
-		mntmUndo.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent evt) {
-				menuUndoActionPerformed();
-			}
-
-			private void menuUndoActionPerformed() {
-//				try {
-//					control.loadAutoSave(control.getUndoSave());
-//
-//					closeInvalidUpperNodeTabs();
-//
-//					control.calculateStateAndVisualForCurrentTimeStep();
-//					log.info("canvas.repaint9");
-//					canvas.repaint();
-//				} catch (IOException e) {
-//					e.printStackTrace();
-//				}
-			}
-		});
-
-		mntmRedo.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent evt) {
-				menuRedoActionPerformed();
-			}
-
-			private void menuRedoActionPerformed() {
-//				try {
-//					control.loadAutoSave(control.getRedoSave());
-//
-//					closeInvalidUpperNodeTabs();
-//
-//					control.calculateStateAndVisualForCurrentTimeStep();
-//					log.info("canvas.repaint10");
-//					canvas.repaint();
-//				} catch (IOException e) {
-//					e.printStackTrace();
-//				}
-			}
-		});
-
-		timePanel = new TimePanel(control);
-		timePanel.setBorder(null);
-		timePanel.getTimeSlider().addChangeListener(changeEvent -> {
-			// TimeSliderChanged event
-			control.calculateStateAndVisualForTimeStep(timePanel.getTimeSlider().getValue());
-			unitGraph.repaint();
-			contentPane.updateUI();
-		});
-		splitPane1.setMinimumSize(new Dimension(0, 25));
-		splitPane.setRightComponent(splitPane1);
-		splitPane.setDividerLocation(200);
-		splitPane1.setDividerLocation(500);
-
-		splitPane.setLeftComponent(scrollPane1);
-		tabbedPaneOriginal.addTab("View", tabbedPaneInnerOriginal);
-
-		myPanel.add(canvasSP, BorderLayout.CENTER);
-
-		tabbedPaneInnerOriginal.addTab("Main Grid", myPanel);
-		splitPane1.setLeftComponent(tabbedPaneOriginal);
-		splitPane1.setRightComponent(splitHolonElPro);
-
-		splitPane1.setResizeWeight(0.9);
-
-		splitHolonElPro.setDividerLocation(700);
-		// containing the graph and the elements-list
-		splitHolonElPro.setTopComponent(inspector);
-		// containing the object's properties
-		splitHolonElPro.setBottomComponent(scrollProperties);
-
-		canvasSP.setViewportView(canvas);
-		// Set up of the Properties section
-		scrollProperties.setViewportView(this.informationPanel);
-		scrollProperties.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
-		scrollProperties.getVerticalScrollBar().setUnitIncrement(16);
-
-		tabbedPaneOriginal.setBorder(null);
-		scrollProperties.setBorder(null);
-		splitPane.setBorder(null);
-		splitPane1.setBorder(null);
-		splitHolonElPro.setBorder(null);
-		panelHolonEl.setBorder(null);
-		canvasSP.setBorder(null);
-
-		holegJFrame.getContentPane().add(timePanel, BorderLayout.SOUTH);
-
-//		try {
-//			control.loadAutoSave(System.getProperty("user.home") + "/.config/HolonGUI/Category/Category.json");
-//		} catch (IOException e1) {
-//		}
-
-		canvasSP.addComponentListener(new ComponentAdapter() {
-			@Override
-			public void componentResized(ComponentEvent e) {
-				GuiSettings.canvasSize.setX(Math.max(GuiSettings.canvasSize.getX(), canvasSP.getViewport().getWidth()));
-				GuiSettings.canvasSize
-						.setY(Math.max(GuiSettings.canvasSize.getY(), canvasSP.getViewport().getHeight()));
-				log.info("canvas.repaint11");
-				canvas.repaint();
-			}
-		});
-	}
-
-	private void tryToAlignObjects() {
-		//TODO(Tom2022-01-14): recreateTryToAlignObjects
-	}
-
-	private JFileChooser initSaveLoadFileChooser(){
-		JFileChooser safeLoadFileChooser = new JFileChooser(Preferences.userRoot().absolutePath());
-		safeLoadFileChooser.setFileFilter(new FileNameExtensionFilter("Holeg json files", "json"));
-		safeLoadFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
-		safeLoadFileChooser.setAcceptAllFileFilterUsed(false);
-		return safeLoadFileChooser;
-	}
-
-
-
-
-	private void initWindowMenu() {
-		menuBar.add(menuWindow);
-		// Algo
-		JMenuItem openMenu = new JMenuItem("Open Algorithm Panel", new ImageIcon(Import
-				.loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
-		openMenu.addActionListener(actionEvent -> {
-			new AddOnWindow(holegJFrame, control);
-		});
-		openMenu.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
-		menuWindow.add(openMenu);
-		// Outliner
-		JMenuItem openOutliner = new JMenuItem("Open Outliner", new ImageIcon(Import
-				.loadImage(ImagePreference.Button.Menu.Outliner).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
-		openOutliner.addActionListener(actionEvent -> {
-			new Outliner(holegJFrame, model, control);
-		});
-		openOutliner
-				.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
-		menuWindow.add(openOutliner);
-		// FlexWindow
-		JMenuItem openFlexMenuItem = new JMenuItem("Open Flexibility Panel", new ImageIcon(Import
-				.loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
-		openFlexMenuItem.addActionListener(actionEvent -> {
-			new FlexWindow(holegJFrame, control);
-		});
-		openFlexMenuItem
-				.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
-		menuWindow.add(openFlexMenuItem);
-	}
-
-
-	/**
-	 * reloads the Categories from Model.
-	 *
-	 * @param categories the current categories
-	 */
-	private void updateCategories(Collection<Category> categories) {
-		DefaultTreeModel treemodel = new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
-
-			private static final long serialVersionUID = 1L;
-
-			{
-				DefaultMutableTreeNode node1;
-				for (Category c : categories) {
-					node1 = new DefaultMutableTreeNode(c.getName());
-
-					for (AbstractCanvasObject obj : c.getObjects()) {
-						node1.add(new DefaultMutableTreeNode(obj.getName()));
-					}
-					add(node1);
-				}
-
-			}
-		});
-		categoryTree.setModel(treemodel);
-	}
-
-	/**
-	 * When changes are made to the Categories.
-	 *
-	 * @param categories the Categories
-	 */
-	public void updateCategoryUI(Collection<Category> categories) {
-		DefaultTreeModel model = (DefaultTreeModel) categoryTree.getModel();
-		updateCategories(categories);
-		model.reload();
-	}
-
-	void setVisible(boolean value) {
-		holegJFrame.setVisible(value);
-	}
-
-	/*
-	 * Open a new Tab with an UpperNodeCanvas
-	 */
-	public void openNewUpperNodeTab(GroupNode node) {
-		chooseTabTemp();
-
-		JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-		if (scrollPane.getViewport().getComponent(0)instanceof Canvas canvasPanel) {
-			unc = new Canvas(control, node);
-		}
-
-		// check if tab already open for clicked NodeOfNode
-		boolean dupl = false;
-
-		for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
-			JScrollPane paneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
-			if (paneOriginal != null && ((Canvas) paneOriginal.getViewport().getComponent(0)).getGroupNode()
-					.getId() == node.getId()) {
-				dupl = true;
-				// set selected component to view
-				tabbedPaneOriginal.setSelectedComponent(tabbedPaneInnerOriginal);
-				// set selected tab in view to found upper-node-canvas
-				tabbedPaneInnerOriginal.setSelectedComponent(tabbedPaneInnerOriginal.getComponentAt(i));
-			}
-
-			// if we found a duplicate, break
-			if (dupl) {
-				break;
-			}
-		}
-		if (!dupl) {
-			JScrollPane sp = new JScrollPane(unc);
-			sp.setBorder(null);
-
-			// Selected tabbed Pane = tabbedPaneOriginal or tabbedPaneSplit
-			if (tabTemp == tabbedPaneOriginal) {
-				this.tabbedPaneInnerOriginal.add(node.getName(), sp);
-				this.tabbedPaneInnerOriginal.setSelectedComponent(sp);
-				this.tabbedPaneInnerOriginal.setTabComponentAt(this.tabbedPaneInnerOriginal.getTabCount() - 1,
-						new ButtonTabComponent(this.tabbedPaneInnerOriginal));
-
-			}
-		}
-	}
-
-	/**
-	 * Removes UpperNodeTab if UpperNode was deleted
-	 *
-	 * @param cps the CPS object that is currently selected
-	 */
-	private void removeUpperNodeTab(AbstractCanvasObject cps) {
-		if (cps instanceof GroupNode) {
-			for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
-				JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
-
-				if (scrollPaneOriginal == null) {
-				} else if (((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).getGroupNode()
-						.getId() == cps.getId()) {
-					((ButtonTabComponent) tabbedPaneInnerOriginal.getTabComponentAt(i)).removeTabs();
-					break;
-				}
-			}
-		}
-	}
-
-	/**
-	 * chooses whether to set the tabTemp to tabbedPaneOriginal or tabbedPaneSplit
-	 */
-	private void chooseTabTemp() {
-		// TODO(Tom2021-12-1) Remove tabTabbed
-		tabTemp = tabbedPaneOriginal;
-	}
-
-	private JScrollPane getScrollPaneFromTabbedPane() {
-		return getScrollPaneFromTabbedPane(-1);
-	}
-
-	private JScrollPane getScrollPaneFromTabbedPane(int index) {
-		Component upperLevelSelectedComponent;
-		if (tabTemp == null) {
-			return null;
-		}
-		if (index == -1) {
-			upperLevelSelectedComponent = tabTemp.getSelectedComponent();
-		} else {
-			upperLevelSelectedComponent = tabTemp.getComponentAt(index);
-		}
-		if (upperLevelSelectedComponent instanceof JTabbedPane) {
-			Component nextLevel = ((JTabbedPane) upperLevelSelectedComponent).getSelectedComponent();
-			if (nextLevel instanceof JPanel panel)
-				return (JScrollPane) panel.getComponent(0);
-			else
-				return (JScrollPane) nextLevel;
-
-		} else if (upperLevelSelectedComponent instanceof JScrollPane scrollPane) {
-			return scrollPane;
-		} else {
-			return null;
-		}
-	}
-
-	private void openWebpage(String URL) {
-		try {
-			java.awt.Desktop.getDesktop().browse(new URI(URL));
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * closes all UpperNodeTabs, that don't have a valid UpperNode (e.g. if it was
-	 * ungrouped/deleted/replaced and so on)
-	 */
-	private void closeInvalidUpperNodeTabs() {
-		/**
-		 * close bugged Tabs
-		 */
-		for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
-			JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
-			if (((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).getGroupNode() == null) {
-				((ButtonTabComponent) tabbedPaneInnerOriginal.getTabComponentAt(i)).removeTabs();
-				break;
-			}
-		}
-	}
-
-	public void repaintCanvas() {
-		log.info("repaintCanvas");
-		tabbedPaneInnerOriginal.revalidate();
-		tabbedPaneInnerOriginal.repaint();
-		for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
-			JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
-			scrollPaneOriginal.revalidate();
-		}
-	}
-
-}

+ 1058 - 0
src/holeg/ui/view/main/Gui.java

@@ -0,0 +1,1058 @@
+package holeg.ui.view.main;
+
+import holeg.interfaces.LocalMode;
+import holeg.model.*;
+import holeg.preferences.ColorPreference;
+import holeg.preferences.ImagePreference;
+import holeg.preferences.PreferenceKeys;
+import holeg.ui.controller.Control;
+import holeg.ui.model.GuiSettings;
+import holeg.ui.view.canvas.Canvas;
+import holeg.ui.view.category.Category;
+import holeg.ui.view.component.ButtonTabComponent;
+import holeg.ui.view.dialog.*;
+import holeg.ui.view.dialog.CreateNewDialog.Option;
+import holeg.ui.view.image.Import;
+import holeg.ui.view.information.HolonInformationPanel;
+import holeg.ui.view.inspector.Inspector;
+import holeg.ui.view.inspector.UnitGraph;
+import holeg.ui.view.window.AddOnWindow;
+import holeg.ui.view.window.FlexWindow;
+import holeg.ui.view.window.Outliner;
+
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.filechooser.FileSystemView;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeCellRenderer;
+import java.awt.*;
+import java.awt.event.*;
+import java.io.File;
+import java.net.URI;
+import java.util.Collection;
+import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+
+/**
+ * Graphical User Interface.
+ *
+ * @author Gruppe14
+ */
+public class Gui {
+    private static final Logger log = Logger.getLogger(Model.class.getName());
+    private static final Preferences prefs = Preferences.userNodeForPackage(Gui.class);
+
+    private final JSplitPane splitPane = new JSplitPane();
+    private final JSplitPane splitPane1 = new JSplitPane();
+    private final JPanel myPanel = new JPanel(new BorderLayout());
+    // the tabbed canvas containing the different sub-net tabs of the grid (Main
+    // Grid + Nodes of Nodes)
+    private final JTabbedPane tabbedPaneInnerOriginal = new JTabbedPane(JTabbedPane.TOP);
+    // the main canvas where we can see the grid currently displayed
+    private final JScrollPane canvasSP = new JScrollPane();
+    private final JScrollPane scrollPane1 = new JScrollPane();
+    // private final JScrollPane holonSP = new JScrollPane();
+    // the original tabbed Pane (containing tabs for view, statistics, holon,
+    // flexibility)
+    private final JTabbedPane tabbedPaneOriginal = new JTabbedPane(JTabbedPane.TOP);
+    private final JPopupMenu popmenuEdit = new JPopupMenu();
+    private final JMenuItem editItem = new JMenuItem("Edit Object");
+    private final JTree categoryTree = new JTree();
+    /******************************************
+     ************* Right Container*************
+     ******************************************
+     * Right Container: here comes the information about the HolonObject, such as
+     * HolonElements Information, Properties and Consumption/Production graph.
+     **/
+    private final Inspector inspector;
+    private final HolonInformationPanel informationPanel;
+    private final JSplitPane splitHolonElPro = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+    private final JScrollPane scrollProperties = new JScrollPane();
+
+    // In this section is the graph for the selected HolonElement of the clicked
+    private final Control control;
+    // In this section are all the Holonelements that correspond to the clicked
+    // HolonObject with consumption/production, name and amount.
+    private final JPanel panel = new JPanel();
+    private final JButton btnAdd = new JButton();
+    // Buttons
+    private final JPopupMenu btnAddPopUp = new JPopupMenu("New");
+    private final JMenuItem mItemNew = new JMenuItem("New..");
+    private final JMenuItem mItemCategory = new JMenuItem("Category");
+    private final JMenuItem mItemObject = new JMenuItem("Object");
+    private final JMenuItem mItemSwitch = new JMenuItem("Switch");
+    private final JButton btnDel = new JButton();
+    private final JToolBar toolBar = new JToolBar();
+    private final JToolBar toolBarHolonEl = new JToolBar();
+    private final UnitGraph unitGraph;
+    /**
+     * Textfield to show the period of an element
+     */
+    private final JTextField unitGraphLocalPeriod = new JTextField(6);
+    // Save / Load
+
+    // Languages
+    private Canvas canvas;
+    // TODO(Tom2021-12-1) make GUI a JFRAME and remove holegJFrame
+    private JFrame holegJFrame;
+
+    // tabbedPaneOriginal or tabbedPaneSplit
+    private JTabbedPane tabTemp;
+    private String catOfObjToBeEdited;
+    private Canvas unc;
+    private JPanel contentPane;
+    // Pop up Windows
+    private AddObjectPopUp addObjectPopUP;
+    private AboutUsPopUp aboutUsPopUp;
+    // variables
+    private boolean dragging = false;
+    private String actualObjectClicked;
+    private Image img = null;
+    private AbstractCanvasObject tempCps = null;
+    // Time Stuff
+    private TimePanel timePanel;
+    private AbstractCanvasObject temp = null;
+    private String eraseCategory = "Do you really want to delete the Category ";
+    private String selectObjBeforeErase = "Please select a Category or an Object in the left library in order to delete something.";
+    private JMenuItem removeItem = new JMenuItem("Remove");
+
+    /**
+     * Create the application.
+     *
+     * @param control the Controller
+     */
+    public Gui(Control control) {
+        this.control = control;
+        this.informationPanel = new HolonInformationPanel(control);
+        inspector = new Inspector(control);
+        control.calculateStateAndVisualForCurrentTimeStep();
+        this.unitGraph = new UnitGraph(control);
+        this.canvas = new Canvas(control, control.getModel().getCanvas());
+        initialize();
+        updateCategories(GuiSettings.getCategories());
+        control.OnCategoryChanged.addListener(() -> this.updateCategoryUI(GuiSettings.getCategories()));
+        this.unc = this.canvas;
+    }
+
+    public TimePanel getTimePanel() {
+        return timePanel;
+    }
+
+    /**
+     * Initialize the contents of the frame.
+     */
+    private void initialize() {
+        holegJFrame = new JFrame();
+        holegJFrame.setTitle("HOLEG Simulator");
+        holegJFrame.setBounds(new Rectangle(1200, 800));
+        //Center
+        holegJFrame.setLocationRelativeTo(null);
+        holegJFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+
+        holegJFrame.addWindowListener(new java.awt.event.WindowAdapter() {
+            @Override
+            public void windowClosing(java.awt.event.WindowEvent windowEvent) {
+                if (JOptionPane.showConfirmDialog(holegJFrame, "Are you sure you want to exit?", "HOLEG",
+                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
+                    //TODO(Tom2022-01-27):
+                    System.exit(0);
+                }
+            }
+        });
+
+        contentPane = (JPanel) holegJFrame.getContentPane();
+
+        int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
+        InputMap inputMap = contentPane.getInputMap(condition);
+        ActionMap actionMap = contentPane.getActionMap();
+
+        String cntrlZDown = "controlZ";
+        inputMap.put(KeyStroke.getKeyStroke("control Z"), cntrlZDown);
+        actionMap.put(cntrlZDown, new AbstractAction() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                //TODO(Tom2022-01-27): CtrlZ
+            }
+        });
+
+        String cntrlYDown = "controlY";
+        inputMap.put(KeyStroke.getKeyStroke("control Y"), cntrlYDown);
+        actionMap.put(cntrlYDown, new AbstractAction() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                //TODO Ctrl Y
+            }
+        });
+
+        String cntrlADown = "controlA";
+        inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
+        AbstractAction controlA = new AbstractAction() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                GuiSettings.getSelectedObjects().clear();
+                //TODO(Tom2022-01-27): Ctrl A
+            }
+        };
+        actionMap.put(cntrlADown, controlA);
+
+        String delDown = "delete";
+        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
+        actionMap.put(delDown, new AbstractAction() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                chooseTabTemp();
+                //TODO(Tom2022-01-27): delete
+                GuiSettings.getSelectedObjects().clear();
+            }
+        });
+        String cntrlCDown = "controlC";
+        inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
+        AbstractAction controlC = new AbstractAction() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                chooseTabTemp();
+                JScrollPane scrollPane = getScrollPaneFromTabbedPane();
+                if (!GuiSettings.getSelectedObjects().isEmpty()) {
+                    if (scrollPane.getViewport().getComponent(0) instanceof Canvas groupNodeCanvas)
+                        control.copy(groupNodeCanvas.getGroupNode());
+                    else
+                        control.copy(null);
+                    if (!GuiSettings.getClipboardObjects().isEmpty()) {
+                        //TODO(Tom2022-01-14): old code changes itemPaste
+                        //OLD: canvas.itemPaste.setEnabled(true);
+                    }
+                }
+            }
+        };
+        actionMap.put(cntrlCDown, controlC);
+
+        String cntrlVDown = "controlV";
+        inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
+        AbstractAction controlV = new AbstractAction() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                //TODO(Tom2022-01-27): Paste
+            }
+        };
+        actionMap.put(cntrlVDown, controlV);
+
+        String cntrlXDown = "controlX";
+        inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
+        AbstractAction controlX = new AbstractAction() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                chooseTabTemp();
+                JScrollPane scrollPane = getScrollPaneFromTabbedPane();
+                if (!GuiSettings.getSelectedObjects().isEmpty()) {
+                    if (scrollPane.getViewport().getComponent(0) instanceof Canvas groupNodeCanvas) {
+                        control.cut(groupNodeCanvas.getGroupNode());
+                        control.calculateStateAndVisualForCurrentTimeStep();
+                        scrollPane.getViewport().getComponent(0).repaint();
+                    } else {
+                        control.cut(null);
+                        control.calculateStateAndVisualForCurrentTimeStep();
+                        log.info("canvas.repaint3");
+                        canvas.repaint();
+                    }
+                    if (!GuiSettings.getClipboardObjects().isEmpty()) {
+                        //TODO(Tom2022-01-14): old code changes itemPaste
+                        //OLD: canvas.itemPaste.setEnabled(true);
+                    }
+                }
+            }
+        };
+        actionMap.put(cntrlXDown, controlX);
+        holegJFrame.setJMenuBar(new GuiMenuBar());
+
+        holegJFrame.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
+
+
+
+
+        tabbedPaneInnerOriginal.addChangeListener(change -> {
+            control.clearSelection();
+        });
+
+        /**
+         * add Help Menu and its items
+         */
+
+        canvas.setBackground(Color.WHITE);
+        canvas.setPreferredSize(new Dimension(GuiSettings.canvasSize.getX(), GuiSettings.canvasSize.getY()));
+
+        /***********************
+         * HolonElement Graph Actions
+         **********************/
+
+        /*
+         * Update Local Period of an Element Graph
+         */
+        unitGraphLocalPeriod.addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyReleased(KeyEvent e) {
+                try {
+                    int localLength = Integer.parseInt(unitGraphLocalPeriod.getText());
+                    unitGraphLocalPeriod.setBackground(Color.WHITE);
+                    /**
+                     * set local graph Period
+                     */
+                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
+                        LocalMode.Period period = new LocalMode.Period(localLength);
+                        period.setInterval(localLength);
+                        unitGraph.setPeriod(period);
+                    }
+                } catch (NumberFormatException ex) {
+                    unitGraphLocalPeriod.setBackground(ColorPreference.GUI.PALE_RED);
+                }
+
+            }
+        });
+
+        /*****************************
+         * RIGHT CONTAINER DONE
+         *****************************/
+
+        holegJFrame.getContentPane().setLayout(new BorderLayout(0, 0));
+        /****************
+         * Tree Stuff
+         ****************/
+
+        // Override Key Actions
+        inputMap = categoryTree.getInputMap();
+        inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
+        inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
+        inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
+        inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
+
+        TreeCellRenderer customRenderer = new TreeCellRenderer() {
+            @Override
+            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
+                                                          boolean leaf, int row, boolean hasFocus) {
+                JLabel label = new JLabel();
+                Image imgR;
+                if (leaf) {
+                    for (Category cat : GuiSettings.getCategories()) {
+                        for (AbstractCanvasObject cps : cat.getObjects()) {
+                            if (value.toString().equals(cps.getName())) {
+                                imgR = Import.loadImage(cps.getImagePath(), 50, 50);
+                                if (imgR != null) {
+                                    label.setIcon(new ImageIcon(imgR));
+                                }
+                                label.setText(cps.getName());
+                            }
+                        }
+                    }
+                }
+                tree.setRowHeight(50);
+                if (hasFocus) {
+                    label.setForeground(ColorPreference.Category.Focus);
+                    label.setOpaque(true);
+                }
+                if (label.getText().isEmpty()) {
+                    label.setText(value.toString());
+                    if (!value.toString().equals("Categories")) {
+                        label.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Category.Folder)));
+                    }
+                }
+
+                return label;
+
+            }
+        };
+
+        categoryTree.setCellRenderer(customRenderer);
+
+        categoryTree.addMouseMotionListener(new MouseMotionAdapter() {
+
+            public void mouseDragged(MouseEvent e) {
+                checkForDragAndDrop(e);
+            }
+
+            /**
+             * checks if an object of the current Panel could be replaced by the dragged
+             * object
+             *
+             * @param e
+             */
+            private void checkForDragAndDrop(MouseEvent e) {
+                try {
+                    /**
+                     * if no object gets dragged -> finished
+                     */
+                    if (!dragging)
+                        return;
+
+                    /**
+                     * select the current Panel
+                     */
+                    chooseTabTemp();
+                    JScrollPane scrollPane = getScrollPaneFromTabbedPane();
+                    if (scrollPane == null)
+                        return;
+                    Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
+
+                    /**
+                     * check for replacements on the canvas
+                     */
+                    if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
+                        if (unc.getMousePosition() == null)
+                            return;
+                        int x = (int) unc.getMousePosition().getX() + 16;
+                        int y = (int) unc.getMousePosition().getY() + 16;
+
+                        /**
+                         * check for replacement
+                         */
+                        groupNodeCanvas.checkForReplacement(x, y);
+
+                        /**
+                         * repaint
+                         */
+                        unc.invalidate();
+                        unc.repaint();
+                    } else {
+                        if (canvas.getMousePosition() == null)
+                            return;
+                        int x = (int) canvas.getMousePosition().getX() + 16;
+                        int y = (int) canvas.getMousePosition().getY() + 16;
+
+                        /**
+                         * check for replacement
+                         */
+                        canvas.checkForReplacement(x, y);
+
+                        /**
+                         * repaint
+                         */
+                        log.info("canvas.repaint5");
+                        canvas.repaint();
+                    }
+                    contentPane.updateUI();
+
+                } catch (Exception eex) {
+                    eex.printStackTrace();
+                }
+            }
+        });
+
+        categoryTree.addMouseListener(new MouseAdapter() {
+
+            public void mouseReleased(MouseEvent e) {
+                try {
+                    if (dragging) {
+                        chooseTabTemp();
+                        JScrollPane scrollPane = getScrollPaneFromTabbedPane();
+                        Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
+
+                        if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
+                            int x = (int) groupNodeCanvas.getMousePosition().getX() + 16;
+                            int y = (int) groupNodeCanvas.getMousePosition().getY() + 16;
+
+                            AbstractCanvasObject h = null;
+                            if (tempCps instanceof HolonObject hO) {
+                                h = new HolonObject(hO);
+                            }
+                            if (tempCps instanceof HolonSwitch sw) {
+                                h = new HolonSwitch(sw);
+                            }
+                            h.setPosition(x, y);
+                            control.addObjectCanvas(control.getModel().getCanvas(), h);
+
+                            /**
+                             * object would be replaced
+                             */
+                            groupNodeCanvas.invalidate();
+                            control.calculateStateAndVisualForCurrentTimeStep();
+                            groupNodeCanvas.repaint();
+                        } else {
+                            int x = (int) canvas.getMousePosition().getX() + 16;
+                            int y = (int) canvas.getMousePosition().getY() + 16;
+
+                            AbstractCanvasObject h = null;
+                            if (tempCps instanceof HolonObject hO) {
+                                h = new HolonObject(hO);
+                            }
+                            if (tempCps instanceof HolonSwitch sw) {
+                                h = new HolonSwitch(sw);
+                            }
+
+                            h.setPosition(x, y);
+
+                            /**
+                             * close UpperNodeTabs of replaced UpperNode
+                             */
+                            //TODO(Tom2022-01-27):
+                            control.addObjectCanvas(control.getModel().getCanvas(), h);
+                            /**
+                             * no object should get replaced
+                             */
+                            log.info("canvas.repaint6");
+                            canvas.repaint();
+                        }
+                        control.calculateStateAndVisualForCurrentTimeStep();
+                        contentPane.updateUI();
+                        dragging = false;
+                    }
+                } catch (Exception eex) {
+                }
+                holegJFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+            }
+        });
+
+        popmenuEdit.add(editItem);
+        popmenuEdit.add(removeItem);
+        editItem.setEnabled(false);
+        editItem.addActionListener(actionEvent -> {
+        });
+        categoryTree.addMouseListener(new MouseAdapter() {
+
+            public void mousePressed(MouseEvent e) {
+                try {
+                    actualObjectClicked = categoryTree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent()
+                            .toString();
+                    // if an Object was selected, the porperties are shown in
+                    // the table
+                    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) categoryTree
+                            .getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
+                    if (SwingUtilities.isRightMouseButton(e)) {
+                        for (Category cat : GuiSettings.getCategories()) {
+                            for (AbstractCanvasObject cps : cat.getObjects()) {
+                                if (actualObjectClicked.equals(cps.getName())
+                                        && !(cps instanceof HolonSwitch)) {
+                                    editItem.setEnabled(true);
+                                    popmenuEdit.show(e.getComponent(), e.getX(), e.getY());
+                                    catOfObjToBeEdited = selectedNode.getParent().toString();
+                                    tempCps = cps;
+                                }
+                            }
+                        }
+                    } else {
+                        for (Category cat : GuiSettings.getCategories()) {
+                            for (AbstractCanvasObject cps : cat.getObjects()) {
+                                if (actualObjectClicked.equals(cps.getName())) {
+                                    File checkPath = new File(cps.getImagePath());
+                                    if (checkPath.exists()) {
+                                        img = new ImageIcon(cps.getImagePath()).getImage().getScaledInstance(32, 32,
+                                                java.awt.Image.SCALE_SMOOTH);
+                                    } else {
+                                        img = Import.loadImage(cps.getImagePath(), 32, 32);
+                                    }
+                                    tempCps = cps;
+                                    dragging = true;
+                                    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
+                                            "Image");
+                                    holegJFrame.setCursor(cursor);
+                                }
+                            }
+                        }
+                    }
+                } catch (Exception eex) {
+                }
+            }
+        });
+        editItem.addActionListener(actionEvent -> {
+            // Remove the selected Object object
+            // AddObjectPopUp(boolean edit, AbstractCpsObject obj, String cat, JFrame
+            // parentFrame)
+            System.out.println("Edit");
+            addObjectPopUP = new AddObjectPopUp(true, tempCps, catOfObjToBeEdited, holegJFrame);
+            addObjectPopUP.setCategory(catOfObjToBeEdited);
+            addObjectPopUP.setController(control);
+            addObjectPopUP.setVisible(true);
+        });
+        removeItem.addActionListener(actionEvent -> {
+            // Remove the selected Object object
+            log.info("catOfObjToBeEdited:" + catOfObjToBeEdited + ", tempCps:" + tempCps);
+            control.findCategoryWithName(catOfObjToBeEdited).ifPresent(cat -> {
+                cat.removeObjectsWithName(tempCps.getName());
+            });
+        });
+        scrollPane1.setViewportView(categoryTree);
+
+        scrollPane1.setColumnHeaderView(panel);
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+        toolBar.setAlignmentX(Component.LEFT_ALIGNMENT);
+        toolBar.setFloatable(false);
+
+        panel.add(toolBar);
+        btnAddPopUp.add(mItemNew);
+        mItemNew.addActionListener(actionEvent -> {
+            new CreateNewDialog(control, holegJFrame);
+        });
+        btnAddPopUp.addSeparator();
+        btnAddPopUp.add(mItemCategory);
+        mItemCategory.addActionListener(actionEvent -> {
+            new CreateNewDialog(control, Option.Category, holegJFrame);
+        });
+        btnAddPopUp.add(mItemObject);
+        mItemObject.addActionListener(actionEvent -> {
+            new CreateNewDialog(control, Option.Object, holegJFrame);
+        });
+        btnAddPopUp.add(mItemSwitch);
+        mItemSwitch.addActionListener(actionEvent -> {
+            new CreateNewDialog(control, Option.Switch, holegJFrame);
+        });
+        btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, -1, +20));
+        btnAdd.setIcon(new ImageIcon(Import.loadImage("images/buttons/plus.png", 16, 16)));
+        btnAdd.setToolTipText("<html><b>New</b><br>Add a new Category or Item to the library.</html>");
+        toolBar.add(btnAdd);
+
+
+        // Del Button
+        btnDel.addActionListener(actionEvent -> {
+            Object nodeInfo = categoryTree.getLastSelectedPathComponent();
+            if (nodeInfo != null) {
+                DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
+                String nodeName = selectedNode.getUserObject().toString();
+                int depthOfNode = selectedNode.getLevel();
+                try {
+                    switch (depthOfNode) {
+                        case 1:
+                            int dialogResult = JOptionPane.showConfirmDialog(holegJFrame, eraseCategory + nodeName + "?",
+                                    "Warning", JOptionPane.YES_NO_OPTION);
+                            if (dialogResult == JOptionPane.YES_OPTION) {
+                                GuiSettings.getCategories().stream().filter(cat -> cat.getName() == nodeName).findAny()
+                                        .ifPresent(cat -> {
+                                            control.deleteCategory(cat);
+                                        });
+                            }
+                            break;
+                        case 2:
+                            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
+                            control.findCategoryWithName(parent.getUserObject().toString()).ifPresent(cat -> {
+                                cat.removeObjectsWithName(nodeName);
+                            });
+                            break;
+
+                        default:
+                            JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
+                    }
+                } catch (Exception e2) {
+                }
+
+            } else {
+                JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
+            }
+            categoryTree.repaint();
+        });
+        btnDel.setIcon(new ImageIcon(Import.loadImage("images/buttons/minus.png", 16, 16)));
+        btnDel.setToolTipText("<html><b>Delete</b><br>Removes a Category or a Category Item.</html>");
+        toolBar.add(btnDel);
+
+        holegJFrame.getContentPane().add(splitPane);
+
+        timePanel = new TimePanel(control);
+        timePanel.setBorder(null);
+        timePanel.getTimeSlider().addChangeListener(changeEvent -> {
+            // TimeSliderChanged event
+            control.calculateStateAndVisualForTimeStep(timePanel.getTimeSlider().getValue());
+            unitGraph.repaint();
+            contentPane.updateUI();
+        });
+        splitPane1.setMinimumSize(new Dimension(0, 25));
+        splitPane.setRightComponent(splitPane1);
+        splitPane.setDividerLocation(200);
+        splitPane1.setDividerLocation(500);
+
+        splitPane.setLeftComponent(scrollPane1);
+        tabbedPaneOriginal.addTab("View", tabbedPaneInnerOriginal);
+
+        myPanel.add(canvasSP, BorderLayout.CENTER);
+
+        tabbedPaneInnerOriginal.addTab("Main Grid", myPanel);
+        splitPane1.setLeftComponent(tabbedPaneOriginal);
+        splitPane1.setRightComponent(splitHolonElPro);
+
+        splitPane1.setResizeWeight(0.9);
+
+        splitHolonElPro.setDividerLocation(700);
+        // containing the graph and the elements-list
+        splitHolonElPro.setTopComponent(inspector);
+        // containing the object's properties
+        splitHolonElPro.setBottomComponent(scrollProperties);
+
+        canvasSP.setViewportView(canvas);
+        // Set up of the Properties section
+        scrollProperties.setViewportView(this.informationPanel);
+        scrollProperties.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+        scrollProperties.getVerticalScrollBar().setUnitIncrement(16);
+
+        tabbedPaneOriginal.setBorder(null);
+        scrollProperties.setBorder(null);
+        splitPane.setBorder(null);
+        splitPane1.setBorder(null);
+        splitHolonElPro.setBorder(null);
+        canvasSP.setBorder(null);
+
+        holegJFrame.getContentPane().add(timePanel, BorderLayout.SOUTH);
+
+//		try {
+//			control.loadAutoSave(System.getProperty("user.home") + "/.config/HolonGUI/Category/Category.json");
+//		} catch (IOException e1) {
+//		}
+
+        canvasSP.addComponentListener(new ComponentAdapter() {
+            @Override
+            public void componentResized(ComponentEvent e) {
+                GuiSettings.canvasSize.setX(Math.max(GuiSettings.canvasSize.getX(), canvasSP.getViewport().getWidth()));
+                GuiSettings.canvasSize
+                        .setY(Math.max(GuiSettings.canvasSize.getY(), canvasSP.getViewport().getHeight()));
+                log.info("canvas.repaint11");
+                canvas.repaint();
+            }
+        });
+    }
+
+
+    /**
+     * reloads the Categories from Model.
+     *
+     * @param categories the current categories
+     */
+    private void updateCategories(Collection<Category> categories) {
+        DefaultTreeModel treemodel = new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
+
+            {
+                DefaultMutableTreeNode node1;
+                for (Category c : categories) {
+                    node1 = new DefaultMutableTreeNode(c.getName());
+
+                    for (AbstractCanvasObject obj : c.getObjects()) {
+                        node1.add(new DefaultMutableTreeNode(obj.getName()));
+                    }
+                    add(node1);
+                }
+
+            }
+        });
+        categoryTree.setModel(treemodel);
+    }
+
+    /**
+     * When changes are made to the Categories.
+     *
+     * @param categories the Categories
+     */
+    public void updateCategoryUI(Collection<Category> categories) {
+        DefaultTreeModel model = (DefaultTreeModel) categoryTree.getModel();
+        updateCategories(categories);
+        model.reload();
+    }
+
+    public void setVisible(boolean value) {
+        holegJFrame.setVisible(value);
+    }
+
+    /*
+     * Open a new Tab with an UpperNodeCanvas
+     */
+    public void openNewUpperNodeTab(GroupNode node) {
+        chooseTabTemp();
+
+        JScrollPane scrollPane = getScrollPaneFromTabbedPane();
+        if (scrollPane.getViewport().getComponent(0) instanceof Canvas canvasPanel) {
+            unc = new Canvas(control, node);
+        }
+
+        // check if tab already open for clicked NodeOfNode
+        boolean dupl = false;
+
+        for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
+            JScrollPane paneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
+            if (paneOriginal != null && ((Canvas) paneOriginal.getViewport().getComponent(0)).getGroupNode()
+                    .getId() == node.getId()) {
+                dupl = true;
+                // set selected component to view
+                tabbedPaneOriginal.setSelectedComponent(tabbedPaneInnerOriginal);
+                // set selected tab in view to found upper-node-canvas
+                tabbedPaneInnerOriginal.setSelectedComponent(tabbedPaneInnerOriginal.getComponentAt(i));
+            }
+
+            // if we found a duplicate, break
+            if (dupl) {
+                break;
+            }
+        }
+        if (!dupl) {
+            JScrollPane sp = new JScrollPane(unc);
+            sp.setBorder(null);
+
+            // Selected tabbed Pane = tabbedPaneOriginal or tabbedPaneSplit
+            if (tabTemp == tabbedPaneOriginal) {
+                this.tabbedPaneInnerOriginal.add(node.getName(), sp);
+                this.tabbedPaneInnerOriginal.setSelectedComponent(sp);
+                this.tabbedPaneInnerOriginal.setTabComponentAt(this.tabbedPaneInnerOriginal.getTabCount() - 1,
+                        new ButtonTabComponent(this.tabbedPaneInnerOriginal));
+
+            }
+        }
+    }
+
+    /**
+     * Removes UpperNodeTab if UpperNode was deleted
+     *
+     * @param cps the CPS object that is currently selected
+     */
+    private void removeUpperNodeTab(AbstractCanvasObject cps) {
+        if (cps instanceof GroupNode) {
+            for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
+                JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
+
+                if (scrollPaneOriginal == null) {
+                } else if (((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).getGroupNode()
+                        .getId() == cps.getId()) {
+                    ((ButtonTabComponent) tabbedPaneInnerOriginal.getTabComponentAt(i)).removeTabs();
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     * chooses whether to set the tabTemp to tabbedPaneOriginal or tabbedPaneSplit
+     */
+    private void chooseTabTemp() {
+        // TODO(Tom2021-12-1) Remove tabTabbed
+        tabTemp = tabbedPaneOriginal;
+    }
+
+    private JScrollPane getScrollPaneFromTabbedPane() {
+        return getScrollPaneFromTabbedPane(-1);
+    }
+
+    private JScrollPane getScrollPaneFromTabbedPane(int index) {
+        Component upperLevelSelectedComponent;
+        if (tabTemp == null) {
+            return null;
+        }
+        if (index == -1) {
+            upperLevelSelectedComponent = tabTemp.getSelectedComponent();
+        } else {
+            upperLevelSelectedComponent = tabTemp.getComponentAt(index);
+        }
+        if (upperLevelSelectedComponent instanceof JTabbedPane) {
+            Component nextLevel = ((JTabbedPane) upperLevelSelectedComponent).getSelectedComponent();
+            if (nextLevel instanceof JPanel panel)
+                return (JScrollPane) panel.getComponent(0);
+            else
+                return (JScrollPane) nextLevel;
+
+        } else if (upperLevelSelectedComponent instanceof JScrollPane scrollPane) {
+            return scrollPane;
+        } else {
+            return null;
+        }
+    }
+
+    private void openWebpage(String URL) {
+        try {
+            java.awt.Desktop.getDesktop().browse(new URI(URL));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * closes all UpperNodeTabs, that don't have a valid UpperNode (e.g. if it was
+     * ungrouped/deleted/replaced and so on)
+     */
+    private void closeInvalidUpperNodeTabs() {
+        /**
+         * close bugged Tabs
+         */
+        for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
+            JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
+            if (((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).getGroupNode() == null) {
+                ((ButtonTabComponent) tabbedPaneInnerOriginal.getTabComponentAt(i)).removeTabs();
+                break;
+            }
+        }
+    }
+
+
+
+    private class GuiMenuBar extends JMenuBar {
+        //Menus
+        private final JMenu fileMenu = new JMenu("File");
+        private final JMenu editMenu = new JMenu("Edit");
+        private final JMenu viewMenu = new JMenu("View");
+        private final JMenu windowMenu = new JMenu("Window");
+        private final JMenu helpMenu = new JMenu("Help");
+
+        // FileMenu
+        private final JMenuItem newMenuButton = new JMenuItem("New");
+        private final JMenuItem openMenuButton = new JMenuItem("Open..");
+        private final JMenuItem saveMenuButton = new JMenuItem("Save");
+        private final JMenuItem saveAsMenuButton = new JMenuItem("Save..");
+
+        // EditMenu
+        private final JMenuItem undoButton = new JMenuItem("Undo");
+        private final JMenuItem redoButton = new JMenuItem("Redo");
+        private final JMenuItem edgePropertiesButton = new JMenuItem("Edge Properties");
+        private final JMenuItem alignAllButton = new JMenuItem("Align All");
+        private final JMenu resetMenu = new JMenu("Reset");
+        private final JMenuItem resetCategoryButton = new JMenuItem("Categories");
+
+
+        //HelpMenu
+        private final JMenuItem introductionButton = new JMenuItem("Introduction");
+        private final JMenuItem userManualButton = new JMenuItem("User Manual");
+        private final JMenuItem algorithmHelpButton = new JMenuItem("Algorithm Introduction");
+        private final JMenuItem codeDocumentationButton = new JMenuItem("Code Documentation");
+        private final JMenuItem aboutUsButton = new JMenuItem("About Us");
+
+        //ViewMenu
+        private final JMenu appearanceMenu = new JMenu("Appearance");
+        private final JMenuItem canvasSizeButton = new JMenuItem("Set View Size");
+        private final JCheckBoxMenuItem showSupplyBarsCheckBox = new JCheckBoxMenuItem("Show supply bars.", true);
+        private final JFileChooser fileChooser = initFileChooser();
+        //WindowMenu
+        JMenuItem algorithmButton = new JMenuItem("Algorithm Panel", new ImageIcon(Import
+                .loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
+        JMenuItem outlinerButton = new JMenuItem("Outliner", new ImageIcon(Import
+                .loadImage(ImagePreference.Button.Menu.Outliner).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
+        JMenuItem flexMenuButton = new JMenuItem("Flexibility Panel", new ImageIcon(Import
+                .loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
+
+        GuiMenuBar() {
+            initMenuLayout();
+            initButtonActions();
+            initButtonShortCuts();
+        }
+
+        private static JFileChooser initFileChooser() {
+            JFileChooser safeLoadFileChooser = new JFileChooser(prefs.get(PreferenceKeys.Gui.DefaultFolder,
+                    FileSystemView.getFileSystemView().getDefaultDirectory().getPath()));
+            safeLoadFileChooser.setFileFilter(new FileNameExtensionFilter("Holeg json files", "json"));
+            safeLoadFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+            safeLoadFileChooser.setAcceptAllFileFilterUsed(false);
+            return safeLoadFileChooser;
+        }
+
+        private void initMenuLayout() {
+            add(fileMenu);
+            add(editMenu);
+            add(viewMenu);
+            add(windowMenu);
+            add(helpMenu);
+
+            fileMenu.add(newMenuButton);
+            fileMenu.add(openMenuButton);
+            fileMenu.addSeparator();
+            fileMenu.add(saveMenuButton);
+            fileMenu.add(saveAsMenuButton);
+
+            editMenu.add(undoButton);
+            editMenu.add(redoButton);
+            editMenu.add(edgePropertiesButton);
+            editMenu.add(alignAllButton);
+            editMenu.add(resetMenu);
+            resetMenu.add(resetCategoryButton);
+
+            helpMenu.add(introductionButton);
+            helpMenu.add(userManualButton);
+            helpMenu.add(algorithmHelpButton);
+            helpMenu.add(codeDocumentationButton);
+            helpMenu.add(aboutUsButton);
+
+            viewMenu.add(appearanceMenu);
+            appearanceMenu.add(showSupplyBarsCheckBox);
+            viewMenu.add(canvasSizeButton);
+
+            windowMenu.add(algorithmButton);
+            windowMenu.add(outlinerButton);
+            windowMenu.add(flexMenuButton);
+        }
+
+        private void initButtonActions() {
+            newMenuButton.addActionListener(clicked -> newFile());
+            openMenuButton.addActionListener(clicked -> openFile());
+            saveMenuButton.addActionListener(clicked -> saveFile());
+            saveAsMenuButton.addActionListener(clicked -> saveNewFile());
+            edgePropertiesButton.addActionListener(actionEvent -> new EditEdgesPopUp(holegJFrame, control));
+            //TODO(Tom2022-01-14): recreateTryToAlignObjects
+            alignAllButton.addActionListener(clicked -> {
+                log.info("Not implemented yet.");
+            });
+            resetCategoryButton.addActionListener(clicked -> control.resetCategories());
+
+            showSupplyBarsCheckBox.addActionListener(clicked -> toggleSupplyBarAppearance());
+            canvasSizeButton.addActionListener(clicked -> new CanvasResizePopUp(control, canvas, tabbedPaneInnerOriginal,
+                    holegJFrame));
+
+
+            algorithmButton.addActionListener(clicked -> new AddOnWindow(holegJFrame, control));
+            outlinerButton.addActionListener(clicked -> new Outliner(holegJFrame, control));
+            flexMenuButton.addActionListener(clicked -> new FlexWindow(holegJFrame, control));
+
+
+            String tkWikiWebpage = "https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons/wiki/";
+            introductionButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "Introduction+V2.1"));
+            userManualButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "User+Manual+V2.1"));
+            algorithmHelpButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "Algorithms+V2.1"));
+            codeDocumentationButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "Code+documentation+V2.1"));
+            aboutUsButton.addActionListener(clicked -> new AboutUsPopUp(holegJFrame));
+        }
+
+        private void initButtonShortCuts() {
+            int defaultModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
+            saveMenuButton.setAccelerator(KeyStroke.getKeyStroke('S', defaultModifier));
+            saveAsMenuButton.setAccelerator(KeyStroke.getKeyStroke('S', defaultModifier + InputEvent.SHIFT_DOWN_MASK));
+            openMenuButton.setAccelerator(KeyStroke.getKeyStroke('O', defaultModifier));
+            newMenuButton.setAccelerator(KeyStroke.getKeyStroke('N', defaultModifier));
+        }
+
+        private void toggleSupplyBarAppearance() {
+            GuiSettings.showSupplyBars = showSupplyBarsCheckBox.isSelected();
+            log.info("canvas.repaint4");
+            canvas.repaint();
+        }
+
+        private void saveFile(){
+            GuiSettings.getActualSaveFile().ifPresentOrElse(control::saveFile, this::saveNewFile);
+        }
+        private void saveNewFile() {
+            if (fileChooser.showSaveDialog(holegJFrame) == JFileChooser.APPROVE_OPTION) {
+                String path = fileChooser.getSelectedFile().getPath();
+                if (!path.endsWith(".json")) {
+                    path += ".json";
+                }
+                prefs.put(PreferenceKeys.Gui.DefaultFolder, fileChooser.getCurrentDirectory().getPath());
+                control.saveFile(new File(path));
+            }
+        }
+        private void openFile() {
+            if (fileChooser.showOpenDialog(holegJFrame) == JFileChooser.APPROVE_OPTION) {
+                prefs.put(PreferenceKeys.Gui.DefaultFolder, fileChooser.getCurrentDirectory().getPath());
+                control.loadFile(fileChooser.getSelectedFile());
+                //TODO(Tom2022-01-27): make better
+                canvas.setGroupNode(control.getModel().getCanvas());
+                canvas.repaint();
+            }
+        }
+
+        private void newFile() {
+            if (control.getModel().getCanvas().getObjectsInThisLayer().findAny().isPresent()) {
+                int selectedOption = JOptionPane.showConfirmDialog(holegJFrame, "Do you want to save your current model?",
+                        "Warning", JOptionPane.YES_NO_OPTION);
+                if (selectedOption == JOptionPane.YES_OPTION) {
+                    saveNewFile();
+                }
+            }
+            control.clearModel();
+        }
+
+    }
+
+}

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

@@ -100,8 +100,7 @@ public class TimePanel extends JPanel implements ActionListener {
 			addMouseListener(tl);
 		}
 	};
-	// private Model model;
-	private Control control;
+	private final Control control;
 	private int dragResetIteration = 0;
 	private JLabel simSpeedLabel = new JLabel("Speed:");
 	private JSlider speedSlider = new JSlider();

+ 17 - 20
src/holeg/ui/view/window/FlexWindow.java

@@ -68,16 +68,15 @@ public class FlexWindow extends JFrame {
 	private JPanel selectedPanel;
 	
 	
-	private JTabbedPane contentPanel = new JTabbedPane();
+	private final JTabbedPane contentPanel = new JTabbedPane();
 	private JScrollPane usageViewPanel;
-	private int boxWidth = 70;
-	private Control control;
-	private Model model;
+	private final static int boxWidth = 70;
+	private final Control control;
 	
 	public boolean isClosed = false;
 	
 	//Flexibility Intermediate
-	private Flexibility intermediateFlex = new Flexibility(null);
+	private final Flexibility intermediateFlex = new Flexibility(null);
 	private boolean offered = true, onConstrain = true, offConstrain =false;
 	
 	
@@ -96,7 +95,6 @@ public class FlexWindow extends JFrame {
 	public FlexWindow(JFrame parentFrame, Control  control){
 		this.intermediateFlex.name = "name";
 		this.control = control;
-		this.model = control.getModel();
 		//InitWindow
 		createMenuBar();
 		initWindowPanel(parentFrame);
@@ -211,7 +209,7 @@ public class FlexWindow extends JFrame {
 
 	private void createFlexPanel(JPanel listPanel, List<Flexibility> flexList) {
 		listPanel.setBackground(Color.white);
-		Insets insets = new Insets(2,2,2,2);		
+		Insets insets = new Insets(2,2,2,2);
 		int panelWidth = Math.max(boxWidth, this.getWidth() - 90);
 		int maxButtonsPerLine = panelWidth / boxWidth;
 		
@@ -373,7 +371,7 @@ public class FlexWindow extends JFrame {
 		
 		listOfAllSelectedHolonObjects.removeAllChildren();
 		//Init with HolonObjects
-		model.getCanvas().getObjectsInThisLayer().forEach(aCps -> {
+		control.getModel().getCanvas().getObjectsInThisLayer().forEach(aCps -> {
 			DefaultMutableTreeNode newObjectChild = new DefaultMutableTreeNode(aCps.getName() + " ID:" + aCps.getId());
 			if(aCps instanceof HolonObject hO) expandTreeHolonObject(hO, newObjectChild);
 			if(aCps instanceof GroupNode groupnode)expandTreeUpperNode(groupnode, newObjectChild);
@@ -433,7 +431,7 @@ public class FlexWindow extends JFrame {
 	
 	
 	private void createDeleteDialog() {
-		Object[] allFlexes = model.getAllFlexibilities().toArray();
+		Object[] allFlexes = control.getModel().getAllFlexibilities().toArray();
 		if(allFlexes.length == 0) {
 			JOptionPane.showMessageDialog(this,
 					"No Flexibility exist.",
@@ -457,7 +455,7 @@ public class FlexWindow extends JFrame {
 
 	//Add Element
 	private void createAddDialog(HolonElement element){
-		if(model.getCanvas().getAllHolonObjectsRecursive().findAny().isEmpty()) {
+		if(control.getModel().getCanvas().getAllHolonObjectsRecursive().findAny().isEmpty()) {
 			JOptionPane.showMessageDialog(this,
 					"No HolonObject exist.",
 					"Warning",
@@ -482,8 +480,8 @@ public class FlexWindow extends JFrame {
 		
 		
 
-		//Erstelle HolonObject AuswahlBox
-		HolonObject[] holonObjects = model.getCanvas().getAllHolonObjectsRecursive().toArray(HolonObject[]::new);
+		//Create HolonObject selection Box
+		HolonObject[] holonObjects = control.getModel().getCanvas().getAllHolonObjectsRecursive().toArray(HolonObject[]::new);
 
 		DefaultComboBoxModel<HolonObject> comboBoxModel = new DefaultComboBoxModel<HolonObject>( holonObjects );
 
@@ -560,11 +558,11 @@ public class FlexWindow extends JFrame {
 		flexAttributesBorderPanel.add(flexDurationLabel);
 		
 		
-		NumberFormatter moreThenZeroIntegerFormater = new NumberFormatter(format);
-		moreThenZeroIntegerFormater.setMinimum(1);
-		moreThenZeroIntegerFormater.setCommitsOnValidEdit(true);
+		NumberFormatter moreThenZeroIntegerFormatter = new NumberFormatter(format);
+		moreThenZeroIntegerFormatter.setMinimum(1);
+		moreThenZeroIntegerFormatter.setCommitsOnValidEdit(true);
 		
-		JFormattedTextField durationTextField = new  JFormattedTextField(moreThenZeroIntegerFormater);
+		JFormattedTextField durationTextField = new  JFormattedTextField(moreThenZeroIntegerFormatter);
 		durationTextField.setValue(intermediateFlex.getDuration());
 		durationTextField.setToolTipText("Only positive Integer bigger then 0.");
 		durationTextField.addPropertyChangeListener(actionEvent -> intermediateFlex.setDuration(Integer.parseInt(durationTextField.getValue().toString())));
@@ -599,7 +597,7 @@ public class FlexWindow extends JFrame {
 		flexAttributesBorderPanel.add(flexCooldownLabel);
 		
 		
-		JFormattedTextField cooldownTextField = new  JFormattedTextField(moreThenZeroIntegerFormater);
+		JFormattedTextField cooldownTextField = new  JFormattedTextField(moreThenZeroIntegerFormatter);
 		cooldownTextField.setValue(intermediateFlex.getCooldown());
 		cooldownTextField.setToolTipText("Only positive Integer.");
 		cooldownTextField.addPropertyChangeListener(actionEvent -> intermediateFlex.setCooldown(Integer.parseInt(cooldownTextField.getValue().toString())));
@@ -634,8 +632,6 @@ public class FlexWindow extends JFrame {
 		
 		JButton createFlexButton = new JButton("Create");
 		createFlexButton.addActionListener(clicked -> {
-			//createFlexButton.requestFocus();
-			//createFlexButton.grabFocus();
 			HolonElement ele;
 			if(element ==null) {				
 				ele = (HolonElement) holonElementSelector.getSelectedItem();
@@ -651,7 +647,8 @@ public class FlexWindow extends JFrame {
 			toCreateFlex.offered=offeredCheckBox.isSelected();
 			if(onConstrainCheckBox.isSelected())toCreateFlex.constrainList.add(Constrain.createOnConstrain());
 			if(offConstrainCheckBox.isSelected())toCreateFlex.constrainList.add(Constrain.createOffConstrain());
-			
+
+			assert ele != null;
 			ele.flexList.add(toCreateFlex);
 			//save checkboxes
 			this.offered=offeredCheckBox.isSelected();

+ 1 - 1
src/holeg/ui/view/window/Outliner.java

@@ -33,7 +33,7 @@ public class Outliner extends JFrame {
 	Set<Holon> list;
 	Runnable update = this::update;
 
-	public Outliner(JFrame parentFrame, Model model, Control control) {
+	public Outliner(JFrame parentFrame, Control control) {
 		setBounds(0, 0, 400, parentFrame.getHeight());
 		this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
 		this.setTitle("Outliner");

+ 1 - 1
src/holeg/utility/events/Action.java

@@ -5,7 +5,7 @@ import java.util.Set;
 import java.util.function.Consumer;
 
 public class Action<T> {
-    private Set<Consumer<T>> listeners = new HashSet<Consumer<T>>();
+    private final Set<Consumer<T>> listeners = new HashSet<Consumer<T>>();
 
     public void addListener(Consumer<T> listener) {
         listeners.add(listener);

+ 2 - 2
src/holeg/utility/events/Event.java

@@ -3,13 +3,13 @@ import java.util.HashSet;
 import java.util.Set;
 
 public class Event {
-    private Set<Runnable> listeners = new HashSet<Runnable>();
+    private final Set<Runnable> listeners = new HashSet<Runnable>();
     public void addListener(Runnable listener) {
         listeners.add(listener);
     }
 
     public void broadcast() {
-        listeners.forEach(x -> x.run());
+        listeners.forEach(Runnable::run);
     }
     
     public void removeListener(Runnable listener) {