- Timestamp:
- 2008-06-13T00:44:00+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/GettingStarted.java
r645 r652 26 26 public class GettingStarted extends JPanel { 27 27 28 29 static private String content = ""; 28 private JPanel panel; 29 static private String content = ""; 30 30 31 32 33 34 35 36 37 38 31 public class LinkGeneral extends JEditorPane implements HyperlinkListener { 32 private String action; 33 public LinkGeneral(String text) { 34 setContentType("text/html"); 35 setText(text); 36 setEditable(false); 37 setOpaque(false); 38 addHyperlinkListener(this); 39 39 } 40 41 42 43 40 public void hyperlinkUpdate(HyperlinkEvent e) { 41 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 42 OpenBrowser.displayUrl(e.getDescription()); 43 } 44 44 } 45 45 } 46 46 47 48 49 50 51 52 53 54 55 motdcontent = tr("<html>\n<h1>JOSM, the Java OpenStreetMap editor</h1>\n<h2>(Message of the day not available)</h2>"); 56 47 private void assignContent() { 48 if (content.length() == 0) { 49 String baseurl = Main.pref.get("help.baseurl", "http://josm.openstreetmap.de"); 50 WikiReader wr = new WikiReader(baseurl); 51 String motdcontent = ""; 52 try { 53 motdcontent = wr.read(baseurl + "/wiki/MessageOfTheDay"); 54 } catch (IOException ioe) { 55 motdcontent = tr("<html>\n<h1>JOSM, the Java OpenStreetMap editor</h1>\n<h2>(Message of the day not available)</h2>"); 56 } 57 57 58 59 60 61 62 63 58 int myVersion; 59 try { 60 myVersion = Integer.parseInt(AboutAction.getVersion()); 61 } catch (NumberFormatException e) { 62 myVersion = 0; 63 } 64 64 65 66 67 65 Pattern commentPattern = Pattern.compile("\\<p\\>\\s*\\/\\*[^\\*]*\\*\\/\\s*\\<\\/p\\>", Pattern.CASE_INSENSITIVE|Pattern.DOTALL|Pattern.MULTILINE); 66 Matcher matcherComment = commentPattern.matcher(motdcontent); 67 motdcontent = matcherComment.replaceAll(""); 68 68 69 /* look for hrefs of the form wiki/MessageOfTheDay>123 where > can also be <,<=,>= and the number is the revision number */ 70 int start = 0; 71 boolean nothingIncluded = true; 72 Pattern versionPattern = Pattern.compile("\\<a[^\\>]*href\\=\\\"([^\\\"]*\\/wiki\\/MessageOfTheDay(\\%3E%3D|%3C%3D|\\%3E|\\%3C)([0-9]+))\\\"[^\\>]*\\>[^\\<]*\\<\\/a\\>", Pattern.CASE_INSENSITIVE|Pattern.DOTALL|Pattern.MULTILINE); 73 Matcher matcher = versionPattern.matcher(motdcontent); 74 matcher.reset(); 75 while (matcher.find()) { 76 int targetVersion = Integer.parseInt(matcher.group(3)); 77 String condition = matcher.group(2); 78 boolean included = false; 79 if (condition.equals("%3E")) { 80 if ((myVersion == 0 || myVersion > targetVersion) && ! Main.pref.getBoolean("motd.gt."+targetVersion)) { 81 Main.pref.put("motd.gt."+targetVersion, true); 82 included = true; 83 } 84 } else if (condition.equals("%3E%3D")) { 85 if ((myVersion == 0 || myVersion >= targetVersion) && ! Main.pref.getBoolean("motd.ge."+targetVersion)) { 86 Main.pref.put("motd.ge."+targetVersion, true); 87 included = true; 88 } 89 } else if (condition.equals("%3C")) { 90 included = myVersion < targetVersion; 91 } else { 92 included = myVersion <= targetVersion; 93 } 94 if (matcher.start() > start) { 95 content += motdcontent.substring(start, matcher.start() - 1); 96 } 97 start = matcher.end(); 98 if (included) { 99 try { 100 content += wr.read(matcher.group(1)).replace("<html>", "").replace("</html>", "").replace("<div id=\"searchable\">", "").replace("</div>", ""); 101 nothingIncluded = false; 102 } catch (IOException ioe) { 103 // do nothing 104 } 105 } 106 } 107 if (nothingIncluded) { 108 content += "<div align=\"center\">Watch this space for announcements</div>"; 109 content += "<div align=\"center\" style=\"font-weight: normal\">(remove the \"motd\" entries in Advanced Preferences to see any available announcements next time)</div>"; 110 } 111 content += motdcontent.substring(start); 112 content = content.replace("<html>", "<html><style>\nbody { font-family: sans-serif; font-weight: bold; }\n</style>"); 113 content = content.replace("<h1", "<h1 align=\"center\""); 114 } 69 /* look for hrefs of the form wiki/MessageOfTheDay>123 where > can also be <,<=,>= and the number is the revision number */ 70 int start = 0; 71 boolean nothingIncluded = true; 72 Pattern versionPattern = Pattern.compile("\\<a[^\\>]*href\\=\\\"([^\\\"]*\\/wiki\\/)(MessageOfTheDay(\\%3E%3D|%3C%3D|\\%3E|\\%3C)([0-9]+))\\\"[^\\>]*\\>[^\\<]*\\<\\/a\\>", Pattern.CASE_INSENSITIVE|Pattern.DOTALL|Pattern.MULTILINE); 73 Matcher matcher = versionPattern.matcher(motdcontent); 74 matcher.reset(); 75 while (matcher.find()) { 76 int targetVersion = Integer.parseInt(matcher.group(4)); 77 String condition = matcher.group(3); 78 boolean included = false; 79 if (condition.equals("%3E")) { 80 if ((myVersion == 0 || myVersion > targetVersion) 81 /* && ! Main.pref.getBoolean("motd.gt."+targetVersion) */) { 82 /* Main.pref.put("motd.gt."+targetVersion, true); */ 83 included = true; 84 } 85 } else if (condition.equals("%3E%3D")) { 86 if ((myVersion == 0 || myVersion >= targetVersion) 87 /* && ! Main.pref.getBoolean("motd.ge."+targetVersion) */) { 88 /* Main.pref.put("motd.ge."+targetVersion, true); */ 89 included = true; 90 } 91 } else if (condition.equals("%3C")) { 92 included = myVersion < targetVersion; 93 } else { 94 included = myVersion <= targetVersion; 95 } 96 if (matcher.start() > start) { 97 content += motdcontent.substring(start, matcher.start() - 1); 98 } 99 start = matcher.end(); 100 if (included) { 101 // translators: set this to a suitable language code to 102 // be able to provide translations in the Wiki. 103 String languageCode = tr("En:"); 104 String url = matcher.group(1) + languageCode + matcher.group(2); 105 try { 106 content += wr.read(url).replace("<html>", "").replace("</html>", "").replace("<div id=\"searchable\">", "").replace("</div>", ""); 107 nothingIncluded = false; 108 } catch (IOException ioe) { 109 url = matcher.group(1) + matcher.group(2); 110 try { 111 content += wr.read(url).replace("<html>", "").replace("</html>", "").replace("<div id=\"searchable\">", "").replace("</div>", ""); 112 nothingIncluded = false; 113 } catch (IOException ioe2) { 114 } 115 } 116 } 117 } 118 if (nothingIncluded) { 119 content += "<div align=\"center\">Watch this space for announcements</div>"; 120 content += "<div align=\"center\" style=\"font-weight: normal\">(remove the \"motd\" entries in Advanced Preferences to see any available announcements next time)</div>"; 121 } 122 content += motdcontent.substring(start); 123 content = content.replace("<html>", "<html><style>\nbody { font-family: sans-serif; font-weight: bold; }\n</style>"); 124 content = content.replace("<h1", "<h1 align=\"center\""); 125 } 115 126 116 117 118 119 120 121 122 123 124 125 126 127 } 128 129 public GettingStarted() { 130 super(new BorderLayout()); 131 assignContent(); 132 133 // panel.add(GBC.glue(0,1), GBC.eol()); 134 //panel.setMinimumSize(new Dimension(400, 600)); 135 JScrollPane scroller = new JScrollPane(new LinkGeneral(content)); 136 scroller.setViewportBorder(new EmptyBorder(100,100,10,100)); 137 add(scroller, BorderLayout.CENTER); 127 138 } 128 139 }
Note:
See TracChangeset
for help on using the changeset viewer.