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

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