Browse Source

Refactors Gui

TomTroppmann 2 years ago
parent
commit
0934b79fae

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

@@ -3,6 +3,10 @@ package holeg.preferences;
 public class PreferenceKeys {
     public static class Gui{
         public static final String DefaultFolder = "DefaultFolder";
+        public static final String XPos = "XPos";
+        public static final String YPos = "YPos";
+        public static final String Width = "Width";
+        public static final String Height = "Height";
     }
     public static class EmailNotification{
         public static final String Hostname = "Hostname";

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

@@ -30,6 +30,8 @@ public class Canvas extends JPanel {
         control.OnGuiSetEnabled.addListener(this::setCanvasEnabled);
         control.OnSelectionChanged.addListener(this::repaint);
         control.OnCanvasUpdate.addListener(this::repaint);
+        this.setBackground(Color.WHITE);
+        this.setPreferredSize(new Dimension(GuiSettings.canvasSize.getX(), GuiSettings.canvasSize.getY()));
         // TODO(Tom2022-01-14): remove listener when not needed anymore
         this.addMouseListener(canvasMouseListener);
         this.addMouseMotionListener(canvasMouseListener);

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

@@ -1,6 +1,45 @@
 package holeg.ui.view.canvas;
 
+import holeg.model.GroupNode;
+import holeg.ui.controller.Control;
+
 import javax.swing.*;
+import java.util.HashMap;
+import java.util.Map;
 
 public class CanvasCollectionPanel extends JTabbedPane {
+    private final Control control;
+    private final Map<JScrollPane, Canvas> canvases= new HashMap<>();
+    private final Map<GroupNode, JScrollPane> canvases2= new HashMap<>();
+    private Canvas main;
+
+    public CanvasCollectionPanel(Control control){
+        this.control = control;
+        createMainCanvas();
+    }
+
+    private void createMainCanvas(){
+        GroupNode mainGroupNode = control.getModel().getCanvas();
+        Canvas canvas = new Canvas(control, mainGroupNode);
+        main = canvas;
+        final JScrollPane scrollPane = new JScrollPane(canvas);
+        //        scrollPane.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();
+//            }
+//        });
+        canvases.put(scrollPane, canvas);
+        canvases2.put(mainGroupNode, scrollPane);
+        this.addTab("Main", scrollPane);
+    }
+
+
+    public Canvas getActualCanvas() {
+        return main;
+    }
 }

+ 19 - 26
src/holeg/ui/view/category/CategoryPanel.java

@@ -31,16 +31,12 @@ public class CategoryPanel extends JScrollPane {
     private final Gui gui;
     private final JPanel buttonPanel = new JPanel();
     // Buttons
-    private final JPopupMenu btnAddPopUp = new JPopupMenu("New");
-    private final JButton btnAdd = new JButton(new ImageIcon(Import.loadImage(ImagePreference.Category.Add, 16, 16)));
-    private final JButton btnDel = new JButton(new ImageIcon(Import.loadImage(ImagePreference.Category.Delete, 16, 16)));
-    private final JToolBar toolBar = new JToolBar();
-    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 JPopupMenu contextMenu = new JPopupMenu();
+    private final JMenu newMenu = new JMenu("New");
     private final JMenuItem editItem = new JMenuItem("Edit Object");
     private final JMenuItem removeItem = new JMenuItem("Remove");
 
@@ -57,8 +53,6 @@ public class CategoryPanel extends JScrollPane {
 
     private void init() {
         this.setMinimumSize(new Dimension(200, 200));
-        toolBar.setAlignmentX(Component.LEFT_ALIGNMENT);
-        toolBar.setFloatable(false);
         initLayout();
         initButtons();
         initContextHandle();
@@ -73,8 +67,12 @@ public class CategoryPanel extends JScrollPane {
     }
 
     private void initContextHandle() {
+        contextMenu.add(newMenu);
         contextMenu.add(editItem);
         contextMenu.add(removeItem);
+        newMenu.add(mItemCategory);
+        newMenu.add(mItemObject);
+        newMenu.add(mItemSwitch);
         editItem.addActionListener(clicked -> getSelectedNode().ifPresent(node -> {
             ObjectTreeNode objectNode = (ObjectTreeNode) node;
             new AddObjectPopUp(control, objectNode.getObject(), objectNode.getCategory(), gui);
@@ -92,25 +90,12 @@ public class CategoryPanel extends JScrollPane {
 
     private void initLayout() {
         buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
-        btnAddPopUp.add(mItemNew);
-        btnAddPopUp.addSeparator();
-        btnAddPopUp.add(mItemCategory);
-        btnAddPopUp.add(mItemObject);
-        btnAddPopUp.add(mItemSwitch);
-        toolBar.add(btnAdd);
-        toolBar.add(btnDel);
-        buttonPanel.add(toolBar);
     }
 
     private void initButtons() {
-        mItemNew.addActionListener(clicked -> new CreateNewDialog(control, gui));
         mItemCategory.addActionListener(clicked -> new CreateNewDialog(control, CreateNewDialog.Option.Category, gui));
         mItemObject.addActionListener(clicked -> new CreateNewDialog(control, CreateNewDialog.Option.Object, gui));
         mItemSwitch.addActionListener(clicked -> new CreateNewDialog(control, CreateNewDialog.Option.Switch, gui));
-        btnAdd.addActionListener(clicked -> btnAddPopUp.show(btnAdd, -1, +20));
-        btnDel.addActionListener(clicked -> TryDeleteSelectedCategory());
-        btnAdd.setToolTipText("<html><b>New</b><br>Add a new Category or Item to the library.</html>");
-        btnDel.setToolTipText("<html><b>Delete</b><br>Removes a Category or a Category Item.</html>");
     }
 
     private void TryDeleteSelectedCategory() {
@@ -131,15 +116,18 @@ public class CategoryPanel extends JScrollPane {
     }
 
 
-    /**
-     * When changes are made to the Categories.
-     */
     private void updateCategories() {
+        categoryTree.setModel(generateCategoryModel());
+    }
+
+    private DefaultTreeModel generateCategoryModel(){
         DefaultMutableTreeNode root = new DefaultMutableTreeNode("Categories");
         GuiSettings.getCategories().stream().map(CategoryTreeNode::new).forEach(root::add);
-        categoryTree.setModel(new DefaultTreeModel(root));
+        return new DefaultTreeModel(root);
     }
 
+
+
     private Optional<DefaultMutableTreeNode> getSelectedNode() {
         return Optional.ofNullable((DefaultMutableTreeNode) categoryTree.getLastSelectedPathComponent());
     }
@@ -158,7 +146,6 @@ public class CategoryPanel extends JScrollPane {
                 label.setIcon(new ImageIcon(image));
             }
             if (hasFocus) {
-                //label.setForeground(ColorPreference.Category.Focus);
                 label.setBackground(ColorPreference.Category.Focus);
                 label.setOpaque(true);
             }
@@ -225,12 +212,18 @@ public class CategoryPanel extends JScrollPane {
             categoryTree.setSelectionPath(categoryTree.getPathForLocation(e.getX(), e.getY()));
             getSelectedNode().ifPresent(selectedNode -> {
                 if (selectedNode instanceof CategoryTreeNode) {
+                    mItemObject.setVisible(true);
+                    mItemSwitch.setVisible(true);
                     editItem.setVisible(false);
                     removeItem.setVisible(true);
                 } else if (selectedNode instanceof ObjectTreeNode) {
+                    mItemSwitch.setVisible(true);
+                    mItemObject.setVisible(true);
                     editItem.setVisible(true);
                     removeItem.setVisible(true);
                 }else{
+                    mItemObject.setVisible(false);
+                    mItemSwitch.setVisible(false);
                     editItem.setVisible(false);
                     removeItem.setVisible(false);
                 }
@@ -243,7 +236,7 @@ public class CategoryPanel extends JScrollPane {
                 return;
             }
             gui.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
-            Canvas groupNodeCanvas = gui.getCanvas();
+            Canvas groupNodeCanvas = gui.getActualCanvas();
             Optional<Point> positionInCanvas = Optional.ofNullable(groupNodeCanvas.getMousePosition());
             AbstractCanvasObject selectedObj = selected;
             selected = null;

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

@@ -7,6 +7,7 @@ import holeg.ui.controller.Control;
 import holeg.ui.model.GuiSettings;
 import holeg.model.Model;
 import holeg.ui.view.canvas.Canvas;
+import holeg.ui.view.canvas.CanvasCollectionPanel;
 import holeg.ui.view.image.Import;
 import holeg.utility.math.vector.Vec2i;
 
@@ -27,11 +28,9 @@ public class CanvasResizePopUp extends JDialog {
     private JLabel lblHeight = new JLabel("Height:");
     private JPanel buttonPanel = new JPanel();
 
-	public CanvasResizePopUp(Control controller, Canvas canvas, JTabbedPane tabbedPane, JFrame parentFrame) {
+	public CanvasResizePopUp(Control controller, JFrame parentFrame) {
         super((java.awt.Frame) null, true);
-		this.tabbedPane = tabbedPane;
 		this.controller = controller;
-		this.canvas = canvas;
 
 		// properties and stuff
 		this.setIconImage(Import.loadImage(ImagePreference.Logo,30,30));

+ 14 - 16
src/holeg/ui/view/inspector/UnitGraph.java

@@ -61,7 +61,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	private final Control control;
 
 	// Intern Variables
-	private class Series {
+	private static class Series {
 		public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
 		public TimelineDependent element;
 		public GraphType type;
@@ -70,16 +70,16 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
 	private final ArrayList<Series> seriesList = new ArrayList<>();
 	private Vec2i editPosition;
-	private Optional<Series> actualSeries;
+	private Series actualSeries = null;
 
-	private class GlobalCurve {
+	private static class GlobalCurve {
 		public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
 		public float minEnergy;
 		public float maxEnergy;
 		public LinkedList<UnitGraphPoint> zeroLinePoints = new LinkedList<UnitGraphPoint>();
 	}
 
-	private Optional<GlobalCurve> globalCurve = Optional.empty();
+	private GlobalCurve globalCurve = null;
 	private boolean editMode = false;
 	private Set<HolonElement> elements;
 	
@@ -104,6 +104,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
+		control.OnCanvasUpdate.addListener(this::repaint);
 	}
 
 	/**
@@ -129,7 +130,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
 	public void setGlobalCurve(Set<HolonElement> elements) {
 		if(elements.isEmpty()) {
-			this.globalCurve = Optional.empty();
+			this.globalCurve = null;
 			return;
 		}
 		GlobalCurve curve = new GlobalCurve();
@@ -162,7 +163,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
 		}
 		// set global curve
-		this.globalCurve = Optional.of(curve);
+		this.globalCurve = curve;
 		this.elements = elements;
 		
 	}
@@ -196,7 +197,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		g2d.setStroke(new BasicStroke(1));
 		drawCurrentIterationLine(g2d);
 		g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[]{6}, 3));
-		this.globalCurve.ifPresent(curve -> {
+		Optional.ofNullable(this.globalCurve).ifPresent(curve -> {
 			g2d.setColor(globalCurveColor);
 			drawDoubleGraph(g2d, curve.points);
 			g2d.setColor(zeroLineColor);
@@ -615,7 +616,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 				p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
 			}
 		}
-		this.globalCurve.ifPresent(curve -> {
+		Optional.ofNullable(this.globalCurve).ifPresent(curve -> {
 			for (UnitGraphPoint p : curve.points) {
 				p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
 			}
@@ -717,10 +718,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	/**
 	 * Determine if a Point is near the Cursor (depends on Mode what near means). To
 	 * detect if it should grab the Point or create a new Point.
-	 * 
-	 * @param actual
-	 * @param target
-	 * @return
+	 *
 	 */
 	private boolean near(Vec2i actual, Vec2i target, GraphType graphType) {
 		switch (graphType) {
@@ -842,7 +840,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 */
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		actualSeries.ifPresent(series -> {
+		Optional.ofNullable(this.actualSeries).ifPresent(series -> {
 			updateEditPointPosition(new Vec2i(e.getPoint().x, e.getPoint().y), this.editPointType, series.type);
 			updateGlobalCurve();
 			repaint();
@@ -874,8 +872,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	@Override
 	public void mousePressed(MouseEvent e) {
 		Vec2i mPosition = new Vec2i(e.getPoint().x, e.getPoint().y);
-		actualSeries = detectSeries(mPosition);
-		actualSeries.ifPresent(series -> {
+		detectSeries(mPosition).ifPresent(series -> {
+			actualSeries = series;
 			if (e.getButton() == MouseEvent.BUTTON3) {
 				// RightMouseButtonEvent
 				editPointType = detectStartEndPoint(series, mPosition);
@@ -903,7 +901,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 	 */
 	@Override
 	public void mouseReleased(MouseEvent e) {
-		if (editMode && actualSeries.isPresent()) {
+		if (editMode && actualSeries != null) {
 			for (Series series : seriesList) {
 				this.insertNewGraphPoint(series, editPosition);
 			}

+ 99 - 444
src/holeg/ui/view/main/Gui.java

@@ -1,20 +1,17 @@
 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.canvas.CanvasCollectionPanel;
 import holeg.ui.view.category.CategoryPanel;
-import holeg.ui.view.component.ButtonTabComponent;
 import holeg.ui.view.dialog.*;
 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;
@@ -30,468 +27,96 @@ import java.net.URI;
 import java.util.logging.Logger;
 import java.util.prefs.Preferences;
 
-/**
- * Graphical User Interface.
- *
- * @author Gruppe14
- */
 public class Gui extends JFrame{
     private static final Logger log = Logger.getLogger(Model.class.getName());
     private static final Preferences prefs = Preferences.userNodeForPackage(Gui.class);
+    private final Control control;
 
-    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 CategoryPanel categoryPanel;
-    // 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);
-
-
-    /******************************************
-     ************* Right Container*************
-     ******************************************
-     * Right Container: here comes the information about the HolonObject, such as
-     * HolonElements Information, Properties and Consumption/Production graph.
-     **/
+    private final CanvasCollectionPanel canvasCollection;
     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 UnitGraph unitGraph;
-    /**
-     * Textfield to show the period of an element
-     */
-    private final JTextField unitGraphLocalPeriod = new JTextField(6);
-    private final Canvas canvas;
-
-    // tabbedPaneOriginal or tabbedPaneSplit
-    private JTabbedPane tabTemp;
-    private Canvas actualOpenCanvas;
-    private JPanel contentPane;
-    // Time Stuff
-    private TimePanel timePanel;
-
-
+    private final TimePanel timePanel;
 
     /**
      * Create the application.
-     *
      * @param control the Controller
      */
     public Gui(Control control) {
+        super("HOLEG Simulator");
         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());
+        this.inspector = new Inspector(control);
         this.categoryPanel = new CategoryPanel(control, this);
-        this.actualOpenCanvas = this.canvas;
-        initialize();
+        this.canvasCollection = new CanvasCollectionPanel(control);
+        this.timePanel = new TimePanel(control);
+        init();
     }
 
-    public TimePanel getTimePanel() {
-        return timePanel;
+    private void init() {
+        initFrame();
+        initLayout();
     }
 
-    /**
-     * Initialize the contents of the frame.
-     */
-    private void initialize() {
-        this.setTitle("HOLEG Simulator");
-        this.setBounds(new Rectangle(1200, 800));
-        //Center
-        this.setLocationRelativeTo(null);
+    private void initFrame() {
+        this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
+        this.setBounds(new Rectangle(prefs.getInt(PreferenceKeys.Gui.Width, 1200), prefs.getInt(PreferenceKeys.Gui.Height, 800)));
+        if(prefs.get(PreferenceKeys.Gui.Width, null) != null){
+            this.setLocation(prefs.getInt(PreferenceKeys.Gui.XPos, 1200), prefs.getInt(PreferenceKeys.Gui.YPos, 800));
+        }else{
+            this.setLocationRelativeTo(null);
+        }
         this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-
         this.addWindowListener((WindowClosingListener) e -> {
+            Rectangle bounds = this.getBounds();
+            prefs.putInt(PreferenceKeys.Gui.XPos, bounds.x);
+            prefs.putInt(PreferenceKeys.Gui.YPos, bounds.y);
+            prefs.putInt(PreferenceKeys.Gui.Width, bounds.width);
+            prefs.putInt(PreferenceKeys.Gui.Height, bounds.height);
             if (JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "HOLEG",
                     JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                 System.exit(0);
             }
         });
+    }
 
-        contentPane = (JPanel) this.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);
+    private void initLayout() {
+        final JSplitPane categorySplit = new JSplitPane();
+        final JSplitPane canvasSplit = new JSplitPane();
+        final JSplitPane elementSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+        final JScrollPane informationPanelScrollPane = new JScrollPane();
         this.setJMenuBar(new GuiMenuBar());
-
-        this.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
-         *****************************/
-
         this.getContentPane().setLayout(new BorderLayout(0, 0));
-        /****************
-         * Tree Stuff
-         ****************/
-
-
-
-
-
-
-
-
-        this.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(categoryPanel);
-        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);
+        this.getContentPane().add(categorySplit);
+        categorySplit.setLeftComponent(categoryPanel);
+        categorySplit.setRightComponent(canvasSplit);
+        categorySplit.setDividerLocation(200);
+        categorySplit.setBorder(null);
+
+        canvasSplit.setMinimumSize(new Dimension(0, 25));
+        canvasSplit.setDividerLocation(500);
+        canvasSplit.setLeftComponent(canvasCollection);
+        canvasSplit.setRightComponent(elementSplit);
+        canvasSplit.setResizeWeight(0.9);
+        canvasSplit.setBorder(null);
+
+        elementSplit.setDividerLocation(700);
+        elementSplit.setTopComponent(inspector);
+        elementSplit.setBottomComponent(informationPanelScrollPane);
+        elementSplit.setBorder(null);
+
+        informationPanelScrollPane.setViewportView(this.informationPanel);
+        informationPanelScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+        informationPanelScrollPane.getVerticalScrollBar().setUnitIncrement(16);
+        informationPanelScrollPane.setBorder(null);
 
         this.getContentPane().add(timePanel, BorderLayout.SOUTH);
-
-        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();
-            }
-        });
-    }
-
-    /*
-     * Open a new Tab with an UpperNodeCanvas
-     */
-    public void openNewUpperNodeTab(GroupNode node) {
-        chooseTabTemp();
-
-        JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-        if (scrollPane.getViewport().getComponent(0) instanceof Canvas canvasPanel) {
-            actualOpenCanvas = 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(actualOpenCanvas);
-            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);
+    public Canvas getActualCanvas() {
+        return this.canvasCollection.getActualCanvas();
     }
 
-    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 Canvas getCanvas() {
-        return canvas;
-    }
-
-    public JFrame getFrame() {
-        return this;
-    }
-
-
     private class GuiMenuBar extends JMenuBar {
         //Menus
         private final JMenu fileMenu = new JMenu("File");
@@ -509,6 +134,14 @@ public class Gui extends JFrame{
         // EditMenu
         private final JMenuItem undoButton = new JMenuItem("Undo");
         private final JMenuItem redoButton = new JMenuItem("Redo");
+        private final JMenuItem copyButton = new JMenuItem("Copy");
+        private final JMenuItem pasteButton = new JMenuItem("Paste");
+        private final JMenuItem cutButton = new JMenuItem("Cut");
+        private final JMenu selectionMenu = new JMenu("Selection");
+        private final JMenuItem selectAllButton = new JMenuItem("All");
+        private final JMenuItem clearSelectionButton = new JMenuItem("Clear");
+        private final JMenuItem invertSelectionButton = new JMenuItem("Invert");
+
         private final JMenuItem edgePropertiesButton = new JMenuItem("Edge Properties");
         private final JMenuItem alignAllButton = new JMenuItem("Align All");
         private final JMenu resetMenu = new JMenu("Reset");
@@ -527,13 +160,15 @@ public class Gui extends JFrame{
         private final JMenuItem canvasSizeButton = new JMenuItem("Set View Size");
         private final JCheckBoxMenuItem showSupplyBarsCheckBox = new JCheckBoxMenuItem("Show supply bars.", true);
         private final JFileChooser fileChooser = initFileChooser();
+
+        private final int IconSize = 15;
         //WindowMenu
         JMenuItem algorithmButton = new JMenuItem("Algorithm Panel", new ImageIcon(Import
-                .loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)));
+                .loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(IconSize, IconSize, 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)));
+                .loadImage(ImagePreference.Button.Menu.Outliner).getScaledInstance(IconSize, IconSize, 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)));
+                .loadImage(ImagePreference.Button.Menu.Algo).getScaledInstance(IconSize, IconSize, java.awt.Image.SCALE_SMOOTH)));
 
         GuiMenuBar() {
             initMenuLayout();
@@ -556,7 +191,6 @@ public class Gui extends JFrame{
             add(viewMenu);
             add(windowMenu);
             add(helpMenu);
-
             fileMenu.add(newMenuButton);
             fileMenu.add(openMenuButton);
             fileMenu.addSeparator();
@@ -565,9 +199,20 @@ public class Gui extends JFrame{
 
             editMenu.add(undoButton);
             editMenu.add(redoButton);
+            editMenu.addSeparator();
+            editMenu.add(copyButton);
+            editMenu.add(pasteButton);
+            editMenu.add(cutButton);
+            editMenu.addSeparator();
+            editMenu.add(selectionMenu);
+            selectionMenu.add(selectAllButton);
+            selectionMenu.add(clearSelectionButton);
+            selectionMenu.add(invertSelectionButton);
+            editMenu.addSeparator();
             editMenu.add(edgePropertiesButton);
             editMenu.add(alignAllButton);
             editMenu.add(resetMenu);
+
             resetMenu.add(resetCategoryButton);
 
             helpMenu.add(introductionButton);
@@ -591,17 +236,14 @@ public class Gui extends JFrame{
             saveMenuButton.addActionListener(clicked -> saveFile());
             saveAsMenuButton.addActionListener(clicked -> saveNewFile());
             edgePropertiesButton.addActionListener(actionEvent -> new EditEdgesPopUp(Gui.this, control));
-            //TODO(Tom2022-01-14): recreateTryToAlignObjects
             alignAllButton.addActionListener(clicked -> {
+                //TODO(Tom2022-01-14): recreateTryToAlignObjects
                 log.info("Not implemented yet.");
             });
             resetCategoryButton.addActionListener(clicked -> control.resetCategories());
 
             showSupplyBarsCheckBox.addActionListener(clicked -> toggleSupplyBarAppearance());
-            canvasSizeButton.addActionListener(clicked -> new CanvasResizePopUp(control, canvas, tabbedPaneInnerOriginal,
-                    Gui.this));
-
-
+            canvasSizeButton.addActionListener(clicked -> new CanvasResizePopUp(control, Gui.this));
             algorithmButton.addActionListener(clicked -> new AddOnWindow(Gui.this, control));
             outlinerButton.addActionListener(clicked -> new Outliner(Gui.this, control));
             flexMenuButton.addActionListener(clicked -> new FlexWindow(Gui.this, control));
@@ -615,23 +257,39 @@ public class Gui extends JFrame{
             aboutUsButton.addActionListener(clicked -> new AboutUsPopUp(Gui.this));
         }
 
+        private void openWebpage(String URL) {
+            try {
+                java.awt.Desktop.getDesktop().browse(new URI(URL));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
         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));
+            undoButton.setAccelerator(KeyStroke.getKeyStroke('Z', defaultModifier));
+            redoButton.setAccelerator(KeyStroke.getKeyStroke('Y', defaultModifier));
+            copyButton.setAccelerator(KeyStroke.getKeyStroke('C', defaultModifier));
+            pasteButton.setAccelerator(KeyStroke.getKeyStroke('V', defaultModifier));
+            cutButton.setAccelerator(KeyStroke.getKeyStroke('X', defaultModifier));
+            selectAllButton.setAccelerator(KeyStroke.getKeyStroke('A', defaultModifier));
+            clearSelectionButton.setAccelerator(KeyStroke.getKeyStroke('A', defaultModifier + InputEvent.SHIFT_DOWN_MASK));
+            invertSelectionButton.setAccelerator(KeyStroke.getKeyStroke('I', 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(this) == JFileChooser.APPROVE_OPTION) {
                 String path = fileChooser.getSelectedFile().getPath();
@@ -642,13 +300,12 @@ public class Gui extends JFrame{
                 control.saveFile(new File(path));
             }
         }
+
         private void openFile() {
             if (fileChooser.showOpenDialog(this) == 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();
             }
         }
 
@@ -662,7 +319,5 @@ public class Gui extends JFrame{
             }
             control.clearModel();
         }
-
     }
-
 }

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

@@ -93,15 +93,12 @@ public class TimePanel extends JPanel implements ActionListener {
 	};
 	private final Control control;
 	private int dragResetIteration = 0;
-	private JLabel simSpeedLabel = new JLabel("Speed:");
-	private JSlider speedSlider = new JSlider();
-	private Timer timer;
+	private final JSlider speedSlider = new JSlider();
+	private final Timer timer;
 	private boolean running = false;
 
 	/**
-	 * Constructor.
-	 * 
-	 * @param mod  the Model
+	 * Constructor
 	 * @param cont the Controller
 	 */
 	public TimePanel(Control cont) {
@@ -122,6 +119,11 @@ public class TimePanel extends JPanel implements ActionListener {
 		timeSlider.setValue(0);
 		timeSlider.addChangeListener(changeEvent -> control.getModel().setCurrentIteration(timeSlider.getValue()));
 
+		this.setBorder(null);
+		timeSlider.addChangeListener(changeEvent -> {
+			control.calculateStateAndVisualForTimeStep(timeSlider.getValue());
+		});
+
 		timeSlider.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
@@ -199,6 +201,7 @@ public class TimePanel extends JPanel implements ActionListener {
 
 		// Speed Panel
 		JPanel speedPanel = new JPanel();
+		JLabel simSpeedLabel = new JLabel("Speed:");
 		speedPanel.add(simSpeedLabel);
 		speedPanel.add(speedSlider);
 		speedSlider.setPaintTicks(true);