Merge lp:~yrke/tapaal/more-testing-and-refactorings into lp:tapaal

Proposed by Kenneth Yrke Jørgensen on 2020-08-30
Status: Work in progress
Proposed branch: lp:~yrke/tapaal/more-testing-and-refactorings
Merge into: lp:tapaal
Diff against target: 6041 lines (+1836/-1910)
74 files modified
src/dk/aau/cs/approximation/OverApproximation.java (+4/-6)
src/dk/aau/cs/gui/BatchProcessingDialog.java (+2/-2)
src/dk/aau/cs/gui/Context.java (+2/-2)
src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java (+3/-3)
src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java (+3/-3)
src/dk/aau/cs/gui/TabContent.java (+181/-243)
src/dk/aau/cs/gui/TabContentActions.java (+1/-4)
src/dk/aau/cs/gui/TemplateExplorer.java (+923/-919)
src/dk/aau/cs/gui/components/StatisticsPanel.java (+85/-97)
src/dk/aau/cs/gui/smartDraw/SmartDrawDialog.java (+17/-5)
src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java (+27/-13)
src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java (+2/-2)
src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java (+2/-2)
src/dk/aau/cs/gui/undo/MovePlaceTransitionObject.java (+1/-2)
src/dk/aau/cs/io/PNMLoader.java (+1/-4)
src/dk/aau/cs/io/TapnLegacyXmlLoader.java (+1/-3)
src/dk/aau/cs/io/TapnXmlLoader.java (+4/-7)
src/dk/aau/cs/io/TraceImportExport.java (+9/-8)
src/dk/aau/cs/io/queries/QueryLoader.java (+2/-2)
src/dk/aau/cs/io/queries/TAPNQueryLoader.java (+1/-1)
src/dk/aau/cs/io/queries/XMLQueryLoader.java (+1/-2)
src/dk/aau/cs/model/tapn/TimedPlace.java (+4/-2)
src/dk/aau/cs/model/tapn/simulation/ManualDelayMode.java (+1/-1)
src/dk/aau/cs/verification/TAPNComposer.java (+5/-7)
src/net/tapaal/TAPAAL.java (+12/-1)
src/pipe/gui/AnimationControlSidePanel.java (+1/-1)
src/pipe/gui/AnimationSettingsDialog.java (+2/-2)
src/pipe/gui/Animator.java (+13/-9)
src/pipe/gui/CreateGui.java (+8/-21)
src/pipe/gui/Export.java (+31/-30)
src/pipe/gui/ExportBatchDialog.java (+1/-1)
src/pipe/gui/Grid.java (+0/-18)
src/pipe/gui/GuiFrame.java (+66/-149)
src/pipe/gui/GuiFrameActions.java (+2/-0)
src/pipe/gui/GuiFrameController.java (+249/-31)
src/pipe/gui/GuiFrameControllerActions.java (+4/-0)
src/pipe/gui/MessengerImpl.java (+1/-2)
src/pipe/gui/RunKBoundAnalysis.java (+2/-2)
src/pipe/gui/RunVerification.java (+5/-5)
src/pipe/gui/SimulationControl.java (+1/-1)
src/pipe/gui/TikZExporter.java (+6/-3)
src/pipe/gui/Verifier.java (+2/-2)
src/pipe/gui/action/EditAnnotationBorderAction.java (+1/-2)
src/pipe/gui/action/SplitArcAction.java (+1/-3)
src/pipe/gui/action/SplitArcPointAction.java (+1/-1)
src/pipe/gui/action/ToggleArcPointAction.java (+1/-2)
src/pipe/gui/canvas/DrawingSurfaceImpl.java (+5/-60)
src/pipe/gui/graphicElements/AnnotationNote.java (+2/-2)
src/pipe/gui/graphicElements/ArcPath.java (+15/-2)
src/pipe/gui/graphicElements/ArcPathPoint.java (+1/-1)
src/pipe/gui/graphicElements/Note.java (+3/-5)
src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java (+0/-4)
src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java (+1/-1)
src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java (+1/-1)
src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java (+1/-1)
src/pipe/gui/handler/ArcHandler.java (+1/-1)
src/pipe/gui/handler/ArcPathPointHandler.java (+1/-3)
src/pipe/gui/handler/LabelHandler.java (+1/-1)
src/pipe/gui/handler/PetriNetObjectHandler.java (+12/-95)
src/pipe/gui/handler/PlaceTransitionObjectHandler.java (+1/-1)
src/pipe/gui/undo/AddArcPathPointEdit.java (+1/-7)
src/pipe/gui/undo/DeleteArcPathPointEdit.java (+1/-7)
src/pipe/gui/widgets/ChooseInclusionPlacesDialog.java (+1/-1)
src/pipe/gui/widgets/ConstantsDialogPanel.java (+48/-44)
src/pipe/gui/widgets/ConstantsPane.java (+11/-11)
src/pipe/gui/widgets/EngineDialogPanel.java (+1/-2)
src/pipe/gui/widgets/GuardDialogue.java (+1/-1)
src/pipe/gui/widgets/NewTAPNPanel.java (+8/-9)
src/pipe/gui/widgets/PlaceEditorPanel.java (+1/-1)
src/pipe/gui/widgets/QueryDialog.java (+19/-16)
src/pipe/gui/widgets/TAPNTransitionEditor.java (+1/-1)
src/pipe/gui/widgets/WorkflowDialog.java (+2/-2)
src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java (+2/-2)
src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java (+2/-2)
To merge this branch: bzr merge lp:~yrke/tapaal/more-testing-and-refactorings
Reviewer Review Type Date Requested Status
TAPAAL Reviewers 2020-08-30 Pending
Review via email: mp+389997@code.launchpad.net
To post a comment you must log in.
1155. By Kenneth Yrke Jørgensen on 2020-08-30

Merged with trunk

1156. By Kenneth Yrke Jørgensen on 2020-08-30

Merged with branch

Unmerged revisions

1156. By Kenneth Yrke Jørgensen on 2020-08-30

Merged with branch

1155. By Kenneth Yrke Jørgensen on 2020-08-30

Merged with trunk

1154. By Kenneth Yrke Jørgensen on 2020-08-23

Removed usage for static accessor to guiFrame

1153. By Kenneth Yrke Jørgensen on 2020-08-21

Removed actions now internal to TabContent

1152. By Kenneth Yrke Jørgensen on 2020-08-21

Merged trunk

1151. By Kenneth Yrke Jørgensen on 2020-08-20

Removed drawingsurface having access to the model. TabContent now saves what template is active

1150. By Kenneth Yrke Jørgensen on 2020-08-18

Replaved chained call to undomanager via getCurrentTab

1149. By Kenneth Yrke Jørgensen on 2020-08-18

Replaced chained calls to getDrawingSurface via get Currenttab

1148. By Kenneth Yrke Jørgensen on 2020-08-18

Removed ference to CreateGui

1147. By Kenneth Yrke Jørgensen on 2020-08-18

Replaces static accessor with parameter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/approximation/OverApproximation.java'
2--- src/dk/aau/cs/approximation/OverApproximation.java 2020-07-20 12:17:24 +0000
3+++ src/dk/aau/cs/approximation/OverApproximation.java 2020-08-30 09:33:26 +0000
4@@ -74,15 +74,13 @@
5 TimedArcPetriNet net = transformedModel.value1();
6
7 LocalTimedPlace currentPlace = new LocalTimedPlace("PTRACE0");
8- TimedToken currentToken = new TimedToken(currentPlace);
9- net.add(currentPlace);
10- currentPlace.addToken(currentToken);
11+ net.add(currentPlace);
12+ currentPlace.addTokens(1);
13
14 // Block place, which secures the net makes at most one transition not in the trace.
15 LocalTimedPlace blockPlace = new LocalTimedPlace("PBLOCK", TimeInvariant.LESS_THAN_INFINITY);
16- TimedToken blockToken = new TimedToken(blockPlace);
17- net.add(blockPlace);
18- blockPlace.addToken(blockToken);
19+ net.add(blockPlace);
20+ blockPlace.addTokens(1);
21
22 // Copy the original transitions
23 ArrayList<TimedTransition> originalTransitions = new ArrayList<TimedTransition>();
24
25=== modified file 'src/dk/aau/cs/gui/BatchProcessingDialog.java'
26--- src/dk/aau/cs/gui/BatchProcessingDialog.java 2020-07-20 07:55:49 +0000
27+++ src/dk/aau/cs/gui/BatchProcessingDialog.java 2020-08-30 09:33:26 +0000
28@@ -295,7 +295,7 @@
29 batchProcessingDialog = null;
30 }
31 if(batchProcessingDialog == null){
32- batchProcessingDialog = new BatchProcessingDialog(CreateGui.getApp(), "Batch Processing", true, ListOfQueries);
33+ batchProcessingDialog = new BatchProcessingDialog(CreateGui.getRootFrame(), "Batch Processing", true, ListOfQueries);
34 batchProcessingDialog.pack();
35 batchProcessingDialog.setPreferredSize(batchProcessingDialog.getSize());
36 //Set the minimum size to 150 less than the preferred, to be consistent with the minimum size of the result panel
37@@ -990,7 +990,7 @@
38 exporter.exportToCSV(tableModel.getResults(), exportFile);
39 } catch (Exception e1) {
40 JOptionPane.showMessageDialog(
41- CreateGui.getApp(),
42+ CreateGui.getRootFrame(),
43 "An error occurred while trying to export the results. Please try again",
44 "Error Exporting Results",
45 JOptionPane.ERROR_MESSAGE
46
47=== modified file 'src/dk/aau/cs/gui/Context.java'
48--- src/dk/aau/cs/gui/Context.java 2019-07-06 09:21:46 +0000
49+++ src/dk/aau/cs/gui/Context.java 2020-08-30 09:33:26 +0000
50@@ -7,7 +7,7 @@
51 import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
52 import dk.aau.cs.util.Require;
53
54-public class Context { // TODO: consider having only currentTab as a field and have methods ask it for the things?
55+public class Context {
56 private final TimedArcPetriNetNetwork network;
57 private final Template selectedTemplate;
58
59@@ -43,6 +43,6 @@
60 }
61
62 public NameGenerator nameGenerator() {
63- return currentTab.drawingSurface().getNameGenerator();
64+ return currentTab.getNameGenerator();
65 }
66 }
67
68=== modified file 'src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java'
69--- src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java 2020-07-21 08:15:45 +0000
70+++ src/dk/aau/cs/gui/DeleteSharedPlaceOrTransition.java 2020-08-30 09:33:26 +0000
71@@ -82,7 +82,7 @@
72 JList listOfComponents = new JList(affectedComponents.toArray());
73 JScrollPane scrollPane = new JScrollPane(listOfComponents);
74 Object[] params = {label, checkBox, new JLabel("Components affected:"), scrollPane};
75- result = JOptionPane.showConfirmDialog(CreateGui.getApp(), params, "Warning", JOptionPane.OK_CANCEL_OPTION);
76+ result = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(), params, "Warning", JOptionPane.OK_CANCEL_OPTION);
77 boolean deleteFromTemplates = checkBox.isSelected();
78 return new DeleteSharedResult(result, deleteFromTemplates);
79 }
80@@ -150,7 +150,7 @@
81 }
82 buffer.append(System.getProperty("line.separator"));
83 buffer.append("Do you want to continue?");
84- int choice = JOptionPane.showConfirmDialog(CreateGui.getApp(), buffer.toString(), "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
85+ int choice = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(), buffer.toString(), "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
86 if(choice == JOptionPane.NO_OPTION) return;
87
88 Command cmd = new DeleteQueriesCommand(tab, affectedQueries);
89@@ -273,7 +273,7 @@
90 }
91 buffer.append(System.getProperty("line.separator"));
92 buffer.append("Do you want to continue?");
93- int choice = JOptionPane.showConfirmDialog(CreateGui.getApp(), buffer.toString(), "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
94+ int choice = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(), buffer.toString(), "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
95 if(choice == JOptionPane.NO_OPTION) return;
96
97 Command cmd = new DeleteQueriesCommand(tab, affectedQueries);
98
99=== modified file 'src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java'
100--- src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2020-08-04 07:07:59 +0000
101+++ src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2020-08-30 09:33:26 +0000
102@@ -75,7 +75,7 @@
103 Require.that(tab != null, "tab cannot be null");
104
105 undoManager = tab.getUndoManager();
106- nameGenerator = tab.drawingSurface().getNameGenerator();
107+ nameGenerator = tab.getNameGenerator();
108 this.tab = tab;
109
110 sharedPlacesListModel = new SharedPlacesListModel(tab.network());
111@@ -385,7 +385,7 @@
112 }
113
114 private void showSharedTransitionNameDialog(SharedTransition transitionToEdit) {
115- EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Edit Shared Transition", true);
116+ EscapableDialog guiDialog = new EscapableDialog(CreateGui.getRootFrame(), "Edit Shared Transition", true);
117 Container contentPane = guiDialog.getContentPane();
118 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
119 JPanel panel = new SharedTransitionNamePanel(guiDialog.getRootPane(), sharedTransitionsListModel, undoManager, nameGenerator, new Context(tab), transitionToEdit);
120@@ -398,7 +398,7 @@
121 }
122
123 private void showSharedPlaceNameDialog(SharedPlace placeToEdit) {
124- EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Edit Shared Place", true);
125+ EscapableDialog guiDialog = new EscapableDialog(CreateGui.getRootFrame(), "Edit Shared Place", true);
126 Container contentPane = guiDialog.getContentPane();
127 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
128
129
130=== modified file 'src/dk/aau/cs/gui/TabContent.java'
131--- src/dk/aau/cs/gui/TabContent.java 2020-08-24 09:50:07 +0000
132+++ src/dk/aau/cs/gui/TabContent.java 2020-08-30 09:33:26 +0000
133@@ -54,7 +54,7 @@
134
135 public class TabContent extends JSplitPane implements TabContentActions{
136
137- private MutableReference<GuiFrameControllerActions> guiFrameControllerActions = new MutableReference<>();
138+ private final MutableReference<GuiFrameControllerActions> guiFrameControllerActions = new MutableReference<>();
139
140 public void setGuiFrameControllerActions(GuiFrameControllerActions guiFrameControllerActions) {
141 this.guiFrameControllerActions.setReference(guiFrameControllerActions);
142@@ -93,7 +93,14 @@
143
144 private final UndoManager undoManager = new UndoManager();
145
146- private enum FeatureOption { TIME, GAME, COLOR };
147+ public static int getNameCounter() {
148+ return newNameCounter;
149+ }
150+
151+ public static void incrementNameCounter() {
152+ newNameCounter++;
153+ }
154+ private static int newNameCounter = 1;
155
156 public final static class Result<T,R> {
157 private final T result;
158@@ -160,7 +167,7 @@
159 Require.notNull(c, "datalyer can't be null");
160 Require.notNull(p, "Point can't be null");
161
162- dk.aau.cs.model.tapn.LocalTimedPlace tp = new dk.aau.cs.model.tapn.LocalTimedPlace(drawingSurface.getNameGenerator().getNewPlaceName(guiModelToModel.get(c)));
163+ dk.aau.cs.model.tapn.LocalTimedPlace tp = new dk.aau.cs.model.tapn.LocalTimedPlace(getNameGenerator().getNewPlaceName(guiModelToModel.get(c)));
164 TimedPlaceComponent pnObject = new TimedPlaceComponent(p.x, p.y, tp, lens);
165 guiModelToModel.get(c).add(tp);
166 c.addPetriNetObject(pnObject);
167@@ -169,8 +176,9 @@
168 return new Result<>(pnObject);
169 }
170
171+
172 public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p, boolean isUncontrollable) {
173- dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));
174+ dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));
175
176 transition.setUncontrollable(isUncontrollable);
177 TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition, lens);
178@@ -434,7 +442,7 @@
179 s.append("\nAre you sure you want to remove the current selection and all associated queries?");
180
181 int choice = queriesAffected ? JOptionPane.showConfirmDialog(
182- CreateGui.getApp(), s.toString(), "Warning",
183+ CreateGui.getRootFrame(), s.toString(), "Warning",
184 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
185 : JOptionPane.YES_OPTION;
186
187@@ -468,8 +476,7 @@
188 Command cmd = new DeleteArcPathPointEdit(
189 arcPathPoint.getArcPath().getArc(),
190 arcPathPoint,
191- arcPathPoint.getIndex(),
192- getModel()
193+ arcPathPoint.getIndex()
194 );
195 cmd.redo();
196 getUndoManager().addEdit(cmd);
197@@ -578,183 +585,19 @@
198
199 }
200
201-
202- /**
203- * Creates a new tab with the selected file, or a new file if filename==null
204- */
205- public static TabContent createNewTabFromInputStream(InputStream file, String name) throws Exception {
206-
207- try {
208- ModelLoader loader = new ModelLoader();
209- LoadedModel loadedModel = loader.load(file);
210-
211- if (loadedModel.getMessages().size() != 0) {
212- new Thread(new Runnable() {
213- @Override
214- public void run() {
215- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
216- String message = "While loading the net we found one or more warnings: \n\n";
217- for (String s : loadedModel.getMessages()) {
218- message += s + "\n\n";
219- }
220-
221- new MessengerImpl().displayInfoMessage(message, "Warning");
222- }
223- }).start();
224- }
225-
226- TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), loadedModel.getLens());
227-
228- tab.setInitialName(name);
229-
230- tab.selectFirstElements();
231-
232- tab.setFile(null);
233-
234- return tab;
235- } catch (Exception e) {
236- throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
237- }
238-
239- }
240-
241- private TabContent createNewTabFromInputStream(InputStream file, String name, FeatureOption option, boolean isYes) throws Exception {
242-
243- try {
244- ModelLoader loader = new ModelLoader();
245- LoadedModel loadedModel = loader.load(file);
246-
247- if (loadedModel.getMessages().size() != 0) {
248- new Thread(new Runnable() {
249- @Override
250- public void run() {
251- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
252- String message = "While loading the net we found one or more warnings: \n\n";
253- for (String s : loadedModel.getMessages()) {
254- message += s + "\n\n";
255- }
256-
257- new MessengerImpl().displayInfoMessage(message, "Warning");
258- }
259- }).start();
260- }
261-
262- TabContent tab;
263-
264- switch (option) {
265- case TIME:
266- tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), isYes, lens.isGame());
267- break;
268- case GAME:
269- tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), lens.isTimed(), isYes);
270- break;
271- default:
272- tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), lens.isTimed(), lens.isGame());
273- break;
274- }
275-
276- tab.setInitialName(name);
277-
278- tab.selectFirstElements();
279-
280- tab.setFile(null);
281-
282- return tab;
283- } catch (Exception e) {
284- throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
285- }
286-
287- }
288-
289- public static TabContent createNewEmptyTab(String name, boolean isTimed, boolean isGame){
290- TabContent tab = new TabContent(isTimed, isGame);
291+ public static TabContent createNewEmptyTab(String name, boolean isTimed, boolean isGame){
292+ TabContent tab = new TabContent(new TimedArcPetriNetNetwork(), new ArrayList<>(), new TAPNLens(isTimed, isGame));
293 tab.setInitialName(name);
294
295 //Set Default Template
296- String templateName = tab.drawingSurface().getNameGenerator().getNewTemplateName();
297+ String templateName = tab.getNameGenerator().getNewTemplateName();
298 Template template = new Template(new TimedArcPetriNet(templateName), new DataLayer(), new Zoomer());
299 tab.addTemplate(template);
300
301 return tab;
302 }
303
304- /**
305- * Creates a new tab with the selected file, or a new file if filename==null
306- */
307-
308- public static TabContent createNewTabFromPNMLFile(File file) throws Exception {
309-
310- if (file != null) {
311- try {
312-
313- LoadedModel loadedModel;
314-
315- PNMLoader loader = new PNMLoader();
316- loadedModel = loader.load(file);
317-
318- TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries());
319-
320- String name = null;
321-
322- if (file != null) {
323- name = file.getName().replaceAll(".pnml", ".tapn");
324- }
325- tab.setInitialName(name);
326-
327- tab.selectFirstElements();
328-
329- tab.setMode(Pipe.ElementType.SELECT);
330-
331- //appView.updatePreferredSize(); //XXX 2018-05-23 kyrke seems not to be needed
332- name = name.replace(".pnml",".tapn"); // rename .pnml input file to .tapn
333- return tab;
334-
335- } catch (Exception e) {
336- throw new Exception("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString());
337- }
338- }
339- return null;
340- }
341-
342- /**
343- * Creates a new tab with the selected file, or a new file if filename==null
344- */
345- //XXX should properly be in controller?
346- public static TabContent createNewTabFromFile(File file) throws Exception {
347- try {
348- String name = file.getName();
349- boolean showFileEndingChangedMessage = false;
350-
351- if(name.toLowerCase().endsWith(".xml")){
352- name = name.substring(0, name.lastIndexOf('.')) + ".tapn";
353- showFileEndingChangedMessage = true;
354- }
355-
356- InputStream stream = new FileInputStream(file);
357- TabContent tab = createNewTabFromInputStream(stream, name);
358- if (tab != null && !showFileEndingChangedMessage) tab.setFile(file);
359-
360- showFileEndingChangedMessage(showFileEndingChangedMessage);
361-
362- return tab;
363- }catch (FileNotFoundException e) {
364- throw new FileNotFoundException("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nFile not found:\n - " + e.toString());
365- }
366- }
367-
368- private static void showFileEndingChangedMessage(boolean showMessage) {
369- if(showMessage) {
370- //We thread this so it does not block the EDT
371- new Thread(new Runnable() {
372- @Override
373- public void run() {
374- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
375- new MessengerImpl().displayInfoMessage("We have changed the ending of TAPAAL files from .xml to .tapn and the opened file was automatically renamed to end with .tapn.\n"
376- + "Once you save the .tapn model, we recommend that you manually delete the .xml file.", "FILE CHANGED");
377- }
378- }).start();
379- }
380- }
381+
382
383 public UndoManager getUndoManager() {
384 return undoManager;
385@@ -808,11 +651,7 @@
386 private WorkflowDialog workflowDialog = null;
387
388
389- private TabContent(boolean isTimed, boolean isGame) {
390- this(new TimedArcPetriNetNetwork(), new ArrayList<>(), new TAPNLens(isTimed,isGame));
391- }
392-
393- private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, TAPNLens lens) {
394+ private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, TAPNLens lens) {
395
396 Require.that(network != null, "network cannot be null");
397 Require.notNull(lens, "Lens can't be null");
398@@ -867,14 +706,7 @@
399 animationModeController = new CanvasAnimationController(getAnimator());
400 }
401
402- private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, boolean isTimed, boolean isGame) {
403- this(network, templates, tapnqueries, new TAPNLens(isTimed, isGame));
404- }
405-
406- private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries) {
407- this(network, templates, tapnqueries, new TAPNLens(true, false));
408- }
409- public TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, TAPNLens lens) {
410+ public TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, TAPNLens lens) {
411 this(network, templates, lens);
412
413 setNetwork(network, templates);
414@@ -1041,8 +873,8 @@
415 String initialName = "";
416 public void setInitialName(String name) {
417 if (name == null || name.isEmpty()) {
418- name = "New Petri net " + (CreateGui.getApp().getNameCounter()) + ".tapn";
419- CreateGui.getApp().incrementNameCounter();
420+ name = "New Petri net " + (getNameCounter()) + ".tapn";
421+ incrementNameCounter();
422 } else if (!name.toLowerCase().endsWith(".tapn")){
423 name = name + ".tapn";
424 }
425@@ -1461,7 +1293,7 @@
426 transitionFireing.showDelayEnabledTransitions(enable);
427 drawingSurface.repaint();
428
429- CreateGui.getAnimator().updateFireableTransitions();
430+ getAnimator().updateFireableTransitions();
431 }
432
433 public void selectFirstElements() {
434@@ -1496,7 +1328,7 @@
435
436 @Override
437 public void importTrace() {
438- TraceImportExport.importTrace();
439+ TraceImportExport.importTrace(animator);
440 }
441
442 @Override
443@@ -1552,7 +1384,7 @@
444 if (!isTime){
445 if (!network().isUntimed()){
446 String removeTimeWarning = "The net contains time information, which will be removed. Do you still wish to make the net untimed?";
447- int choice = JOptionPane.showOptionDialog(CreateGui.getApp(), removeTimeWarning, "Remove time information",
448+ int choice = JOptionPane.showOptionDialog(CreateGui.getRootFrame(), removeTimeWarning, "Remove time information",
449 JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, 0);
450 if (choice == 0) {
451 createNewAndConvertUntimed();
452@@ -1565,7 +1397,6 @@
453 findAndRemoveAffectedQueries(tab);
454 guiFrameControllerActions.ifPresent(o -> o.openTab(tab));
455 }
456- updateFeatureText();
457 }
458 }
459
460@@ -1592,7 +1423,7 @@
461 if (!isGame){
462 if (network().hasUncontrollableTransitions()){
463 String removeTimeWarning = "The net contains game information, which will be removed. Do you still wish to make to remove the game semantics?";
464- int choice = JOptionPane.showOptionDialog(CreateGui.getApp(), removeTimeWarning, "Remove game information",
465+ int choice = JOptionPane.showOptionDialog(CreateGui.getRootFrame(), removeTimeWarning, "Remove game information",
466 JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, 0);
467 if (choice == 0) {
468 createNewAndConvertNonGame();
469@@ -1605,7 +1436,6 @@
470 findAndRemoveGameAffectedQueries(tab);
471 guiFrameControllerActions.ifPresent(o -> o.openTab(tab));
472 }
473- updateFeatureText();
474 }
475 }
476
477@@ -1669,6 +1499,11 @@
478 this.workflowDialog = dialog;
479 }
480
481+ private final NameGenerator nameGenerator = new NameGenerator();
482+ public NameGenerator getNameGenerator() {
483+ return nameGenerator;
484+ }
485+
486 private boolean netChanged = false;
487 @Override
488 public boolean getNetChanged() {
489@@ -1682,7 +1517,8 @@
490 public void changeToTemplate(Template tapn) {
491 Require.notNull(tapn, "Can't change to a Template that is null");
492
493- drawingSurface.setModel(tapn.guiModel(), tapn.model(), tapn.zoomer());
494+ drawingSurface.setModel(tapn.guiModel(), tapn.zoomer());
495+ nameGenerator.add(tapn.model());
496
497 //If the template is currently selected
498 //XXX: kyrke - 2019-07-06, templ solution while refactoring, there is properly a better way
499@@ -1745,7 +1581,7 @@
500 app.ifPresent(o->o.setStatusBarText(textforAnimation));
501
502 } else {
503- JOptionPane.showMessageDialog(CreateGui.getApp(),
504+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
505 "You need at least one active template to enter simulation mode",
506 "Simulation Mode Error", JOptionPane.ERROR_MESSAGE);
507 animationmode = false;
508@@ -1761,8 +1597,6 @@
509
510 switchToEditorComponents();
511
512- setManager(notingManager);
513-
514 drawingSurface().setBackground(Pipe.ELEMENT_FILL_COLOUR);
515 setMode(Pipe.ElementType.SELECT);
516
517@@ -1782,7 +1616,6 @@
518 @Override
519 public void setMode(Pipe.ElementType mode) {
520
521- CreateGui.guiMode = mode;
522 changeStatusbarText(mode);
523
524 //Disable selection and deselect current selection
525@@ -1852,7 +1685,7 @@
526
527 @Override
528 public void showStatistics() {
529- StatisticsPanel.showStatisticsPanel(drawingSurface().getModel().getStatistics());
530+ StatisticsPanel.showStatisticsPanel(currentTemplate().model().getStatistics(), this);
531 }
532
533 @Override
534@@ -1907,7 +1740,7 @@
535 "No"};
536
537 String optionText = "Do you want to replace constants with values?";
538- openCTLDialog = JOptionPane.showOptionDialog(CreateGui.getApp(), optionText, "Merge Net Components Dialog", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
539+ openCTLDialog = JOptionPane.showOptionDialog(CreateGui.getRootFrame(), optionText, "Merge Net Components Dialog", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
540 if(openCTLDialog == JOptionPane.YES_OPTION){
541 inlineConstants = true;
542 } else if(openCTLDialog == JOptionPane.NO_OPTION){
543@@ -1949,8 +1782,6 @@
544
545 updateFeatureText();
546
547- updateFeatureText();
548-
549 //XXX
550 if (isInAnimationMode()) {
551 app.ifPresent(o->o.setGUIMode(GuiFrame.GUIMode.animation));
552@@ -2012,16 +1843,6 @@
553 getAnimator().stepForward();
554 }
555
556- @Override
557- public void timeDelay() {
558- getAnimator().letTimePass(BigDecimal.ONE);
559- }
560-
561- @Override
562- public void delayAndFire() {
563- getTransitionFireingComponent().fireSelectedTransition();
564- }
565-
566 @Override
567 public void undo() {
568 if (!isInAnimationMode()) {
569@@ -2071,7 +1892,7 @@
570 } catch (Exception e) {
571 Logger.log(e);
572 e.printStackTrace();
573- JOptionPane.showMessageDialog(CreateGui.getApp(), e.toString(),
574+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), e.toString(),
575 "File Output Error", JOptionPane.ERROR_MESSAGE);
576 }
577 }
578@@ -2092,7 +1913,7 @@
579
580 } catch (Exception e) {
581 e.printStackTrace();
582- JOptionPane.showMessageDialog(CreateGui.getApp(), e.toString(), "File Output Error", JOptionPane.ERROR_MESSAGE);
583+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), e.toString(), "File Output Error", JOptionPane.ERROR_MESSAGE);
584 }
585 }
586
587@@ -2152,7 +1973,8 @@
588 String composedName = getTabTitle();
589 composedName = composedName.replace(".tapn", "");
590 composedName += appendName;
591- return createNewTabFromInputStream(new ByteArrayInputStream(outputStream.toByteArray()), composedName);
592+ final String composedNameFinal = composedName;
593+ return guiFrameControllerActions.map(o->o.createNewTabFromInputStream(new ByteArrayInputStream(outputStream.toByteArray()), composedNameFinal)).get();
594 } catch (Exception e1) {
595 Logger.log("Could not load model");
596 e1.printStackTrace();
597@@ -2228,7 +2050,7 @@
598 protected void transitionClicked(TimedTransitionComponent pno, MouseEvent e) {
599 if (place != null && transition == null) {
600 transition = pno;
601- CreateGui.getDrawingSurface().clearAllPrototype();
602+ drawingSurface.clearAllPrototype();
603 var result = guiModelManager.addInhibitorArc(getModel(), place, transition, arc.getArcPath());
604 showPopupIfFailed(result);
605 clearPendingArc();
606@@ -2244,7 +2066,7 @@
607 //to avoid this we change the endpoint to set the end point to the same as the end point
608 //needs further refactorings //kyrke 2019-09-05
609 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
610- CreateGui.getDrawingSurface().addPrototype(arc);
611+ drawingSurface.addPrototype(arc);
612 arc.requestFocusInWindow();
613 arc.setSelectable(false);
614 arc.enableDrawingKeyBindings(this::clearPendingArc);
615@@ -2254,7 +2076,7 @@
616 @Override
617 protected void clearPendingArc() {
618 super.clearPendingArc();
619- CreateGui.getDrawingSurface().clearAllPrototype();
620+ drawingSurface.clearAllPrototype();
621 place = null;
622 transition = null;
623 arc = null;
624@@ -2320,8 +2142,8 @@
625 if (arc!=null) {
626 if (!e.isControlDown()) {
627 Point p = e.getPoint();
628- int x = Zoomer.getUnzoomedValue(p.x, CreateGui.getDrawingSurface().getZoom());
629- int y = Zoomer.getUnzoomedValue(p.y, CreateGui.getDrawingSurface().getZoom());
630+ int x = Zoomer.getUnzoomedValue(p.x, drawingSurface.getZoom());
631+ int y = Zoomer.getUnzoomedValue(p.y, drawingSurface.getZoom());
632
633 boolean shiftDown = e.isShiftDown();
634 //XXX: x,y is ignored is overwritten when mouse is moved, this just add a new point to the end of list
635@@ -2354,7 +2176,7 @@
636 }
637
638 JOptionPane.showMessageDialog(
639- CreateGui.getApp(),
640+ CreateGui.getRootFrame(),
641 errorMessage,
642 "Error", JOptionPane.ERROR_MESSAGE
643 );
644@@ -2407,13 +2229,13 @@
645 //to avoid this we change the endpoint to set the end point to the same as the end point
646 //needs further refactorings //kyrke 2019-09-05
647 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
648- CreateGui.getDrawingSurface().addPrototype(arc);
649+ drawingSurface.addPrototype(arc);
650 arc.requestFocusInWindow();
651 arc.setSelectable(false);
652 arc.enableDrawingKeyBindings(this::clearPendingArc);
653 } else if (place != null && transition == null) {
654 transition = pno;
655- CreateGui.getDrawingSurface().clearAllPrototype();
656+ drawingSurface.clearAllPrototype();
657 var result = guiModelManager.addTimedInputArc(getModel(), place, transition, arc.getArcPath());
658 showPopupIfFailed(result);
659 clearPendingArc();
660@@ -2426,7 +2248,7 @@
661 //to avoid this we change the endpoint to set the end point to the same as the end point
662 //needs further refactorings //kyrke 2019-09-05
663 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
664- CreateGui.getDrawingSurface().addPrototype(arc);
665+ drawingSurface.addPrototype(arc);
666 arc.requestFocusInWindow();
667 arc.setSelectable(false);
668 arc.enableDrawingKeyBindings(this::clearPendingArc);
669@@ -2443,13 +2265,13 @@
670 //to avoid this we change the endpoint to set the end point to the same as the end point
671 //needs further refactorings //kyrke 2019-09-05
672 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
673- CreateGui.getDrawingSurface().addPrototype(arc);
674+ drawingSurface.addPrototype(arc);
675 arc.requestFocusInWindow();
676 arc.setSelectable(false);
677 arc.enableDrawingKeyBindings(this::clearPendingArc);
678 } else if (transition != null && place == null) {
679 place = pno;
680- CreateGui.getDrawingSurface().clearAllPrototype();
681+ drawingSurface.clearAllPrototype();
682 var result = guiModelManager.addTimedOutputArc(getModel(), transition, place, arc.getArcPath());
683 showPopupIfFailed(result);
684 clearPendingArc();
685@@ -2462,7 +2284,7 @@
686 //to avoid this we change the endpoint to set the end point to the same as the end point
687 //needs further refactorings //kyrke 2019-09-05
688 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
689- CreateGui.getDrawingSurface().addPrototype(arc);
690+ drawingSurface.addPrototype(arc);
691 arc.requestFocusInWindow();
692 arc.setSelectable(false);
693 arc.enableDrawingKeyBindings(this::clearPendingArc);
694@@ -2473,7 +2295,7 @@
695 @Override
696 protected void clearPendingArc() {
697 super.clearPendingArc();
698- CreateGui.getDrawingSurface().clearAllPrototype();
699+ drawingSurface.clearAllPrototype();
700 place = null;
701 transition = null;
702 arc = null;
703@@ -2481,7 +2303,7 @@
704
705 }
706
707- static class CanvasAnimationController extends AbstractDrawingSurfaceManager {
708+ class CanvasAnimationController extends AbstractDrawingSurfaceManager {
709
710 private final Animator animator;
711
712@@ -2531,7 +2353,7 @@
713 @Override
714 public void teardownManager() {
715 //Remove all mouse-over menus if we exit animation mode
716- ArrayList<PetriNetObject> selection = CreateGui.getCurrentTab().drawingSurface().getGuiModel().getPNObjects();
717+ ArrayList<PetriNetObject> selection = drawingSurface().getGuiModel().getPNObjects();
718
719 for (PetriNetObject pn : selection) {
720 if (pn instanceof TimedPlaceComponent) {
721@@ -2610,7 +2432,7 @@
722 //to avoid this we change the endpoint to set the end point to the same as the end point
723 //needs further refactorings //kyrke 2019-09-05
724 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
725- CreateGui.getDrawingSurface().addPrototype(arc);
726+ drawingSurface.addPrototype(arc);
727 arc.requestFocusInWindow();
728 arc.setSelectable(false);
729 arc.enableDrawingKeyBindings(this::clearPendingArc);
730@@ -2626,13 +2448,13 @@
731 //to avoid this we change the endpoint to set the end point to the same as the end point
732 //needs further refactorings //kyrke 2019-09-05
733 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
734- CreateGui.getDrawingSurface().addPrototype(arc);
735+ drawingSurface.addPrototype(arc);
736 arc.requestFocusInWindow();
737 arc.setSelectable(false);
738 arc.enableDrawingKeyBindings(this::clearPendingArc);
739 } else if (transition != null && place2 == null) {
740 place2 = pno;
741- CreateGui.getDrawingSurface().clearAllPrototype();
742+ drawingSurface.clearAllPrototype();
743 var result = guiModelManager.addTimedTransportArc(getModel(), place1, transition, place2, arc1.getArcPath(), arc2.getArcPath());
744 showPopupIfFailed(result);
745 clearPendingArc();
746@@ -2645,7 +2467,7 @@
747 //to avoid this we change the endpoint to set the end point to the same as the end point
748 //needs further refactorings //kyrke 2019-09-05
749 arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false);
750- CreateGui.getDrawingSurface().addPrototype(arc);
751+ drawingSurface.addPrototype(arc);
752 arc.requestFocusInWindow();
753 arc.setSelectable(false);
754 arc.enableDrawingKeyBindings(this::clearPendingArc);
755@@ -2656,7 +2478,7 @@
756 @Override
757 protected void clearPendingArc() {
758 super.clearPendingArc();
759- CreateGui.getDrawingSurface().clearAllPrototype();
760+ drawingSurface.clearAllPrototype();
761 place1 = place2 = null;
762 transition = null;
763 arc = arc1 = arc2 = null;
764@@ -2665,9 +2487,22 @@
765 }
766
767 private class CanvasGeneralDrawController extends AbstractDrawingSurfaceManager {
768+
769 @Override
770 public void registerEvents() {
771 registerEvent(
772+ e->e.pno instanceof PetriNetObject && e.a == MouseAction.pressed && SwingUtilities.isLeftMouseButton(e.e),
773+ e-> placeTranstionObjectPressed(((PetriNetObject) e.pno), e.e.isShiftDown(), e.e)
774+ );
775+ registerEvent(
776+ e->e.pno instanceof PetriNetObject && e.a == MouseAction.released && SwingUtilities.isLeftMouseButton(e.e),
777+ e-> placeTranstionObjectReleased(((PetriNetObject) e.pno), e.e.isShiftDown(), e.e)
778+ );
779+ registerEvent(
780+ e->e.pno instanceof PetriNetObject && e.a == MouseAction.dragged && SwingUtilities.isLeftMouseButton(e.e),
781+ e-> placeTranstionObjectDragged(((PetriNetObject) e.pno), e.e.isShiftDown(), e.e)
782+ );
783+ registerEvent(
784 e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.doubleClicked,
785 e-> ((TimedTransitionComponent) e.pno).showEditor()
786 );
787@@ -2722,6 +2557,75 @@
788
789 }
790
791+ boolean justSelected = false;
792+ boolean isDragging = false;
793+ Point dragInit;
794+ private int totalX = 0;
795+ private int totalY = 0;
796+
797+ private void placeTranstionObjectPressed(PetriNetObject pno, boolean shiftDown, MouseEvent e) {
798+ dragInit = e.getPoint();
799+ if (!pno.isSelected()) {
800+ if (!shiftDown) {
801+ pno.getParent().getSelectionObject().clearSelection();
802+ }
803+ pno.select();
804+ justSelected = true;
805+ }
806+ }
807+
808+ private void placeTranstionObjectReleased(PetriNetObject pno, boolean shiftDown, MouseEvent e) {
809+ if (isDragging) {
810+ isDragging = false;
811+ drawingSurface.translateSelection(pno.getParent().getSelectionObject().getSelection(), totalX, totalY);
812+ totalX = 0;
813+ totalY = 0;
814+ } else if (!justSelected) {
815+ if (shiftDown) {
816+ pno.deselect();
817+ } else {
818+ pno.getParent().getSelectionObject().clearSelection();
819+ pno.select();
820+ }
821+ }
822+ justSelected = false;
823+ dragInit = null;
824+ totalX = 0;
825+ totalY = 0;
826+ }
827+
828+ private void placeTranstionObjectDragged(PetriNetObject myObject, boolean shiftDown, MouseEvent e) {
829+
830+ if (myObject instanceof Arc) {
831+ //XXX: Current implementation is buggy when dragging an arc, therefore we disable it
832+ return;
833+ }
834+
835+ int previousX = myObject.getX();
836+ int previousY = myObject.getY();
837+
838+ if (!SwingUtilities.isLeftMouseButton(e)) {
839+ return;
840+ }
841+
842+ if (myObject.isDraggable()) {
843+ if (!isDragging) {
844+ isDragging = true;
845+ }
846+ }
847+
848+ // Calculate translation in mouse
849+ int transX = Grid.getModifiedX(e.getX() - dragInit.x);
850+ int transY = Grid.getModifiedY(e.getY() - dragInit.y);
851+ myObject.getParent().getSelectionObject().translateSelection(transX, transY);
852+
853+ //Only register the actual distance and direction moved (in case of dragging past edge)
854+ totalX += myObject.getX() - previousX;
855+ totalY += myObject.getY() - previousY;
856+ }
857+
858+
859+
860 private void timedTranstionMouseWheelWithShift(TimedTransitionComponent p, MouseWheelEvent e) {
861 int rotation = 0;
862 if (e.getWheelRotation() < 0) {
863@@ -2730,7 +2634,7 @@
864 rotation = e.getWheelRotation() * 45;
865 }
866
867- CreateGui.getCurrentTab().getUndoManager().addNewEdit(((Transition) p).rotate(rotation));
868+ getUndoManager().addNewEdit(((Transition) p).rotate(rotation));
869 }
870
871 private void timedPlaceMouseWheelWithShift(TimedPlaceComponent p, MouseWheelEvent e) {
872@@ -2742,7 +2646,7 @@
873 }
874
875 private void arcDoubleClickedWithContrl(Arc arc, MouseEvent e) {
876- CreateGui.getCurrentTab().getUndoManager().addNewEdit(
877+ getUndoManager().addNewEdit(
878 arc.getArcPath().insertPoint(
879 new Point2D.Double(
880 Zoomer.getUnzoomedValue(arc.getX() + e.getX(), arc.getZoom()),
881@@ -2752,6 +2656,21 @@
882 )
883 );
884 }
885+
886+ @Override
887+ public void drawingSurfaceMousePressed(MouseEvent e) {
888+ drawingSurface.getSelectionObject().dispatchEvent(e);
889+ }
890+
891+ @Override
892+ public void drawingSurfaceMouseDragged(MouseEvent e) {
893+ drawingSurface.getSelectionObject().dispatchEvent(e);
894+ }
895+
896+ @Override
897+ public void drawingSurfaceMouseReleased(MouseEvent e) {
898+ drawingSurface.getSelectionObject().dispatchEvent(e);
899+ }
900 }
901 public List<GuiAction> getAvailableDrawActions(){
902 if (lens.isTimed() && !lens.isGame()) {
903@@ -2839,18 +2758,18 @@
904 };
905 private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
906 public void actionPerformed(ActionEvent e) {
907- timeDelay();
908+ getAnimator().letTimePass(BigDecimal.ONE);
909 }
910 };
911 private final GuiAction delayFireAction = new GuiAction("Delay and fire", "Delay and fire selected transition", "F") {
912 public void actionPerformed(ActionEvent e) {
913- delayAndFire();
914+ getTransitionFireingComponent().fireSelectedTransition();
915 }
916 };
917
918 public void updateMode() {
919 // deselect other actions
920- selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);
921+ selectAction.setSelected(editorMode == Pipe.ElementType.SELECT);
922 transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);
923 uncontrollableTransAction.setSelected(editorMode == Pipe.ElementType.UNCONTROLLABLETRANS);
924 timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);
925@@ -2992,4 +2911,23 @@
926 }
927 }
928
929+ @Override
930+ public void alignPNObjectsToGrid() {
931+ ArrayList<PetriNetObject> petriNetObjects = drawingSurface.getGuiModel().getPlaceTransitionObjects();
932+ pipe.gui.undo.UndoManager undoManager = getUndoManager();
933+ undoManager.newEdit();
934+
935+ for(PetriNetObject object : petriNetObjects) {
936+ PlaceTransitionObject ptobject = (PlaceTransitionObject)object;
937+ int x = Grid.getModifiedX(ptobject.getPositionX());
938+ int y = Grid.getModifiedY(ptobject.getPositionY());
939+ Point point = new Point(x,y);
940+ Command command = new MovePlaceTransitionObject(ptobject, point);
941+ command.redo();
942+ undoManager.addEdit(command);
943+ ptobject.updateOnMoveOrZoom();
944+ }
945+
946+ }
947+
948 }
949
950=== modified file 'src/dk/aau/cs/gui/TabContentActions.java'
951--- src/dk/aau/cs/gui/TabContentActions.java 2020-08-11 11:51:55 +0000
952+++ src/dk/aau/cs/gui/TabContentActions.java 2020-08-30 09:33:26 +0000
953@@ -32,10 +32,6 @@
954
955 void stepForward();
956
957- void timeDelay();
958-
959- void delayAndFire();
960-
961 boolean getNetChanged();
962
963 void toggleAnimationMode();
964@@ -96,4 +92,5 @@
965
966 void changeGameFeature(boolean isGame);
967
968+ void alignPNObjectsToGrid();
969 }
970
971=== modified file 'src/dk/aau/cs/gui/TemplateExplorer.java'
972--- src/dk/aau/cs/gui/TemplateExplorer.java 2020-08-04 08:53:19 +0000
973+++ src/dk/aau/cs/gui/TemplateExplorer.java 2020-08-30 09:33:26 +0000
974@@ -67,469 +67,468 @@
975
976 public class TemplateExplorer extends JPanel implements SidePane {
977
978- // Template explorer panel items
979- private JPanel templatePanel;
980- private JScrollPane scrollpane;
981- private JList<Template> templateList;
982- private DefaultListModel<Template> listModel;
983-
984- // Template button panel items
985- private JPanel buttonPanel;
986- private JButton newTemplateButton;
987- private JButton removeTemplateButton;
988- private JButton renameButton;
989- private JButton copyButton;
990-
991- private final TabContent parent;
992- private final UndoManager undoManager;
993- private boolean isInAnimationMode;
994-
995- private JButton moveUpButton;
996- private JButton moveDownButton;
997- private JButton sortButton;
998-
999- private static final String toolTipNewComponent ="Create a new component";
1000- private static final String toolTipRemoveComponent ="Remove the selected component";
1001- private static final String toolTipCopyComponent ="Copy the selected component";
1002- private static final String toolTipRenameComponent="Rename the selected component";
1003- private final static String toolTipSortComponents = "Sort the components alphabetically";
1004- private final static String toolTipMoveUp = "Move the selected component up";
1005- private final static String toolTipMoveDown = "Move the selected component down";
1006+ // Template explorer panel items
1007+ private JPanel templatePanel;
1008+ private JScrollPane scrollpane;
1009+ private JList<Template> templateList;
1010+ private DefaultListModel<Template> listModel;
1011+
1012+ // Template button panel items
1013+ private JPanel buttonPanel;
1014+ private JButton newTemplateButton;
1015+ private JButton removeTemplateButton;
1016+ private JButton renameButton;
1017+ private JButton copyButton;
1018+
1019+ private final TabContent parent;
1020+ private final UndoManager undoManager;
1021+ private boolean isInAnimationMode;
1022+
1023+ private JButton moveUpButton;
1024+ private JButton moveDownButton;
1025+ private JButton sortButton;
1026+
1027+ private static final String toolTipNewComponent = "Create a new component";
1028+ private static final String toolTipRemoveComponent = "Remove the selected component";
1029+ private static final String toolTipCopyComponent = "Copy the selected component";
1030+ private static final String toolTipRenameComponent = "Rename the selected component";
1031+ private final static String toolTipSortComponents = "Sort the components alphabetically";
1032+ private final static String toolTipMoveUp = "Move the selected component up";
1033+ private final static String toolTipMoveDown = "Move the selected component down";
1034 //private static final String toolTipComponents ="Here you can manage the different components of the Net.<html><br/></html>" +
1035- // "A Net can be broken up in several components and connected via shared places and transitions.";
1036-
1037- public TemplateExplorer(TabContent parent) {
1038- this(parent, false);
1039- }
1040-
1041- public TemplateExplorer(TabContent parent, boolean hideButtons) {
1042- this.parent = parent;
1043- undoManager = parent.getUndoManager();
1044- init(hideButtons);
1045- }
1046-
1047- public void selectPrevious(){
1048- int index = templateList.getSelectedIndex()-1;
1049- if(index == -1) index = listModel.getSize()-1;
1050- templateList.setSelectedIndex(index);
1051- }
1052-
1053- public void selectNext(){
1054- int index = templateList.getSelectedIndex()+1;
1055- if(index == listModel.size()) index = 0;
1056- templateList.setSelectedIndex(index);
1057- }
1058-
1059- public Integer indexOfSelectedTemplate() {
1060- return templateList.getSelectedIndex();
1061- }
1062-
1063- public void restoreSelectedTemplate(Integer value) {
1064- templateList.setSelectedIndex(value);
1065- }
1066-
1067- private void init(boolean hideButtons) {
1068- setLayout(new BorderLayout());
1069- isInAnimationMode = false;
1070- initExplorerPanel();
1071- initButtonsPanel();
1072-
1073- setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Components"), BorderFactory.createEmptyBorder(3, 3, 3, 3)));
1074- this.setToolTipText("List of components. Click a component to display it.");
1075- addCreatedComponents(hideButtons);
1076-
1077- this.addComponentListener(new ComponentListener() {
1078- int minimumHegiht = TemplateExplorer.this.getMinimumSize().height + sortButton.getMinimumSize().height;
1079- public void componentShown(ComponentEvent e) {
1080- }
1081-
1082-
1083- public void componentResized(ComponentEvent e) {
1084-
1085- if(!isInAnimationMode){
1086- if(TemplateExplorer.this.getSize().height <= minimumHegiht){
1087- sortButton.setVisible(false);
1088- } else {
1089- sortButton.setVisible(true);
1090- }
1091- }
1092- }
1093-
1094-
1095- public void componentMoved(ComponentEvent e) {
1096- }
1097-
1098-
1099- public void componentHidden(ComponentEvent e) {
1100- }
1101- });
1102- }
1103-
1104- private void addCreatedComponents(boolean hideButtons) {
1105- this.removeAll();
1106- if (!hideButtons) {
1107- this.add(templatePanel, BorderLayout.CENTER);
1108- moveDownButton.setVisible(true);
1109- moveUpButton.setVisible(true);
1110- sortButton.setVisible(true);
1111- this.add(buttonPanel, BorderLayout.PAGE_END);
1112-
1113- } else {
1114- this.add(templatePanel, BorderLayout.CENTER);
1115- moveDownButton.setVisible(false);
1116- moveUpButton.setVisible(false);
1117- sortButton.setVisible(false);
1118-
1119- //Makes the jpanel auto calculate it's minimum size
1120- this.setMinimumSize(null);
1121- }
1122- }
1123-
1124- private void initExplorerPanel() {
1125- templatePanel = new JPanel(new GridBagLayout());
1126- listModel = new DefaultListModel<>();
1127- for (Template net : parent.allTemplates()) {
1128- listModel.addElement(net);
1129- }
1130-
1131- listModel.addListDataListener(new ListDataListener() {
1132- public void contentsChanged(ListDataEvent arg0) {
1133- if (parent.numberOfActiveTemplates() > 1) {
1134- removeTemplateButton.setEnabled(false);
1135- } else {
1136- removeTemplateButton.setEnabled(true);
1137- }
1138- }
1139-
1140- public void intervalAdded(ListDataEvent arg0) {
1141- templateList.setSelectedIndex(arg0.getIndex0());
1142- templateList.ensureIndexIsVisible(arg0.getIndex0());
1143- }
1144-
1145- public void intervalRemoved(ListDataEvent arg0) {
1146- int index = (arg0.getIndex0() == 0) ? 0 : (arg0.getIndex0() - 1);
1147- templateList.setSelectedIndex(index);
1148- templateList.ensureIndexIsVisible(index);
1149- }
1150- });
1151-
1152- templateList = new NonsearchableJList<>(listModel);
1153-
1154- templateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1155- templateList.setSelectedIndex(0);
1156- templateList.setCellRenderer(new TemplateListCellRenderer(templateList.getCellRenderer()));
1157-
1158- TemplateListManager manager = new TemplateListManager(templateList);
1159- templateList.addListSelectionListener(manager);
1160- templateList.addMouseListener(manager);
1161-
1162- //templateList.setFocusTraversalKeysEnabled(false);
1163-
1164- scrollpane = new JScrollPane(templateList);
1165- //Add 10 pixel to the minimumsize of the scrollpane
1166- scrollpane.setMinimumSize(new Dimension(scrollpane.getMinimumSize().width, scrollpane.getMinimumSize().height + 20));
1167-
1168- GridBagConstraints gbc = new GridBagConstraints();
1169- gbc.gridx = 0;
1170- gbc.gridy = 0;
1171- gbc.gridheight = 3;
1172- gbc.weightx = 1;
1173- gbc.weighty = 1;
1174- gbc.fill = GridBagConstraints.BOTH;
1175- gbc.anchor = GridBagConstraints.NORTHWEST;
1176- templatePanel.add(scrollpane, gbc);
1177-
1178- moveUpButton = new JButton(ResourceManager.getIcon("Up.png"));
1179- moveUpButton.setMargin(new Insets(2,2,2,2));
1180- moveUpButton.setEnabled(false);
1181- moveUpButton.setToolTipText(toolTipMoveUp);
1182- moveUpButton.addActionListener(new ActionListener() {
1183- public void actionPerformed(ActionEvent e) {
1184- int index = templateList.getSelectedIndex();
1185-
1186- if(index > 0) {
1187- Command c = new MoveElementUpCommand(TemplateExplorer.this, index, index-1);
1188- undoManager.addNewEdit(c);
1189- c.redo();
1190- templateList.ensureIndexIsVisible(index+1);
1191- templateList.setSelectedIndex(index-1);
1192- }
1193- }
1194- });
1195-
1196- gbc = new GridBagConstraints();
1197- gbc.gridx = 1;
1198- gbc.gridy = 0;
1199- gbc.anchor = GridBagConstraints.SOUTH;
1200- templatePanel.add(moveUpButton,gbc);
1201-
1202- moveDownButton = new JButton(ResourceManager.getIcon("Down.png"));
1203- moveDownButton.setMargin(new Insets(2,2,2,2));
1204- moveDownButton.setEnabled(false);
1205- moveDownButton.setToolTipText(toolTipMoveDown);
1206- moveDownButton.addActionListener(new ActionListener() {
1207- public void actionPerformed(ActionEvent e) {
1208- int index = templateList.getSelectedIndex();
1209-
1210- if(index < parent.network().allTemplates().size() - 1) {
1211- Command c = new MoveElementDownCommand(TemplateExplorer.this, index, index+1);
1212- undoManager.addNewEdit(c);
1213- c.redo();
1214- templateList.ensureIndexIsVisible(index+1);
1215- templateList.setSelectedIndex(index+1);
1216- }
1217- }
1218- });
1219-
1220- gbc = new GridBagConstraints();
1221- gbc.gridx = 1;
1222- gbc.gridy = 1;
1223- gbc.anchor = GridBagConstraints.NORTH;
1224- templatePanel.add(moveDownButton,gbc);
1225-
1226- //Sort button
1227- sortButton = new JButton(ResourceManager.getIcon("Sort.png"));
1228- sortButton.setMargin(new Insets(2,2,2,2));
1229- sortButton.setToolTipText(toolTipSortComponents);
1230- sortButton.setEnabled(false);
1231- sortButton.addActionListener(e -> {
1232- Command command = new SortTemplatesCommand(parent, TemplateExplorer.this, templateList, listModel);
1233- undoManager.addNewEdit(command);
1234- command.redo();
1235- });
1236-
1237- gbc = new GridBagConstraints();
1238- gbc.gridx = 1;
1239- gbc.gridy = 2;
1240- gbc.fill = GridBagConstraints.HORIZONTAL;
1241- gbc.anchor = GridBagConstraints.NORTH;
1242- templatePanel.add(sortButton,gbc);
1243- }
1244-
1245- private void initButtonsPanel() {
1246- buttonPanel = new JPanel(new GridBagLayout());
1247-
1248- Dimension dimension = new Dimension(82, 28);
1249- newTemplateButton = new JButton("New");
1250- newTemplateButton.setEnabled(true);
1251- newTemplateButton.setPreferredSize(dimension);
1252- newTemplateButton.setToolTipText(toolTipNewComponent);
1253-
1254- newTemplateButton.addActionListener(arg0 -> ShowNewTemplateDialog(""));
1255-
1256- GridBagConstraints gbc = new GridBagConstraints();
1257- gbc.gridx = 1;
1258- gbc.gridy = 1;
1259- gbc.anchor = GridBagConstraints.WEST;
1260- buttonPanel.add(newTemplateButton, gbc);
1261-
1262- removeTemplateButton = new JButton("Remove");
1263- removeTemplateButton.setEnabled(false);
1264- removeTemplateButton.setPreferredSize(dimension);
1265- removeTemplateButton.setToolTipText(toolTipRemoveComponent);
1266-
1267- removeTemplateButton.addActionListener(new ActionListener() {
1268- public void actionPerformed(ActionEvent e) {
1269- int index = templateList.getSelectedIndex();
1270- Template template = selectedModel();
1271-
1272- HashSet<TAPNQuery> queriesToDelete = findQueriesAffectedByRemoval(template);
1273-
1274- int choice = JOptionPane.NO_OPTION;
1275- if(!queriesToDelete.isEmpty()){
1276- StringBuilder warning = buildWarningMessage(queriesToDelete);
1277-
1278- choice = JOptionPane.showConfirmDialog(
1279- CreateGui.getApp(), warning.toString(), "Warning",
1280- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
1281-
1282- if (choice == JOptionPane.YES_OPTION) {
1283- for (TAPNQuery q : queriesToDelete) {
1284- parent.removeQuery(q);
1285- }
1286- }
1287- }
1288-
1289- if(queriesToDelete.isEmpty() || choice == JOptionPane.YES_OPTION) {
1290-
1291- ArrayList<Tuple<TimedTransition, SharedTransition>> transitionsToUnshare = new ArrayList<Tuple<TimedTransition,SharedTransition>>();
1292- for(TimedTransition transition : template.model().transitions()){
1293- if(transition.isShared()){
1294- transitionsToUnshare.add(new Tuple<TimedTransition, SharedTransition>(transition, transition.sharedTransition()));
1295- }
1296- }
1297-
1298- Command command = new RemoveTemplateCommand(parent, TemplateExplorer.this, template, index, queriesToDelete, transitionsToUnshare);
1299- undoManager.addNewEdit(command);
1300- command.redo();
1301- }
1302-
1303- }
1304-
1305- private HashSet<TAPNQuery> findQueriesAffectedByRemoval(Template template) {
1306- Iterable<TAPNQuery> queries = parent.queries();
1307- HashSet<TAPNQuery> queriesToDelete = new HashSet<TAPNQuery>();
1308-
1309- for (TimedPlace p : template.model().places()) {
1310- for (TAPNQuery q : queries) {
1311- if (q.getProperty().containsAtomicPropositionWithSpecificPlaceInTemplate(template.model().name(), p.name())) {
1312- queriesToDelete.add(q);
1313- }
1314- }
1315- }
1316-
1317- for (TimedTransition t : template.model().transitions()) {
1318- for (TAPNQuery q : queries) {
1319- if (q.getProperty().containsAtomicPropositionWithSpecificTransitionInTemplate(template.model().name(), t.name())) {
1320- queriesToDelete.add(q);
1321- }
1322- }
1323- }
1324-
1325- return queriesToDelete;
1326- }
1327-
1328- private StringBuilder buildWarningMessage(HashSet<TAPNQuery> queriesToDelete) {
1329- StringBuilder s = new StringBuilder();
1330- s.append("The following queries are associated with the currently selected objects:\n\n");
1331- for (TAPNQuery q : queriesToDelete) {
1332- s.append(q.getName());
1333- s.append('\n');
1334- }
1335- s.append("\nAre you sure you want to remove the current selection and all associated queries?");
1336- return s;
1337- }
1338- });
1339-
1340- gbc = new GridBagConstraints();
1341- gbc.gridx = 0;
1342- gbc.gridy = 1;
1343- gbc.anchor = GridBagConstraints.WEST;
1344- buttonPanel.add(removeTemplateButton, gbc);
1345-
1346- renameButton = new JButton("Rename");
1347- renameButton.setEnabled(false);
1348- renameButton.setPreferredSize(dimension);
1349- renameButton.setToolTipText(toolTipRenameComponent);
1350-
1351- renameButton.addActionListener(new ActionListener() {
1352- public void actionPerformed(ActionEvent arg0) {
1353- showRenameTemplateDialog("");
1354- templateList.validate();
1355- }
1356- });
1357-
1358- gbc = new GridBagConstraints();
1359- gbc.gridx = 1;
1360- gbc.gridy = 0;
1361- gbc.anchor = GridBagConstraints.WEST;
1362- buttonPanel.add(renameButton, gbc);
1363-
1364- copyButton = new JButton("Copy");
1365- copyButton.setEnabled(false);
1366- copyButton.setPreferredSize(dimension);
1367- copyButton.setToolTipText(toolTipCopyComponent);
1368-
1369- copyButton.addActionListener(new ActionListener() {
1370- public void actionPerformed(ActionEvent arg0) {
1371- Template template = selectedModel().copy();
1372-
1373- String name = template.model().name();
1374- if(parent.network().hasTAPNCalled(name)) {
1375- int i = 2;
1376-
1377- while(parent.network().hasTAPNCalled(name + i)) {
1378- i++;
1379- }
1380- template.model().setName(name + i);
1381- }
1382-
1383- int index = listModel.size();
1384- undoManager.addNewEdit(new AddTemplateCommand(TemplateExplorer.this, template, index));
1385-
1386- parent.addTemplate(template);
1387- ArrayList<Constant> tmp = new ArrayList<Constant>();
1388- for(Constant c : parent.network().constants()){
1389- tmp.add(new Constant(c.name(), c.value()));
1390- }
1391- for(Constant c : tmp){
1392- parent.network().updateConstant(c.name(), c);
1393- }
1394- }
1395- });
1396-
1397- gbc = new GridBagConstraints();
1398- gbc.gridx = 0;
1399- gbc.gridy = 0;
1400- gbc.anchor = GridBagConstraints.WEST;
1401- buttonPanel.add(copyButton, gbc);
1402- }
1403-
1404- private EscapableDialog dialog;
1405- private JPanel container;
1406- private JTextField nameTextField;
1407- private Dimension size;
1408- private JLabel nameLabel;
1409- private JPanel buttonContainer;
1410- private JButton okButton;
1411- private JButton cancelButton;
1412- private JPanel nameContainer;
1413-
1414- private void onOKRenameTemplate() {
1415- Template template = selectedModel();
1416- String newName = nameTextField.getText().trim();
1417- if (template.model().name().equals(newName)) {
1418- exit();
1419- return;
1420- }
1421- if (!isNameAllowed(newName)) {
1422- JOptionPane.showMessageDialog(
1423- parent.drawingSurface(),
1424- "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*.\n\nThe component could not be renamed.",
1425- "Error Renaming Component",
1426- JOptionPane.ERROR_MESSAGE);
1427- exit();
1428- showRenameTemplateDialog(newName);
1429- return;
1430- }
1431- else if (parent.network().hasTAPNCalled(newName) && !template.model().name().equalsIgnoreCase(newName)) {
1432- JOptionPane.showMessageDialog(
1433- parent.drawingSurface(),
1434- "A component named \"" + newName + "\" already exists. Try another name.",
1435- "Error", JOptionPane.ERROR_MESSAGE);
1436- exit();
1437- showRenameTemplateDialog(newName);
1438- return;
1439- } else {
1440- parent.drawingSurface().getNameGenerator().updateTemplateIndex(newName);
1441- Command command = new RenameTemplateCommand(this, parent, template.model(), template.model().name(), newName);
1442- undoManager.addNewEdit(command);
1443- command.redo();
1444- }
1445- exit();
1446- }
1447-
1448- private void onOK() {
1449+ // "A Net can be broken up in several components and connected via shared places and transitions.";
1450+
1451+ public TemplateExplorer(TabContent parent) {
1452+ this(parent, false);
1453+ }
1454+
1455+ public TemplateExplorer(TabContent parent, boolean hideButtons) {
1456+ this.parent = parent;
1457+ undoManager = parent.getUndoManager();
1458+ init(hideButtons);
1459+ }
1460+
1461+ public void selectPrevious() {
1462+ int index = templateList.getSelectedIndex() - 1;
1463+ if (index == -1) index = listModel.getSize() - 1;
1464+ templateList.setSelectedIndex(index);
1465+ }
1466+
1467+ public void selectNext() {
1468+ int index = templateList.getSelectedIndex() + 1;
1469+ if (index == listModel.size()) index = 0;
1470+ templateList.setSelectedIndex(index);
1471+ }
1472+
1473+ public Integer indexOfSelectedTemplate() {
1474+ return templateList.getSelectedIndex();
1475+ }
1476+
1477+ public void restoreSelectedTemplate(Integer value) {
1478+ templateList.setSelectedIndex(value);
1479+ }
1480+
1481+ private void init(boolean hideButtons) {
1482+ setLayout(new BorderLayout());
1483+ isInAnimationMode = false;
1484+ initExplorerPanel();
1485+ initButtonsPanel();
1486+
1487+ setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Components"), BorderFactory.createEmptyBorder(3, 3, 3, 3)));
1488+ this.setToolTipText("List of components. Click a component to display it.");
1489+ addCreatedComponents(hideButtons);
1490+
1491+ this.addComponentListener(new ComponentListener() {
1492+ int minimumHegiht = TemplateExplorer.this.getMinimumSize().height + sortButton.getMinimumSize().height;
1493+
1494+ public void componentShown(ComponentEvent e) {
1495+ }
1496+
1497+
1498+ public void componentResized(ComponentEvent e) {
1499+
1500+ if (!isInAnimationMode) {
1501+ if (TemplateExplorer.this.getSize().height <= minimumHegiht) {
1502+ sortButton.setVisible(false);
1503+ } else {
1504+ sortButton.setVisible(true);
1505+ }
1506+ }
1507+ }
1508+
1509+
1510+ public void componentMoved(ComponentEvent e) {
1511+ }
1512+
1513+
1514+ public void componentHidden(ComponentEvent e) {
1515+ }
1516+ });
1517+ }
1518+
1519+ private void addCreatedComponents(boolean hideButtons) {
1520+ this.removeAll();
1521+ if (!hideButtons) {
1522+ this.add(templatePanel, BorderLayout.CENTER);
1523+ moveDownButton.setVisible(true);
1524+ moveUpButton.setVisible(true);
1525+ sortButton.setVisible(true);
1526+ this.add(buttonPanel, BorderLayout.PAGE_END);
1527+
1528+ } else {
1529+ this.add(templatePanel, BorderLayout.CENTER);
1530+ moveDownButton.setVisible(false);
1531+ moveUpButton.setVisible(false);
1532+ sortButton.setVisible(false);
1533+
1534+ //Makes the jpanel auto calculate it's minimum size
1535+ this.setMinimumSize(null);
1536+ }
1537+ }
1538+
1539+ private void initExplorerPanel() {
1540+ templatePanel = new JPanel(new GridBagLayout());
1541+ listModel = new DefaultListModel<>();
1542+ for (Template net : parent.allTemplates()) {
1543+ listModel.addElement(net);
1544+ }
1545+
1546+ listModel.addListDataListener(new ListDataListener() {
1547+ public void contentsChanged(ListDataEvent arg0) {
1548+ if (parent.numberOfActiveTemplates() > 1) {
1549+ removeTemplateButton.setEnabled(false);
1550+ } else {
1551+ removeTemplateButton.setEnabled(true);
1552+ }
1553+ }
1554+
1555+ public void intervalAdded(ListDataEvent arg0) {
1556+ templateList.setSelectedIndex(arg0.getIndex0());
1557+ templateList.ensureIndexIsVisible(arg0.getIndex0());
1558+ }
1559+
1560+ public void intervalRemoved(ListDataEvent arg0) {
1561+ int index = (arg0.getIndex0() == 0) ? 0 : (arg0.getIndex0() - 1);
1562+ templateList.setSelectedIndex(index);
1563+ templateList.ensureIndexIsVisible(index);
1564+ }
1565+ });
1566+
1567+ templateList = new NonsearchableJList<>(listModel);
1568+
1569+ templateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1570+ templateList.setSelectedIndex(0);
1571+ templateList.setCellRenderer(new TemplateListCellRenderer(templateList.getCellRenderer()));
1572+
1573+ TemplateListManager manager = new TemplateListManager(templateList);
1574+ templateList.addListSelectionListener(manager);
1575+ templateList.addMouseListener(manager);
1576+
1577+ //templateList.setFocusTraversalKeysEnabled(false);
1578+
1579+ scrollpane = new JScrollPane(templateList);
1580+ //Add 10 pixel to the minimumsize of the scrollpane
1581+ scrollpane.setMinimumSize(new Dimension(scrollpane.getMinimumSize().width, scrollpane.getMinimumSize().height + 20));
1582+
1583+ GridBagConstraints gbc = new GridBagConstraints();
1584+ gbc.gridx = 0;
1585+ gbc.gridy = 0;
1586+ gbc.gridheight = 3;
1587+ gbc.weightx = 1;
1588+ gbc.weighty = 1;
1589+ gbc.fill = GridBagConstraints.BOTH;
1590+ gbc.anchor = GridBagConstraints.NORTHWEST;
1591+ templatePanel.add(scrollpane, gbc);
1592+
1593+ moveUpButton = new JButton(ResourceManager.getIcon("Up.png"));
1594+ moveUpButton.setMargin(new Insets(2, 2, 2, 2));
1595+ moveUpButton.setEnabled(false);
1596+ moveUpButton.setToolTipText(toolTipMoveUp);
1597+ moveUpButton.addActionListener(new ActionListener() {
1598+ public void actionPerformed(ActionEvent e) {
1599+ int index = templateList.getSelectedIndex();
1600+
1601+ if (index > 0) {
1602+ Command c = new MoveElementUpCommand(TemplateExplorer.this, index, index - 1);
1603+ undoManager.addNewEdit(c);
1604+ c.redo();
1605+ templateList.ensureIndexIsVisible(index + 1);
1606+ templateList.setSelectedIndex(index - 1);
1607+ }
1608+ }
1609+ });
1610+
1611+ gbc = new GridBagConstraints();
1612+ gbc.gridx = 1;
1613+ gbc.gridy = 0;
1614+ gbc.anchor = GridBagConstraints.SOUTH;
1615+ templatePanel.add(moveUpButton, gbc);
1616+
1617+ moveDownButton = new JButton(ResourceManager.getIcon("Down.png"));
1618+ moveDownButton.setMargin(new Insets(2, 2, 2, 2));
1619+ moveDownButton.setEnabled(false);
1620+ moveDownButton.setToolTipText(toolTipMoveDown);
1621+ moveDownButton.addActionListener(new ActionListener() {
1622+ public void actionPerformed(ActionEvent e) {
1623+ int index = templateList.getSelectedIndex();
1624+
1625+ if (index < parent.network().allTemplates().size() - 1) {
1626+ Command c = new MoveElementDownCommand(TemplateExplorer.this, index, index + 1);
1627+ undoManager.addNewEdit(c);
1628+ c.redo();
1629+ templateList.ensureIndexIsVisible(index + 1);
1630+ templateList.setSelectedIndex(index + 1);
1631+ }
1632+ }
1633+ });
1634+
1635+ gbc = new GridBagConstraints();
1636+ gbc.gridx = 1;
1637+ gbc.gridy = 1;
1638+ gbc.anchor = GridBagConstraints.NORTH;
1639+ templatePanel.add(moveDownButton, gbc);
1640+
1641+ //Sort button
1642+ sortButton = new JButton(ResourceManager.getIcon("Sort.png"));
1643+ sortButton.setMargin(new Insets(2, 2, 2, 2));
1644+ sortButton.setToolTipText(toolTipSortComponents);
1645+ sortButton.setEnabled(false);
1646+ sortButton.addActionListener(e -> {
1647+ Command command = new SortTemplatesCommand(parent, TemplateExplorer.this, templateList, listModel);
1648+ undoManager.addNewEdit(command);
1649+ command.redo();
1650+ });
1651+
1652+ gbc = new GridBagConstraints();
1653+ gbc.gridx = 1;
1654+ gbc.gridy = 2;
1655+ gbc.fill = GridBagConstraints.HORIZONTAL;
1656+ gbc.anchor = GridBagConstraints.NORTH;
1657+ templatePanel.add(sortButton, gbc);
1658+ }
1659+
1660+ private void initButtonsPanel() {
1661+ buttonPanel = new JPanel(new GridBagLayout());
1662+
1663+ Dimension dimension = new Dimension(82, 28);
1664+ newTemplateButton = new JButton("New");
1665+ newTemplateButton.setEnabled(true);
1666+ newTemplateButton.setPreferredSize(dimension);
1667+ newTemplateButton.setToolTipText(toolTipNewComponent);
1668+
1669+ newTemplateButton.addActionListener(arg0 -> ShowNewTemplateDialog(""));
1670+
1671+ GridBagConstraints gbc = new GridBagConstraints();
1672+ gbc.gridx = 1;
1673+ gbc.gridy = 1;
1674+ gbc.anchor = GridBagConstraints.WEST;
1675+ buttonPanel.add(newTemplateButton, gbc);
1676+
1677+ removeTemplateButton = new JButton("Remove");
1678+ removeTemplateButton.setEnabled(false);
1679+ removeTemplateButton.setPreferredSize(dimension);
1680+ removeTemplateButton.setToolTipText(toolTipRemoveComponent);
1681+
1682+ removeTemplateButton.addActionListener(new ActionListener() {
1683+ public void actionPerformed(ActionEvent e) {
1684+ int index = templateList.getSelectedIndex();
1685+ Template template = selectedModel();
1686+
1687+ HashSet<TAPNQuery> queriesToDelete = findQueriesAffectedByRemoval(template);
1688+
1689+ int choice = JOptionPane.NO_OPTION;
1690+ if (!queriesToDelete.isEmpty()) {
1691+ StringBuilder warning = buildWarningMessage(queriesToDelete);
1692+
1693+ choice = JOptionPane.showConfirmDialog(
1694+ CreateGui.getRootFrame(), warning.toString(), "Warning",
1695+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE
1696+ );
1697+
1698+ if (choice == JOptionPane.YES_OPTION) {
1699+ for (TAPNQuery q : queriesToDelete) {
1700+ parent.removeQuery(q);
1701+ }
1702+ }
1703+ }
1704+
1705+ if (queriesToDelete.isEmpty() || choice == JOptionPane.YES_OPTION) {
1706+
1707+ ArrayList<Tuple<TimedTransition, SharedTransition>> transitionsToUnshare = new ArrayList<Tuple<TimedTransition, SharedTransition>>();
1708+ for (TimedTransition transition : template.model().transitions()) {
1709+ if (transition.isShared()) {
1710+ transitionsToUnshare.add(new Tuple<TimedTransition, SharedTransition>(transition, transition.sharedTransition()));
1711+ }
1712+ }
1713+
1714+ Command command = new RemoveTemplateCommand(parent, TemplateExplorer.this, template, index, queriesToDelete, transitionsToUnshare);
1715+ undoManager.addNewEdit(command);
1716+ command.redo();
1717+ }
1718+
1719+ }
1720+
1721+ private HashSet<TAPNQuery> findQueriesAffectedByRemoval(Template template) {
1722+ Iterable<TAPNQuery> queries = parent.queries();
1723+ HashSet<TAPNQuery> queriesToDelete = new HashSet<TAPNQuery>();
1724+
1725+ for (TimedPlace p : template.model().places()) {
1726+ for (TAPNQuery q : queries) {
1727+ if (q.getProperty().containsAtomicPropositionWithSpecificPlaceInTemplate(template.model().name(), p.name())) {
1728+ queriesToDelete.add(q);
1729+ }
1730+ }
1731+ }
1732+
1733+ for (TimedTransition t : template.model().transitions()) {
1734+ for (TAPNQuery q : queries) {
1735+ if (q.getProperty().containsAtomicPropositionWithSpecificTransitionInTemplate(template.model().name(), t.name())) {
1736+ queriesToDelete.add(q);
1737+ }
1738+ }
1739+ }
1740+
1741+ return queriesToDelete;
1742+ }
1743+
1744+ private StringBuilder buildWarningMessage(HashSet<TAPNQuery> queriesToDelete) {
1745+ StringBuilder s = new StringBuilder();
1746+ s.append("The following queries are associated with the currently selected objects:\n\n");
1747+ for (TAPNQuery q : queriesToDelete) {
1748+ s.append(q.getName());
1749+ s.append('\n');
1750+ }
1751+ s.append("\nAre you sure you want to remove the current selection and all associated queries?");
1752+ return s;
1753+ }
1754+ });
1755+
1756+ gbc = new GridBagConstraints();
1757+ gbc.gridx = 0;
1758+ gbc.gridy = 1;
1759+ gbc.anchor = GridBagConstraints.WEST;
1760+ buttonPanel.add(removeTemplateButton, gbc);
1761+
1762+ renameButton = new JButton("Rename");
1763+ renameButton.setEnabled(false);
1764+ renameButton.setPreferredSize(dimension);
1765+ renameButton.setToolTipText(toolTipRenameComponent);
1766+
1767+ renameButton.addActionListener(new ActionListener() {
1768+ public void actionPerformed(ActionEvent arg0) {
1769+ showRenameTemplateDialog("");
1770+ templateList.validate();
1771+ }
1772+ });
1773+
1774+ gbc = new GridBagConstraints();
1775+ gbc.gridx = 1;
1776+ gbc.gridy = 0;
1777+ gbc.anchor = GridBagConstraints.WEST;
1778+ buttonPanel.add(renameButton, gbc);
1779+
1780+ copyButton = new JButton("Copy");
1781+ copyButton.setEnabled(false);
1782+ copyButton.setPreferredSize(dimension);
1783+ copyButton.setToolTipText(toolTipCopyComponent);
1784+
1785+ copyButton.addActionListener(new ActionListener() {
1786+ public void actionPerformed(ActionEvent arg0) {
1787+ Template template = selectedModel().copy();
1788+
1789+ String name = template.model().name();
1790+ if (parent.network().hasTAPNCalled(name)) {
1791+ int i = 2;
1792+
1793+ while (parent.network().hasTAPNCalled(name + i)) {
1794+ i++;
1795+ }
1796+ template.model().setName(name + i);
1797+ }
1798+
1799+ int index = listModel.size();
1800+ undoManager.addNewEdit(new AddTemplateCommand(TemplateExplorer.this, template, index));
1801+
1802+ parent.addTemplate(template);
1803+ ArrayList<Constant> tmp = new ArrayList<Constant>();
1804+ for (Constant c : parent.network().constants()) {
1805+ tmp.add(new Constant(c.name(), c.value()));
1806+ }
1807+ for (Constant c : tmp) {
1808+ parent.network().updateConstant(c.name(), c);
1809+ }
1810+ }
1811+ });
1812+
1813+ gbc = new GridBagConstraints();
1814+ gbc.gridx = 0;
1815+ gbc.gridy = 0;
1816+ gbc.anchor = GridBagConstraints.WEST;
1817+ buttonPanel.add(copyButton, gbc);
1818+ }
1819+
1820+ private EscapableDialog dialog;
1821+ private JPanel container;
1822+ private JTextField nameTextField;
1823+ private Dimension size;
1824+ private JLabel nameLabel;
1825+ private JPanel buttonContainer;
1826+ private JButton okButton;
1827+ private JButton cancelButton;
1828+ private JPanel nameContainer;
1829+
1830+ private void onOKRenameTemplate() {
1831+ Template template = selectedModel();
1832+ String newName = nameTextField.getText().trim();
1833+ if (template.model().name().equals(newName)) {
1834+ exit();
1835+ return;
1836+ }
1837+ if (!isNameAllowed(newName)) {
1838+ JOptionPane.showMessageDialog(
1839+ parent.drawingSurface(),
1840+ "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*.\n\nThe component could not be renamed.",
1841+ "Error Renaming Component",
1842+ JOptionPane.ERROR_MESSAGE);
1843+ exit();
1844+ showRenameTemplateDialog(newName);
1845+ return;
1846+ } else if (parent.network().hasTAPNCalled(newName) && !template.model().name().equalsIgnoreCase(newName)) {
1847+ JOptionPane.showMessageDialog(
1848+ parent.drawingSurface(),
1849+ "A component named \"" + newName + "\" already exists. Try another name.",
1850+ "Error", JOptionPane.ERROR_MESSAGE);
1851+ exit();
1852+ showRenameTemplateDialog(newName);
1853+ return;
1854+ } else {
1855+ parent.getNameGenerator().updateTemplateIndex(newName);
1856+ Command command = new RenameTemplateCommand(this, parent, template.model(), template.model().name(), newName);
1857+ undoManager.addNewEdit(command);
1858+ command.redo();
1859+ }
1860+ exit();
1861+ }
1862+
1863+ private void onOK() {
1864 String templateName = nameTextField.getText().trim();
1865- if(!isNameAllowed(templateName)) {
1866- JOptionPane.showMessageDialog(parent.drawingSurface(),
1867- "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nThe new component could not be created.",
1868- "Error Creating Component",
1869- JOptionPane.ERROR_MESSAGE);
1870- exit();
1871- ShowNewTemplateDialog(templateName);
1872- return;
1873- }
1874- else if (parent.network().hasTAPNCalled(templateName)) {
1875- JOptionPane.showMessageDialog(parent.drawingSurface(),
1876- "A component named \"" + templateName + "\" already exists.\n\nThe new component could not be created.",
1877- "Error Creating Component",
1878- JOptionPane.ERROR_MESSAGE);
1879- exit();
1880- ShowNewTemplateDialog(templateName);
1881- return;
1882- }
1883- else {
1884+ if (!isNameAllowed(templateName)) {
1885+ JOptionPane.showMessageDialog(parent.drawingSurface(),
1886+ "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nThe new component could not be created.",
1887+ "Error Creating Component",
1888+ JOptionPane.ERROR_MESSAGE);
1889+ exit();
1890+ ShowNewTemplateDialog(templateName);
1891+ return;
1892+ } else if (parent.network().hasTAPNCalled(templateName)) {
1893+ JOptionPane.showMessageDialog(parent.drawingSurface(),
1894+ "A component named \"" + templateName + "\" already exists.\n\nThe new component could not be created.",
1895+ "Error Creating Component",
1896+ JOptionPane.ERROR_MESSAGE);
1897+ exit();
1898+ ShowNewTemplateDialog(templateName);
1899+ return;
1900+ } else {
1901 Template template = createNewTemplate(templateName);
1902
1903 int index = listModel.size();
1904@@ -538,490 +537,495 @@
1905 }
1906
1907 exit();
1908- }
1909-
1910- private void exit() {
1911- dialog.setVisible(false);
1912- }
1913-
1914- private void initComponentsOfNewTemplateDialog(String nameToShow) {
1915- container = new JPanel();
1916- container.setLayout(new GridBagLayout());
1917- nameContainer = new JPanel();
1918- nameContainer.setLayout(new GridBagLayout());
1919- size = new Dimension(330, 25);
1920-
1921- nameTextField = new javax.swing.JTextField();
1922- nameTextField.setPreferredSize(size);
1923- nameTextField.setText(nameToShow);
1924- nameTextField.addAncestorListener(new RequestFocusListener());
1925- nameTextField.addActionListener(e -> {
1926- okButton.requestFocusInWindow();
1927- okButton.doClick();
1928- });
1929-
1930- GridBagConstraints gbc = new GridBagConstraints();
1931- gbc.gridx = 0;
1932- gbc.gridy = 1;
1933- gbc.gridwidth = 1;
1934- gbc.anchor = GridBagConstraints.WEST;
1935- //gbc.fill = GridBagConstraints.HORIZONTAL;
1936- gbc.insets = new Insets(4, 4, 2, 4);
1937- nameContainer.add(nameTextField,gbc);
1938-
1939- nameLabel = new JLabel();
1940- nameLabel.setText("Name of component: ");
1941- gbc = new GridBagConstraints();
1942- gbc.gridx = 0;
1943- gbc.gridy = 0;
1944- gbc.gridwidth = 1;
1945- gbc.insets = new Insets(4, 4, 2, 4);
1946- gbc.anchor = GridBagConstraints.WEST;
1947- nameContainer.add(nameLabel,gbc);
1948-
1949- buttonContainer = new JPanel();
1950- buttonContainer.setLayout(new GridBagLayout());
1951-
1952- okButton = new JButton();
1953- okButton.setText("OK");
1954- okButton.setMaximumSize(new java.awt.Dimension(100, 25));
1955- okButton.setMinimumSize(new java.awt.Dimension(100, 25));
1956- okButton.setPreferredSize(new java.awt.Dimension(100, 25));
1957- okButton.setMnemonic(KeyEvent.VK_O);
1958- gbc = new GridBagConstraints();
1959- gbc.gridx = 1;
1960- gbc.gridy = 0;
1961- gbc.anchor = java.awt.GridBagConstraints.WEST;
1962- gbc.insets = new java.awt.Insets(5, 5, 5, 5);
1963- buttonContainer.add(okButton,gbc);
1964-
1965- cancelButton = new JButton();
1966- cancelButton.setText("Cancel");
1967- cancelButton.setMaximumSize(new java.awt.Dimension(100, 25));
1968- cancelButton.setMinimumSize(new java.awt.Dimension(100, 25));
1969- cancelButton.setPreferredSize(new java.awt.Dimension(100, 25));
1970- cancelButton.setMnemonic(KeyEvent.VK_C);
1971- gbc = new GridBagConstraints();
1972- gbc.gridx = 0;
1973- gbc.gridy = 0;
1974- gbc.gridwidth = java.awt.GridBagConstraints.RELATIVE;
1975- gbc.anchor = GridBagConstraints.EAST;
1976- buttonContainer.add(cancelButton,gbc);
1977-
1978- okButton.addActionListener(new ActionListener() {
1979- public void actionPerformed(ActionEvent e) {
1980- onOK();
1981- }
1982- });
1983-
1984- cancelButton.addActionListener(new ActionListener() {
1985- public void actionPerformed(ActionEvent e) {
1986- exit();
1987- }
1988- });
1989-
1990- gbc = new GridBagConstraints();
1991- gbc.insets = new Insets(0, 8, 5, 8);
1992- gbc.gridx = 0;
1993- gbc.gridy = 1;
1994- gbc.gridwidth = 1;
1995- gbc.anchor = GridBagConstraints.EAST;
1996- container.add(buttonContainer,gbc);
1997-
1998- gbc = new GridBagConstraints();
1999- gbc.insets = new Insets(0, 8, 5, 8);
2000- gbc.gridx = 0;
2001- gbc.gridy = 0;
2002- gbc.gridwidth = 1;
2003- gbc.anchor = GridBagConstraints.WEST;
2004- container.add(nameContainer,gbc);
2005- }
2006-
2007- private void ShowNewTemplateDialog(String nameToShow) {
2008- dialog = new EscapableDialog(CreateGui.getApp(), "Enter Component Name", true);
2009- initComponentsOfNewTemplateDialog(nameToShow);
2010- dialog.add(container);
2011- dialog.setResizable(false);
2012- dialog.pack();
2013- dialog.setLocationRelativeTo(null);
2014- dialog.setVisible(true);
2015- }
2016-
2017-
2018- private boolean isNameAllowed(String templateName) {
2019- Require.that(templateName != null, "The template name cannot be null");
2020-
2021- return !templateName.isEmpty() && Pattern.matches("[a-zA-Z]([_a-zA-Z0-9])*", templateName);
2022- }
2023-
2024- private void initComponentsOfRenameTemplateDialog(String oldname) {
2025- container = new JPanel();
2026- container.setLayout(new GridBagLayout());
2027- nameContainer = new JPanel();
2028- nameContainer.setLayout(new GridBagLayout());
2029- size = new Dimension(330, 25);
2030-
2031- nameTextField = new javax.swing.JTextField();
2032- nameTextField.setPreferredSize(size);
2033- nameTextField.setText(oldname);
2034- nameTextField.addAncestorListener(new RequestFocusListener());
2035- nameTextField.addActionListener(e -> {
2036- okButton.requestFocusInWindow();
2037- okButton.doClick();
2038- });
2039- GridBagConstraints gbc = new GridBagConstraints();
2040- gbc.gridx = 0;
2041- gbc.gridy = 1;
2042- gbc.gridwidth = 1;
2043- gbc.anchor = GridBagConstraints.WEST;
2044- //gbc.fill = GridBagConstraints.HORIZONTAL;
2045- gbc.insets = new Insets(4, 4, 2, 4);
2046- nameContainer.add(nameTextField,gbc);
2047-
2048- nameLabel = new JLabel();
2049- nameLabel.setText("Name of component: ");
2050- gbc = new GridBagConstraints();
2051- gbc.gridx = 0;
2052- gbc.gridy = 0;
2053- gbc.gridwidth = 1;
2054- gbc.insets = new Insets(4, 4, 2, 4);
2055- gbc.anchor = GridBagConstraints.WEST;
2056- nameContainer.add(nameLabel,gbc);
2057-
2058- buttonContainer = new JPanel();
2059- buttonContainer.setLayout(new GridBagLayout());
2060-
2061- okButton = new JButton();
2062- okButton.setText("OK");
2063- okButton.setMaximumSize(new java.awt.Dimension(100, 25));
2064- okButton.setMinimumSize(new java.awt.Dimension(100, 25));
2065- okButton.setPreferredSize(new java.awt.Dimension(100, 25));
2066- okButton.setMnemonic(KeyEvent.VK_O);
2067- gbc = new GridBagConstraints();
2068- gbc.gridx = 1;
2069- gbc.gridy = 0;
2070- gbc.anchor = java.awt.GridBagConstraints.WEST;
2071- gbc.insets = new java.awt.Insets(5, 5, 5, 5);
2072- buttonContainer.add(okButton,gbc);
2073-
2074- cancelButton = new JButton();
2075- cancelButton.setText("Cancel");
2076- cancelButton.setMaximumSize(new java.awt.Dimension(100, 25));
2077- cancelButton.setMinimumSize(new java.awt.Dimension(100, 25));
2078- cancelButton.setPreferredSize(new java.awt.Dimension(100, 25));
2079- cancelButton.setMnemonic(KeyEvent.VK_C);
2080- gbc = new GridBagConstraints();
2081- gbc.gridx = 0;
2082- gbc.gridy = 0;
2083- gbc.gridwidth = java.awt.GridBagConstraints.RELATIVE;
2084- gbc.anchor = GridBagConstraints.EAST;
2085- buttonContainer.add(cancelButton,gbc);
2086-
2087- okButton.addActionListener(e -> onOKRenameTemplate());
2088-
2089- cancelButton.addActionListener(e -> exit());
2090-
2091- gbc = new GridBagConstraints();
2092- gbc.insets = new Insets(0, 8, 5, 8);
2093- gbc.gridx = 0;
2094- gbc.gridy = 1;
2095- gbc.gridwidth = 1;
2096- gbc.anchor = GridBagConstraints.EAST;
2097- container.add(buttonContainer,gbc);
2098-
2099- gbc = new GridBagConstraints();
2100- gbc.insets = new Insets(0, 8, 5, 8);
2101- gbc.gridx = 0;
2102- gbc.gridy = 0;
2103- gbc.gridwidth = 1;
2104- gbc.anchor = GridBagConstraints.WEST;
2105- container.add(nameContainer,gbc);
2106-
2107- }
2108-
2109- private void showRenameTemplateDialog(String nameToShow) {
2110- dialog = new EscapableDialog(CreateGui.getApp(), "Enter Component Name", true);
2111- Template template = selectedModel();
2112- if (nameToShow.equals("")){
2113- initComponentsOfRenameTemplateDialog(template.model().name());
2114- }
2115- else {
2116- initComponentsOfRenameTemplateDialog(nameToShow);
2117- }
2118- dialog.add(container);
2119- dialog.setResizable(false);
2120- dialog.pack();
2121- dialog.setLocationRelativeTo(null);
2122- dialog.setVisible(true);
2123- }
2124-
2125- public Template createNewTemplate(String name) {
2126- TimedArcPetriNet tapn = new TimedArcPetriNet(name);
2127-
2128- return new Template(tapn, new DataLayer(), new Zoomer());
2129- }
2130-
2131- public void removeTemplate(int index, Template template) {
2132- listModel.removeElement(template);
2133- parent.removeTemplate(template);
2134- templateList.setSelectedIndex(index);
2135- }
2136-
2137- public void addTemplate(int index, Template template) {
2138- listModel.add(index, template);
2139- parent.addTemplate(template);
2140- }
2141-
2142- public void openSelectedTemplate() {
2143- Template tapn = selectedModel();
2144- if (tapn != null) {
2145- parent.changeToTemplate(tapn);
2146- }
2147- //parent.drawingSurface().repaintAll();
2148- }
2149-
2150- public Template selectedModel() {
2151- return templateList.getSelectedValue();
2152- }
2153-
2154- public void updateTemplateList() {
2155- int selectedIndex = templateList.getSelectedIndex();
2156- DefaultListModel<Template> newList = new DefaultListModel<>();
2157-
2158- if(isInAnimationMode) {
2159- for (Template net : parent.activeTemplates()) {
2160- newList.addElement(net);
2161- }
2162- } else {
2163- for (Template net : parent.allTemplates()) {
2164- newList.addElement(net);
2165- }
2166- }
2167- // When removing a component, the listModel has already been updated but the index is invalid (-1), thus we select the last component as the active one
2168- // When adding a component, this function updates the listModel thus it has a new length and the index should be corrected accordingly
2169- templateList.setSelectedIndex(selectedIndex);
2170- if(newList.size() != listModel.size() || selectedIndex == -1){
2171- selectedIndex = newList.size()-1;
2172- }
2173- listModel = newList;
2174- templateList.setModel(listModel);
2175- templateList.setSelectedIndex(selectedIndex);
2176- }
2177-
2178- public void selectFirst() {
2179- templateList.setSelectedIndex(0);
2180- }
2181-
2182- public void hideButtons() {
2183- addCreatedComponents(true);
2184- }
2185-
2186- public void showButtons() {
2187- addCreatedComponents(false);
2188- }
2189-
2190- public void switchToAnimationMode() {
2191- hideButtons();
2192- isInAnimationMode = true;
2193- updateTemplateList();
2194- }
2195-
2196-
2197- public void switchToEditorMode() {
2198- showButtons();
2199- isInAnimationMode = false;
2200- updateTemplateList();
2201- }
2202+ }
2203+
2204+ private void exit() {
2205+ dialog.setVisible(false);
2206+ }
2207+
2208+ private void initComponentsOfNewTemplateDialog(String nameToShow) {
2209+ container = new JPanel();
2210+ container.setLayout(new GridBagLayout());
2211+ nameContainer = new JPanel();
2212+ nameContainer.setLayout(new GridBagLayout());
2213+ size = new Dimension(330, 25);
2214+
2215+ nameTextField = new javax.swing.JTextField();
2216+ nameTextField.setPreferredSize(size);
2217+ nameTextField.setText(nameToShow);
2218+ nameTextField.addAncestorListener(new RequestFocusListener());
2219+ nameTextField.addActionListener(e -> {
2220+ okButton.requestFocusInWindow();
2221+ okButton.doClick();
2222+ });
2223+
2224+ GridBagConstraints gbc = new GridBagConstraints();
2225+ gbc.gridx = 0;
2226+ gbc.gridy = 1;
2227+ gbc.gridwidth = 1;
2228+ gbc.anchor = GridBagConstraints.WEST;
2229+ //gbc.fill = GridBagConstraints.HORIZONTAL;
2230+ gbc.insets = new Insets(4, 4, 2, 4);
2231+ nameContainer.add(nameTextField, gbc);
2232+
2233+ nameLabel = new JLabel();
2234+ nameLabel.setText("Name of component: ");
2235+ gbc = new GridBagConstraints();
2236+ gbc.gridx = 0;
2237+ gbc.gridy = 0;
2238+ gbc.gridwidth = 1;
2239+ gbc.insets = new Insets(4, 4, 2, 4);
2240+ gbc.anchor = GridBagConstraints.WEST;
2241+ nameContainer.add(nameLabel, gbc);
2242+
2243+ buttonContainer = new JPanel();
2244+ buttonContainer.setLayout(new GridBagLayout());
2245+
2246+ okButton = new JButton();
2247+ okButton.setText("OK");
2248+ okButton.setMaximumSize(new java.awt.Dimension(100, 25));
2249+ okButton.setMinimumSize(new java.awt.Dimension(100, 25));
2250+ okButton.setPreferredSize(new java.awt.Dimension(100, 25));
2251+ okButton.setMnemonic(KeyEvent.VK_O);
2252+ gbc = new GridBagConstraints();
2253+ gbc.gridx = 1;
2254+ gbc.gridy = 0;
2255+ gbc.anchor = java.awt.GridBagConstraints.WEST;
2256+ gbc.insets = new java.awt.Insets(5, 5, 5, 5);
2257+ buttonContainer.add(okButton, gbc);
2258+
2259+ cancelButton = new JButton();
2260+ cancelButton.setText("Cancel");
2261+ cancelButton.setMaximumSize(new java.awt.Dimension(100, 25));
2262+ cancelButton.setMinimumSize(new java.awt.Dimension(100, 25));
2263+ cancelButton.setPreferredSize(new java.awt.Dimension(100, 25));
2264+ cancelButton.setMnemonic(KeyEvent.VK_C);
2265+ gbc = new GridBagConstraints();
2266+ gbc.gridx = 0;
2267+ gbc.gridy = 0;
2268+ gbc.gridwidth = java.awt.GridBagConstraints.RELATIVE;
2269+ gbc.anchor = GridBagConstraints.EAST;
2270+ buttonContainer.add(cancelButton, gbc);
2271+
2272+ okButton.addActionListener(new ActionListener() {
2273+ public void actionPerformed(ActionEvent e) {
2274+ onOK();
2275+ }
2276+ });
2277+
2278+ cancelButton.addActionListener(new ActionListener() {
2279+ public void actionPerformed(ActionEvent e) {
2280+ exit();
2281+ }
2282+ });
2283+
2284+ gbc = new GridBagConstraints();
2285+ gbc.insets = new Insets(0, 8, 5, 8);
2286+ gbc.gridx = 0;
2287+ gbc.gridy = 1;
2288+ gbc.gridwidth = 1;
2289+ gbc.anchor = GridBagConstraints.EAST;
2290+ container.add(buttonContainer, gbc);
2291+
2292+ gbc = new GridBagConstraints();
2293+ gbc.insets = new Insets(0, 8, 5, 8);
2294+ gbc.gridx = 0;
2295+ gbc.gridy = 0;
2296+ gbc.gridwidth = 1;
2297+ gbc.anchor = GridBagConstraints.WEST;
2298+ container.add(nameContainer, gbc);
2299+ }
2300+
2301+ private void ShowNewTemplateDialog(String nameToShow) {
2302+ dialog = new EscapableDialog(CreateGui.getRootFrame(), "Enter Component Name", true);
2303+ initComponentsOfNewTemplateDialog(nameToShow);
2304+ dialog.add(container);
2305+ dialog.setResizable(false);
2306+ dialog.pack();
2307+ dialog.setLocationRelativeTo(null);
2308+ dialog.setVisible(true);
2309+ }
2310+
2311+
2312+ private boolean isNameAllowed(String templateName) {
2313+ Require.that(templateName != null, "The template name cannot be null");
2314+
2315+ return !templateName.isEmpty() && Pattern.matches("[a-zA-Z]([_a-zA-Z0-9])*", templateName);
2316+ }
2317+
2318+ private void initComponentsOfRenameTemplateDialog(String oldname) {
2319+ container = new JPanel();
2320+ container.setLayout(new GridBagLayout());
2321+ nameContainer = new JPanel();
2322+ nameContainer.setLayout(new GridBagLayout());
2323+ size = new Dimension(330, 25);
2324+
2325+ nameTextField = new javax.swing.JTextField();
2326+ nameTextField.setPreferredSize(size);
2327+ nameTextField.setText(oldname);
2328+ nameTextField.addAncestorListener(new RequestFocusListener());
2329+ nameTextField.addActionListener(e -> {
2330+ okButton.requestFocusInWindow();
2331+ okButton.doClick();
2332+ });
2333+ GridBagConstraints gbc = new GridBagConstraints();
2334+ gbc.gridx = 0;
2335+ gbc.gridy = 1;
2336+ gbc.gridwidth = 1;
2337+ gbc.anchor = GridBagConstraints.WEST;
2338+ //gbc.fill = GridBagConstraints.HORIZONTAL;
2339+ gbc.insets = new Insets(4, 4, 2, 4);
2340+ nameContainer.add(nameTextField, gbc);
2341+
2342+ nameLabel = new JLabel();
2343+ nameLabel.setText("Name of component: ");
2344+ gbc = new GridBagConstraints();
2345+ gbc.gridx = 0;
2346+ gbc.gridy = 0;
2347+ gbc.gridwidth = 1;
2348+ gbc.insets = new Insets(4, 4, 2, 4);
2349+ gbc.anchor = GridBagConstraints.WEST;
2350+ nameContainer.add(nameLabel, gbc);
2351+
2352+ buttonContainer = new JPanel();
2353+ buttonContainer.setLayout(new GridBagLayout());
2354+
2355+ okButton = new JButton();
2356+ okButton.setText("OK");
2357+ okButton.setMaximumSize(new java.awt.Dimension(100, 25));
2358+ okButton.setMinimumSize(new java.awt.Dimension(100, 25));
2359+ okButton.setPreferredSize(new java.awt.Dimension(100, 25));
2360+ okButton.setMnemonic(KeyEvent.VK_O);
2361+ gbc = new GridBagConstraints();
2362+ gbc.gridx = 1;
2363+ gbc.gridy = 0;
2364+ gbc.anchor = java.awt.GridBagConstraints.WEST;
2365+ gbc.insets = new java.awt.Insets(5, 5, 5, 5);
2366+ buttonContainer.add(okButton, gbc);
2367+
2368+ cancelButton = new JButton();
2369+ cancelButton.setText("Cancel");
2370+ cancelButton.setMaximumSize(new java.awt.Dimension(100, 25));
2371+ cancelButton.setMinimumSize(new java.awt.Dimension(100, 25));
2372+ cancelButton.setPreferredSize(new java.awt.Dimension(100, 25));
2373+ cancelButton.setMnemonic(KeyEvent.VK_C);
2374+ gbc = new GridBagConstraints();
2375+ gbc.gridx = 0;
2376+ gbc.gridy = 0;
2377+ gbc.gridwidth = java.awt.GridBagConstraints.RELATIVE;
2378+ gbc.anchor = GridBagConstraints.EAST;
2379+ buttonContainer.add(cancelButton, gbc);
2380+
2381+ okButton.addActionListener(e -> onOKRenameTemplate());
2382+
2383+ cancelButton.addActionListener(e -> exit());
2384+
2385+ gbc = new GridBagConstraints();
2386+ gbc.insets = new Insets(0, 8, 5, 8);
2387+ gbc.gridx = 0;
2388+ gbc.gridy = 1;
2389+ gbc.gridwidth = 1;
2390+ gbc.anchor = GridBagConstraints.EAST;
2391+ container.add(buttonContainer, gbc);
2392+
2393+ gbc = new GridBagConstraints();
2394+ gbc.insets = new Insets(0, 8, 5, 8);
2395+ gbc.gridx = 0;
2396+ gbc.gridy = 0;
2397+ gbc.gridwidth = 1;
2398+ gbc.anchor = GridBagConstraints.WEST;
2399+ container.add(nameContainer, gbc);
2400+
2401+ }
2402+
2403+ private void showRenameTemplateDialog(String nameToShow) {
2404+ dialog = new EscapableDialog(CreateGui.getRootFrame(), "Enter Component Name", true);
2405+ Template template = selectedModel();
2406+ if (nameToShow.equals("")) {
2407+ initComponentsOfRenameTemplateDialog(template.model().name());
2408+ } else {
2409+ initComponentsOfRenameTemplateDialog(nameToShow);
2410+ }
2411+ dialog.add(container);
2412+ dialog.setResizable(false);
2413+ dialog.pack();
2414+ dialog.setLocationRelativeTo(null);
2415+ dialog.setVisible(true);
2416+ }
2417+
2418+ public Template createNewTemplate(String name) {
2419+ TimedArcPetriNet tapn = new TimedArcPetriNet(name);
2420+
2421+ return new Template(tapn, new DataLayer(), new Zoomer());
2422+ }
2423+
2424+ public void removeTemplate(int index, Template template) {
2425+ listModel.removeElement(template);
2426+ parent.removeTemplate(template);
2427+ templateList.setSelectedIndex(index);
2428+ }
2429+
2430+ public void addTemplate(int index, Template template) {
2431+ listModel.add(index, template);
2432+ parent.addTemplate(template);
2433+ }
2434+
2435+ public void openSelectedTemplate() {
2436+ Template tapn = selectedModel();
2437+ if (tapn != null) {
2438+ parent.changeToTemplate(tapn);
2439+ }
2440+ //parent.drawingSurface().repaintAll();
2441+ }
2442+
2443+ public Template selectedModel() {
2444+ return templateList.getSelectedValue();
2445+ }
2446+
2447+ public void updateTemplateList() {
2448+ int selectedIndex = templateList.getSelectedIndex();
2449+ DefaultListModel<Template> newList = new DefaultListModel<>();
2450+
2451+ if (isInAnimationMode) {
2452+ for (Template net : parent.activeTemplates()) {
2453+ newList.addElement(net);
2454+ }
2455+ } else {
2456+ for (Template net : parent.allTemplates()) {
2457+ newList.addElement(net);
2458+ }
2459+ }
2460+ // When removing a component, the listModel has already been updated but the index is invalid (-1), thus we select the last component as the active one
2461+ // When adding a component, this function updates the listModel thus it has a new length and the index should be corrected accordingly
2462+ templateList.setSelectedIndex(selectedIndex);
2463+ if (newList.size() != listModel.size() || selectedIndex == -1) {
2464+ selectedIndex = newList.size() - 1;
2465+ }
2466+ listModel = newList;
2467+ templateList.setModel(listModel);
2468+ templateList.setSelectedIndex(selectedIndex);
2469+ }
2470+
2471+ public void selectFirst() {
2472+ templateList.setSelectedIndex(0);
2473+ }
2474+
2475+ public void hideButtons() {
2476+ addCreatedComponents(true);
2477+ }
2478+
2479+ public void showButtons() {
2480+ addCreatedComponents(false);
2481+ }
2482+
2483+ public void switchToAnimationMode() {
2484+ hideButtons();
2485+ isInAnimationMode = true;
2486+ updateTemplateList();
2487+ }
2488+
2489+
2490+ public void switchToEditorMode() {
2491+ showButtons();
2492+ isInAnimationMode = false;
2493+ updateTemplateList();
2494+ }
2495
2496 @Override
2497 public void moveUp(int index) {
2498- parent.swapTemplates(index, index-1);
2499+ parent.swapTemplates(index, index - 1);
2500 Template o = listModel.getElementAt(index);
2501- listModel.setElementAt(listModel.getElementAt(index-1), index);
2502- listModel.setElementAt(o, index-1);
2503+ listModel.setElementAt(listModel.getElementAt(index - 1), index);
2504+ listModel.setElementAt(o, index - 1);
2505 }
2506
2507 @Override
2508 public void moveDown(int index) {
2509- parent.swapTemplates(index, index+1);
2510+ parent.swapTemplates(index, index + 1);
2511 Template o = listModel.getElementAt(index);
2512- listModel.setElementAt(listModel.getElementAt(index+1), index);
2513- listModel.setElementAt(o, index+1);
2514+ listModel.setElementAt(listModel.getElementAt(index + 1), index);
2515+ listModel.setElementAt(o, index + 1);
2516 }
2517+
2518 @Override
2519- public JList<Template> getJList(){
2520- return templateList;
2521+ public JList<Template> getJList() {
2522+ return templateList;
2523 }
2524
2525 private class TemplateListCellRenderer extends JPanel implements ListCellRenderer {
2526
2527- private static final String UNCHECK_TO_DEACTIVATE = "Uncheck to deactive the component";
2528- private static final String CHECK_TO_ACTIVATE = "Check to active the component";
2529- private final JCheckBox activeCheckbox = new JCheckBox();
2530- private final ListCellRenderer cellRenderer;
2531-
2532-
2533- public TemplateListCellRenderer(ListCellRenderer renderer) {
2534- cellRenderer = renderer;
2535- setLayout(new BorderLayout());
2536- setOpaque(false);
2537- activeCheckbox.setOpaque(false);
2538- }
2539-
2540- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
2541- Component renderer = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
2542- removeAll();
2543- if(!isInAnimationMode) {
2544- boolean isActive = ((Template)value).isActive();
2545- activeCheckbox.setSelected(isActive);
2546- setToolTipText((isActive)? UNCHECK_TO_DEACTIVATE : CHECK_TO_ACTIVATE);
2547- add(activeCheckbox, BorderLayout.WEST);
2548- } else {
2549-
2550- setToolTipText(null);
2551- }
2552- add(renderer, BorderLayout.CENTER);
2553- return this;
2554- }
2555-
2556-
2557- }
2558-
2559- private class TemplateListManager extends MouseAdapter implements ListSelectionListener, ActionListener {
2560- private final int checkBoxWidth = new JCheckBox().getPreferredSize().width;
2561- private final ListSelectionModel selectionModel;
2562- private final JList list;
2563-
2564- public TemplateListManager(JList list) {
2565- this.list = list;
2566- selectionModel = list.getSelectionModel();
2567- this.list.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
2568- }
2569-
2570- private void toggleSelection(int index) {
2571- if(index<0)
2572- return;
2573-
2574- Template item = ((Template)list.getModel().getElementAt(index));
2575-
2576-
2577- if(!selectionModel.isSelectedIndex(index)) {
2578- selectionModel.addSelectionInterval(index, index);
2579- }
2580-
2581- boolean newValue =!item.isActive();
2582- item.setActive(newValue);
2583-
2584- if(parent.numberOfActiveTemplates() == 0) {
2585- //We got an error, about the change
2586- item.setActive(!newValue);
2587- JOptionPane.showMessageDialog(parent, "At least one component must be active.", "Cannot Deactive All Components", JOptionPane.INFORMATION_MESSAGE);
2588- } else {
2589- //The change was ok, record it to undo/redo history
2590- undoManager.addNewEdit(new ToggleTemplateActivationCommand(parent.getTemplateExplorer(), item, newValue));
2591- }
2592-
2593-
2594- if (!selectedModel().isActive()){
2595- removeTemplateButton.setEnabled(true);
2596- }else {
2597- if (parent.numberOfActiveTemplates() <= 1) {
2598- removeTemplateButton.setEnabled(false);
2599- } else {
2600- removeTemplateButton.setEnabled(true);
2601- }
2602- }
2603-
2604- toggleAffectedQueries();
2605- list.repaint();
2606- }
2607-
2608- private void toggleAffectedQueries() {
2609- for(TAPNQuery query : parent.queries()) {
2610- ContainsPlaceWithDisabledTemplateVisitor visitor = new ContainsPlaceWithDisabledTemplateVisitor(parent.network());
2611- BooleanResult result = new BooleanResult(true);
2612- query.getProperty().accept(visitor, result);
2613-
2614- if(query.isActive()) {
2615- if(!result.result())
2616- query.setActive(false);
2617- } else {
2618- if(result.result())
2619- query.setActive(true);
2620- }
2621- }
2622-
2623- parent.updateQueryList();
2624- }
2625-
2626- public void mouseClicked(MouseEvent e) {
2627- int index = templateList.locationToIndex(e.getPoint());
2628-
2629- if(index<0)
2630- return;
2631-
2632- if(e.getX()>templateList.getCellBounds(index, index).x+checkBoxWidth)
2633- return;
2634-
2635- if (!isInAnimationMode){
2636- toggleSelection(index);
2637- }
2638-
2639- }
2640-
2641- public void valueChanged(ListSelectionEvent e) {
2642- if (!(e.getValueIsAdjusting())) {
2643- int index = templateList.getSelectedIndex();
2644- if (index == -1) {
2645- removeTemplateButton.setEnabled(false);
2646- renameButton.setEnabled(false);
2647- copyButton.setEnabled(false);
2648- moveUpButton.setEnabled(false);
2649- moveDownButton.setEnabled(false);
2650- sortButton.setEnabled(false);
2651- } else {
2652- if (buttonPanel != null) {
2653- if (parent.numberOfActiveTemplates() > 1){
2654- removeTemplateButton.setEnabled(true);
2655- }else{
2656- if (selectedModel().isActive()){
2657- removeTemplateButton.setEnabled(false);
2658- } else {
2659- removeTemplateButton.setEnabled(true);
2660- }
2661- }
2662- renameButton.setEnabled(true);
2663- copyButton.setEnabled(true);
2664- if(templateList.getModel().getSize() >= 2) {
2665+ private static final String UNCHECK_TO_DEACTIVATE = "Uncheck to deactive the component";
2666+ private static final String CHECK_TO_ACTIVATE = "Check to active the component";
2667+ private final JCheckBox activeCheckbox = new JCheckBox();
2668+ private final ListCellRenderer cellRenderer;
2669+
2670+
2671+ public TemplateListCellRenderer(ListCellRenderer renderer) {
2672+ cellRenderer = renderer;
2673+ setLayout(new BorderLayout());
2674+ setOpaque(false);
2675+ activeCheckbox.setOpaque(false);
2676+ }
2677+
2678+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
2679+ Component renderer = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
2680+ removeAll();
2681+ if (!isInAnimationMode) {
2682+ boolean isActive = ((Template) value).isActive();
2683+ activeCheckbox.setSelected(isActive);
2684+ setToolTipText((isActive) ? UNCHECK_TO_DEACTIVATE : CHECK_TO_ACTIVATE);
2685+ add(activeCheckbox, BorderLayout.WEST);
2686+ } else {
2687+
2688+ setToolTipText(null);
2689+ }
2690+ add(renderer, BorderLayout.CENTER);
2691+ return this;
2692+ }
2693+
2694+
2695+ }
2696+
2697+ private class TemplateListManager extends MouseAdapter implements ListSelectionListener, ActionListener {
2698+ private final int checkBoxWidth = new JCheckBox().getPreferredSize().width;
2699+ private final ListSelectionModel selectionModel;
2700+ private final JList list;
2701+
2702+ public TemplateListManager(JList list) {
2703+ this.list = list;
2704+ selectionModel = list.getSelectionModel();
2705+ this.list.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
2706+ }
2707+
2708+ private void toggleSelection(int index) {
2709+ if (index < 0) {
2710+ return;
2711+ }
2712+
2713+ Template item = ((Template) list.getModel().getElementAt(index));
2714+
2715+
2716+ if (!selectionModel.isSelectedIndex(index)) {
2717+ selectionModel.addSelectionInterval(index, index);
2718+ }
2719+
2720+ boolean newValue = !item.isActive();
2721+ item.setActive(newValue);
2722+
2723+ if (parent.numberOfActiveTemplates() == 0) {
2724+ //We got an error, about the change
2725+ item.setActive(!newValue);
2726+ JOptionPane.showMessageDialog(parent, "At least one component must be active.", "Cannot Deactive All Components", JOptionPane.INFORMATION_MESSAGE);
2727+ } else {
2728+ //The change was ok, record it to undo/redo history
2729+ undoManager.addNewEdit(new ToggleTemplateActivationCommand(parent.getTemplateExplorer(), item, newValue));
2730+ }
2731+
2732+
2733+ if (!selectedModel().isActive()) {
2734+ removeTemplateButton.setEnabled(true);
2735+ } else {
2736+ if (parent.numberOfActiveTemplates() <= 1) {
2737+ removeTemplateButton.setEnabled(false);
2738+ } else {
2739+ removeTemplateButton.setEnabled(true);
2740+ }
2741+ }
2742+
2743+ toggleAffectedQueries();
2744+ list.repaint();
2745+ }
2746+
2747+ private void toggleAffectedQueries() {
2748+ for (TAPNQuery query : parent.queries()) {
2749+ ContainsPlaceWithDisabledTemplateVisitor visitor = new ContainsPlaceWithDisabledTemplateVisitor(parent.network());
2750+ BooleanResult result = new BooleanResult(true);
2751+ query.getProperty().accept(visitor, result);
2752+
2753+ if (query.isActive()) {
2754+ if (!result.result()) {
2755+ query.setActive(false);
2756+ }
2757+ } else {
2758+ if (result.result()) {
2759+ query.setActive(true);
2760+ }
2761+ }
2762+ }
2763+
2764+ parent.updateQueryList();
2765+ }
2766+
2767+ public void mouseClicked(MouseEvent e) {
2768+ int index = templateList.locationToIndex(e.getPoint());
2769+
2770+ if (index < 0) {
2771+ return;
2772+ }
2773+
2774+ if (e.getX() > templateList.getCellBounds(index, index).x + checkBoxWidth) {
2775+ return;
2776+ }
2777+
2778+ if (!isInAnimationMode) {
2779+ toggleSelection(index);
2780+ }
2781+
2782+ }
2783+
2784+ public void valueChanged(ListSelectionEvent e) {
2785+ if (!(e.getValueIsAdjusting())) {
2786+ int index = templateList.getSelectedIndex();
2787+ if (index == -1) {
2788+ removeTemplateButton.setEnabled(false);
2789+ renameButton.setEnabled(false);
2790+ copyButton.setEnabled(false);
2791+ moveUpButton.setEnabled(false);
2792+ moveDownButton.setEnabled(false);
2793+ sortButton.setEnabled(false);
2794+ } else {
2795+ if (buttonPanel != null) {
2796+ if (parent.numberOfActiveTemplates() > 1) {
2797+ removeTemplateButton.setEnabled(true);
2798+ } else {
2799+ if (selectedModel().isActive()) {
2800+ removeTemplateButton.setEnabled(false);
2801+ } else {
2802+ removeTemplateButton.setEnabled(true);
2803+ }
2804+ }
2805+ renameButton.setEnabled(true);
2806+ copyButton.setEnabled(true);
2807+ if (templateList.getModel().getSize() >= 2) {
2808 sortButton.setEnabled(true);
2809 } else {
2810 sortButton.setEnabled(false);
2811 }
2812
2813- if(index > 0) {
2814+ if (index > 0) {
2815 moveUpButton.setEnabled(true);
2816 } else {
2817 moveUpButton.setEnabled(false);
2818 }
2819-
2820-
2821- if(index < parent.network().allTemplates().size() - 1) {
2822+
2823+
2824+ if (index < parent.network().allTemplates().size() - 1) {
2825 moveDownButton.setEnabled(true);
2826 } else {
2827 moveDownButton.setEnabled(false);
2828 }
2829- }
2830- templateList.ensureIndexIsVisible(index);
2831- openSelectedTemplate();
2832- }
2833- }
2834- }
2835-
2836- public void actionPerformed(ActionEvent e) {
2837- if (!isInAnimationMode){
2838- toggleSelection(list.getSelectedIndex());
2839- }
2840- }
2841-
2842- }
2843+ }
2844+ templateList.ensureIndexIsVisible(index);
2845+ openSelectedTemplate();
2846+ }
2847+ }
2848+ }
2849+
2850+ public void actionPerformed(ActionEvent e) {
2851+ if (!isInAnimationMode) {
2852+ toggleSelection(list.getSelectedIndex());
2853+ }
2854+ }
2855+
2856+ }
2857 }
2858
2859=== modified file 'src/dk/aau/cs/gui/components/StatisticsPanel.java'
2860--- src/dk/aau/cs/gui/components/StatisticsPanel.java 2020-08-10 06:46:22 +0000
2861+++ src/dk/aau/cs/gui/components/StatisticsPanel.java 2020-08-30 09:33:26 +0000
2862@@ -1,8 +1,6 @@
2863 package dk.aau.cs.gui.components;
2864
2865 import java.awt.*;
2866-import java.awt.event.ActionEvent;
2867-import java.awt.event.ActionListener;
2868 import java.util.List;
2869
2870 import javax.swing.JButton;
2871@@ -13,7 +11,6 @@
2872 import javax.swing.JSeparator;
2873
2874 import dk.aau.cs.model.tapn.TimedPlace;
2875-import pipe.gui.*;
2876 import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
2877 import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
2878 import pipe.gui.undo.DeleteTimedPlaceCommand;
2879@@ -29,7 +26,8 @@
2880
2881 private final int topBottomMargin = 3;
2882 private final int rightMargin = 10;
2883- private Point location;
2884+ private final TabContent tab;
2885+ private Point location;
2886
2887 private JButton removeOrphanTransitions;
2888 private JButton removeOrphanPlaces;
2889@@ -42,16 +40,17 @@
2890 private static JDialog dialog;
2891 private Object[][] contents;
2892
2893- private StatisticsPanel(Object[][] statistics) {
2894+ private StatisticsPanel(Object[][] statistics, TabContent tab) {
2895 super(new GridBagLayout());
2896
2897+ this.tab = tab;
2898 this.contents = statistics;
2899
2900 init();
2901 }
2902
2903- public static void showStatisticsPanel(Object[][] statistics){
2904- StatisticsPanel panel = new StatisticsPanel(statistics);
2905+ public static void showStatisticsPanel(Object[][] statistics, TabContent tab){
2906+ StatisticsPanel panel = new StatisticsPanel(statistics, tab);
2907
2908 JOptionPane optionPane = new JOptionPane(panel, JOptionPane.INFORMATION_MESSAGE);
2909
2910@@ -61,7 +60,7 @@
2911 dialog.setVisible(true);
2912 }
2913
2914- private JPanel init() {
2915+ private void init() {
2916 addRow(headLines, 0, true);
2917
2918 //Add the content - make space for separators (except the orphan transitions)
2919@@ -87,9 +86,7 @@
2920 addOrphanButtons(gbc);
2921
2922 this.setVisible(true);
2923-
2924- return null;
2925- }
2926+ }
2927
2928 private void addRow(Object[] row, int rowNumber, boolean isHeadLine){
2929 GridBagConstraints gbc;
2930@@ -155,12 +152,12 @@
2931
2932 final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
2933
2934- if (orphanTransition) {
2935- addTransitionAction();
2936+ if (orphanTransition) {
2937+ removeOrphanTransitions.addActionListener(e -> removeOrphanTransitions(tab));
2938 buttonsPanel.add(removeOrphanTransitions);
2939 }
2940 if (orphanPlace) {
2941- addPlaceAction();
2942+ removeOrphanPlaces.addActionListener(e -> removeOrphanPlaces(tab));
2943 buttonsPanel.add(removeOrphanPlaces);
2944 }
2945
2946@@ -173,87 +170,78 @@
2947 this.add(buttonsPanel, gbc);
2948 }
2949
2950- private void addTransitionAction() {
2951- removeOrphanTransitions.addActionListener(new ActionListener() {
2952- public void actionPerformed(ActionEvent e) {
2953- TabContent tab = CreateGui.getCurrentTab();
2954- Iterable<Template> templates = tab.allTemplates();
2955-
2956- UndoManager undoManager = tab.getUndoManager();
2957- boolean first = true;
2958- for (Template template : templates) {
2959- List<TimedTransition> orphans = template.model().getOrphanTransitions();
2960- for (TimedTransition trans : orphans) {
2961- TimedTransitionComponent t = (TimedTransitionComponent)template.guiModel().getTransitionByName(trans.name());
2962- Command cmd = new DeleteTimedTransitionCommand(t, t.underlyingTransition().model(), template.guiModel());
2963-
2964- if (first) {
2965- undoManager.addNewEdit(cmd);
2966- first = false;
2967- } else {
2968- undoManager.addEdit(cmd);
2969- }
2970- cmd.redo();
2971- }
2972- contents = template.model().getStatistics();
2973- }
2974- tab.drawingSurface().repaint();
2975-
2976- location = StatisticsPanel.dialog.getLocationOnScreen();
2977-
2978- StatisticsPanel.this.removeAll();
2979- StatisticsPanel.this.init();
2980-
2981- JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE);
2982-
2983- dialog.dispose();
2984- dialog = optionPane.createDialog(DIALOG_TITLE);
2985- dialog.setLocation(location);
2986- dialog.pack();
2987- dialog.setVisible(true);
2988- }
2989- });
2990- }
2991-
2992- private void addPlaceAction() {
2993- removeOrphanPlaces.addActionListener(new ActionListener() {
2994- public void actionPerformed(ActionEvent e) {
2995- TabContent tab = CreateGui.getCurrentTab();
2996- Iterable<Template> templates = tab.allTemplates();
2997-
2998- UndoManager undoManager = tab.getUndoManager();
2999- boolean first = true;
3000- for (Template template : templates) {
3001- List<TimedPlace> orphans = template.model().getOrphanPlaces();
3002- for (TimedPlace place : orphans) {
3003- TimedPlaceComponent timedPlace = (TimedPlaceComponent)template.guiModel().getPlaceByName(place.name());
3004- Command cmd = new DeleteTimedPlaceCommand(timedPlace, template.model(), template.guiModel());
3005-
3006- if (first) {
3007- undoManager.addNewEdit(cmd);
3008- first = false;
3009- } else {
3010- undoManager.addEdit(cmd);
3011- }
3012- cmd.redo();
3013- }
3014- contents = template.model().getStatistics();
3015- }
3016- tab.drawingSurface().repaint();
3017-
3018- location = StatisticsPanel.dialog.getLocationOnScreen();
3019-
3020- StatisticsPanel.this.removeAll();
3021- StatisticsPanel.this.init();
3022-
3023- JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE);
3024-
3025- dialog.dispose();
3026- dialog = optionPane.createDialog(DIALOG_TITLE);
3027- dialog.setLocation(location);
3028- dialog.pack();
3029- dialog.setVisible(true);
3030- }
3031- });
3032- }
3033+ private void removeOrphanPlaces(TabContent tab) {
3034+ Iterable<Template> templates = tab.allTemplates();
3035+
3036+ UndoManager undoManager = tab.getUndoManager();
3037+ boolean first = true;
3038+ for (Template template : templates) {
3039+ List<TimedPlace> orphans = template.model().getOrphanPlaces();
3040+ for (TimedPlace place : orphans) {
3041+ TimedPlaceComponent timedPlace = (TimedPlaceComponent) template.guiModel().getPlaceByName(place.name());
3042+ Command cmd = new DeleteTimedPlaceCommand(timedPlace, template.model(), template.guiModel());
3043+
3044+ if (first) {
3045+ undoManager.addNewEdit(cmd);
3046+ first = false;
3047+ } else {
3048+ undoManager.addEdit(cmd);
3049+ }
3050+ cmd.redo();
3051+ }
3052+ contents = template.model().getStatistics();
3053+ }
3054+ tab.drawingSurface().repaint();
3055+
3056+ location = StatisticsPanel.dialog.getLocationOnScreen();
3057+
3058+ StatisticsPanel.this.removeAll();
3059+ StatisticsPanel.this.init();
3060+
3061+ JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE);
3062+
3063+ dialog.dispose();
3064+ dialog = optionPane.createDialog(DIALOG_TITLE);
3065+ dialog.setLocation(location);
3066+ dialog.pack();
3067+ dialog.setVisible(true);
3068+ }
3069+
3070+ private void removeOrphanTransitions(TabContent tab) {
3071+ Iterable<Template> templates = tab.allTemplates();
3072+
3073+ UndoManager undoManager = tab.getUndoManager();
3074+ boolean first = true;
3075+ for (Template template : templates) {
3076+ List<TimedTransition> orphans = template.model().getOrphanTransitions();
3077+ for (TimedTransition trans : orphans) {
3078+ TimedTransitionComponent t = (TimedTransitionComponent) template.guiModel().getTransitionByName(trans.name());
3079+ Command cmd = new DeleteTimedTransitionCommand(t, t.underlyingTransition().model(), template.guiModel());
3080+
3081+ if (first) {
3082+ undoManager.addNewEdit(cmd);
3083+ first = false;
3084+ } else {
3085+ undoManager.addEdit(cmd);
3086+ }
3087+ cmd.redo();
3088+ }
3089+ contents = template.model().getStatistics();
3090+ }
3091+ tab.drawingSurface().repaint();
3092+
3093+ location = StatisticsPanel.dialog.getLocationOnScreen();
3094+
3095+ StatisticsPanel.this.removeAll();
3096+ StatisticsPanel.this.init();
3097+
3098+ JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE);
3099+
3100+ dialog.dispose();
3101+ dialog = optionPane.createDialog(DIALOG_TITLE);
3102+ dialog.setLocation(location);
3103+ dialog.pack();
3104+ dialog.setVisible(true);
3105+ }
3106+
3107 }
3108
3109=== modified file 'src/dk/aau/cs/gui/smartDraw/SmartDrawDialog.java'
3110--- src/dk/aau/cs/gui/smartDraw/SmartDrawDialog.java 2020-07-13 13:58:47 +0000
3111+++ src/dk/aau/cs/gui/smartDraw/SmartDrawDialog.java 2020-08-30 09:33:26 +0000
3112@@ -132,7 +132,7 @@
3113 public static void showSmartDrawDialog() {
3114
3115 if(smartDrawDialog == null){
3116- smartDrawDialog = new SmartDrawDialog(CreateGui.getApp(), "Smart Draw", true);
3117+ smartDrawDialog = new SmartDrawDialog(CreateGui.getRootFrame(), "Smart Draw", true);
3118 smartDrawDialog.pack();
3119 smartDrawDialog.setPreferredSize(smartDrawDialog.getSize());
3120 smartDrawDialog.setMinimumSize(new Dimension(smartDrawDialog.getWidth(), smartDrawDialog.getHeight()));
3121@@ -189,7 +189,7 @@
3122 helpButton.addActionListener(new ActionListener() {
3123 @Override
3124 public void actionPerformed(ActionEvent e) {
3125- JOptionPane.showMessageDialog(CreateGui.getAppGui(), getMessageComponent(), "Help", JOptionPane.INFORMATION_MESSAGE);
3126+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), getMessageComponent(), "Help", JOptionPane.INFORMATION_MESSAGE);
3127 }
3128 });
3129
3130@@ -209,8 +209,20 @@
3131 @Override
3132 public void actionPerformed(ActionEvent e) {
3133 initLoadingFrame();
3134- worker = new SmartDrawWorker(xSpacing, ySpacing, CreateGui.getDrawingSurface(), searchOption,
3135- straightWeight, diagonalWeight, distanceWeight, overlappingArcWeight, startingObject, minimumIterations);
3136+ worker = new SmartDrawWorker(
3137+ xSpacing,
3138+ ySpacing,
3139+ CreateGui.getDrawingSurface(),
3140+ CreateGui.getUndoManager(),
3141+ searchOption,
3142+ straightWeight,
3143+ diagonalWeight,
3144+ distanceWeight,
3145+ overlappingArcWeight,
3146+ startingObject,
3147+ minimumIterations
3148+ );
3149+
3150 worker.addSmartDrawListener(new SmartDrawListener() {
3151
3152 @Override
3153@@ -688,7 +700,7 @@
3154 }
3155
3156 private void initLoadingFrame() {
3157- loadingDialogFrame = new JDialog(CreateGui.getApp(), "Working...", true);
3158+ loadingDialogFrame = new JDialog(CreateGui.getRootFrame(), "Working...", true);
3159 loadingDialogFrame.setLayout(new GridBagLayout());
3160 loadingDialogFrame.setType(Window.Type.POPUP);
3161 ImageIcon loadingGIF = ResourceManager.getIcon("ajax-loader.gif");
3162
3163=== modified file 'src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java'
3164--- src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java 2020-05-28 12:33:35 +0000
3165+++ src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java 2020-08-30 09:33:26 +0000
3166@@ -11,29 +11,31 @@
3167 import dk.aau.cs.gui.undo.Command;
3168 import dk.aau.cs.gui.undo.MovePlaceTransitionObject;
3169 import dk.aau.cs.util.Require;
3170-import pipe.gui.CreateGui;
3171 import pipe.gui.Zoomer;
3172 import pipe.gui.canvas.DrawingSurfaceImpl;
3173 import pipe.gui.graphicElements.*;
3174 import pipe.gui.undo.DeleteArcPathPointEdit;
3175 import pipe.gui.undo.TransitionRotationEdit;
3176+import pipe.gui.undo.UndoManager;
3177
3178 public class SmartDrawWorker extends SwingWorker<Void, Void>{
3179 List<SmartDrawListener> listeners = new ArrayList<SmartDrawListener>();
3180 PlaceTransitionObject startingObject;
3181 int xSpacing;
3182 int ySpacing;
3183- DrawingSurfaceImpl drawingSurface;
3184 String searchOption;
3185 Point rootPoint;
3186 Point rightMostPointUsed = new Point(0, 0);
3187 Boolean isDone = false;
3188-
3189+
3190 ArrayList<PlaceTransitionObject> objectsPlaced = new ArrayList<PlaceTransitionObject>();
3191 ArrayList<PlaceTransitionObject> placeTransitionObjects = new ArrayList<PlaceTransitionObject>();
3192 ArrayList<Point> pointsReserved = new ArrayList<Point>();
3193- pipe.gui.undo.UndoManager undoManager = CreateGui.getCurrentTab().getUndoManager();
3194-
3195+
3196+
3197+ final DrawingSurfaceImpl drawingSurface;
3198+ final UndoManager undoManager;
3199+
3200 //weights
3201 int diagonalWeight;
3202 int straightWeight;
3203@@ -49,11 +51,23 @@
3204 ArrayList<PlaceTransitionObject> unfinishedObjects = new ArrayList<PlaceTransitionObject>();
3205 ArrayList<Arc> arcsVisited = new ArrayList<Arc>();
3206
3207- public SmartDrawWorker(int xSpacing, int ySpacing, DrawingSurfaceImpl drawingSurface, String searchOption,
3208- int straightWeight, int diagonalWeight, int distanceWeight, int overlappingArcWeight, String startingObject, int minimumIterations) {
3209+ public SmartDrawWorker(
3210+ int xSpacing,
3211+ int ySpacing,
3212+ DrawingSurfaceImpl drawingSurface,
3213+ UndoManager undoManager,
3214+ String searchOption,
3215+ int straightWeight,
3216+ int diagonalWeight,
3217+ int distanceWeight,
3218+ int overlappingArcWeight,
3219+ String startingObject,
3220+ int minimumIterations
3221+ ) {
3222 this.xSpacing = xSpacing;
3223 this.ySpacing = ySpacing;
3224 this.drawingSurface = drawingSurface;
3225+ this.undoManager = undoManager;
3226 this.searchOption = searchOption;
3227 this.straightWeight = straightWeight;
3228 this.diagonalWeight = diagonalWeight;
3229@@ -380,7 +394,7 @@
3230
3231 private void removeArcPathPoints() {
3232 ArrayList<ArcPathPoint> toRemove = new ArrayList<ArcPathPoint>();
3233- for(PetriNetObject object : CreateGui.getDrawingSurface().getGuiModel().getPNObjects()) {
3234+ for(PetriNetObject object : drawingSurface.getGuiModel().getPNObjects()) {
3235 if(object instanceof ArcPathPoint) {
3236 ArcPathPoint arcPathPoint = (ArcPathPoint)object;
3237 if(!(arcPathPoint.isEndPoint())) {
3238@@ -390,7 +404,7 @@
3239
3240 }
3241 for(ArcPathPoint p : toRemove) {
3242- Command command = new DeleteArcPathPointEdit(p.getArcPath().getArc(), p, p.getIndex(), CreateGui.getModel());
3243+ Command command = new DeleteArcPathPointEdit(p.getArcPath().getArc(), p, p.getIndex());
3244 command.redo();
3245 undoManager.addEdit(command);
3246 }
3247@@ -428,11 +442,11 @@
3248 //XXX: out bad handeling of zoom bleads over we need to adjust point relative to zoom
3249 // midpoint is at current zoom level, but when creaing a new point its coords is at 100% zoom
3250 private double unzoom(double pos) {
3251- return Zoomer.getUnzoomedValue(pos, CreateGui.getDrawingSurface().getZoom());
3252+ return Zoomer.getUnzoomedValue(pos, drawingSurface.getZoom());
3253 }
3254 //XXX: when setting nameoffset the position is unzoomed, so we zoom it first so it gets the value we want
3255 private double zoom(double pos){
3256- return Zoomer.getZoomedValue(pos, CreateGui.getDrawingSurface().getZoom());
3257+ return Zoomer.getZoomedValue(pos, drawingSurface.getZoom());
3258 }
3259 /*
3260 * Add arcPathPoints for arcs where
3261@@ -519,8 +533,8 @@
3262 if(objectsPlaced.size() == drawingSurface.getGuiModel().getPlaceTransitionObjects().size()) {
3263 setTransitionsToUpright();
3264 doOffsetForLoops();
3265- CreateGui.getModel().repaintAll(true);
3266- CreateGui.getDrawingSurface().updatePreferredSize();
3267+ drawingSurface.getGuiModel().repaintAll(true);
3268+ drawingSurface.updatePreferredSize();
3269 fireDone(false);
3270 } else {
3271 fireDone(true);
3272
3273=== modified file 'src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java'
3274--- src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java 2020-04-18 14:41:05 +0000
3275+++ src/dk/aau/cs/gui/undo/MakePlaceNewSharedCommand.java 2020-08-30 09:33:26 +0000
3276@@ -25,7 +25,7 @@
3277 private final TimedArcPetriNet tapn;
3278 private final TimedPlaceComponent placeComponent;
3279 private final Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping;
3280- private final List<TimedToken> oldTokens;
3281+ private final int oldTokens;
3282 private final TabContent currentTab;
3283 private final SharedPlacesAndTransitionsPanel sharedPanel;
3284 private SharedPlace sharedPlace;
3285@@ -46,7 +46,7 @@
3286 this.currentTab = currentTab;
3287 this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel();
3288 this.multiShare = multiShare;
3289- oldTokens = place.tokens();
3290+ oldTokens = place.numberOfTokens();
3291 newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>();
3292 }
3293
3294
3295=== modified file 'src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java'
3296--- src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java 2020-06-03 12:16:19 +0000
3297+++ src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java 2020-08-30 09:33:26 +0000
3298@@ -26,7 +26,7 @@
3299 private final boolean multishare;
3300
3301 private final Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping;
3302- private final List<TimedToken> oldTokens;
3303+ private final int oldTokens;
3304 private final TabContent currentTab;
3305
3306 public MakePlaceSharedCommand(TimedArcPetriNet tapn, SharedPlace sharedPlace, TimedPlace place, TimedPlaceComponent placeComponent, TabContent currentTab, boolean multishare){
3307@@ -41,7 +41,7 @@
3308 this.place = place;
3309 this.placeComponent = placeComponent;
3310 this.multishare = multishare;
3311- oldTokens = place.tokens();
3312+ oldTokens = place.numberOfTokens();
3313 this.currentTab = currentTab;
3314 newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>();
3315 }
3316
3317=== modified file 'src/dk/aau/cs/gui/undo/MovePlaceTransitionObject.java'
3318--- src/dk/aau/cs/gui/undo/MovePlaceTransitionObject.java 2020-07-16 08:09:09 +0000
3319+++ src/dk/aau/cs/gui/undo/MovePlaceTransitionObject.java 2020-08-30 09:33:26 +0000
3320@@ -30,7 +30,7 @@
3321
3322 objectToBeMoved.updateOnMoveOrZoom();
3323 objectToBeMoved.repaint();
3324- CreateGui.getDrawingSurface().updatePreferredSize();
3325+
3326 }
3327
3328 @Override
3329@@ -41,7 +41,6 @@
3330
3331 objectToBeMoved.updateOnMoveOrZoom();
3332 objectToBeMoved.repaint();
3333- CreateGui.getDrawingSurface().updatePreferredSize();
3334
3335 }
3336
3337
3338=== modified file 'src/dk/aau/cs/io/PNMLoader.java'
3339--- src/dk/aau/cs/io/PNMLoader.java 2020-08-11 12:18:11 +0000
3340+++ src/dk/aau/cs/io/PNMLoader.java 2020-08-30 09:33:26 +0000
3341@@ -192,6 +192,7 @@
3342 Require.that(places.put(id, place) == null && !transitions.containsKey(id),
3343 "The name: " + id + ", was already used");
3344 tapn.add(place);
3345+ place.addTokens(marking.marking);
3346
3347 if(isNetDrawable()){
3348 //We parse the id as both the name and id as in tapaal name = id, and name/id has to be unique
3349@@ -201,10 +202,6 @@
3350 }
3351
3352 idResolver.add(tapn.name(), id, id);
3353-
3354- for (int i = 0; i < marking.marking; i++) {
3355- tapn.parentNetwork().marking().add(new TimedToken(place));
3356- }
3357 }
3358
3359 private InitialMarking parseMarking(Node node) {
3360
3361=== modified file 'src/dk/aau/cs/io/TapnLegacyXmlLoader.java'
3362--- src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2020-08-11 12:18:11 +0000
3363+++ src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2020-08-30 09:33:26 +0000
3364@@ -562,13 +562,11 @@
3365
3366 LocalTimedPlace p = new LocalTimedPlace(nameInput, TimeInvariant.parse(invariant, constants));
3367 tapn.add(p);
3368+ p.addTokens(initialMarkingInput);
3369
3370 place.setUnderlyingPlace(p);
3371 guiModel.addPetriNetObject(place);
3372
3373- for (int i = 0; i < initialMarkingInput; i++) {
3374- marking.add(new TimedToken(p, new BigDecimal(0.0)));
3375- }
3376 }
3377
3378 private void parseAndAddArcAsOldFormat(Element inputArcElement) throws FormatException {
3379
3380=== modified file 'src/dk/aau/cs/io/TapnXmlLoader.java'
3381--- src/dk/aau/cs/io/TapnXmlLoader.java 2020-08-11 12:18:11 +0000
3382+++ src/dk/aau/cs/io/TapnXmlLoader.java 2020-08-30 09:33:26 +0000
3383@@ -163,13 +163,12 @@
3384 Node node = sharedPlaceNodes.item(i);
3385
3386 if(node instanceof Element){
3387- SharedPlace place = parseSharedPlace((Element)node, network.marking(), constants);
3388- network.add(place);
3389+ parseSharedPlace((Element)node, network, constants);
3390 }
3391 }
3392 }
3393
3394- private SharedPlace parseSharedPlace(Element element, TimedMarking marking, ConstantStore constants) {
3395+ private SharedPlace parseSharedPlace(Element element, TimedArcPetriNetNetwork network, ConstantStore constants) {
3396 String name = element.getAttribute("name");
3397 TimeInvariant invariant = TimeInvariant.parse(element.getAttribute("invariant"), constants);
3398 int numberOfTokens = Integer.parseInt(element.getAttribute("initialMarking"));
3399@@ -183,7 +182,7 @@
3400 }
3401
3402 SharedPlace place = new SharedPlace(name, invariant);
3403- place.setCurrentMarking(marking);
3404+ network.add(place);
3405 place.addTokens(numberOfTokens);
3406
3407
3408@@ -447,9 +446,7 @@
3409 }else{
3410 p = new LocalTimedPlace(nameInput, TimeInvariant.parse(invariant, constants));
3411 tapn.add(p);
3412- for (int i = 0; i < initialMarkingInput; i++) {
3413- network.marking().add(new TimedToken(p));
3414- }
3415+ p.addTokens(initialMarkingInput);
3416 }
3417 nameGenerator.updateIndicesForAllModels(nameInput);
3418 TimedPlaceComponent placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput, lens);
3419
3420=== modified file 'src/dk/aau/cs/io/TraceImportExport.java'
3421--- src/dk/aau/cs/io/TraceImportExport.java 2020-07-16 09:05:56 +0000
3422+++ src/dk/aau/cs/io/TraceImportExport.java 2020-08-30 09:33:26 +0000
3423@@ -1,5 +1,6 @@
3424 package dk.aau.cs.io;
3425
3426+import pipe.gui.Animator;
3427 import pipe.gui.CreateGui;
3428 import java.io.BufferedReader;
3429 import java.io.File;
3430@@ -77,7 +78,7 @@
3431 } catch (NullPointerException e) {
3432 // Aborted by user
3433 } catch (IOException e) {
3434- JOptionPane.showMessageDialog(CreateGui.getApp(), "Error exporting trace.", "Error", JOptionPane.ERROR_MESSAGE);
3435+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), "Error exporting trace.", "Error", JOptionPane.ERROR_MESSAGE);
3436 }
3437 }
3438
3439@@ -147,9 +148,9 @@
3440 return os;
3441 }
3442
3443- public static void importTrace() {
3444- if (pipe.gui.CreateGui.getCurrentTab().getAnimationHistorySidePanel().getListModel().size() > 1) {
3445- int answer = JOptionPane.showConfirmDialog(CreateGui.getApp(),
3446+ public static void importTrace(Animator animator) {
3447+ if (animator.hasNonZeroTrance()) {
3448+ int answer = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(),
3449 "You are about to import a trace. This removes the current trace.",
3450 "Import Trace", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
3451 if (answer != JOptionPane.OK_OPTION) {
3452@@ -164,7 +165,7 @@
3453 return;
3454 }
3455
3456- CreateGui.getAnimator().reset(true);
3457+ animator.reset(true);
3458
3459 try {
3460 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
3461@@ -175,13 +176,13 @@
3462 TimedArcPetriNetTrace traceComposed = traceParser.parseTrace(br);
3463 TAPNTraceDecomposer decomposer = new TAPNTraceDecomposer(traceComposed, CreateGui.getCurrentTab().network(), model.value2());
3464
3465- CreateGui.getAnimator().setTrace(decomposer.decompose());
3466+ animator.setTrace(decomposer.decompose());
3467
3468 } catch (FileNotFoundException e) {
3469 // Will never happen
3470 } catch (Exception e) { //IOException
3471- CreateGui.getAnimator().reset(true);
3472- JOptionPane.showMessageDialog(CreateGui.getApp(), "Error importing trace. Does the trace belong to this model?", "Error", JOptionPane.ERROR_MESSAGE);
3473+ animator.reset(true);
3474+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), "Error importing trace. Does the trace belong to this model?", "Error", JOptionPane.ERROR_MESSAGE);
3475 }
3476
3477 }
3478
3479=== modified file 'src/dk/aau/cs/io/queries/QueryLoader.java'
3480--- src/dk/aau/cs/io/queries/QueryLoader.java 2017-03-12 00:33:00 +0000
3481+++ src/dk/aau/cs/io/queries/QueryLoader.java 2020-08-30 09:33:26 +0000
3482@@ -57,10 +57,10 @@
3483 }
3484
3485 if(queryUsingNonexistentPlaceFound && firstQueryParsingWarning && showErrorMessage) {
3486- JOptionPane.showMessageDialog(CreateGui.getApp(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3487+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3488 firstQueryParsingWarning = false;
3489 } else if(queryUsingNonexistentTransitionFound && firstQueryParsingWarning && showErrorMessage){
3490- JOptionPane.showMessageDialog(CreateGui.getApp(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3491+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3492 firstQueryParsingWarning = false;
3493 }
3494
3495
3496=== modified file 'src/dk/aau/cs/io/queries/TAPNQueryLoader.java'
3497--- src/dk/aau/cs/io/queries/TAPNQueryLoader.java 2020-08-04 08:19:44 +0000
3498+++ src/dk/aau/cs/io/queries/TAPNQueryLoader.java 2020-08-30 09:33:26 +0000
3499@@ -284,7 +284,7 @@
3500 query = TAPAALQueryParser.parse(queryToParse);
3501 } catch (Exception e) {
3502 if(firstQueryParsingWarning) {
3503- JOptionPane.showMessageDialog(CreateGui.getApp(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3504+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), ERROR_PARSING_QUERY_MESSAGE, "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
3505 firstQueryParsingWarning = false;
3506 }
3507 System.err.println("No query was specified: ");
3508
3509=== modified file 'src/dk/aau/cs/io/queries/XMLQueryLoader.java'
3510--- src/dk/aau/cs/io/queries/XMLQueryLoader.java 2020-07-13 13:58:47 +0000
3511+++ src/dk/aau/cs/io/queries/XMLQueryLoader.java 2020-08-30 09:33:26 +0000
3512@@ -168,7 +168,6 @@
3513 }
3514
3515 private void createDialogBox(String text, String header){
3516- JOptionPane.showMessageDialog(CreateGui.getApp(), text,
3517- header, JOptionPane.ERROR_MESSAGE);
3518+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), text, header, JOptionPane.ERROR_MESSAGE);
3519 }
3520 }
3521
3522=== modified file 'src/dk/aau/cs/model/tapn/TimedPlace.java'
3523--- src/dk/aau/cs/model/tapn/TimedPlace.java 2020-08-04 08:53:19 +0000
3524+++ src/dk/aau/cs/model/tapn/TimedPlace.java 2020-08-30 09:33:26 +0000
3525@@ -53,7 +53,8 @@
3526 return tokens().size();
3527 }
3528
3529- public void addToken(TimedToken timedToken) {
3530+ //Removed usage of this function, pending removeal
3531+ private void addToken(TimedToken timedToken) {
3532 Require.that(timedToken != null, "timedToken cannot be null");
3533 Require.that(timedToken.place().equals(this), "token is located in a different place");
3534
3535@@ -61,7 +62,8 @@
3536 fireMarkingChanged();
3537 }
3538
3539- public void addTokens(Iterable<TimedToken> tokens) {
3540+ //Removed usage of this function, pending removeal
3541+ private void addTokens(Iterable<TimedToken> tokens) {
3542 Require.that(tokens != null, "tokens cannot be null");
3543
3544 for(TimedToken token : tokens){
3545
3546=== modified file 'src/dk/aau/cs/model/tapn/simulation/ManualDelayMode.java'
3547--- src/dk/aau/cs/model/tapn/simulation/ManualDelayMode.java 2020-07-20 12:17:24 +0000
3548+++ src/dk/aau/cs/model/tapn/simulation/ManualDelayMode.java 2020-08-30 09:33:26 +0000
3549@@ -62,7 +62,7 @@
3550
3551 //Ask the user
3552 ChooseDelayPanel panel;
3553- dialog = new EscapableDialog(CreateGui.getApp(), "Choose delay", true);
3554+ dialog = new EscapableDialog(CreateGui.getRootFrame(), "Choose delay", true);
3555 panel = new ChooseDelayPanel(transition, dInterval, delayGranularity);
3556 dialog.setContentPane(panel);
3557 dialog.pack();
3558
3559=== modified file 'src/dk/aau/cs/verification/TAPNComposer.java'
3560--- src/dk/aau/cs/verification/TAPNComposer.java 2020-08-11 12:18:11 +0000
3561+++ src/dk/aau/cs/verification/TAPNComposer.java 2020-08-30 09:33:26 +0000
3562@@ -173,10 +173,9 @@
3563
3564 constructedModel.add(constructedPlace);
3565 mapping.addMappingForShared(place.name(), uniquePlaceName);
3566-
3567- for (TimedToken token : place.tokens()) {
3568- constructedPlace.addToken(new TimedToken(constructedPlace, token.age()));
3569- }
3570+
3571+ constructedPlace.addTokens(place.numberOfTokens());
3572+
3573
3574 // Gui work
3575 if (this.guiModels != null) {
3576@@ -223,9 +222,8 @@
3577 constructedModel.add(place);
3578 mapping.addMapping(tapn.name(), timedPlace.name(), uniquePlaceName);
3579
3580- for (TimedToken token : timedPlace.tokens()) {
3581- place.addToken(new TimedToken(place, token.age()));
3582- }
3583+ place.addTokens(timedPlace.numberOfTokens());
3584+
3585
3586 // Gui work
3587 if (this.guiModels != null) {
3588
3589=== modified file 'src/net/tapaal/TAPAAL.java'
3590--- src/net/tapaal/TAPAAL.java 2020-05-21 08:51:39 +0000
3591+++ src/net/tapaal/TAPAAL.java 2020-08-30 09:33:26 +0000
3592@@ -41,10 +41,17 @@
3593 public static final String TOOLNAME = "TAPAAL";
3594 public static final String VERSION = "DEV";
3595
3596+ public static final int MINIMUM_SUPPORTED_JAVAVERSION = 11;
3597+
3598 public static String getProgramName(){
3599 return "" + TAPAAL.TOOLNAME + " " + TAPAAL.VERSION;
3600 }
3601
3602+ //XXX: This values should never be change while running the program
3603+ private static boolean debug = false;
3604+ public static boolean debugEnabled() {
3605+ return debug;
3606+ }
3607
3608 public static void main(String[] args) throws Exception {
3609 // Create a CommandLineParser using Posix Style
3610@@ -67,11 +74,13 @@
3611 // Enable debug
3612 if (commandline.hasOption("debug")) {
3613 Logger.enableLogging(true);
3614+ debug = true;
3615 }
3616
3617 if (TAPAAL.VERSION.equals("DEV")){
3618 Logger.enableLogging(true);
3619 Logger.log("Debug logging is enabled by default in DEV branch");
3620+ debug = true;
3621 }
3622
3623 if (commandline.hasOption("batch")) {
3624@@ -101,7 +110,7 @@
3625 if (file.exists()) { // Open the file
3626 if (file.canRead()) {
3627 try {
3628- CreateGui.getAppGuiController().openTab(TabContent.createNewTabFromFile(file));
3629+ CreateGui.getAppGuiController().createNewTabFromFile(file);
3630 } catch (Exception e) {
3631 // TODO Auto-generated catch block
3632 e.printStackTrace();
3633@@ -122,6 +131,7 @@
3634
3635 private static void batchProcessing(File batchFolder) throws Exception {
3636 //Sadly needs to create the gui
3637+ /*
3638 CreateGui.init();
3639 CreateGui.getApp().setVisible(false);
3640
3641@@ -177,6 +187,7 @@
3642 BatchProcessingResultsExporter exporter = new BatchProcessingResultsExporter();
3643 exporter.exportToCSV(results.getResults(), System.out);
3644 System.out.println("Done" + results.getRowCount());
3645+ */
3646 }
3647
3648 public static File getInstallDir() {
3649
3650=== modified file 'src/pipe/gui/AnimationControlSidePanel.java'
3651--- src/pipe/gui/AnimationControlSidePanel.java 2020-08-17 06:18:11 +0000
3652+++ src/pipe/gui/AnimationControlSidePanel.java 2020-08-30 09:33:26 +0000
3653@@ -332,7 +332,7 @@
3654 if (Pattern.matches("^(([1-9]([0-9])*)?|0)(" + Pattern.quote(Character.toString(localDecimalseparator)) + "([0-9]){6,})?$", oldText)) {
3655 if (oldText.indexOf('.') != -1) {
3656 TimeDelayField.setText(oldText.substring(0,oldText.indexOf('.')+6));
3657- JOptionPane.showMessageDialog(CreateGui.getApp(),
3658+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
3659 PRECISION_ERROR_MESSAGE, PRECISION_ERROR_DIALOG_TITLE,
3660 JOptionPane.INFORMATION_MESSAGE);
3661 }
3662
3663=== modified file 'src/pipe/gui/AnimationSettingsDialog.java'
3664--- src/pipe/gui/AnimationSettingsDialog.java 2020-08-17 06:18:11 +0000
3665+++ src/pipe/gui/AnimationSettingsDialog.java 2020-08-30 09:33:26 +0000
3666@@ -61,12 +61,12 @@
3667 gbc.fill = GridBagConstraints.HORIZONTAL;
3668 contentPane.add(closeDialogButton, gbc);
3669
3670- dialog = new EscapableDialog(CreateGui.getApp(), "Settings", true);
3671+ dialog = new EscapableDialog(CreateGui.getRootFrame(), "Settings", true);
3672 dialog.getRootPane().setDefaultButton(closeDialogButton);
3673 dialog.setContentPane(contentPane);
3674 dialog.pack();
3675 dialog.setResizable(false);
3676- dialog.setLocationRelativeTo(CreateGui.getApp());
3677+ dialog.setLocationRelativeTo(CreateGui.getRootFrame());
3678 dialog.setVisible(true);
3679 }
3680
3681
3682=== modified file 'src/pipe/gui/Animator.java'
3683--- src/pipe/gui/Animator.java 2020-08-10 09:34:06 +0000
3684+++ src/pipe/gui/Animator.java 2020-08-30 09:33:26 +0000
3685@@ -67,7 +67,7 @@
3686 }
3687
3688 public void setTrace(TAPNNetworkTrace trace) {
3689- CreateGui.getCurrentTab().setAnimationMode(true);
3690+ tab.setAnimationMode(true);
3691
3692 if (trace.isConcreteTrace()) {
3693 this.trace = trace;
3694@@ -95,7 +95,7 @@
3695 tab.getUntimedAnimationHistory().setSelectedIndex(0);
3696 setFiringmode("Random");
3697
3698- JOptionPane.showMessageDialog(CreateGui.getApp(),
3699+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
3700 "The verification process returned an untimed trace.\n\n"
3701 + "This means that with appropriate time delays the displayed\n"
3702 + "sequence of discrete transitions can become a concrete trace.\n"
3703@@ -321,7 +321,7 @@
3704 }
3705
3706 if(delayGranularity.compareTo(new BigDecimal("0.00001")) < 0){
3707- JOptionPane.showMessageDialog(CreateGui.getApp(), "<html>Due to the limit of only five decimal points in the simulator</br> its not possible to fire the transition</html>");
3708+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), "<html>Due to the limit of only five decimal points in the simulator</br> its not possible to fire the transition</html>");
3709 } else {
3710 BigDecimal delay = tab.getDelayEnabledTransitionControl().getDelayMode().GetDelay(transition, dInterval, delayGranularity);
3711 if(delay != null){
3712@@ -354,7 +354,7 @@
3713 next = new Tuple<NetworkMarking, List<TimedToken>> (currentMarking().fireTransition(transition, tokensToConsume), tokensToConsume);
3714 }
3715 }catch(RequireException e){
3716- JOptionPane.showMessageDialog(CreateGui.getApp(), "There was an error firing the transition. Reason: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
3717+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), "There was an error firing the transition. Reason: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
3718 return;
3719 }
3720
3721@@ -369,7 +369,7 @@
3722 if(nextFromUntimedTrace.equals(transition.model().name() + "." + transition.name()) || transition.isShared() && nextFromUntimedTrace.equals(transition.name())){
3723 untimedAnimationHistory.stepForward();
3724 }else{
3725- int fireTransition = JOptionPane.showConfirmDialog(CreateGui.getApp(),
3726+ int fireTransition = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(),
3727 "Are you sure you want to fire a transition which does not follow the untimed trace?\n"
3728 + "Firing this transition will discard the untimed trace and revert to standard simulation.",
3729 "Discrading Untimed Trace", JOptionPane.YES_NO_OPTION );
3730@@ -542,6 +542,10 @@
3731 tab.getAnimationController().setToolTipText("Select a method for choosing tokens during transition firing");
3732 }
3733
3734+ public boolean hasNonZeroTrance() {
3735+ return tab.getAnimationHistorySidePanel().getListModel().size() > 1;
3736+ }
3737+
3738 enum FillListStatus{
3739 lessThanWeight,
3740 weight,
3741@@ -605,7 +609,7 @@
3742 }
3743
3744 private List<TimedToken> showSelectSimulatorDialogue(TimedTransition transition) {
3745- EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Select Tokens", true);
3746+ EscapableDialog guiDialog = new EscapableDialog(CreateGui.getRootFrame(), "Select Tokens", true);
3747
3748 Container contentPane = guiDialog.getContentPane();
3749 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
3750@@ -636,7 +640,7 @@
3751
3752 private boolean removeSetTrace(boolean askUser){
3753 if(askUser && isShowingTrace()){ //Warn about deleting trace
3754- int answer = JOptionPane.showConfirmDialog(CreateGui.getApp(),
3755+ int answer = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(),
3756 "You are about to remove the current trace.",
3757 "Removing Trace", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
3758 if(answer != JOptionPane.OK_OPTION) return false;
3759@@ -685,7 +689,7 @@
3760 public final GuiAction stepbackwardAction = CreateGui.getAppGui().stepbackwardAction;
3761
3762 public void updateAnimationButtonsEnabled() {
3763- AnimationHistoryList animationHistory = CreateGui.getCurrentTab().getAnimationHistorySidePanel();
3764+ AnimationHistoryList animationHistory = tab.getAnimationHistorySidePanel();
3765
3766 setEnabledStepforwardAction(animationHistory.isStepForwardAllowed());
3767 setEnabledStepbackwardAction(animationHistory.isStepBackAllowed());
3768@@ -698,7 +702,7 @@
3769 */
3770 private void updateMouseOverInformation() {
3771 // update mouseOverView
3772- for (pipe.gui.graphicElements.Place p : CreateGui.getCurrentTab().getModel().getPlaces()) {
3773+ for (pipe.gui.graphicElements.Place p : tab.getModel().getPlaces()) {
3774 if (((TimedPlaceComponent) p).isAgeOfTokensShown()) {
3775 ((TimedPlaceComponent) p).showAgeOfTokens(true);
3776 }
3777
3778=== modified file 'src/pipe/gui/CreateGui.java'
3779--- src/pipe/gui/CreateGui.java 2020-08-11 06:00:12 +0000
3780+++ src/pipe/gui/CreateGui.java 2020-08-30 09:33:26 +0000
3781@@ -11,6 +11,7 @@
3782 import pipe.dataLayer.DataLayer;
3783 import pipe.gui.canvas.DrawingSurfaceImpl;
3784 import dk.aau.cs.gui.TabContent;
3785+import pipe.gui.undo.UndoManager;
3786
3787 public class CreateGui {
3788
3789@@ -52,21 +53,6 @@
3790 }
3791
3792 @Deprecated
3793- public static DataLayer getModel() {
3794- return getModel(appGui.getSelectedTabIndex());
3795- }
3796-
3797- @Deprecated
3798- public static DataLayer getModel(int index) {
3799- if (index < 0) {
3800- return null;
3801- }
3802-
3803- TabContent tab = (tabs.get(index));
3804- return tab.getModel();
3805- }
3806-
3807- @Deprecated
3808 public static DrawingSurfaceImpl getDrawingSurface() {
3809 return getDrawingSurface(appGui.getSelectedTabIndex());
3810 }
3811@@ -126,6 +112,9 @@
3812 }
3813 return getCurrentTab().getAnimator();
3814 }
3815+
3816+ //Use this only when accessing the Root frame to open a dialog/popup
3817+ public static Frame getRootFrame() {return getApp(); }
3818
3819 //XXX Two Methodes to access same data (created after auto encapsulate)
3820 @Deprecated
3821@@ -140,8 +129,7 @@
3822 //XXX The following function should properly not be used and is only used while refactoring, but is better
3823 // that the chained access via guiFrame, App or drawingsurface now marked with deprecation.
3824 public static TabContent openNewTabFromStream(InputStream file, String name) throws Exception {
3825- TabContent tab = TabContent.createNewTabFromInputStream(file, name);
3826- appGuiController.openTab(tab);
3827+ TabContent tab = appGuiController.createNewTabFromInputStream(file, name);
3828 return tab;
3829 }
3830 public static TabContent openNewTabFromStream(TabContent tab) {
3831@@ -154,11 +142,10 @@
3832 return appGuiController;
3833 }
3834
3835-
3836 public static boolean useExtendedBounds = false;
3837
3838- //XXX Moved from guiframe to static access, while refactoring.
3839 @Deprecated
3840- public static Pipe.ElementType guiMode;
3841-
3842+ public static UndoManager getUndoManager() {
3843+ return getCurrentTab().getUndoManager();
3844+ }
3845 }
3846
3847=== modified file 'src/pipe/gui/Export.java'
3848--- src/pipe/gui/Export.java 2020-04-18 13:45:34 +0000
3849+++ src/pipe/gui/Export.java 2020-08-30 09:33:26 +0000
3850@@ -63,29 +63,29 @@
3851 public static final int PRINTER = 3;
3852 public static final int TIKZ = 5;
3853 public static final int PNML = 6;
3854- public static final int QUERY = 7;
3855-
3856- private static void toPnml(DrawingSurfaceImpl g, String filename)
3857- throws NullPointerException, DOMException, TransformerConfigurationException,
3858- IOException, ParserConfigurationException, TransformerException {
3859- TabContent currentTab = CreateGui.getCurrentTab();
3860- NetworkMarking currentMarking = null;
3861- if(CreateGui.getCurrentTab().isInAnimationMode()){
3862- currentMarking = currentTab.network().marking();
3863- currentTab.network().setMarking(CreateGui.getAnimator().getInitialMarking());
3864- }
3865-
3866- NetWriter tapnWriter = new PNMLWriter(
3867- currentTab.network(),
3868- currentTab.getGuiModels()
3869- );
3870-
3871- tapnWriter.savePNML(new File(filename));
3872-
3873- if(CreateGui.getCurrentTab().isInAnimationMode()){
3874- currentTab.network().setMarking(currentMarking);
3875- }
3876- }
3877+ public static final int QUERY = 7;
3878+
3879+ private static void toPnml(DrawingSurfaceImpl g, String filename) throws NullPointerException, DOMException, IOException, ParserConfigurationException, TransformerException {
3880+
3881+ TabContent currentTab = CreateGui.getCurrentTab();
3882+ NetworkMarking currentMarking = null;
3883+
3884+ if (currentTab.isInAnimationMode()) {
3885+ currentMarking = currentTab.network().marking();
3886+ currentTab.network().setMarking(currentTab.getAnimator().getInitialMarking());
3887+ }
3888+
3889+ NetWriter tapnWriter = new PNMLWriter(
3890+ currentTab.network(),
3891+ currentTab.getGuiModels()
3892+ );
3893+
3894+ tapnWriter.savePNML(new File(filename));
3895+
3896+ if (currentTab.isInAnimationMode()) {
3897+ currentTab.network().setMarking(currentMarking);
3898+ }
3899+ }
3900
3901 private static void toQueryXML(String filename){
3902 toQueryXML(CreateGui.getCurrentTab().network(), filename, CreateGui.getCurrentTab().queries());
3903@@ -232,11 +232,12 @@
3904 case TIKZ:
3905 Object[] possibilities = { "Only the TikZ figure",
3906 "Full compilable LaTex including your figure" };
3907- String figureOptions = (String) JOptionPane.showInputDialog(
3908- CreateGui.getApp(),
3909- "Choose how you would like your TikZ figure outputted: \n",
3910- "Export to TikZ", JOptionPane.PLAIN_MESSAGE,
3911- null, possibilities, "Only the TikZ figure");
3912+ String figureOptions = (String) JOptionPane.showInputDialog(
3913+ CreateGui.getRootFrame(),
3914+ "Choose how you would like your TikZ figure outputted: \n",
3915+ "Export to TikZ", JOptionPane.PLAIN_MESSAGE,
3916+ null, possibilities, "Only the TikZ figure"
3917+ );
3918 TikZExporter.TikZOutputOption tikZOption = TikZExporter.TikZOutputOption.FIGURE_ONLY;
3919 if (figureOptions == null)
3920 break;
3921@@ -248,7 +249,7 @@
3922
3923 filename = FileBrowser.constructor("TikZ figure", "tex", filename).saveFile();
3924 if (filename != null) {
3925- TikZExporter output = new TikZExporter(model, filename, tikZOption);
3926+ TikZExporter output = new TikZExporter(model, filename, tikZOption, CreateGui.getApp().showZeroToInfinityIntervals());
3927 output.ExportToTikZ();
3928 }
3929 break;
3930@@ -268,7 +269,7 @@
3931 }
3932 } catch (Exception e) {
3933 // There was some problem with the action
3934- JOptionPane.showMessageDialog(CreateGui.getApp(),
3935+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
3936 "There were errors performing the requested action:\n" + e,
3937 "Error", JOptionPane.ERROR_MESSAGE);
3938 }
3939
3940=== modified file 'src/pipe/gui/ExportBatchDialog.java'
3941--- src/pipe/gui/ExportBatchDialog.java 2020-07-20 08:09:36 +0000
3942+++ src/pipe/gui/ExportBatchDialog.java 2020-08-30 09:33:26 +0000
3943@@ -109,7 +109,7 @@
3944
3945 public static void ShowExportBatchDialog(){
3946 if(exportBatchDialog == null){
3947- exportBatchDialog = new ExportBatchDialog(CreateGui.getApp(), "Batch Export", true);
3948+ exportBatchDialog = new ExportBatchDialog(CreateGui.getRootFrame(), "Batch Export", true);
3949 exportBatchDialog.pack();
3950 exportBatchDialog.setPreferredSize(exportBatchDialog.getSize());
3951 exportBatchDialog.setMinimumSize(new Dimension(exportBatchDialog.getWidth(), exportBatchDialog.getHeight()));
3952
3953=== modified file 'src/pipe/gui/Grid.java'
3954--- src/pipe/gui/Grid.java 2020-04-02 10:25:07 +0000
3955+++ src/pipe/gui/Grid.java 2020-08-30 09:33:26 +0000
3956@@ -99,23 +99,5 @@
3957 }
3958 return (int) (Math.round(y / gridSpacing) * gridSpacing);
3959 }
3960-
3961- public static void alignPNObjectsToGrid() {
3962- ArrayList<PetriNetObject> petriNetObjects = CreateGui.getDrawingSurface().getGuiModel().getPlaceTransitionObjects();
3963- pipe.gui.undo.UndoManager undoManager = CreateGui.getCurrentTab().getUndoManager();
3964- undoManager.newEdit();
3965-
3966- for(PetriNetObject object : petriNetObjects) {
3967- PlaceTransitionObject ptobject = (PlaceTransitionObject)object;
3968- int x = Grid.getModifiedX(ptobject.getPositionX());
3969- int y = Grid.getModifiedY(ptobject.getPositionY());
3970- Point point = new Point(x,y);
3971- Command command = new MovePlaceTransitionObject(ptobject, point);
3972- command.redo();
3973- undoManager.addEdit(command);
3974- ptobject.updateOnMoveOrZoom();
3975- }
3976-
3977- }
3978
3979 }
3980
3981=== modified file 'src/pipe/gui/GuiFrame.java'
3982--- src/pipe/gui/GuiFrame.java 2020-08-14 10:53:56 +0000
3983+++ src/pipe/gui/GuiFrame.java 2020-08-30 09:33:26 +0000
3984@@ -8,17 +8,12 @@
3985 import java.awt.event.WindowAdapter;
3986 import java.awt.event.WindowEvent;
3987 import java.io.*;
3988-import java.net.*;
3989-import java.nio.charset.StandardCharsets;
3990 import java.util.*;
3991 import java.util.List;
3992-import java.util.jar.JarEntry;
3993-import java.util.jar.JarFile;
3994 import javax.swing.*;
3995
3996 import com.sun.jna.Platform;
3997 import dk.aau.cs.gui.*;
3998-import dk.aau.cs.util.JavaUtil;
3999 import dk.aau.cs.verification.VerifyTAPN.VerifyPN;
4000 import net.tapaal.Preferences;
4001 import net.tapaal.TAPAAL;
4002@@ -40,26 +35,37 @@
4003
4004 public class GuiFrame extends JFrame implements GuiFrameActions, SafeGuiFrameActions {
4005
4006+ /*
4007+ DEBUG
4008+ Set a break point at line actionPerformed, to allow to break execution from the gui. Eg. for inspecting elements
4009+ */
4010+ private final GuiAction breakExecutionAction = new GuiAction("Break Execution", "This action can be used to set a break while debugging, the action has no function.", KeyStroke.getKeyStroke('B',InputEvent.CTRL_DOWN_MASK + InputEvent.ALT_DOWN_MASK + InputEvent.SHIFT_DOWN_MASK)) {
4011+ public void actionPerformed(ActionEvent e) {}
4012+ };
4013+
4014 // for zoom combobox and dropdown
4015 private final int[] zoomLevels = {40, 60, 80, 100, 120, 140, 160, 180, 200, 300};
4016
4017 private final String frameTitle;
4018
4019- private int newNameCounter = 1;
4020-
4021 final MutableReference<GuiFrameControllerActions> guiFrameController = new MutableReference<>();
4022
4023 private final ExtendedJTabbedPane<TabContent> appTab;
4024
4025 private final StatusBar statusBar;
4026 private JMenuBar menuBar;
4027- JMenu drawMenu;
4028- JMenu animateMenu;
4029- JMenu viewMenu;
4030+
4031+ private JMenu fileMenu;
4032+ private JMenu exampleMenu;
4033+ private JMenu drawMenu;
4034+ private JMenu animateMenu;
4035+ private JMenu viewMenu;
4036+
4037 private JToolBar drawingToolBar;
4038- private final JLabel featureInfoText = new JLabel();
4039- private JComboBox<String> timeFeatureOptions = new JComboBox(new String[]{"No", "Yes"});
4040- private JComboBox<String> gameFeatureOptions = new JComboBox(new String[]{"No", "Yes"});
4041+
4042+ private final JComboBox<String> timeFeatureOptions = new JComboBox<>(new String[]{"No", "Yes"});
4043+ private final JComboBox<String> gameFeatureOptions = new JComboBox<>(new String[]{"No", "Yes"});
4044+
4045 private JComboBox<String> zoomComboBox;
4046
4047 private static final int shortcutkey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
4048@@ -198,7 +204,7 @@
4049 };
4050 private final GuiAction alignToGrid = new GuiAction("Align To Grid", "Align Petri net objects to current grid", KeyStroke.getKeyStroke("shift G")) {
4051 public void actionPerformed(ActionEvent e) {
4052- Grid.alignPNObjectsToGrid();
4053+ currentTab.ifPresent(TabContentActions::alignPNObjectsToGrid);
4054 }
4055 };
4056 private final GuiAction netStatisticsAction = new GuiAction("Net statistics", "Shows information about the number of transitions, places, arcs, etc.", KeyStroke.getKeyStroke(KeyEvent.VK_I, shortcutkey)) {
4057@@ -376,7 +382,6 @@
4058 }
4059 };
4060
4061-
4062 private final GuiAction selectAllAction = new GuiAction("Select all", "Select all components", KeyStroke.getKeyStroke('A', shortcutkey)) {
4063 public void actionPerformed(ActionEvent e) {
4064 currentTab.ifPresent(TabContentActions::selectAll);
4065@@ -399,8 +404,7 @@
4066 }
4067 };
4068
4069-
4070- private GuiAction prevcomponentAction = new GuiAction("Previous component", "Previous component", "pressed UP") {
4071+ private final GuiAction prevcomponentAction = new GuiAction("Previous component", "Previous component", "pressed UP") {
4072 public void actionPerformed(ActionEvent e) {
4073 currentTab.ifPresent(TabContentActions::previousComponent);
4074 }
4075@@ -411,14 +415,14 @@
4076 }
4077 };
4078
4079- private GuiAction changeTimeFeatureAction = new GuiAction("Time", "Change time semantics") {
4080+ private final GuiAction changeTimeFeatureAction = new GuiAction("Time", "Change time semantics") {
4081 public void actionPerformed(ActionEvent e) {
4082 boolean isTime = timeFeatureOptions.getSelectedIndex() != 0;
4083 currentTab.ifPresent(o -> o.changeTimeFeature(isTime));
4084 }
4085 };
4086
4087- private GuiAction changeGameFeatureAction = new GuiAction("Game", "Change game semantics") {
4088+ private final GuiAction changeGameFeatureAction = new GuiAction("Game", "Change game semantics") {
4089 public void actionPerformed(ActionEvent e) {
4090 boolean isGame = gameFeatureOptions.getSelectedIndex() != 0;
4091 currentTab.ifPresent(o -> o.changeGameFeature(isGame));
4092@@ -439,8 +443,6 @@
4093 // HAK-arrange for frameTitle to be initialized and the default file
4094 // name to be appended to basic window title
4095
4096- checkJavaVersion();
4097-
4098 frameTitle = title;
4099 setTitle(null);
4100 trySetLookAndFeel();
4101@@ -511,15 +513,6 @@
4102
4103 }
4104
4105- private void checkJavaVersion() {
4106- int version = JavaUtil.getJREMajorVersion();
4107-
4108- if (version < 11) {
4109- JOptionPane.showMessageDialog(CreateGui.getApp(), "You are using an older version of Java than 11. Some of the functionalities may not be shown correctly.");
4110- System.out.println("You are using an older version of Java than 11. Some of the functionalities may not be shown correctly.");
4111- }
4112- }
4113-
4114 private void trySetLookAndFeel() {
4115 try {
4116 // Set the Look and Feel native for the system.
4117@@ -580,10 +573,22 @@
4118 menuBar.add(buildMenuTools());
4119 menuBar.add(buildMenuHelp());
4120
4121+ if (TAPAAL.debugEnabled()){
4122+ menuBar.add(buildMenuDebug());
4123+ }
4124+
4125 setJMenuBar(menuBar);
4126
4127 }
4128
4129+ private JMenu buildMenuDebug() {
4130+ JMenu debugMenu = new JMenu("DEBUG");
4131+
4132+ debugMenu.add(breakExecutionAction);
4133+
4134+ return debugMenu;
4135+ }
4136+
4137 private JMenu buildMenuEdit() {
4138
4139 /* Edit Menu */
4140@@ -724,14 +729,16 @@
4141 JMenu toolsMenu = new JMenu("Tools");
4142 toolsMenu.setMnemonic('t');
4143
4144- toolsMenu.add(verifyAction).setMnemonic('m');
4145-
4146- toolsMenu.add(netStatisticsAction).setMnemonic('i');
4147-
4148 JMenuItem batchProcessing = new JMenuItem(batchProcessingAction);
4149 batchProcessing.setMnemonic('b');
4150 toolsMenu.add(batchProcessing);
4151
4152+ toolsMenu.addSeparator();
4153+
4154+ toolsMenu.add(verifyAction).setMnemonic('m');
4155+
4156+ toolsMenu.add(netStatisticsAction).setMnemonic('i');
4157+
4158 JMenuItem workflowDialog = new JMenuItem(workflowDialogAction);
4159 workflowDialog.setMnemonic('f');
4160 toolsMenu.add(workflowDialog);
4161@@ -934,10 +941,6 @@
4162 timeFeatureOptions.setEnabled(true);
4163 gameFeatureOptions.setEnabled(true);
4164
4165- if (getCurrentTab().restoreWorkflowDialog()) {
4166- WorkflowDialog.showDialog();
4167- }
4168-
4169 //Enable editor focus traversal policy
4170 setFocusTraversalPolicy(new EditorFocusTraversalPolicy());
4171 fixBug812694GrayMenuAfterSimulationOnMac();
4172@@ -1166,13 +1169,12 @@
4173 drawingToolBar.add(new ToggleButtonWithoutText(action));
4174 drawMenu.add(action);
4175 }
4176-
4177- drawingToolBar.add(featureInfoText);
4178 } else {
4179 drawMenu.setEnabled(false);
4180 }
4181
4182 }
4183+
4184 @Override
4185 public void registerAnimationActions(@NotNull List<GuiAction> animationActions) {
4186
4187@@ -1339,7 +1341,7 @@
4188 }
4189
4190 private JMenu buildMenuFiles() {
4191- JMenu fileMenu = new JMenu("File");
4192+ fileMenu = new JMenu("File");
4193 fileMenu.setMnemonic('F');
4194
4195 fileMenu.add(createAction);
4196@@ -1395,15 +1397,22 @@
4197
4198 fileMenu.addSeparator();
4199
4200- // Loads example files, retuns null if not found
4201- String[] nets = loadTestNets();
4202-
4203- // Oliver Haggarty - fixed code here so that if folder contains non
4204- // .xml file the Example x counter is not incremented when that file
4205- // is ignored
4206- if (nets != null && nets.length > 0) {
4207- JMenu exampleMenu = new JMenu("Example nets");
4208- exampleMenu.setIcon(ResourceManager.getIcon("Example.png"));
4209+ exampleMenu = new JMenu("Example nets");
4210+ exampleMenu.setEnabled(false);
4211+ exampleMenu.setIcon(ResourceManager.getIcon("Example.png"));
4212+ fileMenu.add(exampleMenu);
4213+ fileMenu.addSeparator();
4214+
4215+
4216+ fileMenu.add(exitAction);
4217+
4218+ return fileMenu;
4219+ }
4220+
4221+ @Override
4222+ public void registerExampleNets(List<String> nets) {
4223+ if (nets != null && nets.size() > 0) {
4224+ exampleMenu.setEnabled(true);
4225
4226 for (String filename : nets) {
4227 if (filename.toLowerCase().endsWith(".tapn")) {
4228@@ -1413,111 +1422,19 @@
4229 GuiAction tmp = new GuiAction(netname, "Open example file \"" + netname + "\"") {
4230 public void actionPerformed(ActionEvent arg0) {
4231 InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/Example nets/" + filenameFinal);
4232- try {
4233- TabContent net = TabContent.createNewTabFromInputStream(file, netname);
4234- guiFrameController.ifPresent(o -> o.openTab(net));
4235- } catch (Exception e) {
4236- // TODO Auto-generated catch block
4237- e.printStackTrace();
4238- }
4239+ guiFrameController.ifPresent(o -> {
4240+ TabContent tab = o.createNewTabFromInputStream(file, netname);
4241+ o.openTab(tab);
4242+ });
4243 }
4244 };
4245 tmp.putValue(Action.SMALL_ICON, ResourceManager.getIcon("Net.png"));
4246 exampleMenu.add(tmp);
4247 }
4248 }
4249- fileMenu.add(exampleMenu);
4250- fileMenu.addSeparator();
4251-
4252- }
4253-
4254-
4255- fileMenu.add(exitAction);
4256-
4257- return fileMenu;
4258- }
4259-
4260- /**
4261- * The function loads the example nets as InputStream from the resources
4262- * Notice the check for if we are inside a jar file, as files inside a jar cant
4263- * be listed in the normal way.
4264- *
4265- * @author Kenneth Yrke Joergensen <kenneth@yrke.dk>, 2011-06-27
4266- */
4267- private String[] loadTestNets() {
4268-
4269-
4270- String[] nets = null;
4271-
4272- try {
4273- URL dirURL = Thread.currentThread().getContextClassLoader().getResource("resources/Example nets/");
4274- if (dirURL != null && dirURL.getProtocol().equals("file")) {
4275- /* A file path: easy enough */
4276- nets = new File(dirURL.toURI()).list();
4277- }
4278-
4279- if (dirURL == null) {
4280- /*
4281- * In case of a jar file, we can't actually find a directory. Have to assume the
4282- * same jar as clazz.
4283- */
4284- String me = this.getName().replace(".", "/") + ".class";
4285- dirURL = Thread.currentThread().getContextClassLoader().getResource(me);
4286- }
4287-
4288- if (dirURL.getProtocol().equals("jar")) {
4289- /* A JAR path */
4290- String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf('!')); // strip out only the JAR
4291- // file
4292- JarFile jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8));
4293- Enumeration<JarEntry> entries = jar.entries(); // gives ALL entries in jar
4294- Set<String> result = new HashSet<String>(); // avoid duplicates in case it is a subdirectory
4295- while (entries.hasMoreElements()) {
4296- String name = entries.nextElement().getName();
4297- if (name.startsWith("resources/Example nets/")) { // filter according to the path
4298- String entry = name.substring("resources/Example nets/".length());
4299- int checkSubdir = entry.indexOf('/');
4300- if (checkSubdir >= 0) {
4301- // if it is a subdirectory, we just return the directory name
4302- entry = entry.substring(0, checkSubdir);
4303- }
4304- result.add(entry);
4305- }
4306- }
4307- nets = result.toArray(new String[result.size()]);
4308- jar.close();
4309- }
4310-
4311- Arrays.sort(nets, (one, two) -> {
4312-
4313- int toReturn = one.compareTo(two);
4314- // Special hack to get intro-example first and game-example last
4315- if (one.equals("intro-example.tapn")) {
4316- toReturn = -1;
4317- } else if (one.equals("game-harddisk.tapn")) {
4318- toReturn = 1;
4319- }
4320- if (two.equals("intro-example.tapn")) {
4321- toReturn = 1;
4322- } else if (two.equals("game-harddisk.tapn")) {
4323- toReturn = -1;
4324- }
4325- return toReturn;
4326- });
4327- } catch (Exception e) {
4328- Logger.log("Error getting example files:" + e);
4329- e.printStackTrace();
4330- }
4331- return nets;
4332- }
4333-
4334-
4335- public int getNameCounter() {
4336- return newNameCounter;
4337- }
4338-
4339- public void incrementNameCounter() {
4340- newNameCounter++;
4341+ } else {
4342+ exampleMenu.setEnabled(false);
4343+ }
4344 }
4345
4346 public String getCurrentTabName() {
4347
4348=== modified file 'src/pipe/gui/GuiFrameActions.java'
4349--- src/pipe/gui/GuiFrameActions.java 2020-08-11 11:51:55 +0000
4350+++ src/pipe/gui/GuiFrameActions.java 2020-08-30 09:33:26 +0000
4351@@ -51,5 +51,7 @@
4352 void setShowZeroToInfinityIntervalsSelected(boolean b);
4353 void setShowTokenAgeSelected(boolean b);
4354
4355+ void registerExampleNets(List<String> nets);
4356+
4357 void setFeatureInfoText(boolean[] features);
4358 }
4359
4360=== modified file 'src/pipe/gui/GuiFrameController.java'
4361--- src/pipe/gui/GuiFrameController.java 2020-08-17 06:18:11 +0000
4362+++ src/pipe/gui/GuiFrameController.java 2020-08-30 09:33:26 +0000
4363@@ -5,6 +5,10 @@
4364 import dk.aau.cs.gui.TabContent;
4365 import dk.aau.cs.gui.TabContentActions;
4366 import dk.aau.cs.gui.smartDraw.SmartDrawDialog;
4367+import dk.aau.cs.io.LoadedModel;
4368+import dk.aau.cs.io.ModelLoader;
4369+import dk.aau.cs.io.PNMLoader;
4370+import dk.aau.cs.util.JavaUtil;
4371 import net.tapaal.resourcemanager.ResourceManager;
4372 import dk.aau.cs.model.tapn.simulation.ShortestDelayMode;
4373 import dk.aau.cs.verification.UPPAAL.Verifyta;
4374@@ -22,21 +26,26 @@
4375 import javax.swing.*;
4376 import java.awt.*;
4377 import java.awt.event.KeyEvent;
4378-import java.io.File;
4379-import java.io.FileNotFoundException;
4380-import java.io.IOException;
4381+import java.io.*;
4382 import java.math.BigDecimal;
4383 import java.net.URI;
4384 import java.net.URISyntaxException;
4385-import java.util.ArrayList;
4386+import java.net.URL;
4387+import java.net.URLDecoder;
4388+import java.nio.charset.StandardCharsets;
4389+import java.util.*;
4390 import java.util.List;
4391+import java.util.jar.JarEntry;
4392+import java.util.jar.JarFile;
4393
4394 public class GuiFrameController implements GuiFrameControllerActions{
4395
4396+ public static final String WARNING_OLD_JAVAVERSION = "You are using an older version of Java than 11. Some of the functionalities may not work or display correctly.";
4397+
4398 final GuiFrame guiFrameDirectAccess; //XXX - while refactoring shold only use guiFrameActions
4399 final GuiFrameActions guiFrame;
4400
4401- final MutableReference<TabContentActions> currentTab = new MutableReference<>();
4402+ final MutableReference<TabContentActions> activeTab = new MutableReference<>();
4403
4404 public GuiFrameController(GuiFrame appGui) {
4405 super();
4406@@ -44,13 +53,102 @@
4407 guiFrame = appGui;
4408 guiFrameDirectAccess = appGui;
4409
4410+ appGui.registerController(this, activeTab);
4411+
4412 loadPrefrences();
4413- appGui.registerController(this, currentTab);
4414-
4415-
4416- }
4417-
4418- //XXX should be private and should prop. live in controllers not GUI, tmp while refactoring //kyrke 2019-11-05
4419+ loadAndRegisterExampleNets();
4420+ checkJavaVersion();
4421+
4422+ }
4423+
4424+
4425+ private void checkJavaVersion() {
4426+ int version = JavaUtil.getJREMajorVersion();
4427+
4428+ if (version < TAPAAL.MINIMUM_SUPPORTED_JAVAVERSION) {
4429+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), WARNING_OLD_JAVAVERSION);
4430+ System.out.println(WARNING_OLD_JAVAVERSION);
4431+ }
4432+ }
4433+
4434+ private void loadAndRegisterExampleNets() {
4435+ var testNets = loadTestNets();
4436+ guiFrame.registerExampleNets(Arrays.asList(testNets));
4437+ }
4438+ /**
4439+ * The function loads the example nets as InputStream from the resources
4440+ * Notice the check for if we are inside a jar file, as files inside a jar cant
4441+ * be listed in the normal way.
4442+ *
4443+ * @author Kenneth Yrke Joergensen <kenneth@yrke.dk>, 2011-06-27
4444+ */
4445+ private String[] loadTestNets() {
4446+
4447+ String[] nets = null;
4448+
4449+ try {
4450+ URL dirURL = Thread.currentThread().getContextClassLoader().getResource("resources/Example nets/");
4451+ if (dirURL != null && dirURL.getProtocol().equals("file")) {
4452+ /* A file path: easy enough */
4453+ nets = new File(dirURL.toURI()).list();
4454+ }
4455+
4456+ if (dirURL == null) {
4457+ /*
4458+ * In case of a jar file, we can't actually find a directory. Have to assume the
4459+ * same jar as clazz.
4460+ */
4461+ String me = "TAPAAL.class";
4462+ dirURL = Thread.currentThread().getContextClassLoader().getResource(me);
4463+ }
4464+
4465+ if (dirURL.getProtocol().equals("jar")) {
4466+ /* A JAR path */
4467+ String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf('!')); // strip out only the JAR
4468+ // file
4469+ JarFile jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8));
4470+ Enumeration<JarEntry> entries = jar.entries(); // gives ALL entries in jar
4471+ Set<String> result = new HashSet<String>(); // avoid duplicates in case it is a subdirectory
4472+ while (entries.hasMoreElements()) {
4473+ String name = entries.nextElement().getName();
4474+ if (name.startsWith("resources/Example nets/")) { // filter according to the path
4475+ String entry = name.substring("resources/Example nets/".length());
4476+ int checkSubdir = entry.indexOf('/');
4477+ if (checkSubdir >= 0) {
4478+ // if it is a subdirectory, we just return the directory name
4479+ entry = entry.substring(0, checkSubdir);
4480+ }
4481+ result.add(entry);
4482+ }
4483+ }
4484+ nets = result.toArray(new String[result.size()]);
4485+ jar.close();
4486+ }
4487+
4488+ Arrays.sort(nets, (one, two) -> {
4489+
4490+ int toReturn = one.compareTo(two);
4491+ // Special hack to get intro-example first and game-example last
4492+ if (one.equals("intro-example.tapn")) {
4493+ toReturn = -1;
4494+ } else if (one.equals("game-harddisk.tapn")) {
4495+ toReturn = 1;
4496+ }
4497+ if (two.equals("intro-example.tapn")) {
4498+ toReturn = 1;
4499+ } else if (two.equals("game-harddisk.tapn")) {
4500+ toReturn = -1;
4501+ }
4502+ return toReturn;
4503+ });
4504+ } catch (Exception e) {
4505+ Logger.log("Error getting example files:" + e);
4506+ e.printStackTrace();
4507+ }
4508+ return nets;
4509+ }
4510+
4511+ //XXX should be private //kyrke 2019-11-05
4512 boolean showComponents = true;
4513 boolean showSharedPT = true;
4514 boolean showConstants = true;
4515@@ -143,15 +241,15 @@
4516 public void changeToTab(TabContent tab) {
4517
4518 //De-register old model
4519- currentTab.ifPresent(t -> t.setApp(null));
4520+ activeTab.ifPresent(t -> t.setApp(null));
4521
4522 //Set current tab
4523- currentTab.setReference(tab);
4524+ activeTab.setReference(tab);
4525
4526 guiFrame.changeToTab(tab);
4527
4528- currentTab.ifPresent(t -> t.setApp(guiFrame));
4529- guiFrameDirectAccess.setTitle(currentTab.map(TabContentActions::getTabTitle).orElse(null));
4530+ activeTab.ifPresent(t -> t.setApp(guiFrame));
4531+ guiFrameDirectAccess.setTitle(activeTab.map(TabContentActions::getTabTitle).orElse(null));
4532
4533 }
4534
4535@@ -286,7 +384,7 @@
4536 public void openTAPNFile() {
4537 final File[] files = FileBrowser.constructor("Timed-Arc Petri Net","tapn", "xml", FileBrowser.userPath).openFiles();
4538 //show loading cursor
4539- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
4540+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
4541 //Do loading
4542 SwingWorker<java.util.List<TabContent>, Void> worker = new SwingWorker<java.util.List<TabContent>, Void>() {
4543 @Override
4544@@ -295,7 +393,7 @@
4545 for(File f : files){
4546 if(f.exists() && f.isFile() && f.canRead()){
4547 FileBrowser.userPath = f.getParent();
4548- filesOpened.add(TabContent.createNewTabFromFile(f));
4549+ filesOpened.add(createNewTabFromFile(f));
4550 }
4551 }
4552 return filesOpened;
4553@@ -306,14 +404,14 @@
4554 List<TabContent> tabs = get();
4555 openTab(tabs);
4556 } catch (Exception e) {
4557- JOptionPane.showMessageDialog(CreateGui.getApp(),
4558+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4559 e.getMessage(),
4560 "Error loading file",
4561 JOptionPane.ERROR_MESSAGE);
4562 e.printStackTrace();
4563 return;
4564 }finally {
4565- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4566+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4567 }
4568 }
4569 };
4570@@ -336,7 +434,7 @@
4571 final File[] files = FileBrowser.constructor("Import PNML", "pnml", FileBrowser.userPath).openFiles();
4572
4573 //Show loading cursor
4574- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
4575+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
4576 //Do loading of net
4577 SwingWorker<List<TabContent>, Void> worker = new SwingWorker<List<TabContent>, Void>() {
4578 @Override
4579@@ -345,7 +443,7 @@
4580 for(File f : files){
4581 if(f.exists() && f.isFile() && f.canRead()){
4582 FileBrowser.userPath = f.getParent();
4583- fileOpened.add(TabContent.createNewTabFromPNMLFile(f));
4584+ fileOpened.add(createNewTabFromPNMLFile(f));
4585 }
4586 }
4587 return fileOpened;
4588@@ -364,13 +462,13 @@
4589 }
4590
4591 } catch (Exception e) {
4592- JOptionPane.showMessageDialog(CreateGui.getApp(),
4593+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4594 e.getMessage(),
4595 "Error loading file",
4596 JOptionPane.ERROR_MESSAGE);
4597 return;
4598 }finally {
4599- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4600+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4601 }
4602 }
4603 };
4604@@ -479,11 +577,11 @@
4605
4606 @Override
4607 public void save() {
4608- save(currentTab.get());
4609+ save(activeTab.get());
4610 }
4611 @Override
4612 public void saveAs(){
4613- saveAs(currentTab.get());
4614+ saveAs(activeTab.get());
4615 }
4616
4617 @Override
4618@@ -535,7 +633,7 @@
4619 //XXX: this cast should not be done, its a quick fix while refactoring //kyrke 2019-12-31
4620 changeToTab((TabContent) tab);
4621
4622- int result = JOptionPane.showConfirmDialog(CreateGui.getApp(),
4623+ int result = JOptionPane.showConfirmDialog(CreateGui.getRootFrame(),
4624 "The net has been modified. Save the current net?",
4625 "Confirm Save Current File",
4626 JOptionPane.YES_NO_CANCEL_OPTION,
4627@@ -610,7 +708,7 @@
4628 Preferences.getInstance().setShowTokenAge(showTokenAge);
4629
4630 guiFrame.setShowTokenAgeSelected(showTokenAge);
4631- currentTab.ifPresent(TabContentActions::repaintAll);
4632+ activeTab.ifPresent(TabContentActions::repaintAll);
4633
4634 }
4635
4636@@ -624,7 +722,7 @@
4637 guiFrame.setShowZeroToInfinityIntervalsSelected(showZeroToInfinityIntervals);
4638
4639 Preferences.getInstance().setShowZeroInfIntervals(showZeroToInfinityIntervals);
4640- currentTab.ifPresent(TabContentActions::repaintAll);
4641+ activeTab.ifPresent(TabContentActions::repaintAll);
4642 }
4643
4644 @Override
4645@@ -659,7 +757,7 @@
4646 private void setEnabledTransitionsList(boolean b){
4647 showEnabledTransitions = b;
4648 guiFrame.setShowEnabledTransitionsSelected(b);
4649- currentTab.ifPresent(o->o.showEnabledTransitionsList(b));
4650+ activeTab.ifPresent(o->o.showEnabledTransitionsList(b));
4651 }
4652
4653 @Override
4654@@ -670,7 +768,7 @@
4655 private void setDelayEnabledTransitions(boolean b) {
4656 showDelayEnabledTransitions = b;
4657 guiFrame.setShowDelayEnabledTransitionsSelected(b);
4658- currentTab.ifPresent(o->o.showDelayEnabledTransitions(b));
4659+ activeTab.ifPresent(o->o.showDelayEnabledTransitions(b));
4660 }
4661
4662 @Override
4663@@ -710,7 +808,7 @@
4664 setEnabledTransitionsList(true);
4665 setDisplayToolTips(true);
4666
4667- currentTab.ifPresent(TabContentActions::setResizeingDefault);
4668+ activeTab.ifPresent(TabContentActions::setResizeingDefault);
4669
4670 if (advanced) {
4671
4672@@ -729,4 +827,124 @@
4673 SimulationControl.getInstance().setRandomTransitionMode(false);
4674 }
4675
4676+
4677+ /**
4678+ * Creates a new tab with the selected file, or a new file if filename==null
4679+ */
4680+ @Override
4681+ public TabContent createNewTabFromInputStream(InputStream file, String name) {
4682+
4683+ try {
4684+ ModelLoader loader = new ModelLoader();
4685+ LoadedModel loadedModel = loader.load(file);
4686+
4687+ if (loadedModel.getMessages().size() != 0) {
4688+ new Thread(new Runnable() {
4689+ @Override
4690+ public void run() {
4691+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4692+ String message = "While loading the net we found one or more warnings: \n\n";
4693+ for (String s : loadedModel.getMessages()) {
4694+ message += s + "\n\n";
4695+ }
4696+
4697+ new MessengerImpl().displayInfoMessage(message, "Warning");
4698+ }
4699+ }).start();
4700+ }
4701+
4702+ TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), loadedModel.getLens());
4703+
4704+ tab.setInitialName(name);
4705+
4706+ tab.selectFirstElements();
4707+
4708+ tab.setFile(null);
4709+
4710+ return tab;
4711+ } catch (Exception e) {
4712+ Logger.log("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
4713+ System.err.println("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
4714+ //throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
4715+ }
4716+ return null;
4717+
4718+ }
4719+
4720+ /**
4721+ * Creates a new tab with the selected file, or a new file if filename==null
4722+ */
4723+
4724+ public TabContent createNewTabFromPNMLFile(File file) throws Exception {
4725+
4726+ if (file != null) {
4727+ try {
4728+
4729+ LoadedModel loadedModel;
4730+
4731+ PNMLoader loader = new PNMLoader();
4732+ loadedModel = loader.load(file);
4733+
4734+ TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries(), new TabContent.TAPNLens(true, false));
4735+
4736+ String name = null;
4737+
4738+ if (file != null) {
4739+ name = file.getName().replaceAll(".pnml", ".tapn");
4740+ }
4741+ tab.setInitialName(name);
4742+
4743+ tab.selectFirstElements();
4744+
4745+ tab.setMode(Pipe.ElementType.SELECT);
4746+
4747+ //appView.updatePreferredSize(); //XXX 2018-05-23 kyrke seems not to be needed
4748+ name = name.replace(".pnml",".tapn"); // rename .pnml input file to .tapn
4749+ return tab;
4750+
4751+ } catch (Exception e) {
4752+ throw new Exception("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString());
4753+ }
4754+ }
4755+ return null;
4756+ }
4757+
4758+ /**
4759+ * Creates a new tab with the selected file, or a new file if filename==null
4760+ */
4761+ //XXX should properly be in controller?
4762+ public TabContent createNewTabFromFile(File file) throws Exception {
4763+ try {
4764+ String name = file.getName();
4765+ boolean showFileEndingChangedMessage = false;
4766+
4767+ if(name.toLowerCase().endsWith(".xml")){
4768+ name = name.substring(0, name.lastIndexOf('.')) + ".tapn";
4769+ showFileEndingChangedMessage = true;
4770+ }
4771+
4772+ InputStream stream = new FileInputStream(file);
4773+ TabContent tab = createNewTabFromInputStream(stream, name);
4774+ if (tab != null && !showFileEndingChangedMessage) tab.setFile(file);
4775+
4776+ if(showFileEndingChangedMessage) {
4777+ //We thread this so it does not block the EDT
4778+ new Thread(new Runnable() {
4779+ @Override
4780+ public void run() {
4781+ guiFrameDirectAccess.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4782+ new MessengerImpl().displayInfoMessage(FILE_FORMAT_CHANGED_MESSAGE, "FILE CHANGED");
4783+ }
4784+ }).start();
4785+ }
4786+
4787+ return tab;
4788+ }catch (FileNotFoundException e) {
4789+ throw new FileNotFoundException("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nFile not found:\n - " + e.toString());
4790+ }
4791+ }
4792+
4793+ public static final String FILE_FORMAT_CHANGED_MESSAGE = "We have changed the ending of TAPAAL files from .xml to .tapn and the opened file was automatically renamed to end with .tapn.\n"
4794+ + "Once you save the .tapn model, we recommend that you manually delete the .xml file.";
4795+
4796 }
4797
4798=== modified file 'src/pipe/gui/GuiFrameControllerActions.java'
4799--- src/pipe/gui/GuiFrameControllerActions.java 2020-05-18 18:17:06 +0000
4800+++ src/pipe/gui/GuiFrameControllerActions.java 2020-08-30 09:33:26 +0000
4801@@ -2,6 +2,8 @@
4802
4803 import dk.aau.cs.gui.TabContent;
4804
4805+import java.io.InputStream;
4806+
4807 public interface GuiFrameControllerActions {
4808 void openTab(TabContent tab);
4809 default void openTab(Iterable<TabContent> tabs) {
4810@@ -54,4 +56,6 @@
4811 void showAdvancedWorkspace();
4812
4813 void showSimpleWorkspace();
4814+
4815+ TabContent createNewTabFromInputStream(InputStream file, String name);
4816 }
4817
4818=== modified file 'src/pipe/gui/MessengerImpl.java'
4819--- src/pipe/gui/MessengerImpl.java 2011-08-29 23:00:27 +0000
4820+++ src/pipe/gui/MessengerImpl.java 2020-08-30 09:33:26 +0000
4821@@ -29,8 +29,7 @@
4822 }
4823
4824 private void showMessageBox(Object message, String title, int messageType) {
4825- JOptionPane.showMessageDialog(CreateGui.getApp(), message, title,
4826- messageType);
4827+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(), message, title, messageType);
4828 }
4829
4830 public void displayWrappedErrorMessage(String message, String title) {
4831
4832=== modified file 'src/pipe/gui/RunKBoundAnalysis.java'
4833--- src/pipe/gui/RunKBoundAnalysis.java 2020-05-27 12:59:31 +0000
4834+++ src/pipe/gui/RunKBoundAnalysis.java 2020-08-30 09:33:26 +0000
4835@@ -23,12 +23,12 @@
4836 protected void showResult(VerificationResult<TAPNNetworkTrace> result) {
4837 if(result != null && !result.error()) {
4838 if (!result.getQueryResult().boundednessAnalysis().boundednessResult().equals(Boundedness.Bounded)) {
4839- JOptionPane.showMessageDialog(CreateGui.getApp(),
4840+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4841 getAnswerNotBoundedString(), "Analysis Result",
4842 JOptionPane.INFORMATION_MESSAGE);
4843 } else {
4844 spinner.setValue(result.getQueryResult().boundednessAnalysis().usedTokens() - result.getQueryResult().boundednessAnalysis().tokensInNet());
4845- JOptionPane.showMessageDialog(CreateGui.getApp(),
4846+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4847 getAnswerBoundedString(), "Analysis Result",
4848 JOptionPane.INFORMATION_MESSAGE, ResourceManager.satisfiedIcon());
4849 }
4850
4851=== modified file 'src/pipe/gui/RunVerification.java'
4852--- src/pipe/gui/RunVerification.java 2020-07-20 07:19:51 +0000
4853+++ src/pipe/gui/RunVerification.java 2020-08-30 09:33:26 +0000
4854@@ -53,11 +53,11 @@
4855 callback.run(result);
4856 }else{
4857 JOptionPane.showMessageDialog(
4858- CreateGui.getApp(),
4859- createMessagePanel(result),
4860- "Verification Result",
4861- JOptionPane.INFORMATION_MESSAGE,
4862- iconSelector.getIconFor(result)
4863+ CreateGui.getRootFrame(),
4864+ createMessagePanel(result),
4865+ "Verification Result",
4866+ JOptionPane.INFORMATION_MESSAGE,
4867+ iconSelector.getIconFor(result)
4868 );
4869
4870 if (result.getTrace() != null) {
4871
4872=== modified file 'src/pipe/gui/SimulationControl.java'
4873--- src/pipe/gui/SimulationControl.java 2020-08-17 06:18:11 +0000
4874+++ src/pipe/gui/SimulationControl.java 2020-08-30 09:33:26 +0000
4875@@ -148,7 +148,7 @@
4876 gbc.fill = GridBagConstraints.HORIZONTAL;
4877 contentPane.add(stopSimulationButton, gbc);
4878
4879- dialog = new EscapableDialog(CreateGui.getApp(), "Simulation controls", true);
4880+ dialog = new EscapableDialog(CreateGui.getRootFrame(), "Simulation controls", true);
4881
4882 dialog.addComponentListener(new ComponentAdapter() {
4883 public void componentHidden(ComponentEvent e) {
4884
4885=== modified file 'src/pipe/gui/TikZExporter.java'
4886--- src/pipe/gui/TikZExporter.java 2020-08-04 08:19:44 +0000
4887+++ src/pipe/gui/TikZExporter.java 2020-08-30 09:33:26 +0000
4888@@ -20,7 +20,9 @@
4889
4890 public class TikZExporter {
4891
4892- public enum TikZOutputOption {
4893+ private boolean showZeroToInfinityIntervals;
4894+
4895+ public enum TikZOutputOption {
4896 FIGURE_ONLY, FULL_LATEX
4897 }
4898
4899@@ -33,10 +35,11 @@
4900 return Math.round(position * scale * 10)/10.0d;
4901 }
4902
4903- public TikZExporter(DataLayer net, String fullpath, TikZOutputOption option) {
4904+ public TikZExporter(DataLayer net, String fullpath, TikZOutputOption option, boolean showZeroToInfinityIntervals) {
4905 this.net = net;
4906 this.fullpath = fullpath;
4907 this.option = option;
4908+ this.showZeroToInfinityIntervals = showZeroToInfinityIntervals;
4909 }
4910
4911 public void ExportToTikZ() {
4912@@ -156,7 +159,7 @@
4913 }
4914
4915 private String getGuardAsStringIfNotHidden(TimedInputArcComponent arc) {
4916- if (!CreateGui.getApp().showZeroToInfinityIntervals() && arc.getGuardAsString().equals("[0,inf)")){
4917+ if (!showZeroToInfinityIntervals && arc.getGuardAsString().equals("[0,inf)")){
4918 return "";
4919 } else {
4920 return arc.getGuardAsString();
4921
4922=== modified file 'src/pipe/gui/Verifier.java'
4923--- src/pipe/gui/Verifier.java 2020-07-06 11:57:37 +0000
4924+++ src/pipe/gui/Verifier.java 2020-08-30 09:33:26 +0000
4925@@ -119,7 +119,7 @@
4926 );
4927 dialog.setVisible(true);
4928 } else {
4929- JOptionPane.showMessageDialog(CreateGui.getApp(),
4930+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4931 "There was an error converting the model.",
4932 "Conversion error", JOptionPane.ERROR_MESSAGE);
4933 }
4934@@ -205,7 +205,7 @@
4935 thread.execute(verifytapnOptions, tapnNetwork, new dk.aau.cs.model.tapn.TAPNQuery(query.getProperty(), bound), query);
4936 dialog.setVisible(true);
4937 } else {
4938- JOptionPane.showMessageDialog(CreateGui.getApp(),
4939+ JOptionPane.showMessageDialog(CreateGui.getRootFrame(),
4940 "There was an error converting the model.",
4941 "Conversion error", JOptionPane.ERROR_MESSAGE);
4942 }
4943
4944=== modified file 'src/pipe/gui/action/EditAnnotationBorderAction.java'
4945--- src/pipe/gui/action/EditAnnotationBorderAction.java 2020-04-18 14:41:05 +0000
4946+++ src/pipe/gui/action/EditAnnotationBorderAction.java 2020-08-30 09:33:26 +0000
4947@@ -21,8 +21,7 @@
4948
4949 /** Action for editing the text in an AnnotationNote */
4950 public void actionPerformed(ActionEvent e) {
4951- CreateGui.getCurrentTab().getUndoManager().addNewEdit(
4952- selected.showBorder(!selected.isShowingBorder()));
4953+ CreateGui.getUndoManager().addNewEdit(selected.showBorder(!selected.isShowingBorder()));
4954 }
4955
4956 }
4957
4958=== modified file 'src/pipe/gui/action/SplitArcAction.java'
4959--- src/pipe/gui/action/SplitArcAction.java 2020-07-16 10:20:56 +0000
4960+++ src/pipe/gui/action/SplitArcAction.java 2020-08-30 09:33:26 +0000
4961@@ -32,9 +32,7 @@
4962 }
4963
4964 public void actionPerformed(ActionEvent arg0) {
4965- CreateGui.getCurrentTab().getUndoManager().addNewEdit(
4966- selected.getArcPath().insertPoint(mouseposition, false)
4967- );
4968+ CreateGui.getUndoManager().addNewEdit(selected.getArcPath().insertPoint(mouseposition, false));
4969 selected.getArcPath().showPoints();
4970 // selected.split(mouseposition));
4971 }
4972
4973=== modified file 'src/pipe/gui/action/SplitArcPointAction.java'
4974--- src/pipe/gui/action/SplitArcPointAction.java 2020-07-13 13:58:47 +0000
4975+++ src/pipe/gui/action/SplitArcPointAction.java 2020-08-30 09:33:26 +0000
4976@@ -25,7 +25,7 @@
4977 }
4978
4979 public void actionPerformed(ActionEvent e) {
4980- CreateGui.getCurrentTab().getUndoManager().addNewEdit(arcPathPoint.splitPoint());
4981+ CreateGui.getUndoManager().addNewEdit(arcPathPoint.splitPoint());
4982 }
4983
4984 }
4985
4986=== modified file 'src/pipe/gui/action/ToggleArcPointAction.java'
4987--- src/pipe/gui/action/ToggleArcPointAction.java 2020-07-13 13:58:47 +0000
4988+++ src/pipe/gui/action/ToggleArcPointAction.java 2020-08-30 09:33:26 +0000
4989@@ -25,8 +25,7 @@
4990 * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
4991 */
4992 public void actionPerformed(ActionEvent e) {
4993- CreateGui.getCurrentTab().getUndoManager().addNewEdit(
4994- arcPathPoint.togglePointType());
4995+ CreateGui.getUndoManager().addNewEdit(arcPathPoint.togglePointType());
4996 }
4997
4998 }
4999
5000=== modified file 'src/pipe/gui/canvas/DrawingSurfaceImpl.java'
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches