source: josm/trunk/src/org/openstreetmap/josm/actions/AboutAction.java@ 1755

Last change on this file since 1755 was 1755, checked in by stoecker, 15 years ago

fixed build error due to slippy map change, i18n update, added pt_BR

  • Property svn:eol-style set to native
File size: 8.3 KB
Line 
1//License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.Font;
8import java.awt.GridBagLayout;
9import java.awt.event.ActionEvent;
10import java.awt.event.KeyEvent;
11import java.io.BufferedReader;
12import java.io.IOException;
13import java.io.InputStream;
14import java.io.InputStreamReader;
15import java.net.MalformedURLException;
16import java.net.URL;
17import java.util.regex.Matcher;
18import java.util.regex.Pattern;
19import java.util.Properties;
20
21import javax.swing.BorderFactory;
22import javax.swing.JLabel;
23import javax.swing.JOptionPane;
24import javax.swing.JPanel;
25import javax.swing.JScrollPane;
26import javax.swing.JTabbedPane;
27import javax.swing.JTextArea;
28
29import org.openstreetmap.josm.Main;
30import org.openstreetmap.josm.plugins.PluginHandler;
31import org.openstreetmap.josm.tools.GBC;
32import org.openstreetmap.josm.tools.ImageProvider;
33import org.openstreetmap.josm.tools.LanguageInfo;
34import org.openstreetmap.josm.tools.UrlLabel;
35import org.openstreetmap.josm.tools.Shortcut;
36
37/**
38 * Nice about screen. I guess every application need one these days.. *sigh*
39 *
40 * The REVISION resource is read and if present, it shows the revision
41 * information of the jar-file.
42 *
43 * @author imi
44 */
45/**
46 * @author Stephan
47 *
48 */
49public class AboutAction extends JosmAction {
50
51 private static final String version;
52
53 private final static JTextArea revision;
54 private static String time;
55
56 static {
57 boolean manifest = false;
58 URL u = Main.class.getResource("/REVISION");
59 if(u == null) {
60 try {
61 manifest = true;
62 u = new URL("jar:" + Main.class.getProtectionDomain().getCodeSource().getLocation().toString()
63 + "!/META-INF/MANIFEST.MF");
64 } catch (MalformedURLException e) {
65 e.printStackTrace();
66 }
67 }
68 revision = loadFile(u, manifest);
69
70 Pattern versionPattern = Pattern.compile(".*?(?:Revision|Main-Version): ([0-9]*(?: SVN)?).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
71 Matcher match = versionPattern.matcher(revision.getText());
72 version = match.matches() ? match.group(1) : tr("UNKNOWN");
73
74 Pattern timePattern = Pattern.compile(".*?(?:Last Changed Date|Main-Date): ([^\n]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
75 match = timePattern.matcher(revision.getText());
76 time = match.matches() ? match.group(1) : tr("UNKNOWN");
77 }
78
79 /**
80 * Return string describing version.
81 * Note that the strinc contains the version number plus an optional suffix of " SVN" to indicate an unofficial development build.
82 * @return version string
83 */
84 static public String getVersionString() {
85 return version;
86 }
87
88 static public String getTextBlock() {
89 return revision.getText();
90 }
91
92 static public void setUserAgent() {
93 Properties sysProp = System.getProperties();
94 sysProp.put("http.agent", "JOSM/1.5 ("+(version.equals(tr("UNKNOWN"))?"UNKNOWN":version)+" "+LanguageInfo.getLanguageCode()+")");
95 System.setProperties(sysProp);
96 }
97
98 /**
99 * Return the number part of the version string.
100 * @return integer part of version number or Integer.MAX_VALUE if not available
101 */
102 public static int getVersionNumber() {
103 int myVersion=Integer.MAX_VALUE;
104 try {
105 myVersion = Integer.parseInt(version.split(" ")[0]);
106 } catch (NumberFormatException e) {
107 // e.printStackTrace();
108 }
109 return myVersion;
110 }
111
112 /**
113 * check whether the version is a development build out of SVN.
114 * @return true if it is a SVN unofficial build
115 */
116 public static boolean isDevelopmentVersion() {
117 return version.endsWith(" SVN") || version.equals(tr("UNKNOWN"));
118 }
119
120 public AboutAction() {
121 super(tr("About"), "about", tr("Display the about screen."), Shortcut.registerShortcut("system:about", tr("About"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT), true);
122 }
123
124 public void actionPerformed(ActionEvent e) {
125 JTabbedPane about = new JTabbedPane();
126
127 JTextArea readme = loadFile(Main.class.getResource("/README"), false);
128 JTextArea contribution = loadFile(Main.class.getResource("/CONTRIBUTION"), false);
129
130 JPanel info = new JPanel(new GridBagLayout());
131 JLabel caption = new JLabel("JOSM - " + tr("Java OpenStreetMap Editor"));
132 caption.setFont(new Font("Helvetica", Font.BOLD, 20));
133 info.add(caption, GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
134 info.add(GBC.glue(0,10), GBC.eol());
135 info.add(new JLabel(tr("Version {0}",version)), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
136 info.add(GBC.glue(0,5), GBC.eol());
137 info.add(new JLabel(tr("Last change at {0}",time)), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
138 info.add(GBC.glue(0,5), GBC.eol());
139 info.add(new JLabel(tr("Java Version {0}",System.getProperty("java.version"))), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
140 info.add(GBC.glue(0,10), GBC.eol());
141 info.add(new JLabel(tr("Homepage")), GBC.std().insets(10,0,10,0));
142 info.add(new UrlLabel("http://josm.openstreetmap.de"), GBC.eol().fill(GBC.HORIZONTAL));
143 info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10,0,10,0));
144 info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol().fill(GBC.HORIZONTAL));
145
146 about.addTab(tr("Info"), info);
147 about.addTab(tr("Readme"), createScrollPane(readme));
148 about.addTab(tr("Revision"), createScrollPane(revision));
149 about.addTab(tr("Contribution"), createScrollPane(contribution));
150 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
151
152 about.setPreferredSize(new Dimension(500,300));
153
154 JOptionPane.showMessageDialog(Main.parent, about, tr("About JOSM..."),
155 JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo"));
156 }
157
158 private JScrollPane createScrollPane(JTextArea area) {
159 area.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
160 area.setOpaque(false);
161 JScrollPane sp = new JScrollPane(area);
162 sp.setBorder(null);
163 sp.setOpaque(false);
164 return sp;
165 }
166
167 /**
168 * Retrieve the latest JOSM version from the JOSM homepage.
169 * @return An string with the latest version or "UNKNOWN" in case
170 * of problems (e.g. no internet connection).
171 */
172 public static String checkLatestVersion() {
173 String latest;
174 try {
175 InputStream s = new URL("http://josm.openstreetmap.de/current").openStream();
176 latest = new BufferedReader(new InputStreamReader(s)).readLine();
177 s.close();
178 } catch (IOException x) {
179 x.printStackTrace();
180 return tr("UNKNOWN");
181 }
182 return latest;
183 }
184
185 /**
186 * Load the specified resource into an TextArea and return it.
187 * @param resource The resource url to load
188 * @return An read-only text area with the content of "resource"
189 */
190 private static JTextArea loadFile(URL resource, boolean manifest) {
191 JTextArea area = new JTextArea(tr("File could not be found."));
192 area.setEditable(false);
193 Font font = Font.getFont("monospaced");
194 if (font != null)
195 area.setFont(font);
196 if (resource == null)
197 return area;
198 BufferedReader in;
199 try {
200 in = new BufferedReader(new InputStreamReader(resource.openStream()));
201 String s = "";
202 for (String line = in.readLine(); line != null; line = in.readLine())
203 s += line + "\n";
204 if (manifest) {
205 s = Pattern.compile("\n ", Pattern.DOTALL).matcher(s).replaceAll("");
206 s = Pattern.compile("^(SHA1-Digest|Name): .*?$", Pattern.DOTALL|Pattern.MULTILINE).matcher(s).replaceAll("");
207 s = Pattern.compile("\n+$", Pattern.DOTALL).matcher(s).replaceAll("");
208 }
209 area.setText(s);
210 area.setCaretPosition(0);
211 } catch (IOException e) {
212 System.err.println("Cannot load resource " + resource + ": " + e.getMessage());
213 //e.printStackTrace();
214 }
215 return area;
216 }
217}
Note: See TracBrowser for help on using the repository browser.