|
@@ -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());
|
|
|
-
|
|
|
-
|
|
|
- private final JTabbedPane tabbedPaneInnerOriginal = new JTabbedPane(JTabbedPane.TOP);
|
|
|
-
|
|
|
- private final JScrollPane canvasSP = new JScrollPane();
|
|
|
private final CategoryPanel categoryPanel;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 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();
|
|
|
-
|
|
|
-
|
|
|
- private final Control control;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private final UnitGraph unitGraph;
|
|
|
-
|
|
|
- * Textfield to show the period of an element
|
|
|
- */
|
|
|
- private final JTextField unitGraphLocalPeriod = new JTextField(6);
|
|
|
- private final Canvas canvas;
|
|
|
-
|
|
|
-
|
|
|
- private JTabbedPane tabTemp;
|
|
|
- private Canvas actualOpenCanvas;
|
|
|
- private JPanel contentPane;
|
|
|
-
|
|
|
- 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));
|
|
|
-
|
|
|
- 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) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- String cntrlYDown = "controlY";
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control Y"), cntrlYDown);
|
|
|
- actionMap.put(cntrlYDown, new AbstractAction() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- String cntrlADown = "controlA";
|
|
|
- inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
|
|
|
- AbstractAction controlA = new AbstractAction() {
|
|
|
- @Override
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- GuiSettings.getSelectedObjects().clear();
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
- 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();
|
|
|
-
|
|
|
- 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()) {
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- 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) {
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
- 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()) {
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- 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 -> {
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
- splitHolonElPro.setTopComponent(inspector);
|
|
|
-
|
|
|
- splitHolonElPro.setBottomComponent(scrollProperties);
|
|
|
-
|
|
|
- canvasSP.setViewportView(canvas);
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- 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;
|
|
|
-
|
|
|
- tabbedPaneOriginal.setSelectedComponent(tabbedPaneInnerOriginal);
|
|
|
-
|
|
|
- tabbedPaneInnerOriginal.setSelectedComponent(tabbedPaneInnerOriginal.getComponentAt(i));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (dupl) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!dupl) {
|
|
|
- JScrollPane sp = new JScrollPane(actualOpenCanvas);
|
|
|
- sp.setBorder(null);
|
|
|
-
|
|
|
-
|
|
|
- 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() {
|
|
|
-
|
|
|
- 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 {
|
|
|
|
|
|
private final JMenu fileMenu = new JMenu("File");
|
|
@@ -509,6 +134,14 @@ public class Gui extends JFrame{
|
|
|
|
|
|
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;
|
|
|
|
|
|
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));
|
|
|
-
|
|
|
alignAllButton.addActionListener(clicked -> {
|
|
|
+
|
|
|
log.info("Not implemented yet.");
|
|
|
});
|
|
|
resetCategoryButton.addActionListener(clicked -> control.resetCategories());
|
|
|
|
|
|
showSupplyBarsCheckBox.addActionListener(clicked -> toggleSupplyBarAppearance());
|
|
|
- canvasSizeButton.addActionListener(clicked -> new CanvasResizePopUp(control, canvas, tabbedPaneInnerOriginal,
|
|
|
- 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());
|
|
|
|
|
|
- canvas.setGroupNode(control.getModel().getCanvas());
|
|
|
- canvas.repaint();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -662,7 +319,5 @@ public class Gui extends JFrame{
|
|
|
}
|
|
|
control.clearModel();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|