Browse Source

gradle-integration

TomTroppmann 2 years ago
parent
commit
1acab812f6

+ 28 - 0
build.gradle

@@ -0,0 +1,28 @@
+plugins {
+    id 'java'
+}
+group = 'holeg'
+version = '2.2.0'
+description = 'HOLEG'
+
+sourceSets.main.java.srcDirs = ['src']
+sourceSets.test.java.srcDirs = ['tests']
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    implementation 'com.google.code.gson:gson:2.8.9'
+    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'
+    implementation 'com.miglayout:miglayout-swing:5.0'
+    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
+    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
+}
+
+test {
+    useJUnitPlatform()
+    testLogging.showStandardStreams = true
+}

BIN
gradle/wrapper/gradle-wrapper.jar


+ 5 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists

+ 234 - 0
gradlew

@@ -0,0 +1,234 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+#   Gradle start up script for POSIX generated by Gradle.
+#
+#   Important for running:
+#
+#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+#       noncompliant, but you have some other compliant shell such as ksh or
+#       bash, then to run this script, type that shell name before the whole
+#       command line, like:
+#
+#           ksh Gradle
+#
+#       Busybox and similar reduced shells will NOT work, because this script
+#       requires all of these POSIX shell features:
+#         * functions;
+#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+#         * compound commands having a testable exit status, especially «case»;
+#         * various built-in commands including «command», «set», and «ulimit».
+#
+#   Important for patching:
+#
+#   (2) This script targets any POSIX shell, so it avoids extensions provided
+#       by Bash, Ksh, etc; in particular arrays are avoided.
+#
+#       The "traditional" practice of packing multiple parameters into a
+#       space-separated string is a well documented source of bugs and security
+#       problems, so this is (mostly) avoided, by progressively accumulating
+#       options in "$@", and eventually passing that to Java.
+#
+#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+#       see the in-line comments for details.
+#
+#       There are tweaks for specific operating systems such as AIX, CygWin,
+#       Darwin, MinGW, and NonStop.
+#
+#   (3) This script is generated from the Groovy template
+#       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+#       within the Gradle project.
+#
+#       You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+    APP_HOME=${app_path%"${app_path##*/}"}  # leaves a trailing /; empty if no leading path
+    [ -h "$app_path" ]
+do
+    ls=$( ls -ld "$app_path" )
+    link=${ls#*' -> '}
+    case $link in             #(
+      /*)   app_path=$link ;; #(
+      *)    app_path=$APP_HOME$link ;;
+    esac
+done
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+    echo "$*"
+} >&2
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in                #(
+  CYGWIN* )         cygwin=true  ;; #(
+  Darwin* )         darwin=true  ;; #(
+  MSYS* | MINGW* )  msys=true    ;; #(
+  NONSTOP* )        nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD=$JAVA_HOME/jre/sh/java
+    else
+        JAVACMD=$JAVA_HOME/bin/java
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD=java
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+    case $MAX_FD in #(
+      max*)
+        MAX_FD=$( ulimit -H -n ) ||
+            warn "Could not query maximum file descriptor limit"
+    esac
+    case $MAX_FD in  #(
+      '' | soft) :;; #(
+      *)
+        ulimit -n "$MAX_FD" ||
+            warn "Could not set maximum file descriptor limit to $MAX_FD"
+    esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+#   * args from the command line
+#   * the main class name
+#   * -classpath
+#   * -D...appname settings
+#   * --module-path (only if needed)
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+    APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+    CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+    JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    for arg do
+        if
+            case $arg in                                #(
+              -*)   false ;;                            # don't mess with options #(
+              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath
+                    [ -e "$t" ] ;;                      #(
+              *)    false ;;
+            esac
+        then
+            arg=$( cygpath --path --ignore --mixed "$arg" )
+        fi
+        # Roll the args list around exactly as many times as the number of
+        # args, so each arg winds up back in the position where it started, but
+        # possibly modified.
+        #
+        # NB: a `for` loop captures its iteration list before it begins, so
+        # changing the positional parameters here affects neither the number of
+        # iterations, nor the values presented in `arg`.
+        shift                   # remove old arg
+        set -- "$@" "$arg"      # push replacement arg
+    done
+fi
+
+# Collect all arguments for the java command;
+#   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+#     shell script including quotes and variable substitutions, so put them in
+#     double quotes to make sure that they get re-expanded; and
+#   * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+        "-Dorg.gradle.appname=$APP_BASE_NAME" \
+        -classpath "$CLASSPATH" \
+        org.gradle.wrapper.GradleWrapperMain \
+        "$@"
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+#   readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+#   set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+        printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+        xargs -n1 |
+        sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+        tr '\n' ' '
+    )" '"$@"'
+
+exec "$JAVACMD" "$@"

+ 89 - 0
gradlew.bat

@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem      https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 0 - 86
pom.xml

@@ -1,86 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>praktikum-holons</groupId>
-	<artifactId>praktikum-holons</artifactId>
-	<version>2.2.0</version>
-	<name>HOLEG</name>
-	<build>
-		<sourceDirectory>src</sourceDirectory>
-		<testSourceDirectory>tests</testSourceDirectory>
-		<resources>
-			<resource>
-				<directory>src</directory>
-				<excludes>
-					<exclude>**/*.java</exclude>
-				</excludes>
-			</resource>
-		</resources>
-		<plugins>
-			<plugin>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<version>3.8.1</version>
-				<configuration>
-					<release>16</release>
-				</configuration>
-			</plugin>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-jar-plugin</artifactId>
-				<version>3.2.0</version>
-				<configuration>
-					<archive>
-						<manifest>
-							<mainClass>holeg.ui.view.main.Main</mainClass>
-						</manifest>
-					</archive>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-
-
-
-
-	<dependencies>
-		<dependency>
-			<groupId>com.google.code.gson</groupId>
-			<artifactId>gson</artifactId>
-			<version>2.8.9</version>
-		</dependency>
-		<dependency>
-			<groupId>org.junit.jupiter</groupId>
-			<artifactId>junit-jupiter-api</artifactId>
-			<version>5.7.2</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.junit.jupiter</groupId>
-			<artifactId>junit-jupiter-engine</artifactId>
-			<version>5.7.2</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-email</artifactId>
-			<version>1.5</version>
-		</dependency>
-		<dependency>
-			<groupId>org.wso2.orbit.org.apache.commons</groupId>
-			<artifactId>commons-compress</artifactId>
-			<version>1.18.0.wso2v1</version>
-		</dependency>
-		<dependency>
-			<groupId>org.knowm.xchart</groupId>
-			<artifactId>xchart</artifactId>
-			<version>3.8.1</version>
-		</dependency>
-		<dependency>
-			<groupId>com.miglayout</groupId>
-			<artifactId>miglayout-swing</artifactId>
-			<version>5.0</version>
-		</dependency>
-
-	</dependencies>
-</project>

+ 1 - 0
settings.gradle

@@ -0,0 +1 @@
+rootProject.name = 'holeg'

+ 1 - 1
src/holeg/algorithm/binary/BaseLine.java

@@ -198,7 +198,7 @@ public class BaseLine implements AddOn {
 	
 	
 	private void disableGuiInput(boolean bool) {
-		control.guiDisable(bool);
+		control.guiSetEnabled(bool);
 	}
 	
 	

+ 1 - 1
src/holeg/algorithm/example/DemoAlgo.java

@@ -237,7 +237,7 @@ public class DemoAlgo implements AddOn {
 		
 		
 		private void disableGuiInput(boolean bool) {
-			control.guiDisable(bool);
+			control.guiSetEnabled(bool);
 		}
 		
 		

+ 1 - 1
src/holeg/algorithm/example/FlexExample.java

@@ -262,7 +262,7 @@ public class FlexExample implements AddOn {
 		
 		
 		private void disableGuiInput(boolean bool) {
-			control.guiDisable(bool);
+			control.guiSetEnabled(bool);
 		}
 		
 		

+ 2 - 2
src/holeg/api/AlgorithmFrameworkFlex.java

@@ -523,7 +523,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	private void run() {
 		cancel = false;
-		control.guiDisable(true);
+		control.guiSetEnabled(true);
 		runPrinter.openStream();
 		runPrinter.println("");
 		runPrinter.println("Start:" + stringStatFromRunValues(getRunValuesFromActualState()));
@@ -542,7 +542,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		}
 		updateVisual();
 		runProgressbar.finishedCancel();
-		control.guiDisable(false);
+		control.guiSetEnabled(false);
 		if(this.useEmailNotification && !cancel) {
 			EmailNotification.sendEmail(this.getClass().getName() + " finished", "Execution done.");
 		}

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

@@ -521,7 +521,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	private void run() {
 		cancel = false;
-		control.guiDisable(true);
+		control.guiSetEnabled(true);
 		runPrinter.openStream();
 		runPrinter.println("");
 		runPrinter.println("Start:" + stringStatFromActualState());
@@ -541,7 +541,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		TopologieObjectiveFunction.averageLog.clear();
 		updateVisual();
 		runProgressbar.finishedCancel();
-		control.guiDisable(false);
+		control.guiSetEnabled(false);
 	}
 	@SuppressWarnings("rawtypes")
 	private void initParameterStepping() {

+ 6 - 7
src/holeg/model/AbstractCanvasObject.java

@@ -1,5 +1,7 @@
 package holeg.model;
 
+import java.util.Optional;
+
 import com.google.gson.annotations.Expose;
 
 import holeg.ui.model.IdCounter;
@@ -35,7 +37,7 @@ public abstract class AbstractCanvasObject {
 	String sav;
 	
 	
-	private GroupNode groupNode = null;
+	private Optional<GroupNode> groupNode = Optional.empty();
 
 	/**
 	 * Constructor for a CpsObejct with an unique ID.
@@ -49,16 +51,13 @@ public abstract class AbstractCanvasObject {
 	}
 
 	public void setGroupNode(GroupNode groupNode) {
-		this.groupNode = groupNode;
+		this.groupNode = Optional.of(groupNode);
 	}
 	
-	public GroupNode getGroupNode() {
+	public Optional<GroupNode> getGroupNode() {
 		return groupNode;
 	}
-	
-	public boolean isInGroupNode() {
-		return groupNode != null;
-	}
+
 	
 	/**
 	 * Constructor for a new CpsObject with an unique ID (This constructor

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

@@ -250,19 +250,4 @@ public class CanvasController {
 		}
 	}
 	
-	public void updateCanvas() {
-		gui.repaintCanvas();
-	}
-	public GUI getGui() {
-		return gui;
-	}
-
-	public void guiDisable(boolean state) {
-		gui.guiDisable(state);
-	}
-	
-	public void setGui(GUI gui) {
-		this.gui = gui;
-	}
-	
 }

+ 6 - 12
src/holeg/ui/controller/Control.java

@@ -30,6 +30,7 @@ import holeg.ui.model.Model;
 import holeg.ui.view.dialog.CreateTemplatePopUp;
 import holeg.ui.view.main.Category;
 import holeg.ui.view.main.GUI;
+import holeg.utility.events.Action;
 import holeg.utility.events.Event;
 
 /**
@@ -60,7 +61,7 @@ public class Control {
 	public Event OnCategoryChanged = new Event();
 	public Event OnSelectionChanged = new Event();
 	public Event OnCanvasUpdate = new Event();
-	
+	public Action<Boolean> OnGuiSetEnabled = new Action<>(); 
 
 	/**
 	 * Constructor.
@@ -598,19 +599,12 @@ public class Control {
 
 
 	public void updateCanvas() {
-		canvasController.updateCanvas();
-	}
-
-	public GUI getGui() {
-		return canvasController.getGui();
-	}
-
-	public void guiDisable(boolean state) {
-		canvasController.guiDisable(state);
+		log.info("updateCanvas");
 	}
 
-	public void setGui(GUI gui) {
-		canvasController.setGui(gui);
+	public void guiSetEnabled(boolean state) {
+		log.info("guiDisabled");
+		OnGuiSetEnabled.broadcast(state);
 	}
 
 }

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

@@ -56,12 +56,12 @@ public class MinimumModel {
 			AbstractCanvasObject objectA = edge.getA();
 			AbstractCanvasObject objectB = edge.getB();
 			ArrayList<GroupNode> list = new ArrayList<GroupNode>(); 
-			if(objectA.getGroupNode() != null) {
-				list.add(objectA.getGroupNode());
-			}
-			if(objectB.getGroupNode() != null) {
-				list.add(objectB.getGroupNode());					
-			}
+			objectA.getGroupNode().ifPresent(groupNode -> {
+				list.add(groupNode);				
+			});
+			objectB.getGroupNode().ifPresent(groupNode -> {
+				list.add(groupNode);				
+			});
 			inGroupEdges.put(edge, list);
 		}
 		//Calculate Energy of HolonObjects

+ 0 - 393
src/holeg/ui/view/canvas/AbstractCanvas.java

@@ -1,393 +0,0 @@
-package holeg.ui.view.canvas;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Point;
-import java.awt.event.MouseEvent;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.TimerTask;
-import java.util.stream.Stream;
-
-import javax.swing.JMenuItem;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.Timer;
-
-import holeg.model.AbstractCanvasObject;
-import holeg.model.Edge;
-import holeg.model.GroupNode;
-import holeg.model.HolonObject;
-import holeg.model.Node;
-import holeg.ui.controller.Control;
-import holeg.ui.model.GuiSettings;
-import holeg.ui.model.Model;
-import holeg.utility.math.vector.Vec2i;
-
-/**
- * Collection of methods and values needed in both <code>MyCanvas</code> and
- * <code>UpperNodeCanvas</code>
- * <p>
- * Although Java works on references we chose to add explicit return values for
- * clearer code understanding in most cases
- *
- * @author: I. Dix
- */
-public abstract class AbstractCanvas extends JPanel {
-	/**
-	 * Version
-	 */
-	private static final long serialVersionUID = 1L;
-
-	final JMenuItem itemCut = new JMenuItem("Cut");
-	final JMenuItem itemCopy = new JMenuItem("Copy");
-	public final JMenuItem itemPaste = new JMenuItem("Paste");
-	final JMenuItem itemDelete = new JMenuItem("Delete");
-	final JMenuItem itemGroup = new JMenuItem("Group");
-	final JMenuItem itemUngroup = new JMenuItem("Ungroup");
-	final JMenuItem itemAlign = new JMenuItem("Align selected");
-	final JMenuItem itemCreateTemplate = new JMenuItem("Create Template");
-
-	final int ANIMTIME = 500; // animation Time
-	private final int animFPS = 60;
-	final int animDelay = 1000 / animFPS; // animation Delay
-	protected Model model;
-	protected Control control;
-	protected int x = 0;
-	protected int y = 0;
-	// Selection
-	//TODO(Tom2021-12-20): remove tmpCps or make is optional 
-	public AbstractCanvasObject tempCps = null;
-
-	// Replacement
-	/**
-	 * the CpsObject that might be replaced by drag&drop
-	 */
-	public AbstractCanvasObject mayBeReplaced = null;
-
-	// PopUpMenu
-	JPopupMenu popmenu = new JPopupMenu();
-	// Tooltip
-	boolean toolTip; // Tooltip on or off
-	Vec2i toolTipPos = new Vec2i(); // Tooltip Position
-	String toolTipText = "";
-	protected Set<AbstractCanvasObject> tempSelected = new HashSet<>();
-	boolean showConnectionInformation;
-	boolean dragging = false; // for dragging
-	boolean dragged = false; // if an object/objects was/were dragged
-	boolean drawEdge = false; // for drawing edges
-	boolean doMark = false; // for double click
-	public Edge edgeHighlight = null;
-	Point mousePosition = new Point(); // Mouse Position when
-	ArrayList<Vec2i> savePos;
-	// edge Object Start Point
-	int cx, cy;
-	int sx, sy; // Mark Coords
-	Vec2i unPos;
-	// Animation
-	Timer animT; // animation Timer
-	int animDuration = ANIMTIME; // animation Duration
-	int animSteps = animDuration / animDelay; // animation Steps;
-	List<AbstractCanvasObject> animCps = null;
-	// Graphics
-	Image img = null; // Contains the image to draw on the Canvas
-	Graphics2D g2; // For Painting
-	float scalediv20 = GuiSettings.getPictureScale() / 20;
-	// Mouse
-	private boolean click = false;
-
-	// ------------------------------------------ METHODS
-	// ------------------------------------------
-
-	class ACpsHandle {
-		public AbstractCanvasObject object;
-
-		ACpsHandle(AbstractCanvasObject object) {
-			this.object = object;
-		}
-
-		public String toString() {
-			return object.toString();
-		}
-	}
-
-	void drawMarker() {
-		if (sx > x && sy > y) {
-			g2.drawRect(x, y, sx - x, sy - y);
-		} else if (sx < x && sy < y) {
-			g2.drawRect(sx, sy, x - sx, y - sy);
-		} else if (sx >= x) {
-			g2.drawRect(x, sy, sx - x, y - sy);
-		} else if (sy >= y) {
-			g2.drawRect(sx, y, x - sx, sy - y);
-		}
-	}
-
-	/**
-	 * @deprecated
-	 * @param g
-	 */
-	void showTooltip(Graphics g) {
-		if (toolTip) {
-			g2.setColor(new Color(255, 225, 150));
-			g2.setStroke(new BasicStroke(1));
-			int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text
-			// width
-
-			// fixed x and y Position to the screen
-			int fixXPos = toolTipPos.getX() - (textWidth >> 1) + GuiSettings.getPictureScaleDiv2();
-			int fixYPos = toolTipPos.getY();
-
-			if (fixXPos < 0) {
-				fixXPos = 0;
-			} else if (fixXPos + textWidth + 1 > this.getWidth()) {
-				fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
-			}
-			if (fixYPos + 16 > this.getHeight()) {
-				fixYPos -= (fixYPos + 16) - this.getHeight();
-			}
-			g2.fillRect(fixXPos, fixYPos, textWidth, 15);
-			g2.setColor(Color.BLACK);
-			g2.drawRect(fixXPos, fixYPos, textWidth, 15);
-			g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
-		}
-	}
-
-	void setRightClickMenu(MouseEvent e) {
-		if (e.getButton() == MouseEvent.BUTTON3) {
-			itemPaste.setEnabled(true);
-			if (tempCps != null) {
-				itemPaste.setEnabled(true);
-				itemDelete.setEnabled(true);
-				itemCut.setEnabled(true);
-				itemCopy.setEnabled(true);
-				itemAlign.setEnabled(true);
-				// tracking
-				if (tempCps != null) {
-					itemGroup.setEnabled(true);
-				}
-				// ungrouping
-				if (tempCps instanceof GroupNode)
-					itemUngroup.setEnabled(true);
-				else
-					itemUngroup.setEnabled(false);
-				if (GuiSettings.getSelectedObjects().isEmpty()) {
-					control.addSelectedObject(tempCps);
-				}
-				if (tempCps instanceof HolonObject) {
-					itemCreateTemplate.setEnabled(true);
-				} else {
-					itemCreateTemplate.setEnabled(false);
-				}
-			} else {
-				itemAlign.setEnabled(false);
-				itemCut.setEnabled(false);
-				itemCopy.setEnabled(false);
-				itemGroup.setEnabled(false);
-				itemUngroup.setEnabled(false);
-				itemCreateTemplate.setEnabled(false);
-				if (edgeHighlight != null) {
-					itemDelete.setEnabled(true);
-					itemPaste.setEnabled(false);
-				} else {
-					itemDelete.setEnabled(false);
-					itemPaste.setEnabled(true);
-				}
-			}
-			mousePosition = this.getMousePosition();
-			popmenu.show(e.getComponent(), e.getX(), e.getY());
-		}
-	}
-
-	void markObjects() {
-		if (doMark) {
-			doMark = false;
-			if (!tempSelected.isEmpty()) {
-				control.toggleSelectedObjects(tempSelected);
-				control.getObjectsInDepth();
-				tempSelected.clear();
-			}
-			
-		}
-	}
-
-	int[] determineMousePositionOnEdge(Edge p) {
-		int lx, ly, hx, hy;
-
-		if (p.getA().getPosition().getX() > p.getB().getPosition().getX()) {
-			hx = p.getA().getPosition().getX() + GuiSettings.getPictureScaleDiv2() + 7;
-			lx = p.getB().getPosition().getX() + GuiSettings.getPictureScaleDiv2() - 7;
-		} else {
-			lx = p.getA().getPosition().getX() + GuiSettings.getPictureScaleDiv2() - 7;
-			hx = p.getB().getPosition().getX() + GuiSettings.getPictureScaleDiv2() + 7;
-		}
-		if (p.getA().getPosition().getY() > p.getB().getPosition().getY()) {
-			hy = p.getA().getPosition().getY() + GuiSettings.getPictureScaleDiv2() + 7;
-			ly = p.getB().getPosition().getY() + GuiSettings.getPictureScaleDiv2() - 7;
-		} else {
-			ly = p.getA().getPosition().getY() + GuiSettings.getPictureScaleDiv2() - 7;
-			hy = p.getB().getPosition().getY() + GuiSettings.getPictureScaleDiv2() + 7;
-		}
-
-		return new int[] { lx, ly, hx, hy };
-	}
-
-	/**
-	 * Checks if a double click was made.
-	 *
-	 * @return true if doublecklick, false if not
-	 */
-	boolean doubleClick() {
-		if (click) {
-			click = false;
-			return true;
-		} else {
-			click = true;
-			java.util.Timer t = new java.util.Timer("doubleclickTimer", false);
-			t.schedule(new TimerTask() {
-				@Override
-				public void run() {
-					click = false;
-				}
-			}, 500);
-		}
-		return false;
-	}
-
-
-
-	abstract void drawDeleteEdge();
-
-	/**
-	 * Checks if {@code draggedCps} or a new cpsObject at Position (x,y) could
-	 * replace exactly one object in {@code objects}. Saves the object that would be
-	 * replaced in {@link AbstractCanvas}.{@code MayBeReplaced}
-	 * 
-	 * @param objects    list of objects that could be replaced
-	 * @param draggedCps Object that might replace
-	 * @param x          Position of the objects that might replace
-	 * @param y          Position of the objects that might replace
-	 * @return true if exactly one Object could be replaced
-	 */
-	protected boolean checkForReplacement(Stream<AbstractCanvasObject> objects, AbstractCanvasObject draggedCps,
-			int x, int y) {
-
-		/** distance treshold for replacement */
-		int treshhold = GuiSettings.getPictureScaleDiv2();
-
-		/** number of Objects that might be replaced (should be 1) */
-		int replaceCounter = 0;
-
-		/** last object that could be replaced */
-		AbstractCanvasObject toBeReplaced = null;
-
-		/** Position of object that might be replaced */
-		Vec2i p;
-
-		/** for each cps on Canvas */
-		if (draggedCps == null || !(draggedCps instanceof Node) && !(draggedCps instanceof Node)) {
-			for (AbstractCanvasObject cps : objects.toList()) {
-				/** same object -> ignore */
-				if (cps == draggedCps)
-					continue;
-
-				/** set Position of object that might be replaced */
-				p = cps.getPosition();
-
-				/** if near enough */
-				if (Math.abs(x - p.getX()) < treshhold && Math.abs(y - p.getY()) < treshhold) {
-					replaceCounter++;
-					toBeReplaced = cps;
-
-					/**
-					 * if too many Objects could be replaced: stop searching, because it would not
-					 * be clear which one should be replaced
-					 */
-					if (replaceCounter > 1)
-						break;
-				}
-			}
-		}
-		/**
-		 * return true if exactly one obect would be replaced
-		 */
-		if (replaceCounter == 1 && toBeReplaced != null) {
-			mayBeReplaced = toBeReplaced;
-			return true;
-		} else {
-			mayBeReplaced = null;
-			return false;
-		}
-	}
-
-	/**
-	 * Checks if an inserted new Object could replace exactly one object on the
-	 * canvas. Saves the object that would be replaced in
-	 * {@link AbstractCanvas}.{@code MayBeReplaced}
-	 * 
-	 * @param x Position of the objects that might replace
-	 * @param y Position of the objects that might replace
-	 * @return true if exactly one Object could be replaced
-	 */
-	public abstract boolean checkForReplacement(int x, int y);
-
-	/**
-	 * highlights the object that mayBeReplaced
-	 * 
-	 * @param g2
-	 */
-	protected void highlightMayBeReplaced(Graphics2D g2) {
-		if (mayBeReplaced != null) {
-			g2.setColor(Color.RED);
-			g2.fillRect((int) (mayBeReplaced.getPosition().getX() - GuiSettings.getPictureScaleDiv2() - (scalediv20 + 3)),
-					(int) (mayBeReplaced.getPosition().getY() - GuiSettings.getPictureScaleDiv2() - (scalediv20 + 3)),
-					(int) (GuiSettings.getPictureScale() + ((scalediv20 + 3) * 2)),
-					(int) (GuiSettings.getPictureScale() + ((scalediv20 + 3) * 2)));
-		}
-	}
-
-	/**
-	 * Align alle Objects on the Canvas to a Grid with objects every 10 pixels
-	 */
-	public abstract void tryToAlignObjects();
-
-	/**
-	 * Aligns the Object the a grid
-	 * 
-	 * @param cps      Object that should be aligned
-	 * @param distance distance between the AlignmentGrid Lines. (objects every
-	 *                 'distance' pixels
-	 */
-	protected void align(AbstractCanvasObject cps, int distance) {
-		/** Position of the AbstractCpsObject which should be aligned */
-		Vec2i p = cps.getPosition();
-
-		// calculate how many pixels the cps should be decreased to align
-		/** x offset relative to a grid with lines every distance pixels */
-		int x_off = cps.getPosition().getX() % distance;
-
-		/** y offset relative to a grid with lines every distance pixels */
-		int y_off = cps.getPosition().getY() % distance;
-
-		// align to the other Line, if it is nearer
-		if (x_off > distance / 2)
-			x_off -= distance;
-		if (y_off > distance / 2)
-			y_off -= distance;
-
-		/** set new Position */
-		cps.setPosition(p.getX() - x_off, p.getY() - y_off);
-	}
-
-	/**
-	 * Closes a tab of the UpperNode with ID upperNodeID
-	 * 
-	 * @param upperNodeId
-	 */
-	public abstract void closeUpperNodeTab(int upperNodeId);
-}

+ 73 - 730
src/holeg/ui/view/canvas/Canvas.java

@@ -1,264 +1,49 @@
 package holeg.ui.view.canvas;
 
-import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.geom.Line2D;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Optional;
 import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-import javax.swing.ImageIcon;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-import javax.swing.JTabbedPane;
-import javax.swing.SwingUtilities;
 
-import com.google.gson.JsonParseException;
+import javax.swing.JPanel;
 
-import holeg.model.AbstractCanvasObject;
-import holeg.model.Edge;
 import holeg.model.GroupNode;
 import holeg.model.HolonObject;
-import holeg.model.HolonObject.HolonObjectState;
-import holeg.model.HolonSwitch.SwitchMode;
-import holeg.model.HolonSwitch;
-import holeg.model.Node;
 import holeg.preferences.ColorPreference;
-import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
-import holeg.ui.view.inspector.UnitGraph;
 import holeg.utility.image.Import;
 import holeg.utility.math.vector.Vec2i;
 
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+
 /**
  * This Class is the Canvas. All Objects will be visualized here
  *
  * @author Gruppe14
  */
-public class Canvas extends AbstractCanvas implements MouseListener, MouseMotionListener {
+public class Canvas extends JPanel {
 	private static final Logger log = Logger.getLogger(Canvas.class.getName());
-	private static final long serialVersionUID = 1L;
-	public boolean disabled = false;
-
-	GroupNode groupNode = null;
+	private boolean enabled = false;
 
+	private GroupNode groupNode;
+	private Control control;
 	private static Color[] colors = { ColorPreference.HolonObject.Producer, ColorPreference.HolonObject.NotSupplied,
 			ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.Supplied,
 			ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.NoEnergy };
 
-
-	/**
-	 * Constructor.
-	 *
-	 * @param mod       the Model
-	 * @param control   the Controller
-	 * @param unitGraph
-	 */
-	public Canvas(Control control, UnitGraph unitGraph, GroupNode groupNode) {
-		toolTip = false;
+	public Canvas(Control control, GroupNode groupNode) {
 		this.control = control;
-		this.model = control.getModel();
 		this.groupNode = groupNode;
-		
-
-		showConnectionInformation = true;
-		popmenu.add(itemCut);
-		popmenu.add(itemCopy);
-		popmenu.add(itemPaste);
-		popmenu.add(itemDelete);
-		popmenu.add(itemAlign);
-		popmenu.addSeparator();
-		popmenu.add(itemGroup);
-		popmenu.add(itemUngroup);
-		popmenu.add(itemCreateTemplate);
-
-		itemDelete.setEnabled(false);
-		itemCut.setEnabled(false);
-		itemCopy.setEnabled(false);
-		itemPaste.setEnabled(true);
-		itemAlign.setEnabled(false);
-		itemGroup.setEnabled(false);
-		itemUngroup.setEnabled(false);
-
-		itemCut.setText("Cut");
-
-		itemGroup.addActionListener(actionEvent -> {
-			// calculate uppernode pos (taken from the controller)
-			unPos = new Vec2i(0, 0);
-			animCps = new ArrayList<>();
-			for (AbstractCanvasObject cps : GuiSettings.getSelectedObjects()) {
-				animCps.add(cps); // add to animation Cps ArrayList
-				unPos = unPos.add(cps.getPosition());
-			}
-			unPos = unPos.divide(animCps.size());
-
-			// save old Position
-			savePos = new ArrayList<>();
-			for (int i = 0; i < animCps.size(); i++) {
-				savePos.add(new Vec2i(animCps.get(i).getPosition()));
-			}
-
-			animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
-				if (animDuration - animDelay > 0 && animCps.size() > 1) {
-					for (AbstractCanvasObject animCpObject : animCps) {
-						Vec2i pos = animCpObject.getPosition();
-						Vec2i difference = pos.subtract(unPos);
-						Vec2i result = pos.subtract(difference.divide(animSteps));
-						pos.set(result);
-					}
-					repaint();
-					animDuration -= animDelay;
-					animSteps--;
-				} else {
-					animDuration = ANIMTIME;
-					animSteps = animDuration / animDelay;
-					animT.stop();
-					for (int i = 0; i < animCps.size(); i++) {
-						animCps.get(i).getPosition().set(savePos.get(i));
-					}
-					control.addGroupNode("GroupNode", groupNode, animCps);
-					control.calculateStateAndVisualForCurrentTimeStep();
-					control.clearSelection();
-					repaint();
-				}
-			});
-			animT.start();
-		});
-
-		itemUngroup.addActionListener(actionEvent -> {
-			// save old Position
-			int upperNodeId = tempCps.getId();
-
-			closeUpperNodeTab(upperNodeId);
-
-			savePos = new ArrayList<>();
-			animCps = ((GroupNode) tempCps).getAllObjectsRecursive().toList();
-			control.undoGroupNode((GroupNode) tempCps, groupNode);
-
-			for (int i = 0; i < animCps.size(); i++) {
-				savePos.add(new Vec2i(animCps.get(i).getPosition()));
-			}
-			for (AbstractCanvasObject cps : animCps) {
-				int x = tempCps.getPosition().getX();
-				int y = tempCps.getPosition().getY();
-
-				cps.setPosition(new Vec2i(x, y));
-			}
-
-			animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
-				control.clearSelection();
-				if (animDuration - animDelay >= 0) {
-					for (int i = 0; i < animCps.size(); i++) {
-						Vec2i pos = animCps.get(i).getPosition();
-						Vec2i difference = pos.subtract(savePos.get(i));
-						Vec2i result = pos.subtract(difference.divide(animSteps));
-						pos.set(result);
-					}
-					repaint();
-					animDuration -= animDelay;
-					animSteps--;
-				} else {
-					animDuration = ANIMTIME;
-					animSteps = animDuration / animDelay;
-					animT.stop();
-					for (int i = 0; i < animCps.size(); i++) {
-						animCps.get(i).getPosition().set(savePos.get(i));
-					}
-					control.calculateStateAndVisualForCurrentTimeStep();
-					repaint();
-				}
-			});
-			animT.start();
-		});
-
-		// adds the selected object(s) to the statistic panel
-
-		itemDelete.addActionListener(actionEvent -> {
-			// Remove the selected Object objects
-			// Edge Deleting
-			if (tempCps == null && edgeHighlight != null) {
-				control.removeEdgesOnCanvas(edgeHighlight);
-				// Look for a CPSNode with no Connections and delete them
-				if (edgeHighlight.getA() instanceof Node) {
-					control.delCanvasObject(edgeHighlight.getA(), false);
-				}
-				if (edgeHighlight.getB() instanceof Node) { // Look on the other end of the cable
-					control.delCanvasObject(edgeHighlight.getB(), false);
-				}
-				edgeHighlight = null;
-			}
-			for (AbstractCanvasObject cps : GuiSettings.getSelectedObjects()) {
-				control.delCanvasObject(cps, false);
-				toolTip = false;
-			}
-			control.tryAutoSave();
-			control.clearSelection();
-			tempCps = null;
-			repaint();
-		});
-
-		itemCut.addActionListener(actionEvent -> {
-			control.cut(null);
-			itemPaste.setEnabled(true);
-			repaint();
-		});
-
-		itemCopy.addActionListener(actionEvent -> {
-			if (tempCps instanceof GroupNode)
-				control.getObjectsInDepth();
-			control.copy(null);
-			itemPaste.setEnabled(true);
-			repaint();
-		});
-
-		itemAlign.addActionListener(actionEvent -> {
-			for (AbstractCanvasObject cps : GuiSettings.getSelectedObjects())
-				align(cps, GuiSettings.getPictureScaleDiv2());
-			repaint();
-		});
-		itemPaste.addActionListener(actionEvent -> {
-			try {
-				control.paste(null, mousePosition);
-
-			} catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
-				JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
-				JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
-			}
-			repaint();
-		});
-
-		/*
-		 * create Template
-		 */
-		itemCreateTemplate.addActionListener(actionEvent -> {
-			control.createTemplate((HolonObject) tempCps, (JFrame) SwingUtilities.getRoot(this));
-		});
-
-		this.addMouseListener(this);
-		this.addMouseMotionListener(this);
+		control.OnGuiSetEnabled.addListener(this::setCanvasEnabled);
+		// TODO(Tom2022-01-14): remove listener when not needed anymore
 	}
 
-	/**
-	 * Paints all Components on the Canvas.
-	 *
-	 * @param g Graphics
-	 */
-
-
+	private void setCanvasEnabled(boolean state) {
+		enabled = state;
+	}
 
 //	protected void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject) {
 //		Vec2i pos = decoratedHolonObject.getModel().getPosition();
@@ -413,66 +198,40 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 //		return percentages;
 //	}
 
-	private void paintSupplyBar(Graphics2D g, float percentage, Color color, Vec2i pos) {
-		// +1, -2, -1 little Adjustment for pixel perfect alignment
-		int barWidth = (int) (GuiSettings.getPictureScale());
-		int barHeight = (int) (GuiSettings.getPictureScale() / 5);
-		g.setColor(Color.WHITE);
-		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, (int) barWidth,
-				barHeight);
-		g.setColor(color);
-		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
-				(int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
-		g.setColor(Color.BLACK);
-		g.setStroke(new BasicStroke(1));
-		g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, barWidth - 1,
-				barHeight);
-		g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
-		String percentageString = (Math.round((percentage * 100))) + "%";
-		int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
-		if (percentage > 1.0f)
-			g.setColor(Color.WHITE); // Just to see better on purple
-		g.drawString(percentageString, pos.getX() + 1 - stringWidth / 2,
-				pos.getY() + GuiSettings.getPictureScaleDiv2() - 1 + barHeight);
-
-	}
-
-	// old code
-	void drawMarker(Graphics2D g) {
-		Color transparentGrey = ColorPreference.Panel.ObjectSelection;
-		if (sx > x && sy > y) {
-			g.drawRect(x, y, sx - x, sy - y);
-			g.setColor(transparentGrey);
-			g.fillRect(x, y, sx - x, sy - y);
-		} else if (sx < x && sy < y) {
-			g.drawRect(sx, sy, x - sx, y - sy);
-			g.setColor(transparentGrey);
-			g.fillRect(sx, sy, x - sx, y - sy);
-		} else if (sx >= x) {
-			g.drawRect(x, sy, sx - x, y - sy);
-			g.setColor(transparentGrey);
-			g.fillRect(x, sy, sx - x, y - sy);
-		} else if (sy >= y) {
-			g.drawRect(sx, y, x - sx, sy - y);
-			g.setColor(transparentGrey);
-			g.fillRect(sx, y, x - sx, sy - y);
-		}
-	}
+//	private void paintSupplyBar(Graphics2D g, float percentage, Color color, Vec2i pos) {
+//		// +1, -2, -1 little Adjustment for pixel perfect alignment
+//		int barWidth = (int) (GuiSettings.getPictureScale());
+//		int barHeight = (int) (GuiSettings.getPictureScale() / 5);
+//		g.setColor(Color.WHITE);
+//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, (int) barWidth,
+//				barHeight);
+//		g.setColor(color);
+//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
+//				(int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
+//		g.setColor(Color.BLACK);
+//		g.setStroke(new BasicStroke(1));
+//		g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, barWidth - 1,
+//				barHeight);
+//		g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
+//		String percentageString = (Math.round((percentage * 100))) + "%";
+//		int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
+//		if (percentage > 1.0f)
+//			g.setColor(Color.WHITE); // Just to see better on purple
+//		g.drawString(percentageString, pos.getX() + 1 - stringWidth / 2,
+//				pos.getY() + GuiSettings.getPictureScaleDiv2() - 1 + barHeight);
+//
+//	}
 
+	@Override
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
-//		Graphics2D g2d = (Graphics2D) g;
-//		g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
-//		// -->Old code TODO(Tom2021-12-1): remove
-//		if (drawEdge) {
-//			g2d.setColor(Color.BLACK);
-//			g2d.setStroke(new BasicStroke(1));
-//			g2d.drawLine(tempCps.getPosition().getX(), tempCps.getPosition().getY(), x, y);
-//		}
-//		// <--
-//		// timstep:
-//		g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-//		g2d.setColor(Color.BLACK);
+		Graphics2D g2d = initGraphics2D(g);
+		log.info("Draw");
+		
+		groupNode.getHolonObjects().forEach(hO -> {
+			drawHolonObject(g2d, hO);
+		});
+
 //		
 //		Optional<VisualRepresentationalState> optVisualState = control.getSimManager().getActualVisualRepresentationalState();
 //		// VisualState Representation:
@@ -553,454 +312,34 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 //		// <-- OldCode
 	}
 
-	@Override
-	public void mouseClicked(MouseEvent e) {
-	}
-
-	@Override
-	public void mouseEntered(MouseEvent e) {
-	}
-
-	@Override
-	public void mouseExited(MouseEvent e) {
-	}
-
-	@Override
-	public void mousePressed(MouseEvent e) {
-		this.grabFocus();
-		if (!disabled) {
-			tempCps = null;
-			edgeHighlight = null;
-			GuiSettings.getSelectedEdges().clear();
-			// Object Selection
-			for (AbstractCanvasObject cps : groupNode.getObjectsInThisLayer().toList()) {
-				cx = cps.getPosition().getX() - GuiSettings.getPictureScaleDiv2();
-				cy = cps.getPosition().getY() - GuiSettings.getPictureScaleDiv2();
-				if (x - GuiSettings.getPictureScale() <= cx && y - GuiSettings.getPictureScale() <= cy && x >= cx && y >= cy) {
-					tempCps = cps;
-
-					dragging = true;
-
-					if (e.isControlDown() && tempCps != null) {
-						System.out.println("Add Remove Selection CANVAS");
-						if (GuiSettings.getSelectedObjects().contains(tempCps)) {
-							control.removeObjectFromSelection(tempCps);
-						} else {
-							control.addSelectedObject(tempCps);
-						}
-
-					}
-					if (e.isShiftDown()) {
-						drawEdge = true;
-						dragging = false;
-					}
-				}
-			}
-
-			// Edge Selection
-			if (tempCps == null) {
-				edgeHighlight = mousePositionOnEdge(x, y);
-				GuiSettings.getSelectedEdges().add(edgeHighlight);
-				if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
-					control.clearSelection();
-				}
-			}
-
-			if (edgeHighlight == null && tempCps == null) {
-				sx = e.getX();
-				sy = e.getY();
-				doMark = true;
-			}
-
-			repaint();
-		}
-	}
-
-	@Override
-	public void mouseReleased(MouseEvent e) {
-		if (!disabled) {
-			x = e.getX();
-			y = e.getY();
-
-			dragging = false;
-
-			if (drawEdge) {
-				drawEdge = false;
-				drawDeleteEdge();
-			}
-
-			if (dragged) {
-				control.tryAutoSave();
-
-				/**
-				 * check if a unique tempCps could replace an Object on the canvas
-				 */
-				if (GuiSettings.getSelectedObjects().size() == 1 && checkForReplacement(groupNode.getObjectsInThisLayer(),
-						tempCps, tempCps.getPosition().getX(), tempCps.getPosition().getY())) {
-					/**
-					 * if UpperNode would be replaced, close its tabs
-					 */
-					if (mayBeReplaced instanceof GroupNode)
-						closeUpperNodeTab(mayBeReplaced.getId());
-					/**
-					 * replace on canvas (will save)
-					 */
-					control.replaceCanvasObject(mayBeReplaced, tempCps);
-					mayBeReplaced = null;
-				}
-			}
-
-			if (!e.isControlDown() && !dragged && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
-				control.clearSelection();
-				control.addSelectedObject(tempCps);
-				if (tempCps instanceof GroupNode)
-					control.getObjectsInDepth();
-			}
-
-			dragged = false;
-
-			// Rightclick List
-			setRightClickMenu(e);
-
-			markObjects();
-
-			boolean doubleclick = doubleClick();
-			if (doubleclick && tempCps instanceof HolonSwitch sw && MouseEvent.BUTTON3 != e.getButton()
-					&& tempCps != null) {
-				
-				sw.setMode(SwitchMode.Manual);
-				sw.flipManualState();
-			}
-			if (doubleclick && tempCps != null && tempCps instanceof GroupNode groupnode) {
-				control.getGui().openNewUpperNodeTab(groupnode);
-			}
-			control.calculateStateAndVisualForTimeStep(model.getCurrentIteration());
-
-			repaint();
-		}
-	}
-
-	@Override
-	public void mouseDragged(MouseEvent e) {
-		if (!disabled) {
-			// If Edge is drawn
-			x = e.getX();
-			y = e.getY();
-
-			if (!GuiSettings.getSelectedObjects().contains(tempCps) && !doMark) {
-				control.clearSelection();
-				if (tempCps != null) {
-					control.addSelectedObject(tempCps);
-				}
-			}
-			if (dragging) {
-				try {
-					dragged = true;
-					float xDist, yDist; // Distance
-
-					x = e.getX();
-					y = e.getY();
-
-					// Make sure its in bounds
-					int scaleDiv2 = GuiSettings.getPictureScaleDiv2();
-					if (e.getX() < scaleDiv2)
-						x = scaleDiv2;
-					else if (e.getX() > this.getWidth() - scaleDiv2)
-						x = this.getWidth() - scaleDiv2;
-					if (e.getY() < scaleDiv2)
-						y = scaleDiv2;
-					else if (e.getY() > this.getHeight() - scaleDiv2)
-						y = this.getHeight() - scaleDiv2;
-
-					// Distance
-					xDist = x - tempCps.getPosition().getX();
-					yDist = y - tempCps.getPosition().getY();
-
-					tempCps.setPosition(x, y); // Drag Position
-					// ToolTipText Position and name
-					toolTip = true;
-					toolTipText = tempCps.getName() + ", " + tempCps.getId();
-					toolTipPos.setX(tempCps.getPosition().getX() - scaleDiv2);
-					toolTipPos.setY(tempCps.getPosition().getY() + scaleDiv2);
-
-					// All Selected Objects
-					for (AbstractCanvasObject cps : GuiSettings.getSelectedObjects()) {
-						if (cps != tempCps) {
-							x = (int) (cps.getPosition().getX() + xDist);
-							y = (int) (cps.getPosition().getY() + yDist);
-
-							// Make sure its in bounds
-							if (x <= scaleDiv2)
-								x = scaleDiv2;
-							else if (x > this.getWidth() - scaleDiv2)
-								x = this.getWidth() - scaleDiv2;
-							if (y <= scaleDiv2)
-								y = scaleDiv2;
-							else if (y > this.getHeight() - scaleDiv2)
-								y = this.getHeight() - scaleDiv2;
-
-							cps.setPosition(x, y);
-						}
-					}
-
-					/**
-					 * check if something might be replaced
-					 */
-					if (GuiSettings.getSelectedObjects().size() == 1)
-						checkForReplacement(groupNode.getObjectsInThisLayer(), tempCps, x, y);
-
-					repaint();
-				} catch (Exception eex) {
-				}
-			}
-
-			// Mark Objects
-			if (doMark) {
-				tempSelected.clear();
-				for (AbstractCanvasObject cps : groupNode.getObjectsInThisLayer().toList()) {
-					int x1 = sx, x2 = x, y1 = sy, y2 = y;
-
-					if (sx >= x) {
-						x1 = x;
-						x2 = sx;
-					}
-					if (sy >= y) {
-						y1 = y;
-						y2 = sy;
-					}
-					if (x1 <= cps.getPosition().getX() + GuiSettings.getPictureScaleDiv2()
-							&& y1 <= cps.getPosition().getY() + GuiSettings.getPictureScaleDiv2() && x2 >= cps.getPosition().getX()
-							&& y2 >= cps.getPosition().getY()) {
-						tempSelected.add(cps);
-
-					}
-				}
-			}
-
-			repaint();
-		}
-	}
-
-	@Override
-	public void mouseMoved(MouseEvent e) {
-		if (!disabled) {
-			x = e.getX();
-			y = e.getY();
-
-			// Everything for the tooltip :)
-			boolean on = false;
-			for (AbstractCanvasObject cps : groupNode.getObjectsInThisLayer().toList()) {
-				cx = cps.getPosition().getX() - GuiSettings.getPictureScaleDiv2();
-				cy = cps.getPosition().getY() - GuiSettings.getPictureScaleDiv2();
-
-				if (x - GuiSettings.getPictureScale() <= cx && y - GuiSettings.getPictureScale() <= cy && x >= cx && y >= cy) {
-					on = true;
-					toolTipPos.setX(cps.getPosition().getX() - GuiSettings.getPictureScaleDiv2());
-					toolTipPos.setY(cps.getPosition().getY() + GuiSettings.getPictureScaleDiv2());
-					toolTipText = cps.getName() + ", " + cps.getId();
-				}
-			}
-			if (on || (!on && toolTip))
-				repaint();
-			toolTip = on;
-		}
-	}
-
-	/**
-	 * Draws or Deletes an Edge.
-	 */
-	void drawDeleteEdge() {
-		if (getMousePosition() != null) {
-			boolean node = true;
-			boolean newEdge = true;
-			boolean onEdge = true;
-			boolean deleteNode = false;
-			Edge e = null;
-
-			for (AbstractCanvasObject cps : groupNode.getObjectsInThisLayer().toList()) {
-				cx = cps.getPosition().getX() - GuiSettings.getPictureScaleDiv2();
-				cy = cps.getPosition().getY() - GuiSettings.getPictureScaleDiv2();
-				if (x - GuiSettings.getPictureScale() <= cx && y - GuiSettings.getPictureScale() <= cy && x >= cx && y >= cy
-						&& cps != tempCps) {
-					node = false;
-					onEdge = false;
-					if (!newEdge) {
-						control.removeEdgesOnCanvas(e);
-						// Node ohne Edge?
-						if (e.getA().getClass() == Node.class) {
-							tempCps = e.getA();
-							deleteNode = true;
-						}
-						if (e.getB().getClass() == Node.class) {
-							deleteNode = true;
-						}
-					} else {
-						if (!(cps instanceof GroupNode || tempCps instanceof GroupNode)) {
-							e = new Edge(cps, tempCps, GuiSettings.maxCapacityForNewCreatedEdges);
-							control.addEdgeOnCanvas(e);
-						} else if (cps instanceof GroupNode groupnode && !(tempCps instanceof GroupNode)) {
-							GroupNode thisUpperNode = groupnode;
-							Object[] possibilities = thisUpperNode.getObjectsInThisLayer().map(aCps -> new ACpsHandle(aCps))
-									.filter(aCpsHandle -> !(aCpsHandle.object instanceof GroupNode)).toArray();
-							if (possibilities.length != 0) {
-								ACpsHandle selected = (ACpsHandle) JOptionPane.showInputDialog(this,
-										"Select a inside Object:", "Connection To?", JOptionPane.OK_OPTION,
-										new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)),
-										possibilities, "");
-								if (selected != null) {
-									e = new Edge(selected.object, tempCps, GuiSettings.maxCapacityForNewCreatedEdges);
-									control.addEdgeOnCanvas(e);
-								}
-							} else {
-								Node n = new Node("Node");
-
-								n.setPosition(x, y);
-								control.addObjectInGroupNode(n, thisUpperNode);
-								e = new Edge(n, tempCps, GuiSettings.maxCapacityForNewCreatedEdges);
-								control.addEdgeOnCanvas(e);
-							}
-
-						}
-
-					}
-				}
-			}
-			// Edge auf eine Edge gezogen?
-			if (onEdge && !checkForReplacement(x, y)) {
-				Edge p = mousePositionOnEdge(x, y);
-				if (p != null) {
-					Edge e1;
-					Edge e2;
-
-					node = false;
-
-					Node n = new Node("Node");
-
-					n.setPosition(x, y);
-					control.addObjectCanvas(n);
-
-					AbstractCanvasObject r, k;
-					r = p.getA();
-					k = p.getB();
-
-					e = new Edge(n, tempCps, GuiSettings.maxCapacityForNewCreatedEdges);
-
-					e1 = new Edge(n, r, GuiSettings.maxCapacityForNewCreatedEdges);
-
-					e2 = new Edge(n, k, GuiSettings.maxCapacityForNewCreatedEdges);
-
-					control.removeEdgesOnCanvas(p);
-					control.addEdgeOnCanvas(e);
-					control.addEdgeOnCanvas(e1);
-					control.addEdgeOnCanvas(e2);
-				}
-			} else {
-				mayBeReplaced = null;
-			}
-
-			// ins leere Gedragged
-			if (node && !checkForReplacement(x, y)) {
-				Node n = new Node("Node");
-
-				n.setPosition(x, y);
-
-				control.addObjectCanvas(n);
-
-				e = new Edge(n, tempCps, GuiSettings.maxCapacityForNewCreatedEdges);
-
-				control.addEdgeOnCanvas(e);
-			} else {
-				mayBeReplaced = null;
-			}
-
-			// Wenn ein Node ohne Connections da ist
-			if (deleteNode) {
-				control.delCanvasObject(tempCps, true);
-				tempCps = null;
-			}
-		}
-	}
-
-	/**
-	 * Checks if the mouse is on an Edge.
-	 *
-	 * @param x Position of the Mouse
-	 * @param y Position of the Mouse
-	 * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
-	 */
-	protected Edge mousePositionOnEdge(int x, int y) {
-		x += GuiSettings.getPictureScaleDiv2();
-		y += GuiSettings.getPictureScaleDiv2();
-		for (Edge p : model.getEdgesOnCanvas()) {
-			Line2D l = new Line2D.Float(p.getA().getPosition().getX(), p.getA().getPosition().getY(),
-					p.getB().getPosition().getX(), p.getB().getPosition().getY());
-
-			int[] positions = determineMousePositionOnEdge(p);
-			int lx = positions[0];
-			int ly = positions[1];
-			int hx = positions[2];
-			int hy = positions[3];
-
-			// distance from a point to a line and between both Objects
-			if (l.ptLineDistSq(x - GuiSettings.getPictureScaleDiv2(), y - GuiSettings.getPictureScaleDiv2()) < 20 && x > lx && x < hx && y > ly
-					&& y < hy) {
-				return p;
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * set toolTip
-	 *
-	 * @param bool
-	 */
-	public void setToolTip(boolean bool) {
-		this.toolTip = bool;
+	private void drawHolonObject(Graphics2D g, HolonObject hO) {
+		Vec2i pos = hO.getPosition();
+//		Color statecolor = ColorPreference.HolonObject.getStateColor(hO.getState());
+//		g.setColor(statecolor);
+		g.setColor(Color.cyan);
+		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
+				GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
+		drawCanvasObject(g, hO.getImage(), pos);
 	}
 
-	/**
-	 * Set the Mouse
-	 *
-	 * @param x
-	 * @param y
-	 */
-	public void setXY(int x, int y) {
-		this.x = x;
-		this.y = y;
+	private void drawCanvasObject(Graphics2D g, String imageName, Vec2i pos) {
+		int pictureScale = GuiSettings.getPictureScale();
+		int pictureScaleDiv2 = GuiSettings.getPictureScaleDiv2();
+		Image image = Import.loadImage(imageName, pictureScale, pictureScale);
+		g.drawImage(image, pos.getX() - pictureScaleDiv2, pos.getY() - pictureScaleDiv2, pictureScale, pictureScale,
+				null);
 	}
 
-	@Override
-	public boolean checkForReplacement(int x, int y) {
+	private static final RenderingHints RenderingHint = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+			RenderingHints.VALUE_ANTIALIAS_ON);
+	private static final Font CanvasFont = new Font("TimesNewRoman", Font.PLAIN,
+			Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10));
 
-		return checkForReplacement(model.getCanvas().getObjectsInThisLayer(), null, x, y);
-	}
-
-	@Override
-	public void tryToAlignObjects() {
-		/**
-		 * Align all Objects
-		 */
-		model.getCanvas().getAllObjectsRecursive().forEach(cps -> {
-			align(cps, 3 * GuiSettings.getPictureScaleDiv2());			
-		});
-
-		/**
-		 * AutoSave new Positons
-		 */
-		control.tryAutoSave();
-	}
-
-	@Override
-	public void closeUpperNodeTab(int upperNodeId) {
-		JTabbedPane tabbedPaneInner = (JTabbedPane) getParent().getParent().getParent().getParent();
-		for (int i = 1; i < tabbedPaneInner.getTabCount(); i++) {
-			if (((Canvas) ((JScrollPane) tabbedPaneInner.getComponentAt(i)).getViewport().getComponent(0))
-					.getGroupNode().getId() == upperNodeId) {
-				tabbedPaneInner.remove(i);
-				break;
-			}
-		}
+	private static Graphics2D initGraphics2D(Graphics g) {
+		Graphics2D g2d = (Graphics2D) g;
+		g2d.setRenderingHints(RenderingHint);
+		g2d.setFont(CanvasFont);
+		return g2d;
 	}
 
 	public GroupNode getGroupNode() {
@@ -1011,4 +350,8 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 		this.groupNode = groupNode;
 	}
 
+	public void checkForReplacement(int x, int y) {
+
+	}
+
 }

+ 25 - 46
src/holeg/ui/view/main/GUI.java

@@ -76,7 +76,6 @@ import holeg.ui.model.IdCounter;
 import holeg.ui.model.IdCounter.CounterType;
 import holeg.ui.model.Model;
 import holeg.ui.model.Model.FairnessModel;
-import holeg.ui.view.canvas.AbstractCanvas;
 import holeg.ui.view.canvas.Canvas;
 import holeg.ui.view.component.ButtonTabComponent;
 import holeg.ui.view.dialog.AboutUsPopUp;
@@ -249,10 +248,9 @@ public class GUI {
 		this.informationPanel = new HolonInformationPanel(control);
 		this.model = control.getModel();
 		inspector = new Inspector(control);
-		control.setGui(this);
 		control.calculateStateAndVisualForCurrentTimeStep();
 		this.unitGraph = new UnitGraph(control);
-		this.canvas = new Canvas(control, unitGraph, model.getCanvas());
+		this.canvas = new Canvas(control, model.getCanvas());
 		initialize();
 		updateCategories(GuiSettings.getCategories());
 		control.OnCategoryChanged.addListener(() -> this.updateCategoryUI(GuiSettings.getCategories()));
@@ -322,6 +320,7 @@ public class GUI {
 					closeInvalidUpperNodeTabs();
 
 					control.calculateStateAndVisualForCurrentTimeStep();
+					log.info("canvas.repaint0");
 					canvas.repaint();
 					updateUpperNodes();
 				} catch (IOException eex) {
@@ -344,6 +343,7 @@ public class GUI {
 					closeInvalidUpperNodeTabs();
 
 					control.calculateStateAndVisualForCurrentTimeStep();
+					log.info("canvas.repaint1");
 					canvas.repaint();
 					updateUpperNodes();
 				} catch (IOException ex) {
@@ -400,7 +400,6 @@ public class GUI {
 					for (AbstractCanvasObject cps : GuiSettings.getSelectedObjects()) {
 						if (groupNodeCanvas.getGroupNode().getObjectsInThisLayer().anyMatch(object -> object == cps)) {
 							control.deleteObjectInGroupNode(cps, groupNodeCanvas.getGroupNode());
-							unc.setToolTip(false);
 
 							// remove UpperNodeTab if UpperNode deleted
 							removeUpperNodeTab(cps);
@@ -427,7 +426,6 @@ public class GUI {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				chooseTabTemp();
-				System.out.println("heiCopy - control C");
 				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 				if (!GuiSettings.getSelectedObjects().isEmpty()) {
 					if (scrollPane.getViewport().getComponent(0)instanceof Canvas groupNodeCanvas)
@@ -435,7 +433,8 @@ public class GUI {
 					else
 						control.copy(null);
 					if (!GuiSettings.getClipboardObjects().isEmpty()) {
-						canvas.itemPaste.setEnabled(true);
+						//TODO(Tom2022-01-14): old code changes itemPaste
+						//OLD: canvas.itemPaste.setEnabled(true);
 					}
 				}
 			}
@@ -469,6 +468,7 @@ public class GUI {
 					} else {
 						control.paste(null, canvas.getMousePosition());
 						control.calculateStateAndVisualForCurrentTimeStep();
+						log.info("canvas.repaint2");
 						canvas.repaint();
 					}
 				} catch (HeadlessException | JsonParseException | UnsupportedFlavorException | IOException e1) {
@@ -497,10 +497,12 @@ public class GUI {
 					} else {
 						control.cut(null);
 						control.calculateStateAndVisualForCurrentTimeStep();
+						log.info("canvas.repaint3");
 						canvas.repaint();
 					}
 					if (!GuiSettings.getClipboardObjects().isEmpty()) {
-						canvas.itemPaste.setEnabled(true);
+						//TODO(Tom2022-01-14): old code changes itemPaste
+						//OLD: canvas.itemPaste.setEnabled(true);
 					}
 				}
 			}
@@ -538,12 +540,7 @@ public class GUI {
 		mntmAlignAll.addActionListener(actionEvent -> {
 			// getScrollPaneFromTabbedPane().getViewport().getComponent(0) is always the
 			// active canvas
-			AbstractCanvas activeCanvas = ((AbstractCanvas) getScrollPaneFromTabbedPane().getViewport()
-					.getComponent(0));
-			if (activeCanvas != null) {
-				activeCanvas.tryToAlignObjects();
-				activeCanvas.repaint();
-			}
+			tryToAlignObjects();
 		});
 
 		menuBar.add(mnNewMenuOptions);
@@ -614,7 +611,7 @@ public class GUI {
 		showSupplyBarsCheckBox.setSelected(true);
 		showSupplyBarsCheckBox.addActionListener(arg0 -> {
 			GuiSettings.showSupplyBars = showSupplyBarsCheckBox.isSelected();
-
+			log.info("canvas.repaint4");
 			canvas.repaint();
 
 			// Update UpperNodes
@@ -790,7 +787,7 @@ public class GUI {
 						/**
 						 * repaint
 						 */
-						canvas.invalidate();
+						log.info("canvas.repaint5");
 						canvas.repaint();
 					}
 					contentPane.updateUI();
@@ -826,21 +823,15 @@ public class GUI {
 							/**
 							 * close UpperNodeTabs of replaced UpperNode
 							 */
-							if (groupNodeCanvas.mayBeReplaced != null
-									&& groupNodeCanvas.mayBeReplaced instanceof GroupNode) {
-								groupNodeCanvas.closeUpperNodeTab(groupNodeCanvas.mayBeReplaced.getId());
-							}
+							//TODO(Tom2022-01-14): replacement with upperNode
 							control.addObjectInGroupNode(h, groupNodeCanvas.getGroupNode());
 
 							/**
 							 * object would be replaced
 							 */
-							groupNodeCanvas.mayBeReplaced = null;
 							groupNodeCanvas.invalidate();
 							control.calculateStateAndVisualForCurrentTimeStep();
 							groupNodeCanvas.repaint();
-							groupNodeCanvas.setXY((int) canvas.getMousePosition().getX(),
-									(int) canvas.getMousePosition().getY());
 						} else {
 							int x = (int) canvas.getMousePosition().getX() + 16;
 							int y = (int) canvas.getMousePosition().getY() + 16;
@@ -858,17 +849,11 @@ public class GUI {
 							/**
 							 * close UpperNodeTabs of replaced UpperNode
 							 */
-							if (canvas.mayBeReplaced != null && canvas.mayBeReplaced instanceof GroupNode) {
-								canvas.closeUpperNodeTab(canvas.mayBeReplaced.getId());
-							}
 							control.addObjectCanvas(h);
 							/**
 							 * no object should get replaced
 							 */
-							canvas.mayBeReplaced = null;
-							canvas.invalidate();
-							canvas.setXY((int) canvas.getMousePosition().getX(),
-									(int) canvas.getMousePosition().getY());
+							log.info("canvas.repaint6");
 							canvas.repaint();
 						}
 						control.calculateStateAndVisualForCurrentTimeStep();
@@ -1092,7 +1077,7 @@ public class GUI {
 			GuiSettings.getSelectedEdges().clear();
 			control.getModel().setCurrentIteration(0);
 			elementGraph.setText("None");
-			canvas.tempCps = null;
+			log.info("canvas.repaint7");
 			canvas.repaint();
 			IdCounter.resetObjectCounter(CounterType.Object);
 			IdCounter.resetObjectCounter(CounterType.Element);
@@ -1120,6 +1105,7 @@ public class GUI {
 						}
 						GuiSettings.getSelectedObjects().clear();
 						control.loadFile(file.getAbsolutePath());
+						log.info("canvas.repaint8");
 						canvas.repaint();
 						categoryTree.repaint();
 						control.calculateStateAndVisualForCurrentTimeStep();
@@ -1187,6 +1173,7 @@ public class GUI {
 					closeInvalidUpperNodeTabs();
 
 					control.calculateStateAndVisualForCurrentTimeStep();
+					log.info("canvas.repaint9");
 					canvas.repaint();
 				} catch (IOException e) {
 					e.printStackTrace();
@@ -1207,6 +1194,7 @@ public class GUI {
 					closeInvalidUpperNodeTabs();
 
 					control.calculateStateAndVisualForCurrentTimeStep();
+					log.info("canvas.repaint10");
 					canvas.repaint();
 				} catch (IOException e) {
 					e.printStackTrace();
@@ -1271,11 +1259,16 @@ public class GUI {
 				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 void initWindowMenu() {
 		menuBar.add(menuWindow);
 		// Algo
@@ -1377,8 +1370,7 @@ public class GUI {
 
 		JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 		if (scrollPane.getViewport().getComponent(0)instanceof Canvas canvasPanel) {
-			unc = new Canvas(control, unitGraph, node);
-
+			unc = new Canvas(control, node);
 		}
 
 		// check if tab already open for clicked NodeOfNode
@@ -1515,6 +1507,7 @@ public class GUI {
 	}
 
 	public void repaintCanvas() {
+		log.info("repaintCanvas");
 		tabbedPaneInnerOriginal.revalidate();
 		tabbedPaneInnerOriginal.repaint();
 		for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
@@ -1523,18 +1516,4 @@ public class GUI {
 		}
 	}
 
-	/**
-	 * TODO(Tom2021-12-1): Class should be reworked as soon as possible!
-	 * 
-	 * @param state
-	 */
-	public void guiDisable(boolean state) {
-		canvas.disabled = state;
-		for (int i = 1; i < tabbedPaneInnerOriginal.getTabCount(); i++) {
-			JScrollPane scrollPaneOriginal = (JScrollPane) tabbedPaneInnerOriginal.getComponentAt(i);
-			if (((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).getGroupNode() != null) {
-				((Canvas) scrollPaneOriginal.getViewport().getComponent(0)).disabled = state;
-			}
-		}
-	}
 }

+ 37 - 36
src/holeg/ui/view/main/Main.java

@@ -16,52 +16,53 @@ 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 LogManager logManager = LogManager.getLogManager();
     private static final Logger log = Logger.getLogger(Main.class.getName());
-    static{
+
+    static {
         try {
             logManager.readConfiguration(new FileInputStream("./config/log.properties"));
         } catch (IOException exception) {
-            log.log(Level.SEVERE, "Error in loading configuration",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);
-				IndexTranslator.model = model;
-				view.setVisible(true);
-		});
-	}
 
-	private static void setLocale() {
-		Locale.setDefault(Locale.US);
-	}
+    /**
+     * 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);
+            IndexTranslator.model = model;
+            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) {
-		}
-	}
+    /**
+     * 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) {
+        }
+    }
 
 }