~tapaal-contributor/tapaal/unselect-objects-after-undo-1894108

« back to all changes in this revision

Viewing changes to src/pipe/gui/GuiFrame.java

  • Committer: srba.jiri at gmail
  • Date: 2020-08-19 12:02:28 UTC
  • mfrom: (1071.2.34 untimed-timed-gui)
  • Revision ID: srba.jiri@gmail.com-20200819120228-ktxdev3ou3kuj3l0
merged in lp:~tapaal-contributor/tapaal/untimed-timed-gui adding timed/untimed lens projection

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import java.net.*;
12
12
import java.nio.charset.StandardCharsets;
13
13
import java.util.*;
 
14
import java.util.List;
14
15
import java.util.jar.JarEntry;
15
16
import java.util.jar.JarFile;
16
17
import javax.swing.*;
25
26
import net.tapaal.helpers.Reference.Reference;
26
27
import net.tapaal.swinghelpers.ExtendedJTabbedPane;
27
28
import net.tapaal.swinghelpers.ToggleButtonWithoutText;
 
29
import org.jetbrains.annotations.NotNull;
28
30
import pipe.gui.Pipe.ElementType;
29
31
import pipe.gui.action.GuiAction;
30
32
import pipe.gui.widgets.WorkflowDialog;
43
45
 
44
46
    private final String frameTitle;
45
47
 
46
 
    private Pipe.ElementType mode;
47
 
 
48
48
    private int newNameCounter = 1;
49
49
 
50
50
    final MutableReference<GuiFrameControllerActions> guiFrameController = new MutableReference<>();
53
53
 
54
54
    private final StatusBar statusBar;
55
55
    private JMenuBar menuBar;
 
56
    JMenu drawMenu;
 
57
    JMenu animateMenu;
 
58
    JMenu viewMenu;
56
59
    private JToolBar drawingToolBar;
57
60
    private final JLabel featureInfoText = new JLabel();
58
61
    private JComboBox<String> timeFeatureOptions = new JComboBox(new String[]{"No", "Yes"});
281
284
            currentTab.ifPresent(o -> o.setMode(ElementType.ANNOTATION));
282
285
        }
283
286
    };
284
 
    private final GuiAction inhibarcAction = new GuiAction("Inhibitor arc", "Add an inhibitor arc (I)", "I", true) {
285
 
        public void actionPerformed(ActionEvent e) {
286
 
            currentTab.ifPresent(o -> o.setMode(ElementType.TAPNINHIBITOR_ARC));
287
 
        }
288
 
    };
289
 
    private final GuiAction transAction = new GuiAction("Transition", "Add a transition (T)", "T", true) {
290
 
        public void actionPerformed(ActionEvent e) {
291
 
            currentTab.ifPresent(o -> o.setMode(ElementType.TAPNTRANS));
292
 
        }
293
 
    };
294
 
    private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {
295
 
        public void actionPerformed(ActionEvent e) {
296
 
            currentTab.ifPresent(o -> o.setMode(ElementType.ADDTOKEN));
297
 
        }
298
 
    };
299
 
    private final GuiAction selectAction = new GuiAction("Select", "Select components (S)", "S", true) {
300
 
        public void actionPerformed(ActionEvent e) {
301
 
            currentTab.ifPresent(o -> o.setMode(ElementType.SELECT));
302
 
        }
303
 
    };
304
 
    private final GuiAction deleteTokenAction = new GuiAction("Delete token", "Delete a token (-)", "typed -", true) {
305
 
        public void actionPerformed(ActionEvent e) {
306
 
            currentTab.ifPresent(o -> o.setMode(ElementType.DELTOKEN));
307
 
        }
308
 
    };
309
 
    private final GuiAction timedPlaceAction = new GuiAction("Place", "Add a place (P)", "P", true) {
310
 
        public void actionPerformed(ActionEvent e) {
311
 
            currentTab.ifPresent(o -> o.setMode(ElementType.TAPNPLACE));
312
 
        }
313
 
    };
314
 
 
315
 
    private final GuiAction timedArcAction = new GuiAction("Arc", "Add an arc (A)", "A", true) {
316
 
        public void actionPerformed(ActionEvent e) {
317
 
            currentTab.ifPresent(o -> o.setMode(ElementType.TAPNARC));
318
 
        }
319
 
    };
320
 
    private final GuiAction transportArcAction = new GuiAction("Transport arc", "Add a transport arc (R)", "R", true) {
321
 
        public void actionPerformed(ActionEvent e) {
322
 
            currentTab.ifPresent(o -> o.setMode(ElementType.TRANSPORTARC));
323
 
        }
324
 
    };
325
287
 
326
288
    private final GuiAction showTokenAgeAction = new GuiAction("Display token age", "Show/hide displaying the token age 0.0 (when hidden the age 0.0 is drawn as a dot)", KeyStroke.getKeyStroke('9', shortcutkey), true) {
327
289
        public void actionPerformed(ActionEvent e) {
436
398
            currentTab.ifPresent(TabContentActions::stepBackwards);
437
399
        }
438
400
    };
439
 
    private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
440
 
        public void actionPerformed(ActionEvent e) {
441
 
            currentTab.ifPresent(TabContentActions::timeDelay);
442
 
        }
443
 
    };
444
 
    private final GuiAction delayFireAction = new GuiAction("Delay and fire", "Delay and fire selected transition", "F") {
445
 
        public void actionPerformed(ActionEvent e) {
446
 
            currentTab.ifPresent(TabContentActions::delayAndFire);
447
 
        }
448
 
    };
449
 
    private final GuiAction prevcomponentAction = new GuiAction("Previous component", "Previous component", "pressed UP") {
 
401
 
 
402
 
 
403
    private GuiAction prevcomponentAction = new GuiAction("Previous component", "Previous component", "pressed UP") {
450
404
        public void actionPerformed(ActionEvent e) {
451
405
            currentTab.ifPresent(TabContentActions::previousComponent);
452
406
        }
477
431
 
478
432
    private JCheckBoxMenuItem showZeroToInfinityIntervalsCheckBox;
479
433
    private JCheckBoxMenuItem showTokenAgeCheckBox;
 
434
    private JCheckBoxMenuItem showDelayEnabledTransitionsCheckbox;
480
435
 
481
436
    private JMenu zoomMenu;
482
437
 
496
451
        this.setMinimumSize(new Dimension(825, 480));
497
452
 
498
453
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
499
 
        appTab= new ExtendedJTabbedPane<TabContent>() {
 
454
        appTab = new ExtendedJTabbedPane<TabContent>() {
500
455
            @Override
501
456
            public Component generator() {
502
457
                return new TabComponent(this) {
586
541
        }
587
542
 
588
543
 
589
 
        if (Platform.isMac()){
 
544
        if (Platform.isMac()) {
590
545
 
591
546
            //Set specific settings
592
547
            System.setProperty("apple.laf.useScreenMenuBar", "true");
616
571
     **/
617
572
    private void buildMenus() {
618
573
        menuBar = new JMenuBar();
619
 
 
620
574
        menuBar.add(buildMenuFiles());
621
575
        menuBar.add(buildMenuEdit());
622
576
        menuBar.add(buildMenuView());
623
577
        menuBar.add(buildMenuDraw());
 
578
 
624
579
        menuBar.add(buildMenuAnimation());
625
580
        menuBar.add(buildMenuTools());
626
581
        menuBar.add(buildMenuHelp());
658
613
 
659
614
    private JMenu buildMenuDraw() {
660
615
        /* Draw menu */
661
 
        JMenu drawMenu = new JMenu("Draw");
 
616
        drawMenu = new JMenu("Draw");
662
617
        drawMenu.setMnemonic('D');
663
 
 
664
 
        drawMenu.add(selectAction);
665
 
        drawMenu.addSeparator();
666
 
 
667
 
        drawMenu.add(timedPlaceAction);
668
 
 
669
 
        drawMenu.add(transAction);
670
 
 
671
 
        drawMenu.add(timedArcAction);
672
 
 
673
 
        drawMenu.add(transportArcAction);
674
 
 
675
 
        drawMenu.add(inhibarcAction);
676
 
 
677
 
        drawMenu.add(annotationAction);
678
 
 
679
 
        drawMenu.addSeparator();
680
 
 
681
 
        drawMenu.add(tokenAction);
682
 
 
683
 
        drawMenu.add(deleteTokenAction);
684
618
        return drawMenu;
685
619
    }
686
620
 
687
621
    private JMenu buildMenuView() {
688
622
        /* ViewMenu */
689
 
        JMenu viewMenu = new JMenu("View");
 
623
        viewMenu = new JMenu("View");
690
624
        viewMenu.setMnemonic('V');
691
625
 
692
626
        zoomMenu = new JMenu("Zoom");
725
659
 
726
660
        addCheckboxMenuItem(viewMenu, showEnabledTransitionsAction);
727
661
 
728
 
        addCheckboxMenuItem(viewMenu, showDelayEnabledTransitionsAction);
 
662
        showDelayEnabledTransitionsCheckbox = addCheckboxMenuItem(viewMenu, showDelayEnabledTransitionsAction);
729
663
 
730
664
        showZeroToInfinityIntervalsCheckBox = addCheckboxMenuItem(viewMenu, showZeroToInfinityIntervals(), showZeroToInfinityIntervalsAction);
731
665
 
744
678
 
745
679
    private JMenu buildMenuAnimation() {
746
680
        /* Simulator */
747
 
        JMenu animateMenu = new JMenu("Simulator");
 
681
        animateMenu = new JMenu("Simulator");
748
682
        animateMenu.setMnemonic('A');
749
683
        animateMenu.add(startAction);
750
684
 
752
686
        animateMenu.add(stepbackwardAction);
753
687
        animateMenu.add(stepforwardAction);
754
688
 
755
 
        animateMenu.add(timeAction);
756
 
 
757
 
        animateMenu.add(delayFireAction);
758
 
 
759
689
        animateMenu.add(prevcomponentAction);
760
690
 
761
691
        animateMenu.add(nextcomponentAction);
878
808
        drawingToolBar.addSeparator();
879
809
        drawingToolBar.setRequestFocusEnabled(false);
880
810
 
881
 
        // Normal arraw
882
 
        drawingToolBar.add(new ToggleButtonWithoutText(selectAction));
883
 
 
884
 
 
885
 
        // Drawing elements
886
 
        drawingToolBar.addSeparator();
887
 
        drawingToolBar.add(new ToggleButtonWithoutText(timedPlaceAction));
888
 
        drawingToolBar.add(new ToggleButtonWithoutText(transAction));
889
 
        drawingToolBar.add(new ToggleButtonWithoutText(timedArcAction));
890
 
        drawingToolBar.add(new ToggleButtonWithoutText(transportArcAction));
891
 
        drawingToolBar.add(new ToggleButtonWithoutText(inhibarcAction));
892
 
 
893
 
        drawingToolBar.add(new ToggleButtonWithoutText(annotationAction));
894
 
 
895
 
        // Tokens
896
 
        drawingToolBar.addSeparator();
897
 
        drawingToolBar.add(new ToggleButtonWithoutText(tokenAction));
898
 
        drawingToolBar.add(new ToggleButtonWithoutText(deleteTokenAction));
899
 
 
900
811
        // Create panel to put toolbars in
901
812
        JPanel toolBarPanel = new JPanel();
902
813
        toolBarPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1001
912
                exportTraceAction.setEnabled(false);
1002
913
                importTraceAction.setEnabled(false);
1003
914
 
1004
 
                timedPlaceAction.setEnabled(true);
1005
 
                timedArcAction.setEnabled(true);
1006
 
                inhibarcAction.setEnabled(true);
1007
 
                transportArcAction.setEnabled(true);
1008
 
 
1009
915
                annotationAction.setEnabled(true);
1010
 
                transAction.setEnabled(true);
1011
 
                tokenAction.setEnabled(true);
1012
916
                deleteAction.setEnabled(true);
1013
917
                selectAllAction.setEnabled(true);
1014
 
                selectAction.setEnabled(true);
1015
 
                deleteTokenAction.setEnabled(true);
1016
918
 
1017
 
                timeAction.setEnabled(false);
1018
 
                delayFireAction.setEnabled(false);
1019
919
                stepbackwardAction.setEnabled(false);
1020
920
                stepforwardAction.setEnabled(false);
1021
921
                prevcomponentAction.setEnabled(false);
1038
938
                    WorkflowDialog.showDialog();
1039
939
                }
1040
940
 
1041
 
                statusBar.changeText(StatusBar.textforDrawing);
1042
941
                //Enable editor focus traversal policy
1043
942
                setFocusTraversalPolicy(new EditorFocusTraversalPolicy());
1044
943
                fixBug812694GrayMenuAfterSimulationOnMac();
1047
946
            case animation:
1048
947
                enableAllActions(true);
1049
948
 
1050
 
                timedPlaceAction.setEnabled(false);
1051
 
                timedArcAction.setEnabled(false);
1052
 
                inhibarcAction.setEnabled(false);
1053
 
                transportArcAction.setEnabled(false);
1054
 
 
1055
949
                annotationAction.setEnabled(false);
1056
 
                transAction.setEnabled(false);
1057
 
                tokenAction.setEnabled(false);
1058
950
                deleteAction.setEnabled(false);
1059
951
                selectAllAction.setEnabled(false);
1060
 
                selectAction.setEnabled(false);
1061
 
                deleteTokenAction.setEnabled(false);
1062
952
 
1063
953
                alignToGrid.setEnabled(false);
1064
954
 
1066
956
                showConstantsAction.setEnabled(false);
1067
957
                showQueriesAction.setEnabled(false);
1068
958
 
1069
 
                timeAction.setEnabled(true);
1070
 
 
1071
 
                delayFireAction.setEnabled(true);
1072
959
                stepbackwardAction.setEnabled(true);
1073
960
                stepforwardAction.setEnabled(true);
1074
961
                prevcomponentAction.setEnabled(true);
1091
978
 
1092
979
                getCurrentTab().getAnimationController().requestFocusInWindow();
1093
980
 
1094
 
                statusBar.changeText(StatusBar.textforAnimation);
1095
981
                //Enable simulator focus traversal policy
1096
982
                setFocusTraversalPolicy(new SimulatorFocusTraversalPolicy());
1097
983
 
1101
987
                importTraceAction.setEnabled(false);
1102
988
                verifyAction.setEnabled(false);
1103
989
 
1104
 
                timedPlaceAction.setEnabled(false);
1105
 
                timedArcAction.setEnabled(false);
1106
 
                inhibarcAction.setEnabled(false);
1107
 
                transportArcAction.setEnabled(false);
1108
 
 
1109
990
                annotationAction.setEnabled(false);
1110
 
                transAction.setEnabled(false);
1111
 
                tokenAction.setEnabled(false);
1112
 
                deleteAction.setEnabled(false);
1113
991
                selectAllAction.setEnabled(false);
1114
 
                selectAction.setEnabled(false);
1115
 
                deleteTokenAction.setEnabled(false);
1116
992
 
1117
 
                timeAction.setEnabled(false);
1118
 
                delayFireAction.setEnabled(false);
1119
993
                stepbackwardAction.setEnabled(false);
1120
994
                stepforwardAction.setEnabled(false);
1121
995
 
1135
1009
                enableAllActions(false);
1136
1010
 
1137
1011
                // Disable All Actions
1138
 
                statusBar.changeText(StatusBar.textforNoNet);
 
1012
                statusBar.changeText("Open a net to start editing");
1139
1013
                setFocusTraversalPolicy(null);
1140
1014
 
1141
1015
                break;
1262
1136
                break;
1263
1137
            case noNet:
1264
1138
                setFeatureInfoText(null);
 
1139
                registerDrawingActions(List.of());
 
1140
                registerAnimationActions(List.of());
 
1141
                //registerViewActions(List.of());
1265
1142
                break;
1266
1143
 
1267
1144
            default:
1270
1147
 
1271
1148
        // Enable actions based on GUI mode
1272
1149
        enableGUIActions(mode);
1273
 
 
 
1150
        if (currentTab != null) {
 
1151
            currentTab.ifPresent(o -> o.updateEnabledActions(mode));
 
1152
        }
 
1153
    }
 
1154
 
 
1155
    @Override
 
1156
    public void registerDrawingActions(@NotNull List<GuiAction> drawActions) {
 
1157
 
 
1158
        drawingToolBar.removeAll();
 
1159
        drawMenu.removeAll();
 
1160
 
 
1161
        if (drawActions.size() > 0) {
 
1162
            drawMenu.setEnabled(true);
 
1163
            drawingToolBar.addSeparator();
 
1164
 
 
1165
            for (GuiAction action : drawActions) {
 
1166
                drawingToolBar.add(new ToggleButtonWithoutText(action));
 
1167
                drawMenu.add(action);
 
1168
            }
 
1169
 
 
1170
            drawingToolBar.addSeparator();
 
1171
            drawingToolBar.add(featureInfoText);
 
1172
        } else {
 
1173
            drawMenu.setEnabled(false);
 
1174
        }
 
1175
 
 
1176
    }
 
1177
    @Override
 
1178
    public void registerAnimationActions(@NotNull List<GuiAction> animationActions) {
 
1179
 
 
1180
        animateMenu.removeAll();
 
1181
 
 
1182
        if (animationActions.size() > 0) {
 
1183
 
 
1184
            animateMenu.setEnabled(true);
 
1185
            animateMenu.add(startAction);
 
1186
 
 
1187
            animateMenu.add(stepbackwardAction);
 
1188
            animateMenu.add(stepforwardAction);
 
1189
 
 
1190
            for (GuiAction action : animationActions) {
 
1191
                animateMenu.add(action);
 
1192
            }
 
1193
 
 
1194
            animateMenu.add(prevcomponentAction);
 
1195
            animateMenu.add(nextcomponentAction);
 
1196
 
 
1197
            animateMenu.addSeparator();
 
1198
            animateMenu.add(exportTraceAction);
 
1199
            animateMenu.add(importTraceAction);
 
1200
        } else {
 
1201
            animateMenu.setEnabled(false);
 
1202
        }
 
1203
    }
 
1204
 
 
1205
    @Override
 
1206
    public void registerViewActions(@NotNull List<GuiAction> viewActions) {
 
1207
        //TODO: This is a temporary implementation until view actions can be moved to tab content
 
1208
 
 
1209
        if (!getCurrentTab().getLens().isTimed()) {
 
1210
            showZeroToInfinityIntervalsCheckBox.setVisible(false);
 
1211
            showTokenAgeCheckBox.setVisible(false);
 
1212
            showDelayEnabledTransitionsCheckbox.setVisible(false);
 
1213
        } else {
 
1214
            showZeroToInfinityIntervalsCheckBox.setVisible(true);
 
1215
            showTokenAgeCheckBox.setVisible(true);
 
1216
            showDelayEnabledTransitionsCheckbox.setVisible(true);
 
1217
        }
1274
1218
    }
1275
1219
 
1276
1220
    private void fixBug812694GrayMenuAfterSimulationOnMac() {
1284
1228
        a.dispose();
1285
1229
    }
1286
1230
 
1287
 
    //XXX temp while refactoring, kyrke - 2019-07-25, should only be called from TabContent
1288
1231
    @Override
1289
 
    public void updateMode(Pipe.ElementType _mode) {
1290
 
 
1291
 
        mode = _mode;
1292
 
 
1293
 
        // deselect other actions
1294
 
        transAction.setSelected(mode == ElementType.TAPNTRANS);
1295
 
        timedPlaceAction.setSelected(mode == ElementType.TAPNPLACE);
1296
 
        timedArcAction.setSelected(mode == ElementType.TAPNARC);
1297
 
        transportArcAction.setSelected(mode == ElementType.TRANSPORTARC);
1298
 
        inhibarcAction.setSelected(mode == ElementType.TAPNINHIBITOR_ARC);
1299
 
        tokenAction.setSelected(mode == ElementType.ADDTOKEN);
1300
 
        deleteTokenAction.setSelected(mode == ElementType.DELTOKEN);
1301
 
        selectAction.setSelected(mode == ElementType.SELECT);
1302
 
        annotationAction.setSelected(mode == ElementType.ANNOTATION);
1303
 
 
1304
 
        statusBar.changeText(mode);
 
1232
    public void setStatusBarText(String s) {
 
1233
        statusBar.changeText(Objects.requireNonNullElse(s, ""));
1305
1234
    }
1306
1235
 
1307
1236
 
1368
1297
        showTokenAgeAction.setSelected(b);
1369
1298
    }
1370
1299
 
1371
 
    public Pipe.ElementType getMode() {
1372
 
        return mode;
1373
 
    }
1374
 
 
1375
1300
    public void setTitle(String title) {
1376
1301
        super.setTitle((title == null) ? frameTitle : frameTitle + ": " + title);
1377
1302
    }
1403
1328
        zoomComboBox.addActionListener(zoomComboListener);
1404
1329
    }
1405
1330
 
1406
 
 
1407
1331
    private boolean canNetBeSavedAndShowMessage() {
1408
1332
        if (getCurrentTab().network().paintNet()) {
1409
1333
            return true;