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

Last change on this file since 9073 was 9019, checked in by Don-vip, 8 years ago

fix #12112 - Use java.util.Properties to read REVISION file in the Version-class (patch by floscher) + checkstyle

  • 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.Image;
10import java.awt.event.ActionEvent;
11import java.awt.event.KeyEvent;
12import java.io.BufferedReader;
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.InputStreamReader;
16
17import javax.swing.BorderFactory;
18import javax.swing.ImageIcon;
19import javax.swing.JLabel;
20import javax.swing.JOptionPane;
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.util.GuiHelper;
29import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
30import org.openstreetmap.josm.gui.widgets.JosmTextArea;
31import org.openstreetmap.josm.gui.widgets.UrlLabel;
32import org.openstreetmap.josm.plugins.PluginHandler;
33import org.openstreetmap.josm.tools.BugReportExceptionHandler;
34import org.openstreetmap.josm.tools.GBC;
35import org.openstreetmap.josm.tools.ImageProvider;
36import org.openstreetmap.josm.tools.Shortcut;
37import org.openstreetmap.josm.tools.Utils;
38
39/**
40 * Nice about screen.
41 *
42 * The REVISION resource is read and if present, it shows the revision information of the jar-file.
43 *
44 * @author imi
45 */
46public class AboutAction extends JosmAction {
47
48 /**
49 * Constructs a new {@code AboutAction}.
50 */
51 public AboutAction() {
52 super(tr("About"), "logo", tr("Display the about screen."),
53 Shortcut.registerShortcut("system:about", tr("About"),
54 KeyEvent.VK_F1, Shortcut.SHIFT), true);
55 }
56
57 @Override
58 public void actionPerformed(ActionEvent e) {
59 final JTabbedPane about = new JTabbedPane();
60
61 Version version = Version.getInstance();
62
63 JosmTextArea readme = new JosmTextArea();
64 readme.setEditable(false);
65 setTextFromResourceFile(readme, "/README");
66 readme.setCaretPosition(0);
67
68 JosmTextArea revision = new JosmTextArea();
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 info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10, 0, 10, 0));
99 info.add(BugReportExceptionHandler.getBugReportUrlLabel(Utils.strip(ShowStatusReportAction.getReportHeader())),
100 GBC.eol().fill(GBC.HORIZONTAL));
101
102 about.addTab(tr("Info"), info);
103 about.addTab(tr("Readme"), createScrollPane(readme));
104 about.addTab(tr("Revision"), createScrollPane(revision));
105 about.addTab(tr("Contribution"), createScrollPane(contribution));
106 about.addTab(tr("License"), createScrollPane(license));
107 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
108
109 // Intermediate panel to allow proper optionPane resizing
110 JPanel panel = new JPanel(new GridBagLayout());
111 panel.setPreferredSize(new Dimension(600, 300));
112 panel.add(about, GBC.std().fill());
113
114 GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
115 JOptionPane.showMessageDialog(Main.parent, panel, tr("About JOSM..."), JOptionPane.INFORMATION_MESSAGE,
116 new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH)));
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 {
131 BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
132 String line;
133 while ((line = br.readLine()) != null) {
134 ta.append(line+'\n');
135 }
136 br.close();
137 } catch (IOException e) {
138 Main.warn(e);
139 displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
140 }
141 }
142 }
143
144 private static void displayErrorMessage(JTextArea ta, String msg) {
145 Main.warn(msg);
146 ta.setForeground(new Color(200, 0, 0));
147 ta.setText(msg);
148 }
149
150 private static JScrollPane createScrollPane(JosmTextArea area) {
151 area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
152 area.setOpaque(false);
153 JScrollPane sp = new JScrollPane(area);
154 sp.setBorder(null);
155 sp.setOpaque(false);
156 return sp;
157 }
158}
Note: See TracBrowser for help on using the repository browser.