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

Last change on this file since 10629 was 10428, checked in by stoecker, 8 years ago

see #9995 - patch mainly by strump - improve HIDPI behaviour

  • Property svn:eol-style set to native
File size: 6.2 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.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 */
42public 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.setEditable(false);
61 setTextFromResourceFile(readme, "/README");
62 readme.setCaretPosition(0);
63
64 JosmTextArea revision = new JosmTextArea();
65 revision.setEditable(false);
66 revision.setText(version.getReleaseAttributes());
67 revision.setCaretPosition(0);
68
69 JosmTextArea contribution = new JosmTextArea();
70 contribution.setEditable(false);
71 setTextFromResourceFile(contribution, "/CONTRIBUTION");
72 contribution.setCaretPosition(0);
73
74 JosmTextArea license = new JosmTextArea();
75 license.setEditable(false);
76 setTextFromResourceFile(license, "/LICENSE");
77 license.setCaretPosition(0);
78
79 JPanel info = new JPanel(new GridBagLayout());
80 final JMultilineLabel label = new JMultilineLabel("<html>" +
81 "<h1>" + "JOSM – " + tr("Java OpenStreetMap Editor") + "</h1>" +
82 "<p style='font-size:75%'></p>" +
83 "<p>" + tr("Version {0}", version.getVersionString()) + "</p>" +
84 "<p style='font-size:50%'></p>" +
85 "<p>" + tr("Last change at {0}", version.getTime()) + "</p>" +
86 "<p style='font-size:50%'></p>" +
87 "<p>" + tr("Java Version {0}", System.getProperty("java.version")) + "</p>" +
88 "<p style='font-size:50%'></p>" +
89 "</html>");
90 info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
91 info.add(new JLabel(tr("Homepage")), GBC.std().insets(10, 0, 10, 0));
92 info.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eol().fill(GBC.HORIZONTAL));
93 info.add(GBC.glue(0, 5), GBC.eol());
94
95 about.addTab(tr("Info"), info);
96 about.addTab(tr("Readme"), createScrollPane(readme));
97 about.addTab(tr("Revision"), createScrollPane(revision));
98 about.addTab(tr("Contribution"), createScrollPane(contribution));
99 about.addTab(tr("License"), createScrollPane(license));
100 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
101
102 // Intermediate panel to allow proper optionPane resizing
103 JPanel panel = new JPanel(new GridBagLayout());
104 panel.setPreferredSize(new Dimension(890, 300));
105 panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
106 JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
107 panel.add(about, GBC.std().fill());
108
109 GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
110 int ret = new ExtendedDialog(Main.parent, tr("About JOSM..."), new String[] {tr("OK"), tr("Report bug")})
111 .setButtonIcons(new String[] {"ok", "bug"})
112 .setContent(panel, false)
113 .showDialog().getValue();
114 if (2 == ret) {
115 Main.main.menu.reportbug.actionPerformed(null);
116 }
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 (InputStreamReader reader = new InputStreamReader(is, "UTF-8");
131 BufferedReader br = new BufferedReader(reader)) {
132 String line;
133 while ((line = br.readLine()) != null) {
134 ta.append(line+'\n');
135 }
136 } catch (IOException e) {
137 Main.warn(e);
138 displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
139 }
140 }
141 }
142
143 private static void displayErrorMessage(JTextArea ta, String msg) {
144 Main.warn(msg);
145 ta.setForeground(new Color(200, 0, 0));
146 ta.setText(msg);
147 }
148
149 private static JScrollPane createScrollPane(JosmTextArea area) {
150 area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
151 area.setOpaque(false);
152 JScrollPane sp = new JScrollPane(area);
153 sp.setBorder(null);
154 sp.setOpaque(false);
155 return sp;
156 }
157}
Note: See TracBrowser for help on using the repository browser.