|
@@ -8,10 +8,9 @@ import holeg.preferences.PreferenceKeys;
|
|
|
import holeg.ui.controller.Control;
|
|
|
import holeg.ui.model.GuiSettings;
|
|
|
import holeg.ui.view.canvas.Canvas;
|
|
|
-import holeg.ui.view.category.Category;
|
|
|
+import holeg.ui.view.category.CategoryPanel;
|
|
|
import holeg.ui.view.component.ButtonTabComponent;
|
|
|
import holeg.ui.view.dialog.*;
|
|
|
-import holeg.ui.view.dialog.CreateNewDialog.Option;
|
|
|
import holeg.ui.view.image.Import;
|
|
|
import holeg.ui.view.information.HolonInformationPanel;
|
|
|
import holeg.ui.view.inspector.Inspector;
|
|
@@ -19,18 +18,15 @@ import holeg.ui.view.inspector.UnitGraph;
|
|
|
import holeg.ui.view.window.AddOnWindow;
|
|
|
import holeg.ui.view.window.FlexWindow;
|
|
|
import holeg.ui.view.window.Outliner;
|
|
|
+import holeg.utility.listener.WindowClosingListener;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
import javax.swing.filechooser.FileSystemView;
|
|
|
-import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
-import javax.swing.tree.DefaultTreeModel;
|
|
|
-import javax.swing.tree.TreeCellRenderer;
|
|
|
import java.awt.*;
|
|
|
import java.awt.event.*;
|
|
|
import java.io.File;
|
|
|
import java.net.URI;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.logging.Logger;
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
@@ -39,7 +35,7 @@ import java.util.prefs.Preferences;
|
|
|
*
|
|
|
* @author Gruppe14
|
|
|
*/
|
|
|
-public class Gui {
|
|
|
+public class Gui extends JFrame{
|
|
|
private static final Logger log = Logger.getLogger(Model.class.getName());
|
|
|
private static final Preferences prefs = Preferences.userNodeForPackage(Gui.class);
|
|
|
|
|
@@ -51,14 +47,14 @@ public class Gui {
|
|
|
private final JTabbedPane tabbedPaneInnerOriginal = new JTabbedPane(JTabbedPane.TOP);
|
|
|
|
|
|
private final JScrollPane canvasSP = new JScrollPane();
|
|
|
- private final JScrollPane scrollPane1 = new JScrollPane();
|
|
|
+ private final CategoryPanel categoryPanel;
|
|
|
|
|
|
|
|
|
|
|
|
private final JTabbedPane tabbedPaneOriginal = new JTabbedPane(JTabbedPane.TOP);
|
|
|
private final JPopupMenu popmenuEdit = new JPopupMenu();
|
|
|
private final JMenuItem editItem = new JMenuItem("Edit Object");
|
|
|
- private final JTree categoryTree = new JTree();
|
|
|
+
|
|
|
|
|
|
************* Right Container*************
|
|
|
******************************************
|
|
@@ -74,48 +70,22 @@ public class Gui {
|
|
|
private final Control control;
|
|
|
|
|
|
|
|
|
- private final JPanel panel = new JPanel();
|
|
|
- private final JButton btnAdd = new JButton();
|
|
|
-
|
|
|
- private final JPopupMenu btnAddPopUp = new JPopupMenu("New");
|
|
|
- private final JMenuItem mItemNew = new JMenuItem("New..");
|
|
|
- private final JMenuItem mItemCategory = new JMenuItem("Category");
|
|
|
- private final JMenuItem mItemObject = new JMenuItem("Object");
|
|
|
- private final JMenuItem mItemSwitch = new JMenuItem("Switch");
|
|
|
- private final JButton btnDel = new JButton();
|
|
|
- private final JToolBar toolBar = new JToolBar();
|
|
|
- private final JToolBar toolBarHolonEl = new JToolBar();
|
|
|
+
|
|
|
private final UnitGraph unitGraph;
|
|
|
|
|
|
* Textfield to show the period of an element
|
|
|
*/
|
|
|
private final JTextField unitGraphLocalPeriod = new JTextField(6);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private Canvas canvas;
|
|
|
-
|
|
|
- private JFrame holegJFrame;
|
|
|
+ private final Canvas canvas;
|
|
|
|
|
|
|
|
|
private JTabbedPane tabTemp;
|
|
|
- private String catOfObjToBeEdited;
|
|
|
- private Canvas unc;
|
|
|
+ private Canvas actualOpenCanvas;
|
|
|
private JPanel contentPane;
|
|
|
-
|
|
|
- private AddObjectPopUp addObjectPopUP;
|
|
|
- private AboutUsPopUp aboutUsPopUp;
|
|
|
-
|
|
|
- private boolean dragging = false;
|
|
|
- private String actualObjectClicked;
|
|
|
- private Image img = null;
|
|
|
- private AbstractCanvasObject tempCps = null;
|
|
|
|
|
|
private TimePanel timePanel;
|
|
|
- private AbstractCanvasObject temp = null;
|
|
|
- private String eraseCategory = "Do you really want to delete the Category ";
|
|
|
- private String selectObjBeforeErase = "Please select a Category or an Object in the left library in order to delete something.";
|
|
|
- private JMenuItem removeItem = new JMenuItem("Remove");
|
|
|
+
|
|
|
+ private final JMenuItem removeItem = new JMenuItem("Remove");
|
|
|
|
|
|
|
|
|
* Create the application.
|
|
@@ -129,10 +99,9 @@ public class Gui {
|
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
this.unitGraph = new UnitGraph(control);
|
|
|
this.canvas = new Canvas(control, control.getModel().getCanvas());
|
|
|
+ this.categoryPanel = new CategoryPanel(control, this);
|
|
|
+ this.actualOpenCanvas = this.canvas;
|
|
|
initialize();
|
|
|
- updateCategories(GuiSettings.getCategories());
|
|
|
- control.OnCategoryChanged.addListener(() -> this.updateCategoryUI(GuiSettings.getCategories()));
|
|
|
- this.unc = this.canvas;
|
|
|
}
|
|
|
|
|
|
public TimePanel getTimePanel() {
|
|
@@ -143,25 +112,20 @@ public class Gui {
|
|
|
* Initialize the contents of the frame.
|
|
|
*/
|
|
|
private void initialize() {
|
|
|
- holegJFrame = new JFrame();
|
|
|
- holegJFrame.setTitle("HOLEG Simulator");
|
|
|
- holegJFrame.setBounds(new Rectangle(1200, 800));
|
|
|
+ this.setTitle("HOLEG Simulator");
|
|
|
+ this.setBounds(new Rectangle(1200, 800));
|
|
|
|
|
|
- holegJFrame.setLocationRelativeTo(null);
|
|
|
- holegJFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|
|
+ this.setLocationRelativeTo(null);
|
|
|
+ this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|
|
|
|
|
- holegJFrame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
- @Override
|
|
|
- public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
|
|
- if (JOptionPane.showConfirmDialog(holegJFrame, "Are you sure you want to exit?", "HOLEG",
|
|
|
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
|
|
|
-
|
|
|
- System.exit(0);
|
|
|
- }
|
|
|
+ this.addWindowListener((WindowClosingListener) e -> {
|
|
|
+ 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) holegJFrame.getContentPane();
|
|
|
+ contentPane = (JPanel) this.getContentPane();
|
|
|
|
|
|
int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
|
|
|
InputMap inputMap = contentPane.getInputMap(condition);
|
|
@@ -273,9 +237,9 @@ public class Gui {
|
|
|
}
|
|
|
};
|
|
|
actionMap.put(cntrlXDown, controlX);
|
|
|
- holegJFrame.setJMenuBar(new GuiMenuBar());
|
|
|
+ this.setJMenuBar(new GuiMenuBar());
|
|
|
|
|
|
- holegJFrame.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
|
|
|
+ this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
|
|
|
|
|
|
|
|
|
|
|
@@ -323,334 +287,40 @@ public class Gui {
|
|
|
* RIGHT CONTAINER DONE
|
|
|
*****************************/
|
|
|
|
|
|
- holegJFrame.getContentPane().setLayout(new BorderLayout(0, 0));
|
|
|
+ this.getContentPane().setLayout(new BorderLayout(0, 0));
|
|
|
|
|
|
* Tree Stuff
|
|
|
****************/
|
|
|
|
|
|
-
|
|
|
- inputMap = categoryTree.getInputMap();
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
|
|
|
-
|
|
|
- TreeCellRenderer customRenderer = new TreeCellRenderer() {
|
|
|
- @Override
|
|
|
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
|
|
|
- boolean leaf, int row, boolean hasFocus) {
|
|
|
- JLabel label = new JLabel();
|
|
|
- Image imgR;
|
|
|
- if (leaf) {
|
|
|
- for (Category cat : GuiSettings.getCategories()) {
|
|
|
- for (AbstractCanvasObject cps : cat.getObjects()) {
|
|
|
- if (value.toString().equals(cps.getName())) {
|
|
|
- imgR = Import.loadImage(cps.getImagePath(), 50, 50);
|
|
|
- if (imgR != null) {
|
|
|
- label.setIcon(new ImageIcon(imgR));
|
|
|
- }
|
|
|
- label.setText(cps.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- tree.setRowHeight(50);
|
|
|
- if (hasFocus) {
|
|
|
- label.setForeground(ColorPreference.Category.Focus);
|
|
|
- label.setOpaque(true);
|
|
|
- }
|
|
|
- if (label.getText().isEmpty()) {
|
|
|
- label.setText(value.toString());
|
|
|
- if (!value.toString().equals("Categories")) {
|
|
|
- label.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Category.Folder)));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return label;
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- categoryTree.setCellRenderer(customRenderer);
|
|
|
-
|
|
|
- categoryTree.addMouseMotionListener(new MouseMotionAdapter() {
|
|
|
|
|
|
- public void mouseDragged(MouseEvent e) {
|
|
|
- checkForDragAndDrop(e);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * checks if an object of the current Panel could be replaced by the dragged
|
|
|
- * object
|
|
|
- *
|
|
|
- * @param e
|
|
|
- */
|
|
|
- private void checkForDragAndDrop(MouseEvent e) {
|
|
|
- try {
|
|
|
-
|
|
|
- * if no object gets dragged -> finished
|
|
|
- */
|
|
|
- if (!dragging)
|
|
|
- return;
|
|
|
-
|
|
|
-
|
|
|
- * select the current Panel
|
|
|
- */
|
|
|
- chooseTabTemp();
|
|
|
- JScrollPane scrollPane = getScrollPaneFromTabbedPane();
|
|
|
- if (scrollPane == null)
|
|
|
- return;
|
|
|
- Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
|
|
|
-
|
|
|
-
|
|
|
- * check for replacements on the canvas
|
|
|
- */
|
|
|
- if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
|
|
|
- if (unc.getMousePosition() == null)
|
|
|
- return;
|
|
|
- int x = (int) unc.getMousePosition().getX() + 16;
|
|
|
- int y = (int) unc.getMousePosition().getY() + 16;
|
|
|
-
|
|
|
-
|
|
|
- * check for replacement
|
|
|
- */
|
|
|
- groupNodeCanvas.checkForReplacement(x, y);
|
|
|
-
|
|
|
-
|
|
|
- * repaint
|
|
|
- */
|
|
|
- unc.invalidate();
|
|
|
- unc.repaint();
|
|
|
- } else {
|
|
|
- if (canvas.getMousePosition() == null)
|
|
|
- return;
|
|
|
- int x = (int) canvas.getMousePosition().getX() + 16;
|
|
|
- int y = (int) canvas.getMousePosition().getY() + 16;
|
|
|
-
|
|
|
-
|
|
|
- * check for replacement
|
|
|
- */
|
|
|
- canvas.checkForReplacement(x, y);
|
|
|
-
|
|
|
-
|
|
|
- * repaint
|
|
|
- */
|
|
|
- log.info("canvas.repaint5");
|
|
|
- canvas.repaint();
|
|
|
- }
|
|
|
- contentPane.updateUI();
|
|
|
-
|
|
|
- } catch (Exception eex) {
|
|
|
- eex.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- categoryTree.addMouseListener(new MouseAdapter() {
|
|
|
-
|
|
|
- public void mouseReleased(MouseEvent e) {
|
|
|
- try {
|
|
|
- if (dragging) {
|
|
|
- chooseTabTemp();
|
|
|
- JScrollPane scrollPane = getScrollPaneFromTabbedPane();
|
|
|
- Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
|
|
|
-
|
|
|
- if (canvasOrUpperNodeCanvas instanceof Canvas groupNodeCanvas) {
|
|
|
- int x = (int) groupNodeCanvas.getMousePosition().getX() + 16;
|
|
|
- int y = (int) groupNodeCanvas.getMousePosition().getY() + 16;
|
|
|
-
|
|
|
- AbstractCanvasObject h = null;
|
|
|
- if (tempCps instanceof HolonObject hO) {
|
|
|
- h = new HolonObject(hO);
|
|
|
- }
|
|
|
- if (tempCps instanceof HolonSwitch sw) {
|
|
|
- h = new HolonSwitch(sw);
|
|
|
- }
|
|
|
- h.setPosition(x, y);
|
|
|
- control.addObjectCanvas(control.getModel().getCanvas(), h);
|
|
|
-
|
|
|
-
|
|
|
- * object would be replaced
|
|
|
- */
|
|
|
- groupNodeCanvas.invalidate();
|
|
|
- control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
- groupNodeCanvas.repaint();
|
|
|
- } else {
|
|
|
- int x = (int) canvas.getMousePosition().getX() + 16;
|
|
|
- int y = (int) canvas.getMousePosition().getY() + 16;
|
|
|
-
|
|
|
- AbstractCanvasObject h = null;
|
|
|
- if (tempCps instanceof HolonObject hO) {
|
|
|
- h = new HolonObject(hO);
|
|
|
- }
|
|
|
- if (tempCps instanceof HolonSwitch sw) {
|
|
|
- h = new HolonSwitch(sw);
|
|
|
- }
|
|
|
-
|
|
|
- h.setPosition(x, y);
|
|
|
-
|
|
|
-
|
|
|
- * close UpperNodeTabs of replaced UpperNode
|
|
|
- */
|
|
|
-
|
|
|
- control.addObjectCanvas(control.getModel().getCanvas(), h);
|
|
|
-
|
|
|
- * no object should get replaced
|
|
|
- */
|
|
|
- log.info("canvas.repaint6");
|
|
|
- canvas.repaint();
|
|
|
- }
|
|
|
- control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
- contentPane.updateUI();
|
|
|
- dragging = false;
|
|
|
- }
|
|
|
- } catch (Exception eex) {
|
|
|
- }
|
|
|
- holegJFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
popmenuEdit.add(editItem);
|
|
|
popmenuEdit.add(removeItem);
|
|
|
editItem.setEnabled(false);
|
|
|
- editItem.addActionListener(actionEvent -> {
|
|
|
- });
|
|
|
- categoryTree.addMouseListener(new MouseAdapter() {
|
|
|
-
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
- try {
|
|
|
- actualObjectClicked = categoryTree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent()
|
|
|
- .toString();
|
|
|
-
|
|
|
-
|
|
|
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) categoryTree
|
|
|
- .getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
|
|
|
- if (SwingUtilities.isRightMouseButton(e)) {
|
|
|
- for (Category cat : GuiSettings.getCategories()) {
|
|
|
- for (AbstractCanvasObject cps : cat.getObjects()) {
|
|
|
- if (actualObjectClicked.equals(cps.getName())
|
|
|
- && !(cps instanceof HolonSwitch)) {
|
|
|
- editItem.setEnabled(true);
|
|
|
- popmenuEdit.show(e.getComponent(), e.getX(), e.getY());
|
|
|
- catOfObjToBeEdited = selectedNode.getParent().toString();
|
|
|
- tempCps = cps;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- for (Category cat : GuiSettings.getCategories()) {
|
|
|
- for (AbstractCanvasObject cps : cat.getObjects()) {
|
|
|
- if (actualObjectClicked.equals(cps.getName())) {
|
|
|
- File checkPath = new File(cps.getImagePath());
|
|
|
- if (checkPath.exists()) {
|
|
|
- img = new ImageIcon(cps.getImagePath()).getImage().getScaledInstance(32, 32,
|
|
|
- java.awt.Image.SCALE_SMOOTH);
|
|
|
- } else {
|
|
|
- img = Import.loadImage(cps.getImagePath(), 32, 32);
|
|
|
- }
|
|
|
- tempCps = cps;
|
|
|
- dragging = true;
|
|
|
- Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
|
|
|
- "Image");
|
|
|
- holegJFrame.setCursor(cursor);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception eex) {
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ String catOfObjToBeEdited = "TEST";
|
|
|
editItem.addActionListener(actionEvent -> {
|
|
|
|
|
|
|
|
|
|
|
|
- System.out.println("Edit");
|
|
|
- addObjectPopUP = new AddObjectPopUp(true, tempCps, catOfObjToBeEdited, holegJFrame);
|
|
|
+ log.warning("EDITITEM");
|
|
|
+ AddObjectPopUp addObjectPopUP = new AddObjectPopUp(true, null, catOfObjToBeEdited, this);
|
|
|
addObjectPopUP.setCategory(catOfObjToBeEdited);
|
|
|
addObjectPopUP.setController(control);
|
|
|
addObjectPopUP.setVisible(true);
|
|
|
});
|
|
|
removeItem.addActionListener(actionEvent -> {
|
|
|
|
|
|
- log.info("catOfObjToBeEdited:" + catOfObjToBeEdited + ", tempCps:" + tempCps);
|
|
|
+ log.warning("REMOVEITEM");
|
|
|
+ log.info("catOfObjToBeEdited:" + catOfObjToBeEdited + ", tempCps:" + null);
|
|
|
control.findCategoryWithName(catOfObjToBeEdited).ifPresent(cat -> {
|
|
|
- cat.removeObjectsWithName(tempCps.getName());
|
|
|
+ cat.removeObjectsWithName("");
|
|
|
});
|
|
|
});
|
|
|
- scrollPane1.setViewportView(categoryTree);
|
|
|
|
|
|
- scrollPane1.setColumnHeaderView(panel);
|
|
|
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
- toolBar.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
|
- toolBar.setFloatable(false);
|
|
|
|
|
|
- panel.add(toolBar);
|
|
|
- btnAddPopUp.add(mItemNew);
|
|
|
- mItemNew.addActionListener(actionEvent -> {
|
|
|
- new CreateNewDialog(control, holegJFrame);
|
|
|
- });
|
|
|
- btnAddPopUp.addSeparator();
|
|
|
- btnAddPopUp.add(mItemCategory);
|
|
|
- mItemCategory.addActionListener(actionEvent -> {
|
|
|
- new CreateNewDialog(control, Option.Category, holegJFrame);
|
|
|
- });
|
|
|
- btnAddPopUp.add(mItemObject);
|
|
|
- mItemObject.addActionListener(actionEvent -> {
|
|
|
- new CreateNewDialog(control, Option.Object, holegJFrame);
|
|
|
- });
|
|
|
- btnAddPopUp.add(mItemSwitch);
|
|
|
- mItemSwitch.addActionListener(actionEvent -> {
|
|
|
- new CreateNewDialog(control, Option.Switch, holegJFrame);
|
|
|
- });
|
|
|
- btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, -1, +20));
|
|
|
- btnAdd.setIcon(new ImageIcon(Import.loadImage("images/buttons/plus.png", 16, 16)));
|
|
|
- btnAdd.setToolTipText("<html><b>New</b><br>Add a new Category or Item to the library.</html>");
|
|
|
- toolBar.add(btnAdd);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- btnDel.addActionListener(actionEvent -> {
|
|
|
- Object nodeInfo = categoryTree.getLastSelectedPathComponent();
|
|
|
- if (nodeInfo != null) {
|
|
|
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
|
|
|
- String nodeName = selectedNode.getUserObject().toString();
|
|
|
- int depthOfNode = selectedNode.getLevel();
|
|
|
- try {
|
|
|
- switch (depthOfNode) {
|
|
|
- case 1:
|
|
|
- int dialogResult = JOptionPane.showConfirmDialog(holegJFrame, eraseCategory + nodeName + "?",
|
|
|
- "Warning", JOptionPane.YES_NO_OPTION);
|
|
|
- if (dialogResult == JOptionPane.YES_OPTION) {
|
|
|
- GuiSettings.getCategories().stream().filter(cat -> cat.getName() == nodeName).findAny()
|
|
|
- .ifPresent(cat -> {
|
|
|
- control.deleteCategory(cat);
|
|
|
- });
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
|
|
|
- control.findCategoryWithName(parent.getUserObject().toString()).ifPresent(cat -> {
|
|
|
- cat.removeObjectsWithName(nodeName);
|
|
|
- });
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
|
|
|
- }
|
|
|
- } catch (Exception e2) {
|
|
|
- }
|
|
|
|
|
|
- } else {
|
|
|
- JOptionPane.showMessageDialog(holegJFrame, selectObjBeforeErase);
|
|
|
- }
|
|
|
- categoryTree.repaint();
|
|
|
- });
|
|
|
- btnDel.setIcon(new ImageIcon(Import.loadImage("images/buttons/minus.png", 16, 16)));
|
|
|
- btnDel.setToolTipText("<html><b>Delete</b><br>Removes a Category or a Category Item.</html>");
|
|
|
- toolBar.add(btnDel);
|
|
|
|
|
|
- holegJFrame.getContentPane().add(splitPane);
|
|
|
+ this.getContentPane().add(splitPane);
|
|
|
|
|
|
timePanel = new TimePanel(control);
|
|
|
timePanel.setBorder(null);
|
|
@@ -665,7 +335,7 @@ public class Gui {
|
|
|
splitPane.setDividerLocation(200);
|
|
|
splitPane1.setDividerLocation(500);
|
|
|
|
|
|
- splitPane.setLeftComponent(scrollPane1);
|
|
|
+ splitPane.setLeftComponent(categoryPanel);
|
|
|
tabbedPaneOriginal.addTab("View", tabbedPaneInnerOriginal);
|
|
|
|
|
|
myPanel.add(canvasSP, BorderLayout.CENTER);
|
|
@@ -695,7 +365,7 @@ public class Gui {
|
|
|
splitHolonElPro.setBorder(null);
|
|
|
canvasSP.setBorder(null);
|
|
|
|
|
|
- holegJFrame.getContentPane().add(timePanel, BorderLayout.SOUTH);
|
|
|
+ this.getContentPane().add(timePanel, BorderLayout.SOUTH);
|
|
|
|
|
|
canvasSP.addComponentListener(new ComponentAdapter() {
|
|
|
@Override
|
|
@@ -709,46 +379,6 @@ public class Gui {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- * reloads the Categories from Model.
|
|
|
- *
|
|
|
- * @param categories the current categories
|
|
|
- */
|
|
|
- private void updateCategories(Collection<Category> categories) {
|
|
|
- DefaultTreeModel treemodel = new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
|
|
|
-
|
|
|
- {
|
|
|
- DefaultMutableTreeNode node1;
|
|
|
- for (Category c : categories) {
|
|
|
- node1 = new DefaultMutableTreeNode(c.getName());
|
|
|
-
|
|
|
- for (AbstractCanvasObject obj : c.getObjects()) {
|
|
|
- node1.add(new DefaultMutableTreeNode(obj.getName()));
|
|
|
- }
|
|
|
- add(node1);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- categoryTree.setModel(treemodel);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * When changes are made to the Categories.
|
|
|
- *
|
|
|
- * @param categories the Categories
|
|
|
- */
|
|
|
- public void updateCategoryUI(Collection<Category> categories) {
|
|
|
- DefaultTreeModel model = (DefaultTreeModel) categoryTree.getModel();
|
|
|
- updateCategories(categories);
|
|
|
- model.reload();
|
|
|
- }
|
|
|
-
|
|
|
- public void setVisible(boolean value) {
|
|
|
- holegJFrame.setVisible(value);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* Open a new Tab with an UpperNodeCanvas
|
|
|
*/
|
|
@@ -757,7 +387,7 @@ public class Gui {
|
|
|
|
|
|
JScrollPane scrollPane = getScrollPaneFromTabbedPane();
|
|
|
if (scrollPane.getViewport().getComponent(0) instanceof Canvas canvasPanel) {
|
|
|
- unc = new Canvas(control, node);
|
|
|
+ actualOpenCanvas = new Canvas(control, node);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -780,7 +410,7 @@ public class Gui {
|
|
|
}
|
|
|
}
|
|
|
if (!dupl) {
|
|
|
- JScrollPane sp = new JScrollPane(unc);
|
|
|
+ JScrollPane sp = new JScrollPane(actualOpenCanvas);
|
|
|
sp.setBorder(null);
|
|
|
|
|
|
|
|
@@ -875,6 +505,13 @@ public class Gui {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public Canvas getCanvas() {
|
|
|
+ return canvas;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JFrame getFrame() {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private class GuiMenuBar extends JMenuBar {
|
|
@@ -975,7 +612,7 @@ public class Gui {
|
|
|
openMenuButton.addActionListener(clicked -> openFile());
|
|
|
saveMenuButton.addActionListener(clicked -> saveFile());
|
|
|
saveAsMenuButton.addActionListener(clicked -> saveNewFile());
|
|
|
- edgePropertiesButton.addActionListener(actionEvent -> new EditEdgesPopUp(holegJFrame, control));
|
|
|
+ edgePropertiesButton.addActionListener(actionEvent -> new EditEdgesPopUp(Gui.this, control));
|
|
|
|
|
|
alignAllButton.addActionListener(clicked -> {
|
|
|
log.info("Not implemented yet.");
|
|
@@ -984,12 +621,12 @@ public class Gui {
|
|
|
|
|
|
showSupplyBarsCheckBox.addActionListener(clicked -> toggleSupplyBarAppearance());
|
|
|
canvasSizeButton.addActionListener(clicked -> new CanvasResizePopUp(control, canvas, tabbedPaneInnerOriginal,
|
|
|
- holegJFrame));
|
|
|
+ Gui.this));
|
|
|
|
|
|
|
|
|
- algorithmButton.addActionListener(clicked -> new AddOnWindow(holegJFrame, control));
|
|
|
- outlinerButton.addActionListener(clicked -> new Outliner(holegJFrame, control));
|
|
|
- flexMenuButton.addActionListener(clicked -> new FlexWindow(holegJFrame, control));
|
|
|
+ algorithmButton.addActionListener(clicked -> new AddOnWindow(Gui.this, control));
|
|
|
+ outlinerButton.addActionListener(clicked -> new Outliner(Gui.this, control));
|
|
|
+ flexMenuButton.addActionListener(clicked -> new FlexWindow(Gui.this, control));
|
|
|
|
|
|
|
|
|
String tkWikiWebpage = "https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons/wiki/";
|
|
@@ -997,7 +634,7 @@ public class Gui {
|
|
|
userManualButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "User+Manual+V2.1"));
|
|
|
algorithmHelpButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "Algorithms+V2.1"));
|
|
|
codeDocumentationButton.addActionListener(clicked -> openWebpage(tkWikiWebpage + "Code+documentation+V2.1"));
|
|
|
- aboutUsButton.addActionListener(clicked -> new AboutUsPopUp(holegJFrame));
|
|
|
+ aboutUsButton.addActionListener(clicked -> new AboutUsPopUp(Gui.this));
|
|
|
}
|
|
|
|
|
|
private void initButtonShortCuts() {
|
|
@@ -1018,7 +655,7 @@ public class Gui {
|
|
|
GuiSettings.getActualSaveFile().ifPresentOrElse(control::saveFile, this::saveNewFile);
|
|
|
}
|
|
|
private void saveNewFile() {
|
|
|
- if (fileChooser.showSaveDialog(holegJFrame) == JFileChooser.APPROVE_OPTION) {
|
|
|
+ if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
|
String path = fileChooser.getSelectedFile().getPath();
|
|
|
if (!path.endsWith(".json")) {
|
|
|
path += ".json";
|
|
@@ -1028,7 +665,7 @@ public class Gui {
|
|
|
}
|
|
|
}
|
|
|
private void openFile() {
|
|
|
- if (fileChooser.showOpenDialog(holegJFrame) == JFileChooser.APPROVE_OPTION) {
|
|
|
+ if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
|
prefs.put(PreferenceKeys.Gui.DefaultFolder, fileChooser.getCurrentDirectory().getPath());
|
|
|
control.loadFile(fileChooser.getSelectedFile());
|
|
|
|
|
@@ -1039,7 +676,7 @@ public class Gui {
|
|
|
|
|
|
private void newFile() {
|
|
|
if (control.getModel().getCanvas().getObjectsInThisLayer().findAny().isPresent()) {
|
|
|
- int selectedOption = JOptionPane.showConfirmDialog(holegJFrame, "Do you want to save your current model?",
|
|
|
+ int selectedOption = JOptionPane.showConfirmDialog(this, "Do you want to save your current model?",
|
|
|
"Warning", JOptionPane.YES_NO_OPTION);
|
|
|
if (selectedOption == JOptionPane.YES_OPTION) {
|
|
|
saveNewFile();
|