Changeset 1350 in josm
- Timestamp:
- 2009-01-31T14:39:28+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/GettingStarted.java
r1290 r1350 7 7 import java.io.IOException; 8 8 import java.util.ArrayList; 9 import java.util.concurrent.Executors; 10 import java.util.concurrent.ExecutorService; 11 import java.util.concurrent.Callable; 12 import java.util.concurrent.Future; 9 13 import java.util.regex.Matcher; 10 14 import java.util.regex.Pattern; … … 12 16 import java.awt.BorderLayout; 13 17 import java.awt.Component; 18 import java.awt.EventQueue; 14 19 15 20 import javax.swing.JScrollPane; … … 41 46 OpenBrowser.displayUrl(e.getDescription()); 42 47 } 48 } 49 } 50 51 public class readMOTD implements Callable<String> { 52 private boolean isLocalized; 53 private boolean isHelp; 54 private String urlLoc; 55 private String urlIntl; 56 private String urlBase; 57 58 readMOTD(boolean isLocalized, String urlBase, String urlLoc, String urlIntl, boolean isHelp) { 59 this.isLocalized = isLocalized; 60 this.urlBase = urlBase; 61 this.urlLoc = urlLoc; 62 this.urlIntl = urlIntl; 63 this.isHelp = isHelp; 64 } 65 66 public String call() { 67 WikiReader wr = new WikiReader(urlBase); 68 String content = ""; 69 try { 70 // If we hit a non-localized link here, we already know there's no translated version available 71 String message = isLocalized ? wr.read(urlLoc) : ""; 72 // Look for non-localized version 73 if (message.equals("")) 74 message = wr.read(urlIntl); 75 76 if (!message.equals("")) 77 if(isHelp) 78 content += message; 79 else 80 content += "<ul><li>"+ message.substring(8)+"</li></ul>"; 81 } catch (IOException ioe) { 82 try { 83 if(isHelp) 84 content += wr.read(urlIntl); 85 else 86 content += "<ul><li>"+wr.read(urlIntl).substring(8)+"</li></ul>"; 87 } catch (IOException ioe2) { 88 } 89 } 90 91 return content; 43 92 } 44 93 } … … 72 121 matcher.reset(); 73 122 74 ArrayList< Object> links = new ArrayList<Object>();123 ArrayList<String[]> links = new ArrayList<String[]>(); 75 124 String linksList=""; 76 125 while (matcher.find()) { … … 82 131 linksList += matcher.group(1)+matcher.group(2)+matcher.group(3)+": "; 83 132 } 84 133 134 // We cannot use Main.worker here because it's single-threaded and 135 // setting it to multi-threading will cause problems elsewhere 136 ExecutorService slave = Executors.newCachedThreadPool(); 137 138 ArrayList<Future<String>> linkContent = new ArrayList<Future<String>>(); 85 139 for(int i=0; i < links.size(); i++) { 86 140 String[] obj = (String[])links.get(i); … … 90 144 91 145 // Prefer localized over non-localized links, if they're otherwise the same 92 if(!isLocalized && linksList.indexOf(condition +obj[1]+languageCode+" ") >= 0)146 if(!isLocalized && linksList.indexOf(condition + obj[1] + languageCode + " ") >= 0) 93 147 continue; 94 148 … … 107 161 108 162 if(!included) continue; 109 110 Boolean isHelp = targetVersion == 1; 111 163 164 boolean isHelp = targetVersion == 1; 112 165 String urlStart = baseurl + "/wiki/"; 113 166 String urlEnd = "MessageOfTheDay" + condition + targetVersion + (isHelp ? "" : "?format=txt"); 114 167 String urlLoc = urlStart + languageCode + urlEnd; 168 String urlIntl = urlStart + urlEnd; 169 170 // This adds all links to the worker which will download them concurrently 171 linkContent.add(slave.submit(new readMOTD(isLocalized, baseurl, urlLoc, urlIntl, isHelp))); 172 } 173 174 for(int i=0; i < linkContent.size(); i++) { 115 175 try { 116 // If we hit a non-localized link here, we already know there's no translated version available 117 String message = isLocalized ? wr.read(urlStart + languageCode + urlEnd) : ""; 118 // Look for non-localized version 119 if (message.equals("")) 120 message = wr.read(urlStart + urlEnd); 121 122 if (!message.equals("")) 123 if(isHelp) 124 content += message; 125 else 126 content += "<ul><li>"+ message.substring(8)+"</li></ul>"; 127 } catch (IOException ioe) { 128 try { 129 if(isHelp) 130 content += wr.read(urlStart + urlEnd); 131 else 132 content += "<ul><li>"+wr.read(urlStart + urlEnd).substring(8)+"</li></ul>"; 133 } catch (IOException ioe2) { 134 } 135 } 136 } 137 176 content += linkContent.get(i).get(); 177 } catch (Exception e) {} 178 } 179 138 180 content = "<html>\n"+ 139 181 "<style type=\"text/css\">\n"+ … … 148 190 public GettingStarted() { 149 191 super(new BorderLayout()); 150 assignContent();151 192 final LinkGeneral lg = new LinkGeneral(tr("Download \"Message of the day\"")); 193 JScrollPane scroller = new JScrollPane(lg); 152 194 // panel.add(GBC.glue(0,1), GBC.eol()); 153 195 //panel.setMinimumSize(new Dimension(400, 600)); 154 196 Component linkGeneral = new LinkGeneral(content); 155 JScrollPane scroller = new JScrollPane(linkGeneral);156 197 scroller.setViewportBorder(new EmptyBorder(10,100,10,100)); 157 198 add(scroller, BorderLayout.CENTER); 158 199 200 // Asynchronously get MOTD to speed-up JOSM startup 201 Thread t = new Thread(new Runnable() { 202 public void run() { 203 assignContent(); 204 EventQueue.invokeLater(new Runnable() { 205 public void run() { 206 lg.setText(content); 207 lg.moveCaretPosition(0); 208 } 209 }); 210 } 211 }, "MOTD-Loader"); 212 t.setDaemon(true); 213 t.start(); 214 159 215 new FileDrop(linkGeneral); 160 216 } -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r1258 r1350 22 22 import java.awt.event.MouseEvent; 23 23 import java.awt.event.MouseMotionListener; 24 import java.awt.event.MouseListener; 24 25 import java.lang.reflect.InvocationTargetException; 25 26 import java.text.DecimalFormat; … … 345 346 return "Statusline"; 346 347 } 348 349 @Override 350 public void addMouseListener(MouseListener ml) { 351 //super.addMouseListener(ml); 352 lonText.addMouseListener(ml); 353 latText.addMouseListener(ml); 354 } 347 355 348 356 public void setHelpText(String t) { … … 360 368 distText.setText(dist < 0 ? "--" : text); 361 369 } 362 363 370 }
Note:
See TracChangeset
for help on using the changeset viewer.