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

Last change on this file since 13464 was 12643, checked in by Don-vip, 7 years ago

see #15182 - deprecate Main.main.menu. Replacement: gui.MainApplication.getMenu()

  • 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;
36
37/**
38 * Nice about screen.
39 *
40 * The REVISION resource is read and if present, it shows the revision information of the jar-file.
41 *
42 * @author imi
43 */
44public final class AboutAction extends JosmAction {
45
46 /**
47 * Constructs a new {@code AboutAction}.
48 */
49 public AboutAction() {
50 super(tr("About"), "logo", tr("Display the about screen."),
51 Shortcut.registerShortcut("system:about", tr("About"),
52 KeyEvent.VK_F1, Shortcut.SHIFT), true);
53 }
54
55 @Override
56 public void actionPerformed(ActionEvent e) {
57 final JTabbedPane about = new JTabbedPane();
58
59 Version version = Version.getInstance();
60
61 JosmTextArea readme = new JosmTextArea();
62 readme.setFont(GuiHelper.getMonospacedFont(readme));
63 readme.setEditable(false);
64 setTextFromResourceFile(readme, "/README");
65 readme.setCaretPosition(0);
66
67 JosmTextArea revision = new JosmTextArea();
68 revision.setFont(GuiHelper.getMonospacedFont(revision));
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
99 about.addTab(tr("Info"), info);
100 about.addTab(tr("Readme"), createScrollPane(readme));
101 about.addTab(tr("Revision"), createScrollPane(revision));
102 about.addTab(tr("Contribution"), createScrollPane(contribution));
103 about.addTab(tr("License"), createScrollPane(license));
104 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
105
106 // Intermediate panel to allow proper optionPane resizing
107 JPanel panel = new JPanel(new GridBagLayout());
108 panel.setPreferredSize(new Dimension(890, 300));
109 panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
110 JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
111 panel.add(about, GBC.std().fill());
112
113 GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
114 int ret = new ExtendedDialog(Main.parent, tr("About JOSM..."), tr("OK"), tr("Report bug"))
115 .setButtonIcons("ok", "bug")
116 .setContent(panel, false)
117 .showDialog().getValue();
118 if (2 == ret) {
119 MainApplication.getMenu().reportbug.actionPerformed(null);
120 }
121 }
122
123 /**
124 * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text
125 * into the {@link JTextArea} given by the {@code ta}-attribute.
126 * @param ta the {@link JTextArea} to put the files contents into
127 * @param filePath the path where the resource file to read resides
128 */
129 private void setTextFromResourceFile(JTextArea ta, String filePath) {
130 InputStream is = getClass().getResourceAsStream(filePath);
131 if (is == null) {
132 displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
133 } else {
134 try (InputStreamReader reader = new InputStreamReader(is, "UTF-8");
135 BufferedReader br = new BufferedReader(reader)) {
136 String line;
137 while ((line = br.readLine()) != null) {
138 ta.append(line+'\n');
139 }
140 } catch (IOException e) {
141 Logging.warn(e);
142 displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
143 }
144 }
145 }
146
147 private static void displayErrorMessage(JTextArea ta, String msg) {
148 Logging.warn(msg);
149 ta.setForeground(new Color(200, 0, 0));
150 ta.setText(msg);
151 }
152
153 private static JScrollPane createScrollPane(JosmTextArea area) {
154 area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
155 area.setOpaque(false);
156 JScrollPane sp = new JScrollPane(area);
157 sp.setBorder(null);
158 sp.setOpaque(false);
159 return sp;
160 }
161}
Note: See TracBrowser for help on using the repository browser.