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