1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.Dimension;
|
---|
8 | import java.awt.GridBagLayout;
|
---|
9 | import java.awt.Image;
|
---|
10 | import java.awt.event.ActionEvent;
|
---|
11 | import java.awt.event.KeyEvent;
|
---|
12 | import java.io.BufferedReader;
|
---|
13 | import java.io.IOException;
|
---|
14 | import java.io.InputStream;
|
---|
15 | import java.io.InputStreamReader;
|
---|
16 |
|
---|
17 | import javax.swing.BorderFactory;
|
---|
18 | import javax.swing.ImageIcon;
|
---|
19 | import javax.swing.JLabel;
|
---|
20 | import javax.swing.JOptionPane;
|
---|
21 | import javax.swing.JPanel;
|
---|
22 | import javax.swing.JScrollPane;
|
---|
23 | import javax.swing.JTabbedPane;
|
---|
24 | import javax.swing.JTextArea;
|
---|
25 |
|
---|
26 | import org.openstreetmap.josm.Main;
|
---|
27 | import org.openstreetmap.josm.data.Version;
|
---|
28 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
29 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
30 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
31 | import org.openstreetmap.josm.gui.widgets.UrlLabel;
|
---|
32 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
33 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
34 | import org.openstreetmap.josm.tools.GBC;
|
---|
35 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
36 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
37 | import org.openstreetmap.josm.tools.Utils;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Nice about screen.
|
---|
41 | *
|
---|
42 | * The REVISION resource is read and if present, it shows the revision information of the jar-file.
|
---|
43 | *
|
---|
44 | * @author imi
|
---|
45 | */
|
---|
46 | public class AboutAction extends JosmAction {
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Constructs a new {@code AboutAction}.
|
---|
50 | */
|
---|
51 | public AboutAction() {
|
---|
52 | super(tr("About"), "logo", tr("Display the about screen."),
|
---|
53 | Shortcut.registerShortcut("system:about", tr("About"),
|
---|
54 | KeyEvent.VK_F1, Shortcut.SHIFT), true);
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void actionPerformed(ActionEvent e) {
|
---|
59 | final JTabbedPane about = new JTabbedPane();
|
---|
60 |
|
---|
61 | Version version = Version.getInstance();
|
---|
62 |
|
---|
63 | JosmTextArea readme = new JosmTextArea();
|
---|
64 | readme.setEditable(false);
|
---|
65 | setTextFromResourceFile(readme, "/README");
|
---|
66 | readme.setCaretPosition(0);
|
---|
67 |
|
---|
68 | JosmTextArea revision = new JosmTextArea();
|
---|
69 | revision.setEditable(false);
|
---|
70 | revision.setText(version.getReleaseAttributes());
|
---|
71 | revision.setCaretPosition(0);
|
---|
72 |
|
---|
73 | JosmTextArea contribution = new JosmTextArea();
|
---|
74 | contribution.setEditable(false);
|
---|
75 | setTextFromResourceFile(contribution, "/CONTRIBUTION");
|
---|
76 | contribution.setCaretPosition(0);
|
---|
77 |
|
---|
78 | JosmTextArea license = new JosmTextArea();
|
---|
79 | license.setEditable(false);
|
---|
80 | setTextFromResourceFile(license, "/LICENSE");
|
---|
81 | license.setCaretPosition(0);
|
---|
82 |
|
---|
83 | JPanel info = new JPanel(new GridBagLayout());
|
---|
84 | final JMultilineLabel label = new JMultilineLabel("<html>" +
|
---|
85 | "<h1>" + "JOSM – " + tr("Java OpenStreetMap Editor") + "</h1>" +
|
---|
86 | "<p style='font-size:75%'></p>" +
|
---|
87 | "<p>" + tr("Version {0}", version.getVersionString()) + "</p>" +
|
---|
88 | "<p style='font-size:50%'></p>" +
|
---|
89 | "<p>" + tr("Last change at {0}", version.getTime()) + "</p>" +
|
---|
90 | "<p style='font-size:50%'></p>" +
|
---|
91 | "<p>" + tr("Java Version {0}", System.getProperty("java.version")) + "</p>" +
|
---|
92 | "<p style='font-size:50%'></p>" +
|
---|
93 | "</html>");
|
---|
94 | info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
|
---|
95 | info.add(new JLabel(tr("Homepage")), GBC.std().insets(10, 0, 10, 0));
|
---|
96 | info.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
97 | info.add(GBC.glue(0, 5), GBC.eol());
|
---|
98 | info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10, 0, 10, 0));
|
---|
99 | info.add(BugReportExceptionHandler.getBugReportUrlLabel(Utils.strip(ShowStatusReportAction.getReportHeader())),
|
---|
100 | GBC.eol().fill(GBC.HORIZONTAL));
|
---|
101 |
|
---|
102 | about.addTab(tr("Info"), info);
|
---|
103 | about.addTab(tr("Readme"), createScrollPane(readme));
|
---|
104 | about.addTab(tr("Revision"), createScrollPane(revision));
|
---|
105 | about.addTab(tr("Contribution"), createScrollPane(contribution));
|
---|
106 | about.addTab(tr("License"), createScrollPane(license));
|
---|
107 | about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
|
---|
108 |
|
---|
109 | // Intermediate panel to allow proper optionPane resizing
|
---|
110 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
111 | panel.setPreferredSize(new Dimension(600, 300));
|
---|
112 | panel.add(about, GBC.std().fill());
|
---|
113 |
|
---|
114 | GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
|
---|
115 | JOptionPane.showMessageDialog(Main.parent, panel, tr("About JOSM..."), JOptionPane.INFORMATION_MESSAGE,
|
---|
116 | new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH)));
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text
|
---|
121 | * into the {@link JTextArea} given by the {@code ta}-attribute.
|
---|
122 | * @param ta the {@link JTextArea} to put the files contents into
|
---|
123 | * @param filePath the path where the resource file to read resides
|
---|
124 | */
|
---|
125 | private void setTextFromResourceFile(JTextArea ta, String filePath) {
|
---|
126 | InputStream is = getClass().getResourceAsStream(filePath);
|
---|
127 | if (is == null) {
|
---|
128 | displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
|
---|
129 | } else {
|
---|
130 | try {
|
---|
131 | BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
---|
132 | String line;
|
---|
133 | while ((line = br.readLine()) != null) {
|
---|
134 | ta.append(line+'\n');
|
---|
135 | }
|
---|
136 | br.close();
|
---|
137 | } catch (IOException e) {
|
---|
138 | Main.warn(e);
|
---|
139 | displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | private static void displayErrorMessage(JTextArea ta, String msg) {
|
---|
145 | Main.warn(msg);
|
---|
146 | ta.setForeground(new Color(200, 0, 0));
|
---|
147 | ta.setText(msg);
|
---|
148 | }
|
---|
149 |
|
---|
150 | private static JScrollPane createScrollPane(JosmTextArea area) {
|
---|
151 | area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
152 | area.setOpaque(false);
|
---|
153 | JScrollPane sp = new JScrollPane(area);
|
---|
154 | sp.setBorder(null);
|
---|
155 | sp.setOpaque(false);
|
---|
156 | return sp;
|
---|
157 | }
|
---|
158 | }
|
---|