Merge lp:~tapaal-contributor/tapaal/export-import-PNML-1853823 into lp:tapaal

Proposed by Peter Haahr Taankvist
Status: Merged
Approved by: Jiri Srba
Approved revision: 1033
Merged at revision: 1032
Proposed branch: lp:~tapaal-contributor/tapaal/export-import-PNML-1853823
Merge into: lp:tapaal
Diff against target: 202 lines (+58/-26)
3 files modified
src/dk/aau/cs/io/PNMLWriter.java (+3/-2)
src/net/tapaal/TAPAAL.java (+6/-1)
src/pipe/gui/GuiFrame.java (+49/-23)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/export-import-PNML-1853823
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+376201@code.launchpad.net

Commit message

Commented out some code which seemed to fix the problem. Also, made some better bughandling with the new way of loading nets (the worker handles exceptions instead of the functions run by the worker).

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/io/PNMLWriter.java'
2--- src/dk/aau/cs/io/PNMLWriter.java 2018-10-16 19:49:39 +0000
3+++ src/dk/aau/cs/io/PNMLWriter.java 2019-11-29 19:18:12 +0000
4@@ -177,8 +177,9 @@
5
6 Element initialMarking = document.createElement("initialMarking"); //Name
7 placeElement.appendChild(name);
8- Element initialMarkingGraphics = document.createElement("graphics");
9- initialMarking.appendChild(initialMarkingGraphics);
10+ //Seems to break the PNML file
11+ /*Element initialMarkingGraphics = document.createElement("graphics");
12+ initialMarking.appendChild(initialMarkingGraphics);*/
13 Element initialMarkingText = document.createElement("text");
14 initialMarking.appendChild(initialMarkingText);
15 initialMarkingText.setTextContent(((Integer) inputPlace.getNumberOfTokens() != null ? String.valueOf((Integer) inputPlace.getNumberOfTokens()) : "0"));
16
17=== modified file 'src/net/tapaal/TAPAAL.java'
18--- src/net/tapaal/TAPAAL.java 2018-05-23 16:03:49 +0000
19+++ src/net/tapaal/TAPAAL.java 2019-11-29 19:18:12 +0000
20@@ -69,7 +69,12 @@
21
22 if (file.exists()) { // Open the file
23 if (file.canRead()) {
24- CreateGui.getAppGui().createNewTabFromFile(file);
25+ try {
26+ CreateGui.getAppGui().createNewTabFromFile(file);
27+ } catch (Exception e) {
28+ // TODO Auto-generated catch block
29+ e.printStackTrace();
30+ }
31 } else if (file.exists()) {
32 System.err.println("Can not read file " + file.toString());
33 }
34
35=== modified file 'src/pipe/gui/GuiFrame.java'
36--- src/pipe/gui/GuiFrame.java 2019-11-23 11:48:43 +0000
37+++ src/pipe/gui/GuiFrame.java 2019-11-29 19:18:12 +0000
38@@ -12,12 +12,8 @@
39 import java.io.*;
40 import java.math.BigDecimal;
41 import java.net.*;
42-import java.time.LocalTime;
43-import java.time.temporal.ChronoUnit;
44 import java.util.*;
45 import java.util.List;
46-import java.util.Timer;
47-import java.util.concurrent.ExecutionException;
48 import java.util.jar.JarEntry;
49 import java.util.jar.JarFile;
50 import javax.imageio.ImageIO;
51@@ -1746,11 +1742,12 @@
52
53 /**
54 * Creates a new tab with the selected file, or a new file if filename==null
55+ * @throws Exception
56 */
57- public TabContent createNewTabFromFile(InputStream file, String name) {
58+ public TabContent createNewTabFromFile(InputStream file, String name) throws Exception {
59 int freeSpace = CreateGui.getFreeSpace(NetType.TAPN);
60 boolean showFileEndingChangedMessage = false;
61-
62+ String origName = name;
63
64 setObjects(freeSpace);
65 int currentlySelected = appTab.getSelectedIndex();
66@@ -1790,11 +1787,12 @@
67 tab.setFile(null);
68 } catch (Exception e) {
69 undoAddTab(currentlySelected);
70- JOptionPane.showMessageDialog(GuiFrame.this,
71- "TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString(),
72- "Error loading file: " + name,
73+ throw new Exception("TAPAAL encountered an error while loading the file: " + origName + "\n\nPossible explanations:\n - " + e.toString());
74+ /*JOptionPane.showMessageDialog(GuiFrame.this,
75+ "TAPAAL encountered an error while loading the file: " + origName + "\n\nPossible explanations:\n - " + e.toString(),
76+ "Error loading file: " + origName,
77 JOptionPane.ERROR_MESSAGE);
78- return null;
79+ return null;*/
80 }
81
82
83@@ -1809,8 +1807,9 @@
84
85 /**
86 * Creates a new tab with the selected file, or a new file if filename==null
87+ * @throws Exception
88 */
89- public void createNewTabFromPNMLFile(File file) {
90+ public void createNewTabFromPNMLFile(File file) throws Exception {
91 int freeSpace = CreateGui.getFreeSpace(NetType.TAPN);
92 String name;
93
94@@ -1850,11 +1849,13 @@
95
96 } catch (Exception e) {
97 undoAddTab(currentlySelected);
98- JOptionPane.showMessageDialog(GuiFrame.this,
99- "TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString(),
100- "Error loading file: " + name,
101+ throw new Exception("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString());
102+ //e.printStackTrace();
103+ /*JOptionPane.showMessageDialog(GuiFrame.this,
104+ "TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString(),
105+ "Error loading file: " + file.getName(),
106 JOptionPane.ERROR_MESSAGE);
107- return;
108+ return;*/
109 }
110 }
111
112@@ -1868,17 +1869,19 @@
113
114 /**
115 * Creates a new tab with the selected file, or a new file if filename==null
116+ * @throws FileNotFoundException
117 */
118- public void createNewTabFromFile(File file) {
119+ public void createNewTabFromFile(File file) throws Exception {
120 try {
121 InputStream stream = new FileInputStream(file);
122 TabContent tab = createNewTabFromFile(stream, file.getName());
123 if (tab != null) tab.setFile(file);
124 }catch (FileNotFoundException e) {
125- JOptionPane.showMessageDialog(GuiFrame.this,
126+ throw new FileNotFoundException("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nFile not found:\n - " + e.toString());
127+ /*JOptionPane.showMessageDialog(GuiFrame.this,
128 "TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nFile not found:\n - " + e.toString(),
129 "Error loading file: " + file.getName(),
130- JOptionPane.ERROR_MESSAGE);
131+ JOptionPane.ERROR_MESSAGE);*/
132 }
133 }
134
135@@ -2480,7 +2483,7 @@
136 //Do loading
137 SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
138 @Override
139- protected Void doInBackground() throws InterruptedException {
140+ protected Void doInBackground() throws InterruptedException, Exception, FileNotFoundException {
141 for(File f : files){
142 if(f.exists() && f.isFile() && f.canRead()){
143 FileBrowser.userPath = f.getParent();
144@@ -2491,7 +2494,16 @@
145 }
146 @Override
147 protected void done() {
148- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
149+ try {
150+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
151+ get();
152+ } catch (Exception e) {
153+ JOptionPane.showMessageDialog(GuiFrame.this,
154+ e.getMessage(),
155+ "Error loading file",
156+ JOptionPane.ERROR_MESSAGE);
157+ return;
158+ }
159 }
160 };
161 worker.execute();
162@@ -2554,7 +2566,7 @@
163 //Do loading of net
164 SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
165 @Override
166- protected Void doInBackground() throws InterruptedException {
167+ protected Void doInBackground() throws InterruptedException, Exception {
168 for(File f : files){
169 if(f.exists() && f.isFile() && f.canRead()){
170 FileBrowser.userPath = f.getParent();
171@@ -2565,7 +2577,16 @@
172 }
173 @Override
174 protected void done() {
175- CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
176+ try {
177+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
178+ get();
179+ } catch (Exception e) {
180+ JOptionPane.showMessageDialog(GuiFrame.this,
181+ e.getMessage(),
182+ "Error loading file",
183+ JOptionPane.ERROR_MESSAGE);
184+ return;
185+ }
186 }
187 };
188 worker.execute();
189@@ -2704,7 +2725,12 @@
190 GuiAction tmp = new GuiAction(netname, "Open example file \"" + netname + "\"") {
191 public void actionPerformed(ActionEvent arg0) {
192 InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/Example nets/" + filenameFinal);
193- createNewTabFromFile(file, netname);
194+ try {
195+ createNewTabFromFile(file, netname);
196+ } catch (Exception e) {
197+ // TODO Auto-generated catch block
198+ e.printStackTrace();
199+ }
200 }
201 };
202 tmp.putValue(Action.SMALL_ICON, new ImageIcon(Thread.currentThread()

Subscribers

People subscribed via source and target branches