[josm-dev] [PATCH v2] Make start-up feel faster by asynchronously loading the MOTD.
Michel Marti
mcdmx at users.sf.net
Mon Nov 17 23:00:39 GMT 2008
Since loading and parsing the MOTD from the wiki now takes place
in a separate thread, the main GUI will be ready for action (much)
earlier (especially on slow network links).
Signed-off-by: Michel Marti <mcdmx at users.sf.net>
---
Just outed myself as a total Swing amateur... Delegating the actual
update of the Swing component to the event-dispatch-thread (using
EventQueue.invokeLater() should be fine then?
src/org/openstreetmap/josm/gui/GettingStarted.java | 22 +++++++++++++++++--
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/org/openstreetmap/josm/gui/GettingStarted.java b/src/org/openstreetmap/josm/gui/GettingStarted.java
index 7174aeb..8697955 100644
--- a/src/org/openstreetmap/josm/gui/GettingStarted.java
+++ b/src/org/openstreetmap/josm/gui/GettingStarted.java
@@ -9,6 +9,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.BorderLayout;
+import java.awt.EventQueue;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;
@@ -134,12 +135,27 @@ public class GettingStarted extends JPanel {
public GettingStarted() {
super(new BorderLayout());
- assignContent();
-
+ final LinkGeneral lg = new LinkGeneral(tr("Loading MOTD..."));
+ JScrollPane scroller = new JScrollPane(lg);
// panel.add(GBC.glue(0,1), GBC.eol());
//panel.setMinimumSize(new Dimension(400, 600));
- JScrollPane scroller = new JScrollPane(new LinkGeneral(content));
scroller.setViewportBorder(new EmptyBorder(10,100,10,100));
add(scroller, BorderLayout.CENTER);
+
+ // Asynchronously get MOTD to speed-up JOSM startup
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ assignContent();
+ EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ lg.setText(content);
+ lg.moveCaretPosition(0);
+ }
+ });
+ }
+ }, "MOTD-Loader");
+ t.setDaemon(true);
+ t.start();
+
}
}
--
1.5.6.5
More information about the josm-dev
mailing list