~boginw/tapaal/multiplayer

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/gui/BatchProcessingDialog.java

  • Committer: Bogi Napoleon Wennerstrøm
  • Date: 2020-04-08 13:12:38 UTC
  • mfrom: (998.2.361 testbranch)
  • Revision ID: bogi.wennerstrom@gmail.com-20200408131238-6daa9ocph3zgx1ag
merged ~yrke changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import javax.swing.JSeparator;
41
41
import javax.swing.JSplitPane;
42
42
import javax.swing.JTable;
43
 
import javax.swing.ListCellRenderer;
44
43
import javax.swing.ListSelectionModel;
45
44
import javax.swing.SwingConstants;
46
45
import javax.swing.SwingWorker.StateValue;
49
48
import javax.swing.border.Border;
50
49
import javax.swing.event.ChangeEvent;
51
50
import javax.swing.event.ChangeListener;
52
 
import javax.swing.event.ListSelectionEvent;
53
 
import javax.swing.event.ListSelectionListener;
54
51
import javax.swing.event.TableModelEvent;
55
52
import javax.swing.event.TableModelListener;
56
53
import javax.swing.table.TableCellRenderer;
60
57
import pipe.dataLayer.TAPNQuery;
61
58
import pipe.dataLayer.TAPNQuery.SearchOption;
62
59
import pipe.gui.CreateGui;
63
 
import pipe.gui.widgets.CustomJSpinner;
 
60
import net.tapaal.swinghelpers.CustomJSpinner;
64
61
import pipe.gui.widgets.EscapableDialog;
65
62
import pipe.gui.widgets.filebrowser.FileBrowser;
66
63
import pipe.gui.widgets.QueryPane;
217
214
        private JButton addFilesButton;
218
215
        private JButton clearFilesButton;
219
216
        private JButton removeFileButton;
220
 
        private JList fileList;
221
 
        private DefaultListModel listModel;
 
217
        private JList<File> fileList;
 
218
        private DefaultListModel<File> listModel;
222
219
 
223
220
        private JLabel statusLabel;
224
221
        private JLabel fileStatusLabel;
230
227
        private JLabel memory;
231
228
        private long startTimeMs = 0;
232
229
 
233
 
        private JComboBox searchOption;
 
230
        private JComboBox<String> searchOption;
234
231
        private JButton exportButton;
235
232
        private JButton closeButton;
236
 
        private JComboBox queryPropertyOption;
 
233
        private JComboBox<String> queryPropertyOption;
237
234
        private JPanel verificationOptionsPanel;
238
235
        private CustomJSpinner numberOfExtraTokensInNet;
239
236
        private JCheckBox keepQueryCapacity;
240
 
        private JComboBox symmetryOption;
241
 
        private JComboBox stubbornReductionOption;
 
237
        private JComboBox<String> symmetryOption;
 
238
        private JComboBox<String> stubbornReductionOption;
242
239
        private JCheckBox noTimeoutCheckbox;
243
240
        private JCheckBox noOOMCheckbox;
244
241
        private CustomJSpinner timeoutValue;
245
242
        private CustomJSpinner oomValue;
246
 
        private JComboBox approximationMethodOption;
 
243
        private JComboBox<String> approximationMethodOption;
247
244
        private CustomJSpinner approximationDenominator;
248
245
        private JCheckBox approximationDenominatorCheckbox;
249
 
        private JList ListOfQueries;
 
246
        private JList<TAPNQuery> ListOfQueries;
250
247
        
251
 
        private Timer timeoutTimer = new Timer(30000, new ActionListener() {
252
 
                public void actionPerformed(ActionEvent e) {
253
 
                        timeoutCurrentVerificationTask();
254
 
                }
255
 
        });
 
248
        private Timer timeoutTimer = new Timer(30000, e -> timeoutCurrentVerificationTask());
256
249
 
257
250
        private BatchProcessingResultsTableModel tableModel;
258
251
 
328
321
        BatchProcessing was called from QueryPane
329
322
        (should maybe be boolean)
330
323
        */
331
 
        public static void showBatchProcessingDialog(JList ListOfQueries){
 
324
        public static void showBatchProcessingDialog(JList<TAPNQuery> ListOfQueries){
332
325
                if(ListOfQueries.getModel().getSize() != 0) {
333
326
                        batchProcessingDialog = null;
334
327
                }
344
337
                batchProcessingDialog.setVisible(true);
345
338
        }
346
339
 
347
 
        private BatchProcessingDialog(Frame frame, String title, boolean modal, JList ListOfQueries) {
 
340
        private BatchProcessingDialog(Frame frame, String title, boolean modal, JList<TAPNQuery> ListOfQueries) {
348
341
                super(frame, title, modal);
349
342
                
350
343
                addWindowListener(new WindowAdapter() {
390
383
        }
391
384
        
392
385
        private boolean isQueryListEmpty() {
393
 
                if(ListOfQueries.getModel().getSize() == 0)
394
 
                        return true;
395
 
                else
396
 
                        return false;
 
386
                return ListOfQueries.getModel().getSize() == 0;
397
387
        }
398
388
 
399
389
        private void initFileListPanel() {
413
403
                        }
414
404
                });
415
405
 
416
 
                fileList.addListSelectionListener(new ListSelectionListener() {
417
 
 
418
 
                        public void valueChanged(ListSelectionEvent e) {
419
 
                                if (!(e.getValueIsAdjusting())) {
420
 
                                        if (fileList.getSelectedIndex() == -1) {
421
 
                                                removeFileButton.setEnabled(false);
422
 
                                        } else {
423
 
                                                removeFileButton.setEnabled(true);
424
 
                                        }
 
406
                fileList.addListSelectionListener(e -> {
 
407
                        if (!(e.getValueIsAdjusting())) {
 
408
                                if (fileList.getSelectedIndex() == -1) {
 
409
                                        removeFileButton.setEnabled(false);
 
410
                                } else {
 
411
                                        removeFileButton.setEnabled(true);
425
412
                                }
426
413
                        }
427
414
                });
446
433
                
447
434
                addFilesButton = new JButton("Add models");
448
435
                addFilesButton.setToolTipText(TOOL_TIP_AddFilesButton);
449
 
                addFilesButton.addActionListener(new ActionListener() {
450
 
                        public void actionPerformed(ActionEvent arg0) {
451
 
                                addFiles();
452
 
                        }
453
 
                });
 
436
                addFilesButton.addActionListener(arg0 -> addFiles());
454
437
 
455
438
                gbc = new GridBagConstraints();
456
439
                gbc.anchor = GridBagConstraints.NORTHWEST;
463
446
                removeFileButton = new JButton("Remove models");
464
447
                removeFileButton.setToolTipText(TOOL_TIP_RemoveFilesButton);
465
448
                removeFileButton.setEnabled(false);
466
 
                removeFileButton.addActionListener(new ActionListener() {
467
 
 
468
 
                        public void actionPerformed(ActionEvent arg0) {
469
 
                                removeSelectedFiles();
470
 
                        }
471
 
                });
 
449
                removeFileButton.addActionListener(arg0 -> removeSelectedFiles());
472
450
                gbc = new GridBagConstraints();
473
451
                gbc.gridx = 1;
474
452
                gbc.gridy = 0;
479
457
                clearFilesButton = new JButton("Clear");
480
458
                clearFilesButton.setToolTipText(TOOL_TIP_ClearFilesButton);
481
459
                clearFilesButton.setEnabled(false);
482
 
                clearFilesButton.addActionListener(new ActionListener() {
483
 
 
484
 
                        public void actionPerformed(ActionEvent e) {
485
 
                                clearFiles();
486
 
                                enableButtons();
487
 
                        }
 
460
                clearFilesButton.addActionListener(e -> {
 
461
                        clearFiles();
 
462
                        enableButtons();
488
463
                });
489
464
 
490
465
                gbc = new GridBagConstraints();
892
867
        }
893
868
 
894
869
        private SearchOption getSearchOption() {
895
 
                if (((String) searchOption.getSelectedItem()).equals(name_DFS))
 
870
                if (searchOption.getSelectedItem().equals(name_DFS))
896
871
                        return SearchOption.DFS;
897
 
                else if (((String) searchOption.getSelectedItem()).equals(name_Random))
 
872
                else if (searchOption.getSelectedItem().equals(name_Random))
898
873
                        return SearchOption.RANDOM;
899
 
                else if (((String) searchOption.getSelectedItem())
 
874
                else if (searchOption.getSelectedItem()
900
875
                                .equals(name_HEURISTIC))
901
876
                        return SearchOption.HEURISTIC;
902
 
                else if (((String) searchOption.getSelectedItem()).equals(name_BFS))
 
877
                else if (searchOption.getSelectedItem().equals(name_BFS))
903
878
                        return SearchOption.BFS;
904
879
                else
905
880
                        return SearchOption.BatchProcessingKeepQueryOption;
957
932
 
958
933
        private QueryPropertyOption getQueryPropertyOption() {
959
934
                String propertyOptionString = (String) queryPropertyOption.getSelectedItem();
960
 
                if (propertyOptionString.equals(name_SEARCHWHOLESTATESPACE))
961
 
                        return QueryPropertyOption.SearchWholeStateSpace;
962
 
        else if (propertyOptionString.equals(name_EXISTDEADLOCK))
963
 
                return QueryPropertyOption.ExistDeadlock;
964
 
        else if (propertyOptionString.equals(name_STRONGSOUNDNESS))
965
 
                return QueryPropertyOption.StrongSoundness;
966
 
        else if (propertyOptionString.equals(name_SOUNDNESS))
967
 
                return QueryPropertyOption.Soundness;
968
 
        else
969
 
                        return QueryPropertyOption.KeepQueryOption;
 
935
                switch (propertyOptionString) {
 
936
                        case name_SEARCHWHOLESTATESPACE:
 
937
                                return QueryPropertyOption.SearchWholeStateSpace;
 
938
                        case name_EXISTDEADLOCK:
 
939
                                return QueryPropertyOption.ExistDeadlock;
 
940
                        case name_STRONGSOUNDNESS:
 
941
                                return QueryPropertyOption.StrongSoundness;
 
942
                        case name_SOUNDNESS:
 
943
                                return QueryPropertyOption.Soundness;
 
944
                        default:
 
945
                                return QueryPropertyOption.KeepQueryOption;
 
946
                }
970
947
        }
971
948
        
972
949
        private ApproximationMethodOption getApproximationMethodOption() {
973
950
                String ApproximationMethodOptionString = (String) approximationMethodOption.getSelectedItem();
974
 
                if(ApproximationMethodOptionString.equals(name_OVER_APPROXIMATION)) {
975
 
                        return ApproximationMethodOption.OverApproximation;
976
 
                } else if (ApproximationMethodOptionString.equals(name_UNDER_APPROXIMATION)) {
977
 
                        return ApproximationMethodOption.UnderApproximation;
978
 
                } else if (ApproximationMethodOptionString.equals(name_NONE_APPROXIMATION)) {
979
 
                        return ApproximationMethodOption.None;
980
 
                } else {
981
 
                        return ApproximationMethodOption.KeepQueryOption;
 
951
                switch (ApproximationMethodOptionString) {
 
952
                        case name_OVER_APPROXIMATION:
 
953
                                return ApproximationMethodOption.OverApproximation;
 
954
                        case name_UNDER_APPROXIMATION:
 
955
                                return ApproximationMethodOption.UnderApproximation;
 
956
                        case name_NONE_APPROXIMATION:
 
957
                                return ApproximationMethodOption.None;
 
958
                        default:
 
959
                                return ApproximationMethodOption.KeepQueryOption;
982
960
                }
983
961
        }
984
962
        
1034
1012
                        }
1035
1013
 
1036
1014
                        private void exportResults() {
1037
 
                                String filename = FileBrowser.constructor("CSV file", "csv", lastPath)
1038
 
                                                .saveFile("results");
 
1015
                                String filename = FileBrowser.constructor("CSV file", "csv", lastPath).saveFile("results");
 
1016
 
1039
1017
                                if (filename != null) {
1040
1018
                                        File exportFile = new File(filename);
1041
1019
                                        lastPath = exportFile.getParent();
1042
1020
                                        BatchProcessingResultsExporter exporter = new BatchProcessingResultsExporter();
1043
1021
                                        try {
1044
 
                                                exporter.exportToCSV(tableModel.getResults(),
1045
 
                                                                exportFile);
 
1022
                                                exporter.exportToCSV(tableModel.getResults(), exportFile);
1046
1023
                                        } catch (Exception e1) {
1047
1024
                                                JOptionPane.showMessageDialog(
1048
1025
                                                                CreateGui.getApp(),
1049
1026
                                                                "An error occurred while trying to export the results. Please try again",
1050
1027
                                                                "Error Exporting Results",
1051
 
                                                                JOptionPane.ERROR_MESSAGE);
 
1028
                                                                JOptionPane.ERROR_MESSAGE
 
1029
                                                );
1052
1030
                                                e1.printStackTrace();
1053
1031
                                        }
1054
1032
                                }
1063
1041
                
1064
1042
                closeButton = new JButton("Close");
1065
1043
                closeButton.setToolTipText(TOOL_TIP_CloseButton);
1066
 
                closeButton.addActionListener(new ActionListener() {
1067
 
                        public void actionPerformed(ActionEvent e) {
1068
 
                                exit();
1069
 
                        }
1070
 
                });
 
1044
                closeButton.addActionListener(e -> exit());
 
1045
 
1071
1046
                gbc = new GridBagConstraints();
1072
1047
                gbc.gridx = 1;
1073
1048
                gbc.gridy = 1;
1084
1059
                                                Integer.MAX_VALUE); // disable tooltips disappearing
1085
1060
                                ToolTipManager.sharedInstance().setInitialDelay(200);
1086
1061
                                return new MultiLineAutoWrappingToolTip();
1087
 
                        };
 
1062
                        }
1088
1063
                };
1089
1064
                ResultTableCellRenderer renderer = new ResultTableCellRenderer(true);
1090
1065
                table.getColumnModel().getColumn(0).setMinWidth(70);
1097
1072
                table.getColumn("Verification Time").setCellRenderer(renderer);
1098
1073
                table.getColumn("Memory Usage").setCellRenderer(renderer);
1099
1074
 
1100
 
                tableModel.addTableModelListener(new TableModelListener() {
1101
 
                        public void tableChanged(TableModelEvent e) {
1102
 
                                if (e.getType() == TableModelEvent.INSERT) {
1103
 
                                        table.scrollRectToVisible(table.getCellRect(e.getLastRow(),
1104
 
                                                        e.getLastRow(), true));
1105
 
                                }
 
1075
                tableModel.addTableModelListener(e -> {
 
1076
                        if (e.getType() == TableModelEvent.INSERT) {
 
1077
                                table.scrollRectToVisible(table.getCellRect(e.getLastRow(), e.getLastRow(), true));
1106
1078
                        }
1107
1079
                });
1108
1080
                
1116
1088
                table.setRowSorter(sorter);
1117
1089
 
1118
1090
                JScrollPane scrollPane = new JScrollPane(table);
1119
 
                scrollPane
1120
 
                                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
1121
 
                scrollPane
1122
 
                                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 
1091
                scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
 
1092
                scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
1123
1093
                Dimension scrollPanePrefDims = new Dimension(850, 250);
1124
1094
                //Set the minimum size to 150 lets than the preferred, to be consistat with theh minimum size of the window
1125
1095
                Dimension scrollPaneMinDims = new Dimension(850, 250-150);
1277
1247
                cancelButton.setPreferredSize(new java.awt.Dimension(85, 25));
1278
1248
                
1279
1249
                cancelButton.setEnabled(false);
1280
 
                cancelButton.addActionListener(new ActionListener() {
 
1250
                cancelButton.addActionListener(e -> {
 
1251
                        terminateBatchProcessing();
 
1252
                        fileStatusLabel.setText("");
 
1253
                        statusLabel.setText("Batch processing cancelled");
 
1254
                        enableButtons();
 
1255
                });
1281
1256
 
1282
 
                        public void actionPerformed(ActionEvent e) {
1283
 
                                terminateBatchProcessing();
1284
 
                                fileStatusLabel.setText("");
1285
 
                                statusLabel.setText("Batch processing cancelled");
1286
 
                                enableButtons();
1287
 
                        }
1288
 
                });
1289
1257
                gbc = new GridBagConstraints();
1290
1258
                gbc.gridx = 4;
1291
1259
                gbc.gridy = 2;
1300
1268
                skipFileButton.setPreferredSize(new java.awt.Dimension(85, 25));
1301
1269
                
1302
1270
                skipFileButton.setEnabled(false);
1303
 
                skipFileButton.addActionListener(new ActionListener() {
 
1271
                skipFileButton.addActionListener(e -> skipCurrentFile());
1304
1272
 
1305
 
                        public void actionPerformed(ActionEvent e) {
1306
 
                                skipCurrentFile();
1307
 
                        }
1308
 
                });
1309
1273
                gbc = new GridBagConstraints();
1310
1274
                gbc.gridx = 4;
1311
1275
                gbc.gridy = 1;
1333
1297
 
1334
1298
                        public void propertyChange(PropertyChangeEvent evt) {
1335
1299
                                if (evt.getPropertyName().equals("state")) {
1336
 
                                        if ((StateValue) evt.getNewValue() == StateValue.DONE) {
 
1300
                                        if (evt.getNewValue() == StateValue.DONE) {
1337
1301
                                                enableButtons();
1338
1302
                                                cancelButton.setEnabled(false);
1339
1303
                                                skipFileButton.setEnabled(false);
1341
1305
                                                timer.stop();
1342
1306
                                                stopMemoryTimer();
1343
1307
                                                timeoutTimer.stop();
1344
 
                                        } else if ((StateValue) evt.getNewValue() == StateValue.STARTED) {
 
1308
                                        } else if (evt.getNewValue() == StateValue.STARTED) {
1345
1309
                                                disableButtonsDuringProcessing();
1346
1310
                                                cancelButton.setEnabled(true);
1347
1311
                                                skipFileButton.setEnabled(true);
1371
1335
                                startTimeMs = System.currentTimeMillis();
1372
1336
                        }
1373
1337
 
1374
 
                        public void fireVerificationTaskComplete(
1375
 
                                        VerificationTaskCompleteEvent e) {
1376
 
                                if (timer.isRunning())
 
1338
                        public void fireVerificationTaskComplete(VerificationTaskCompleteEvent e) {
 
1339
                                if (timer.isRunning()) {
1377
1340
                                        timer.stop();
 
1341
                                }
1378
1342
                                stopMemoryTimer();
1379
 
                                if (timeoutTimer.isRunning())
 
1343
                                if (timeoutTimer.isRunning()) {
1380
1344
                                        timeoutTimer.stop();
 
1345
                                }
1381
1346
                                int tasksCompleted = e.verificationTasksCompleted();
1382
1347
                                progressLabel.setText(e.verificationTasksCompleted()
1383
1348
                                                + " verification task"
1490
1455
 
1491
1456
        // Custom cell renderer for the Query Column of the result table display the
1492
1457
        // property of the query
1493
 
        private class ResultTableCellRenderer extends JLabel implements
1494
 
                        TableCellRenderer {
 
1458
        private class ResultTableCellRenderer extends JLabel implements TableCellRenderer {
1495
1459
                private static final long serialVersionUID = 3054497986242852099L;
1496
1460
                Border unselectedBorder = null;
1497
1461
                Border selectedBorder = null;
1501
1465
                        this.isBordered = isBordered;
1502
1466
                }
1503
1467
 
1504
 
                public Component getTableCellRendererComponent(JTable table,
1505
 
                                Object value, boolean isSelected, boolean hasFocus, int row,
1506
 
                                int column) {
 
1468
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
1507
1469
                        if (isBordered) {
1508
1470
                                if (isSelected) {
1509
1471
                                        setBackground(table.getSelectionBackground());
1542
1504
                                        }
1543
1505
                                        setForeground(table.getForeground());
1544
1506
                                        if (unselectedBorder == null) {
1545
 
                                                unselectedBorder = BorderFactory.createMatteBorder(2,
1546
 
                                                                5, 2, 5, table.getBackground());
 
1507
                                                unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getBackground());
1547
1508
                                        }
1548
1509
                                        setBorder(unselectedBorder);
1549
1510
                                }
1559
1520
 
1560
1521
                                        setToolTipText(generateTooltipTextFromQuery(newQuery));
1561
1522
                                        setText(newQuery.getName());
1562
 
                                } else if (table.getColumnName(column).equals(
1563
 
                                                "Verification Time")
 
1523
                                } else if (table.getColumnName(column).equals("Verification Time")
1564
1524
                                                || table.getColumnName(column).equals("Method")
1565
1525
                                                || table.getColumnName(column).equals("Memory Usage")) {
1566
1526
                                        setText(value.toString());
1579
1539
                                                setToolTipText(result != null ? generateMemoryToolTipText(result)
1580
1540
                                                                : value.toString());
1581
1541
                                        else
1582
 
                                                setToolTipText(result != null ? generateReductionString(result
1583
 
                                                                .query()) : value.toString());
 
1542
                                                setToolTipText(result != null ? generateReductionString(result.query()) : value.toString());
1584
1543
                                } else {
1585
1544
                                        setToolTipText(value.toString());
1586
1545
                                        setText(value.toString());
1593
1552
                        return this;
1594
1553
                }
1595
1554
 
1596
 
                private String generateStatsToolTipText(
1597
 
                                BatchProcessingVerificationResult result) {
 
1555
                private String generateStatsToolTipText(BatchProcessingVerificationResult result) {
1598
1556
                        StringBuilder s = new StringBuilder();
1599
1557
                        s.append("Verification Time: ");
1600
1558
                        s.append((result.verificationTimeInMs() / 1000.0));
1608
1566
                        return s.toString();
1609
1567
                }
1610
1568
                
1611
 
                private String generateMemoryToolTipText(
1612
 
                                BatchProcessingVerificationResult result) {
 
1569
                private String generateMemoryToolTipText(BatchProcessingVerificationResult result) {
1613
1570
                        StringBuilder s = new StringBuilder();
1614
1571
                        s.append("Peak memory usage (estimate): ");
1615
1572
                        s.append(result.verificationMemory());
1759
1716
                        
1760
1717
                        chooseReductionOptions = new JButton(STATUS_TEXT_DONT_OVERRIDE);
1761
1718
                        chooseReductionOptions.setToolTipText(TOOL_TIP_ReductionOption);
1762
 
                        chooseReductionOptions.addActionListener(new ActionListener() {
1763
 
                                public void actionPerformed(ActionEvent arg0) {
1764
 
                                        //reductionOptionDialog.setOverride(true);
1765
 
                                        reductionOptionDialog.setVisible(true);
1766
 
                                }
 
1719
                        chooseReductionOptions.addActionListener(arg0 -> {
 
1720
                                //reductionOptionDialog.setOverride(true);
 
1721
                                reductionOptionDialog.setVisible(true);
1767
1722
                        });
1768
1723
                        this.add(chooseReductionOptions);
1769
1724