Merge lp:~tapaal-contributor/tapaal/undo-redo-batchprocessing-3.6-1870904 into lp:tapaal/3.6

Proposed by Jiri Srba
Status: Merged
Merged at revision: 1050
Proposed branch: lp:~tapaal-contributor/tapaal/undo-redo-batchprocessing-3.6-1870904
Merge into: lp:tapaal/3.6
Diff against target: 339 lines (+142/-57)
4 files modified
src/dk/aau/cs/gui/BatchProcessingDialog.java (+44/-41)
src/dk/aau/cs/verification/batchProcessing/Undo/AddFileCommand.java (+34/-0)
src/dk/aau/cs/verification/batchProcessing/Undo/RemoveFileCommand.java (+35/-0)
src/pipe/gui/undo/UndoManager.java (+29/-16)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/undo-redo-batchprocessing-3.6-1870904
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+383675@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/gui/BatchProcessingDialog.java'
2--- src/dk/aau/cs/gui/BatchProcessingDialog.java 2019-02-12 13:57:23 +0000
3+++ src/dk/aau/cs/gui/BatchProcessingDialog.java 2020-05-10 20:01:44 +0000
4@@ -1,15 +1,6 @@
5 package dk.aau.cs.gui;
6
7-import java.awt.Color;
8-import java.awt.Component;
9-import java.awt.Dimension;
10-import java.awt.FlowLayout;
11-import java.awt.Frame;
12-import java.awt.GridBagConstraints;
13-import java.awt.GridBagLayout;
14-import java.awt.GridLayout;
15-import java.awt.Insets;
16-import java.awt.Point;
17+import java.awt.*;
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.awt.event.KeyAdapter;
21@@ -23,29 +14,8 @@
22 import java.util.Comparator;
23 import java.util.List;
24
25-import javax.swing.AbstractAction;
26-import javax.swing.BorderFactory;
27-import javax.swing.ButtonGroup;
28-import javax.swing.DefaultListModel;
29-import javax.swing.JButton;
30-import javax.swing.JCheckBox;
31-import javax.swing.JComboBox;
32-import javax.swing.JDialog;
33-import javax.swing.JLabel;
34-import javax.swing.JList;
35-import javax.swing.JOptionPane;
36-import javax.swing.JPanel;
37-import javax.swing.JRadioButton;
38-import javax.swing.JScrollPane;
39-import javax.swing.JSeparator;
40-import javax.swing.JSplitPane;
41-import javax.swing.JTable;
42-import javax.swing.ListCellRenderer;
43-import javax.swing.ListSelectionModel;
44-import javax.swing.SwingConstants;
45+import javax.swing.*;
46 import javax.swing.SwingWorker.StateValue;
47-import javax.swing.Timer;
48-import javax.swing.ToolTipManager;
49 import javax.swing.border.Border;
50 import javax.swing.event.ChangeEvent;
51 import javax.swing.event.ChangeListener;
52@@ -57,9 +27,13 @@
53 import javax.swing.table.TableModel;
54 import javax.swing.table.TableRowSorter;
55
56+import dk.aau.cs.gui.undo.Command;
57+import dk.aau.cs.verification.batchProcessing.Undo.AddFileCommand;
58+import dk.aau.cs.verification.batchProcessing.Undo.RemoveFileCommand;
59 import pipe.dataLayer.TAPNQuery;
60 import pipe.dataLayer.TAPNQuery.SearchOption;
61 import pipe.gui.CreateGui;
62+import pipe.gui.undo.UndoManager;
63 import pipe.gui.widgets.CustomJSpinner;
64 import pipe.gui.widgets.EscapableDialog;
65 import pipe.gui.widgets.filebrowser.FileBrowser;
66@@ -272,6 +246,7 @@
67 private static int memoryTimerCount = 0;
68 private static int memoryTimerMode = 0;
69 private static int peakMemory = -1;
70+ private UndoManager undoManager = new UndoManager(null,null,null);
71
72 private void startMemoryTimer(){
73 if(memoryTimer.isRunning()){
74@@ -358,6 +333,7 @@
75 this.ListOfQueries = ListOfQueries;
76
77 initComponents();
78+ makeShortcuts();
79 //Runs the BatchProcessing if it is called from the QueryPane
80 if(!(isQueryListEmpty())) {
81 process();
82@@ -520,24 +496,27 @@
83
84 File[] filesArray = browser.openFiles();
85 if (filesArray.length>0) {
86+ undoManager.newEdit();
87 for (File file : filesArray) {
88 lastPath = file.getParent();
89 if (!files.contains(file)) {
90- files.add(file);
91- listModel.addElement(file);
92+ Command c = new AddFileCommand(listModel,file,files,this);
93+ c.redo();
94+ undoManager.addEdit(c);
95+
96 }
97 }
98-
99 enableButtons();
100-
101 }
102 }
103
104 private void removeSelectedFiles() {
105+ undoManager.newEdit();
106 for (Object o : fileList.getSelectedValuesList()) {
107 File file = (File) o;
108- files.remove(file);
109- listModel.removeElement(file);
110+ Command c = new RemoveFileCommand(listModel, file,files,this);
111+ c.redo();
112+ undoManager.addEdit(c);
113 }
114
115 enableButtons();
116@@ -1451,8 +1430,13 @@
117 }
118
119 private void clearFiles() {
120- files.clear();
121- listModel.removeAllElements();
122+ undoManager.newEdit();
123+ for (Object o : listModel.toArray()) {
124+ File file = (File)o;
125+ Command c = new RemoveFileCommand(listModel,file, files, this );
126+ c.redo();
127+ undoManager.addEdit(c);
128+ }
129 }
130
131 private void disableButtonsDuringProcessing() {
132@@ -1466,7 +1450,7 @@
133 disableVerificationOptionsButtons();
134 }
135
136- private void enableButtons() {
137+ public void enableButtons() {
138 fileList.setEnabled(true);
139 addFilesButton.setEnabled(true);
140
141@@ -1487,6 +1471,25 @@
142
143 enabledVerificationOptionButtons();
144 }
145+ private void makeShortcuts(){
146+ int shortcutkey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
147+ ActionMap am = splitpane.getActionMap();
148+ am.put("undo", new AbstractAction() {
149+ @Override
150+ public void actionPerformed(ActionEvent e) {
151+ undoManager.undo();
152+ }
153+ });
154+ am.put("redo", new AbstractAction() {
155+ @Override
156+ public void actionPerformed(ActionEvent e) {
157+ undoManager.redo();
158+ }
159+ });
160+ InputMap im = splitpane.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW);
161+ im.put(KeyStroke.getKeyStroke('Z', shortcutkey), "undo");
162+ im.put(KeyStroke.getKeyStroke('Y', shortcutkey), "redo");
163+ }
164
165 // Custom cell renderer for the Query Column of the result table display the
166 // property of the query
167
168=== added directory 'src/dk/aau/cs/verification/batchProcessing/Undo'
169=== added file 'src/dk/aau/cs/verification/batchProcessing/Undo/AddFileCommand.java'
170--- src/dk/aau/cs/verification/batchProcessing/Undo/AddFileCommand.java 1970-01-01 00:00:00 +0000
171+++ src/dk/aau/cs/verification/batchProcessing/Undo/AddFileCommand.java 2020-05-10 20:01:44 +0000
172@@ -0,0 +1,34 @@
173+package dk.aau.cs.verification.batchProcessing.Undo;
174+
175+import dk.aau.cs.gui.BatchProcessingDialog;
176+import dk.aau.cs.gui.undo.Command;
177+
178+import javax.swing.*;
179+import java.io.File;
180+import java.util.List;
181+
182+public class AddFileCommand extends Command {
183+ private DefaultListModel listModel;
184+ List<File> files;
185+ File file;
186+ private BatchProcessingDialog dialog;
187+ public AddFileCommand(DefaultListModel listModel, File file, List<File> files, BatchProcessingDialog dialog){
188+ this.listModel = listModel;
189+ this.file = file;
190+ this.files = files;
191+ this.dialog = dialog;
192+ }
193+ @Override
194+ public void redo() {
195+ files.add(file);
196+ listModel.addElement(file);
197+ dialog.enableButtons();
198+ }
199+
200+ @Override
201+ public void undo() {
202+ files.remove(file);
203+ listModel.removeElement(file);
204+ dialog.enableButtons();
205+ }
206+}
207
208=== added file 'src/dk/aau/cs/verification/batchProcessing/Undo/RemoveFileCommand.java'
209--- src/dk/aau/cs/verification/batchProcessing/Undo/RemoveFileCommand.java 1970-01-01 00:00:00 +0000
210+++ src/dk/aau/cs/verification/batchProcessing/Undo/RemoveFileCommand.java 2020-05-10 20:01:44 +0000
211@@ -0,0 +1,35 @@
212+package dk.aau.cs.verification.batchProcessing.Undo;
213+
214+import dk.aau.cs.gui.BatchProcessingDialog;
215+import dk.aau.cs.gui.undo.Command;
216+
217+import javax.swing.*;
218+import java.io.File;
219+import java.util.List;
220+
221+public class RemoveFileCommand extends Command {
222+ private DefaultListModel listModel;
223+ List<File> files;
224+ File file;
225+ private BatchProcessingDialog dialog;
226+ public RemoveFileCommand(DefaultListModel listModel, File file, List<File> files, BatchProcessingDialog dialog){
227+ this.listModel = listModel;
228+ this.file = file;
229+ this.files = files;
230+ this.dialog = dialog;
231+ }
232+ @Override
233+ public void redo() {
234+ files.remove(file);
235+ listModel.removeElement(file);
236+ dialog.enableButtons();
237+ }
238+
239+ @Override
240+ public void undo() {
241+ files.add(file);
242+ listModel.addElement(file);
243+ dialog.enableButtons();
244+ }
245+}
246+
247
248=== modified file 'src/pipe/gui/undo/UndoManager.java'
249--- src/pipe/gui/undo/UndoManager.java 2020-05-05 18:58:31 +0000
250+++ src/pipe/gui/undo/UndoManager.java 2020-05-10 20:01:44 +0000
251@@ -57,8 +57,10 @@
252 view = _view;
253 guiModel = _model;
254 app = _app;
255- app.setUndoActionEnabled(false);
256- app.setRedoActionEnabled(false);
257+ if(app != null) {
258+ app.setUndoActionEnabled(false);
259+ app.setRedoActionEnabled(false);
260+ }
261 for (int i = 0; i < UNDO_BUFFER_CAPACITY; i++) {
262 edits.add(null);
263 }
264@@ -67,8 +69,10 @@
265 public void redo() {
266
267 if (undoneEdits > 0) {
268- checkArcBeingDrawn();
269- checkMode();
270+ if(app != null && view != null) {
271+ checkArcBeingDrawn();
272+ checkMode();
273+ }
274
275 // The currentEdit to redo
276 Iterator<Command> currentEdit = edits.get(indexOfNextAdd)
277@@ -79,10 +83,12 @@
278 indexOfNextAdd = (indexOfNextAdd + 1) % UNDO_BUFFER_CAPACITY;
279 sizeOfBuffer++;
280 undoneEdits--;
281- if (undoneEdits == 0) {
282- app.setRedoActionEnabled(false);
283+ if(app != null) {
284+ if (undoneEdits == 0) {
285+ app.setRedoActionEnabled(false);
286+ }
287+ app.setUndoActionEnabled(true);
288 }
289- app.setUndoActionEnabled(true);
290 }
291 }
292
293@@ -99,8 +105,10 @@
294 public void undo() {
295
296 if (sizeOfBuffer > 0) {
297- checkArcBeingDrawn();
298- checkMode();
299+ if(app != null && view != null) {
300+ checkArcBeingDrawn();
301+ checkMode();
302+ }
303
304 if (--indexOfNextAdd < 0) {
305 indexOfNextAdd += UNDO_BUFFER_CAPACITY;
306@@ -113,11 +121,12 @@
307 for (int i = currentEdit.size() - 1; i >= 0; i--) {
308 currentEdit.get(i).undo();
309 }
310-
311- if (sizeOfBuffer == 0) {
312- app.setUndoActionEnabled(false);
313+ if(app != null) {
314+ if (sizeOfBuffer == 0) {
315+ app.setUndoActionEnabled(false);
316+ }
317+ app.setRedoActionEnabled(true);
318 }
319- app.setRedoActionEnabled(true);
320 }
321 }
322
323@@ -137,9 +146,13 @@
324 }
325
326 undoneEdits = 0;
327- app.setUndoActionEnabled(true);
328- app.setRedoActionEnabled(false);
329- view.setNetChanged(true);
330+ if(app != null) {
331+ app.setUndoActionEnabled(true);
332+ app.setRedoActionEnabled(false);
333+ }
334+ if(view != null){
335+ view.setNetChanged(true);
336+ }
337
338 ArrayList<Command> compoundEdit = new ArrayList<Command>();
339 edits.set(indexOfNextAdd, compoundEdit);

Subscribers

People subscribed via source and target branches