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

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

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

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