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

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

see #8011 - improve About dialog to promote translations:

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