[8378] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
[302] | 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
[9019] | 6 | import java.awt.Color;
|
---|
[302] | 7 | import java.awt.Dimension;
|
---|
| 8 | import java.awt.GridBagLayout;
|
---|
| 9 | import java.awt.event.ActionEvent;
|
---|
| 10 | import java.awt.event.KeyEvent;
|
---|
[9019] | 11 | import java.io.BufferedReader;
|
---|
| 12 | import java.io.IOException;
|
---|
| 13 | import java.io.InputStream;
|
---|
| 14 | import java.io.InputStreamReader;
|
---|
[302] | 15 |
|
---|
| 16 | import javax.swing.BorderFactory;
|
---|
| 17 | import javax.swing.JLabel;
|
---|
| 18 | import javax.swing.JPanel;
|
---|
| 19 | import javax.swing.JScrollPane;
|
---|
| 20 | import javax.swing.JTabbedPane;
|
---|
[9019] | 21 | import javax.swing.JTextArea;
|
---|
[302] | 22 |
|
---|
| 23 | import org.openstreetmap.josm.Main;
|
---|
[2358] | 24 | import org.openstreetmap.josm.data.Version;
|
---|
[10062] | 25 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
[5493] | 26 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[6901] | 27 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
[5886] | 28 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
[6340] | 29 | import org.openstreetmap.josm.gui.widgets.UrlLabel;
|
---|
[1326] | 30 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
[302] | 31 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 32 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[2017] | 33 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[623] | 34 |
|
---|
[626] | 35 | /**
|
---|
[8442] | 36 | * Nice about screen.
|
---|
[1023] | 37 | *
|
---|
[8442] | 38 | * The REVISION resource is read and if present, it shows the revision information of the jar-file.
|
---|
[1023] | 39 | *
|
---|
[626] | 40 | * @author imi
|
---|
| 41 | */
|
---|
[10234] | 42 | public final class AboutAction extends JosmAction {
|
---|
[2370] | 43 |
|
---|
[5886] | 44 | /**
|
---|
| 45 | * Constructs a new {@code AboutAction}.
|
---|
| 46 | */
|
---|
[1169] | 47 | public AboutAction() {
|
---|
[7771] | 48 | super(tr("About"), "logo", tr("Display the about screen."),
|
---|
[4942] | 49 | Shortcut.registerShortcut("system:about", tr("About"),
|
---|
[4982] | 50 | KeyEvent.VK_F1, Shortcut.SHIFT), true);
|
---|
[1169] | 51 | }
|
---|
[626] | 52 |
|
---|
[6084] | 53 | @Override
|
---|
[1169] | 54 | public void actionPerformed(ActionEvent e) {
|
---|
[5493] | 55 | final JTabbedPane about = new JTabbedPane();
|
---|
[2370] | 56 |
|
---|
[5194] | 57 | Version version = Version.getInstance();
|
---|
| 58 |
|
---|
[5886] | 59 | JosmTextArea readme = new JosmTextArea();
|
---|
[10713] | 60 | readme.setFont(GuiHelper.getMonospacedFont(readme));
|
---|
[2358] | 61 | readme.setEditable(false);
|
---|
[9019] | 62 | setTextFromResourceFile(readme, "/README");
|
---|
[5194] | 63 | readme.setCaretPosition(0);
|
---|
[626] | 64 |
|
---|
[5886] | 65 | JosmTextArea revision = new JosmTextArea();
|
---|
[10713] | 66 | revision.setFont(GuiHelper.getMonospacedFont(revision));
|
---|
[5194] | 67 | revision.setEditable(false);
|
---|
| 68 | revision.setText(version.getReleaseAttributes());
|
---|
| 69 | revision.setCaretPosition(0);
|
---|
| 70 |
|
---|
[5886] | 71 | JosmTextArea contribution = new JosmTextArea();
|
---|
[2358] | 72 | contribution.setEditable(false);
|
---|
[9019] | 73 | setTextFromResourceFile(contribution, "/CONTRIBUTION");
|
---|
[5194] | 74 | contribution.setCaretPosition(0);
|
---|
[626] | 75 |
|
---|
[5886] | 76 | JosmTextArea license = new JosmTextArea();
|
---|
[2358] | 77 | license.setEditable(false);
|
---|
[9019] | 78 | setTextFromResourceFile(license, "/LICENSE");
|
---|
[5194] | 79 | license.setCaretPosition(0);
|
---|
[2370] | 80 |
|
---|
[1169] | 81 | JPanel info = new JPanel(new GridBagLayout());
|
---|
[6901] | 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));
|
---|
[8510] | 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());
|
---|
[626] | 96 |
|
---|
[1169] | 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));
|
---|
[1802] | 101 | about.addTab(tr("License"), createScrollPane(license));
|
---|
[1326] | 102 | about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
|
---|
[626] | 103 |
|
---|
[5493] | 104 | // Intermediate panel to allow proper optionPane resizing
|
---|
| 105 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
[10062] | 106 | panel.setPreferredSize(new Dimension(890, 300));
|
---|
[10428] | 107 | panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
|
---|
[10062] | 108 | JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
|
---|
[5493] | 109 | panel.add(about, GBC.std().fill());
|
---|
[6069] | 110 |
|
---|
[5493] | 111 | GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
|
---|
[10062] | 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 | }
|
---|
[1169] | 119 | }
|
---|
[626] | 120 |
|
---|
[9019] | 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 {
|
---|
[10234] | 132 | try (InputStreamReader reader = new InputStreamReader(is, "UTF-8");
|
---|
| 133 | BufferedReader br = new BufferedReader(reader)) {
|
---|
[9019] | 134 | String line;
|
---|
| 135 | while ((line = br.readLine()) != null) {
|
---|
| 136 | ta.append(line+'\n');
|
---|
| 137 | }
|
---|
| 138 | } catch (IOException e) {
|
---|
| 139 | Main.warn(e);
|
---|
| 140 | displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | private static void displayErrorMessage(JTextArea ta, String msg) {
|
---|
| 146 | Main.warn(msg);
|
---|
| 147 | ta.setForeground(new Color(200, 0, 0));
|
---|
| 148 | ta.setText(msg);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[8870] | 151 | private static JScrollPane createScrollPane(JosmTextArea area) {
|
---|
[8510] | 152 | area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
[1169] | 153 | area.setOpaque(false);
|
---|
| 154 | JScrollPane sp = new JScrollPane(area);
|
---|
| 155 | sp.setBorder(null);
|
---|
| 156 | sp.setOpaque(false);
|
---|
| 157 | return sp;
|
---|
| 158 | }
|
---|
[626] | 159 | }
|
---|