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

Last change on this file since 655 was 655, checked in by ramack, 16 years ago

patch by bruce89, closes #812; thanks bruce

  • Property svn:eol-style set to native
File size: 6.4 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.URL;
16import java.util.Map.Entry;
17import java.util.regex.Matcher;
18import java.util.regex.Pattern;
19
20import javax.swing.AbstractAction;
21import javax.swing.BorderFactory;
22import javax.swing.Box;
23import javax.swing.JButton;
24import javax.swing.JLabel;
25import javax.swing.JOptionPane;
26import javax.swing.JPanel;
27import javax.swing.JScrollPane;
28import javax.swing.JTabbedPane;
29import javax.swing.JTextArea;
30
31import org.openstreetmap.josm.Main;
32import org.openstreetmap.josm.plugins.PluginProxy;
33import org.openstreetmap.josm.tools.GBC;
34import org.openstreetmap.josm.tools.ImageProvider;
35import org.openstreetmap.josm.tools.UrlLabel;
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 */
45public class AboutAction extends JosmAction {
46
47 public static final String version;
48
49 private final static JTextArea revision;
50 private static String time;
51
52 static {
53 revision = loadFile(Main.class.getResource("/REVISION"));
54
55 Pattern versionPattern = Pattern.compile(".*?Revision: ([0-9]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
56 Matcher match = versionPattern.matcher(revision.getText());
57 version = match.matches() ? match.group(1) : "UNKNOWN";
58
59 Pattern timePattern = Pattern.compile(".*?Last Changed Date: ([^\n]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
60 match = timePattern.matcher(revision.getText());
61 time = match.matches() ? match.group(1) : "UNKNOWN";
62 }
63
64 static public String getVersion() {
65 return version;
66 }
67
68 public AboutAction() {
69 super(tr("About"), "about",tr("Display the about screen."), KeyEvent.VK_F1, KeyEvent.SHIFT_DOWN_MASK, true);
70 }
71
72 public void actionPerformed(ActionEvent e) {
73 JTabbedPane about = new JTabbedPane();
74
75 JTextArea readme = loadFile(Main.class.getResource("/README"));
76 JTextArea contribution = loadFile(Main.class.getResource("/CONTRIBUTION"));
77
78 JPanel info = new JPanel(new GridBagLayout());
79 info.add(new JLabel(tr("Java OpenStreetMap Editor Version {0}",version)), GBC.eol().fill(GBC.HORIZONTAL));
80 info.add(new JLabel(tr("last change at {0}",time)), GBC.eol().fill(GBC.HORIZONTAL));
81 info.add(new JLabel(tr("Java Version {0}",System.getProperty("java.version"))), GBC.eol().fill(GBC.HORIZONTAL));
82 info.add(GBC.glue(0,10), GBC.eol());
83 info.add(new JLabel(tr("Homepage")), GBC.std().insets(0,0,10,0));
84 info.add(new UrlLabel("http://josm.openstreetmap.de"), GBC.eol().fill(GBC.HORIZONTAL));
85 info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(0,0,10,0));
86 info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol().fill(GBC.HORIZONTAL));
87 info.add(new JLabel(tr("News about JOSM")), GBC.std().insets(0,0,10,0));
88 info.add(new UrlLabel("http://www.opengeodata.org/?cat=17"), GBC.eol().fill(GBC.HORIZONTAL));
89
90 about.addTab(tr("Info"), info);
91 about.addTab(tr("Readme"), createScrollPane(readme));
92 about.addTab(tr("Revision"), createScrollPane(revision));
93 about.addTab(tr("Contribution"), createScrollPane(contribution));
94
95 JPanel pluginTab = new JPanel(new GridBagLayout());
96 for (final PluginProxy p : Main.plugins) {
97 String name = p.info.name + (p.info.version != null && !p.info.version.equals("") ? " Version: "+p.info.version : "");
98 pluginTab.add(new JLabel(name), GBC.std());
99 pluginTab.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
100 pluginTab.add(new JButton(new AbstractAction(tr("Information")){
101 public void actionPerformed(ActionEvent event) {
102 StringBuilder b = new StringBuilder();
103 for (Entry<String,String> e : p.info.attr.entrySet()) {
104 b.append(e.getKey());
105 b.append(": ");
106 b.append(e.getValue());
107 b.append("\n");
108 }
109 JTextArea a = new JTextArea(10,40);
110 a.setEditable(false);
111 a.setText(b.toString());
112 JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a));
113 }
114 }), GBC.eol());
115 JLabel label = new JLabel("<html><i>"+(p.info.description==null?tr("no description available"):p.info.description)+"</i></html>");
116 label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0));
117 label.setMaximumSize(new Dimension(450,1000));
118 pluginTab.add(label, GBC.eop().fill(GBC.HORIZONTAL));
119 }
120 about.addTab(tr("Plugins"), new JScrollPane(pluginTab));
121
122 about.setPreferredSize(new Dimension(500,300));
123
124 JOptionPane.showMessageDialog(Main.parent, about, tr("About JOSM..."),
125 JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo"));
126 }
127
128 private JScrollPane createScrollPane(JTextArea area) {
129 area.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
130 area.setOpaque(false);
131 JScrollPane sp = new JScrollPane(area);
132 sp.setBorder(null);
133 sp.setOpaque(false);
134 return sp;
135 }
136
137 /**
138 * Retrieve the latest JOSM version from the JOSM homepage.
139 * @return An string with the latest version or "UNKNOWN" in case
140 * of problems (e.g. no internet connection).
141 */
142 public static String checkLatestVersion() {
143 String latest;
144 try {
145 InputStream s = new URL("http://josm.openstreetmap.de/current").openStream();
146 latest = new BufferedReader(new InputStreamReader(s)).readLine();
147 s.close();
148 } catch (IOException x) {
149 x.printStackTrace();
150 return "UNKNOWN";
151 }
152 return latest;
153 }
154
155 /**
156 * Load the specified resource into an TextArea and return it.
157 * @param resource The resource url to load
158 * @return An read-only text area with the content of "resource"
159 */
160 private static JTextArea loadFile(URL resource) {
161 JTextArea area = new JTextArea(tr("File could not be found."));
162 area.setEditable(false);
163 Font font = Font.getFont("monospaced");
164 if (font != null)
165 area.setFont(font);
166 if (resource == null)
167 return area;
168 BufferedReader in;
169 try {
170 in = new BufferedReader(new InputStreamReader(resource.openStream()));
171 StringBuilder sb = new StringBuilder();
172 for (String line = in.readLine(); line != null; line = in.readLine()) {
173 sb.append(line);
174 sb.append('\n');
175 }
176 area.setText(sb.toString());
177 area.setCaretPosition(0);
178 } catch (IOException e) {
179 e.printStackTrace();
180 }
181 return area;
182 }
183}
Note: See TracBrowser for help on using the repository browser.