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

Last change on this file since 13745 was 13647, checked in by Don-vip, 6 years ago

see #16204 - Allow to start and close JOSM in WebStart sandbox mode (where every external access is denied). This was very useful to reproduce some very tricky bugs that occured in real life but were almost impossible to diagnose.

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