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

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

see #12652 - about dialog: replace old bug report link with new bug report button, remove unused code

  • 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.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.JPanel;
21import javax.swing.JScrollPane;
22import javax.swing.JTabbedPane;
23import javax.swing.JTextArea;
24
25import org.openstreetmap.josm.Main;
26import org.openstreetmap.josm.data.Version;
27import org.openstreetmap.josm.gui.ExtendedDialog;
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.GBC;
34import org.openstreetmap.josm.tools.ImageProvider;
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 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.setEditable(false);
63 setTextFromResourceFile(readme, "/README");
64 readme.setCaretPosition(0);
65
66 JosmTextArea revision = new JosmTextArea();
67 revision.setEditable(false);
68 revision.setText(version.getReleaseAttributes());
69 revision.setCaretPosition(0);
70
71 JosmTextArea contribution = new JosmTextArea();
72 contribution.setEditable(false);
73 setTextFromResourceFile(contribution, "/CONTRIBUTION");
74 contribution.setCaretPosition(0);
75
76 JosmTextArea license = new JosmTextArea();
77 license.setEditable(false);
78 setTextFromResourceFile(license, "/LICENSE");
79 license.setCaretPosition(0);
80
81 JPanel info = new JPanel(new GridBagLayout());
82 final JMultilineLabel label = new JMultilineLabel("<html>" +
83 "<h1>" + "JOSM – " + tr("Java OpenStreetMap Editor") + "</h1>" +
84 "<p style='font-size:75%'></p>" +
85 "<p>" + tr("Version {0}", version.getVersionString()) + "</p>" +
86 "<p style='font-size:50%'></p>" +
87 "<p>" + tr("Last change at {0}", version.getTime()) + "</p>" +
88 "<p style='font-size:50%'></p>" +
89 "<p>" + tr("Java Version {0}", System.getProperty("java.version")) + "</p>" +
90 "<p style='font-size:50%'></p>" +
91 "</html>");
92 info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
93 info.add(new JLabel(tr("Homepage")), GBC.std().insets(10, 0, 10, 0));
94 info.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eol().fill(GBC.HORIZONTAL));
95 info.add(GBC.glue(0, 5), GBC.eol());
96
97 about.addTab(tr("Info"), info);
98 about.addTab(tr("Readme"), createScrollPane(readme));
99 about.addTab(tr("Revision"), createScrollPane(revision));
100 about.addTab(tr("Contribution"), createScrollPane(contribution));
101 about.addTab(tr("License"), createScrollPane(license));
102 about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
103
104 // Intermediate panel to allow proper optionPane resizing
105 JPanel panel = new JPanel(new GridBagLayout());
106 panel.setPreferredSize(new Dimension(890, 300));
107 panel.add(new JLabel("", new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH)),
108 JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
109 panel.add(about, GBC.std().fill());
110
111 GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
112 int ret = new ExtendedDialog(Main.parent, tr("About JOSM..."), new String[] {tr("OK"), tr("Report bug")})
113 .setButtonIcons(new String[] {"ok", "bug"})
114 .setContent(panel, false)
115 .showDialog().getValue();
116 if (2 == ret) {
117 Main.main.menu.reportbug.actionPerformed(null);
118 }
119 }
120
121 /**
122 * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text
123 * into the {@link JTextArea} given by the {@code ta}-attribute.
124 * @param ta the {@link JTextArea} to put the files contents into
125 * @param filePath the path where the resource file to read resides
126 */
127 private void setTextFromResourceFile(JTextArea ta, String filePath) {
128 InputStream is = getClass().getResourceAsStream(filePath);
129 if (is == null) {
130 displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
131 } else {
132 try {
133 BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
134 String line;
135 while ((line = br.readLine()) != null) {
136 ta.append(line+'\n');
137 }
138 br.close();
139 } catch (IOException e) {
140 Main.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 Main.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.