1 | package org.openstreetmap.josm.actions;
|
---|
2 |
|
---|
3 | import java.awt.Dimension;
|
---|
4 | import java.awt.Font;
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.io.BufferedReader;
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.io.InputStreamReader;
|
---|
11 | import java.net.URL;
|
---|
12 | import java.util.regex.Matcher;
|
---|
13 | import java.util.regex.Pattern;
|
---|
14 |
|
---|
15 | import javax.swing.AbstractAction;
|
---|
16 | import javax.swing.JEditorPane;
|
---|
17 | import javax.swing.JLabel;
|
---|
18 | import javax.swing.JOptionPane;
|
---|
19 | import javax.swing.JPanel;
|
---|
20 | import javax.swing.JScrollPane;
|
---|
21 | import javax.swing.JTabbedPane;
|
---|
22 | import javax.swing.JTextArea;
|
---|
23 | import javax.swing.event.HyperlinkEvent;
|
---|
24 | import javax.swing.event.HyperlinkListener;
|
---|
25 |
|
---|
26 | import org.openstreetmap.josm.gui.GBC;
|
---|
27 | import org.openstreetmap.josm.gui.ImageProvider;
|
---|
28 | import org.openstreetmap.josm.gui.Main;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Nice about screen. I guess every application need one these days.. *sigh*
|
---|
32 | *
|
---|
33 | * The REVISION resource is read and if present, it shows the revision
|
---|
34 | * information of the jar-file.
|
---|
35 | *
|
---|
36 | * @author imi
|
---|
37 | */
|
---|
38 | public class AboutAction extends AbstractAction {
|
---|
39 |
|
---|
40 | public AboutAction() {
|
---|
41 | super("About", ImageProvider.get("about"));
|
---|
42 | putValue(MNEMONIC_KEY, KeyEvent.VK_A);
|
---|
43 | putValue(SHORT_DESCRIPTION, "Display the about screen.");
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void actionPerformed(ActionEvent e) {
|
---|
47 | JTabbedPane about = new JTabbedPane();
|
---|
48 |
|
---|
49 | JTextArea readme = loadFile(Main.class.getResource("/README"));
|
---|
50 | JTextArea revision = loadFile(Main.class.getResource("/REVISION"));
|
---|
51 |
|
---|
52 | Pattern versionPattern = Pattern.compile(".*?Revision: ([0-9]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
|
---|
53 | Pattern timePattern = Pattern.compile(".*?Last Changed Date: ([^\n]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
|
---|
54 |
|
---|
55 | Matcher match = versionPattern.matcher(revision.getText());
|
---|
56 | String version = match.matches() ? match.group(1) : "UNKNOWN";
|
---|
57 | match = timePattern.matcher(revision.getText());
|
---|
58 | String time = match.matches() ? match.group(1) : "UNKNOWN";
|
---|
59 |
|
---|
60 | JPanel info = new JPanel(new GridBagLayout());
|
---|
61 | info.add(new JLabel("Java OpenStreetMap Editor Version "+version), GBC.eop());
|
---|
62 | info.add(new JLabel("last change at "+time), GBC.eop());
|
---|
63 | info.add(new JLabel("Homepage"), GBC.std().insets(0,0,10,0));
|
---|
64 | JEditorPane homepage = new JEditorPane();
|
---|
65 | homepage.setContentType("text/html");
|
---|
66 | homepage.setText("<html><a href=\"http://wiki.eigenheimstrasse.de/wiki/JOSM\">" +
|
---|
67 | "http://wiki.eigenheimstrasse.de/wiki/JOSM</a></html>");
|
---|
68 | homepage.setEditable(false);
|
---|
69 | homepage.setOpaque(false);
|
---|
70 | homepage.addHyperlinkListener(new HyperlinkListener(){
|
---|
71 | public void hyperlinkUpdate(HyperlinkEvent e) {
|
---|
72 | if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
---|
73 | //TODO: Open browser
|
---|
74 | }
|
---|
75 | }
|
---|
76 | });
|
---|
77 | info.add(homepage, GBC.eol());
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | about.addTab("Info", info);
|
---|
82 | about.addTab("Readme", new JScrollPane(readme));
|
---|
83 | about.addTab("Revision", new JScrollPane(revision));
|
---|
84 |
|
---|
85 | about.setPreferredSize(new Dimension(500,300));
|
---|
86 |
|
---|
87 | JOptionPane.showMessageDialog(Main.main, about, "About JOSM...",
|
---|
88 | JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo"));
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Load the specified ressource into an TextArea and return it.
|
---|
93 | * @param resource The resource url to load
|
---|
94 | * @return An read-only text area with the content of "resource"
|
---|
95 | */
|
---|
96 | private JTextArea loadFile(URL resource) {
|
---|
97 | JTextArea area = new JTextArea("File could not be found.");
|
---|
98 | area.setEditable(false);
|
---|
99 | Font font = Font.getFont("monospaced");
|
---|
100 | if (font != null)
|
---|
101 | area.setFont(font);
|
---|
102 | if (resource == null)
|
---|
103 | return area;
|
---|
104 | BufferedReader in;
|
---|
105 | try {
|
---|
106 | in = new BufferedReader(new InputStreamReader(resource.openStream()));
|
---|
107 | StringBuilder sb = new StringBuilder();
|
---|
108 | for (String line = in.readLine(); line != null; line = in.readLine()) {
|
---|
109 | sb.append(line);
|
---|
110 | sb.append('\n');
|
---|
111 | }
|
---|
112 | area.setText(sb.toString());
|
---|
113 | area.setCaretPosition(0);
|
---|
114 | } catch (IOException e) {
|
---|
115 | e.printStackTrace();
|
---|
116 | }
|
---|
117 | return area;
|
---|
118 | }
|
---|
119 | }
|
---|