Merge lp:~tapaal-contributor/tapaal/loading-of-large-nets-1848945 into lp:tapaal

Proposed by Peter Haahr Taankvist
Status: Merged
Approved by: Jiri Srba
Approved revision: 1037
Merged at revision: 1030
Proposed branch: lp:~tapaal-contributor/tapaal/loading-of-large-nets-1848945
Merge into: lp:tapaal
Diff against target: 133 lines (+77/-15)
1 file modified
src/pipe/gui/GuiFrame.java (+77/-15)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/loading-of-large-nets-1848945
Reviewer Review Type Date Requested Status
Kenneth Yrke Jørgensen Approve
Jiri Srba Approve
Review via email: mp+375641@code.launchpad.net

Commit message

Now uses swingworkers when opening nets via ctrl + O (tapn) and ctrl + X (pnml). Shows loading dialog that will remain until the net is fully loaded and tapaal is available for interaction.

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

Looks good but is unacceptably slow. I tried loading discovery_10_a PNML model
and it took 37 seconds to load in this branch, compared to 2 seconds that it takes in 3.6.0.
The speed has to be improved, otherwise we cannot merge it to trunk.

review: Needs Fixing
1032. By Peter Taankvist <email address hidden>

it is very fast now. EDT is slept until we are ready to draw. Still some problems with loading dialog

1033. By Peter Taankvist <email address hidden>

Don't show loading dialog and only sleep EDT

1034. By Peter Taankvist <email address hidden>

Show loading cursor

1035. By Peter Taankvist <email address hidden>

Delete debug line

1036. By Peter Taankvist <email address hidden>

Cleanup

1037. By Peter Taankvist <email address hidden>

Threaded FILE ENDING CHANGED message such that it does not block the EDT

Revision history for this message
Jiri Srba (srba) wrote :

Tested and it works about twice as fast compared to 3.6.0.

review: Approve
Revision history for this message
Kenneth Yrke Jørgensen (yrke) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pipe/gui/GuiFrame.java'
2--- src/pipe/gui/GuiFrame.java 2019-11-01 10:48:48 +0000
3+++ src/pipe/gui/GuiFrame.java 2019-11-23 11:48:50 +0000
4@@ -12,8 +12,12 @@
5 import java.io.*;
6 import java.math.BigDecimal;
7 import java.net.*;
8+import java.time.LocalTime;
9+import java.time.temporal.ChronoUnit;
10 import java.util.*;
11 import java.util.List;
12+import java.util.Timer;
13+import java.util.concurrent.ExecutionException;
14 import java.util.jar.JarEntry;
15 import java.util.jar.JarFile;
16 import javax.imageio.ImageIO;
17@@ -165,7 +169,7 @@
18 private GuiAction showReportBugAction;
19 private GuiAction showFAQAction;
20 private GuiAction checkUpdate;
21-
22+
23
24 private GuiAction selectAllAction;
25
26@@ -2470,13 +2474,38 @@
27
28 fileMenu.add(openAction = new GuiAction("Open", "Open", KeyStroke.getKeyStroke('O', shortcutkey )) {
29 public void actionPerformed(ActionEvent arg0) {
30- File[] files = FileBrowser.constructor("Timed-Arc Petri Net","tapn", "xml", FileBrowser.userPath).openFiles();
31- for (File f : files) {
32- if (f.exists() && f.isFile() && f.canRead()) {
33- FileBrowser.userPath = f.getParent();
34- createNewTabFromFile(f);
35+ final File[] files = FileBrowser.constructor("Timed-Arc Petri Net","tapn", "xml", FileBrowser.userPath).openFiles();
36+ //show loading cursor
37+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
38+ //Do loading
39+ SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
40+ @Override
41+ protected Void doInBackground() throws InterruptedException {
42+ for(File f : files){
43+ if(f.exists() && f.isFile() && f.canRead()){
44+ FileBrowser.userPath = f.getParent();
45+ createNewTabFromFile(f);
46+ }
47+ }
48+ return null;
49+ }
50+ @Override
51+ protected void done() {
52+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
53+ }
54+ };
55+ worker.execute();
56+
57+ //Sleep redrawing thread (EDT) until worker is done
58+ //This enables the EDT to schedule the many redraws called in createNewTabFromPNMLFile(f); much better
59+ while(!worker.isDone()) {
60+ try {
61+ Thread.sleep(1000);
62+ } catch (InterruptedException e) {
63+ // TODO Auto-generated catch block
64+ e.printStackTrace();
65 }
66- }
67+ }
68 }
69 });
70
71@@ -2518,13 +2547,39 @@
72
73 importMenu.add(importPNMLAction = new GuiAction("PNML untimed net", "Import an untimed net in the PNML format", KeyStroke.getKeyStroke('X', shortcutkey)) {
74 public void actionPerformed(ActionEvent arg0) {
75- File[] files = FileBrowser.constructor("Import PNML", "pnml", FileBrowser.userPath).openFiles();
76- for(File f : files){
77- if(f.exists() && f.isFile() && f.canRead()){
78- FileBrowser.userPath = f.getParent();
79- createNewTabFromPNMLFile(f);
80+ final File[] files = FileBrowser.constructor("Import PNML", "pnml", FileBrowser.userPath).openFiles();
81+
82+ //Show loading cursor
83+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
84+ //Do loading of net
85+ SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
86+ @Override
87+ protected Void doInBackground() throws InterruptedException {
88+ for(File f : files){
89+ if(f.exists() && f.isFile() && f.canRead()){
90+ FileBrowser.userPath = f.getParent();
91+ createNewTabFromPNMLFile(f);
92+ }
93+ }
94+ return null;
95+ }
96+ @Override
97+ protected void done() {
98+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
99+ }
100+ };
101+ worker.execute();
102+
103+ //Sleep redrawing thread (EDT) until worker is done
104+ //This enables the EDT to schedule the many redraws called in createNewTabFromPNMLFile(f); much better
105+ while(!worker.isDone()) {
106+ try {
107+ Thread.sleep(1000);
108+ } catch (InterruptedException e) {
109+ // TODO Auto-generated catch block
110+ e.printStackTrace();
111 }
112- }
113+ }
114 }
115 });
116
117@@ -2860,8 +2915,15 @@
118 public int getSelectedTabIndex() { return appTab.getSelectedIndex(); };
119 public void showFileEndingChangedMessage(boolean showMessage) {
120 if(showMessage) {
121- 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"
122- + "Once you save the .tapn model, we recommend that you manually delete the .xml file.", "FILE CHANGED");
123+ //We thread this so it does not block the EDT
124+ new Thread(new Runnable() {
125+ @Override
126+ public void run() {
127+ CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
128+ 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"
129+ + "Once you save the .tapn model, we recommend that you manually delete the .xml file.", "FILE CHANGED");
130+ }
131+ }).start();
132 }
133 }
134

Subscribers

People subscribed via source and target branches