[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;
|
---|
[13781] | 8 | import java.awt.FlowLayout;
|
---|
[302] | 9 | import java.awt.GridBagLayout;
|
---|
| 10 | import java.awt.event.ActionEvent;
|
---|
| 11 | import java.awt.event.KeyEvent;
|
---|
[13781] | 12 | import java.awt.event.MouseAdapter;
|
---|
| 13 | import java.awt.event.MouseEvent;
|
---|
[9019] | 14 | import java.io.BufferedReader;
|
---|
| 15 | import java.io.IOException;
|
---|
| 16 | import java.io.InputStream;
|
---|
| 17 | import java.io.InputStreamReader;
|
---|
[302] | 18 |
|
---|
| 19 | import javax.swing.BorderFactory;
|
---|
| 20 | import javax.swing.JLabel;
|
---|
| 21 | import javax.swing.JPanel;
|
---|
| 22 | import javax.swing.JScrollPane;
|
---|
| 23 | import javax.swing.JTabbedPane;
|
---|
[9019] | 24 | import javax.swing.JTextArea;
|
---|
[302] | 25 |
|
---|
[2358] | 26 | import org.openstreetmap.josm.data.Version;
|
---|
[10062] | 27 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
[12643] | 28 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[5493] | 29 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[6901] | 30 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
[5886] | 31 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
[6340] | 32 | import org.openstreetmap.josm.gui.widgets.UrlLabel;
|
---|
[1326] | 33 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
[14119] | 34 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
[302] | 35 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 36 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[13781] | 37 | import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
|
---|
[12620] | 38 | import org.openstreetmap.josm.tools.Logging;
|
---|
[13781] | 39 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
[2017] | 40 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[13647] | 41 | import org.openstreetmap.josm.tools.Utils;
|
---|
[623] | 42 |
|
---|
[626] | 43 | /**
|
---|
[8442] | 44 | * Nice about screen.
|
---|
[1023] | 45 | *
|
---|
[8442] | 46 | * The REVISION resource is read and if present, it shows the revision information of the jar-file.
|
---|
[1023] | 47 | *
|
---|
[626] | 48 | * @author imi
|
---|
| 49 | */
|
---|
[10234] | 50 | public final class AboutAction extends JosmAction {
|
---|
[2370] | 51 |
|
---|
[5886] | 52 | /**
|
---|
| 53 | * Constructs a new {@code AboutAction}.
|
---|
| 54 | */
|
---|
[1169] | 55 | public AboutAction() {
|
---|
[7771] | 56 | super(tr("About"), "logo", tr("Display the about screen."),
|
---|
[4942] | 57 | Shortcut.registerShortcut("system:about", tr("About"),
|
---|
[4982] | 58 | KeyEvent.VK_F1, Shortcut.SHIFT), true);
|
---|
[1169] | 59 | }
|
---|
[626] | 60 |
|
---|
[6084] | 61 | @Override
|
---|
[1169] | 62 | public void actionPerformed(ActionEvent e) {
|
---|
[5493] | 63 | final JTabbedPane about = new JTabbedPane();
|
---|
[2370] | 64 |
|
---|
[5194] | 65 | Version version = Version.getInstance();
|
---|
| 66 |
|
---|
[5886] | 67 | JosmTextArea readme = new JosmTextArea();
|
---|
[10713] | 68 | readme.setFont(GuiHelper.getMonospacedFont(readme));
|
---|
[2358] | 69 | readme.setEditable(false);
|
---|
[9019] | 70 | setTextFromResourceFile(readme, "/README");
|
---|
[5194] | 71 | readme.setCaretPosition(0);
|
---|
[626] | 72 |
|
---|
[5886] | 73 | JosmTextArea revision = new JosmTextArea();
|
---|
[10713] | 74 | revision.setFont(GuiHelper.getMonospacedFont(revision));
|
---|
[5194] | 75 | revision.setEditable(false);
|
---|
| 76 | revision.setText(version.getReleaseAttributes());
|
---|
| 77 | revision.setCaretPosition(0);
|
---|
| 78 |
|
---|
[5886] | 79 | JosmTextArea contribution = new JosmTextArea();
|
---|
[2358] | 80 | contribution.setEditable(false);
|
---|
[9019] | 81 | setTextFromResourceFile(contribution, "/CONTRIBUTION");
|
---|
[5194] | 82 | contribution.setCaretPosition(0);
|
---|
[626] | 83 |
|
---|
[5886] | 84 | JosmTextArea license = new JosmTextArea();
|
---|
[2358] | 85 | license.setEditable(false);
|
---|
[9019] | 86 | setTextFromResourceFile(license, "/LICENSE");
|
---|
[5194] | 87 | license.setCaretPosition(0);
|
---|
[2370] | 88 |
|
---|
[1169] | 89 | JPanel info = new JPanel(new GridBagLayout());
|
---|
[6901] | 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>" +
|
---|
[13647] | 97 | "<p>" + tr("Java Version {0}", Utils.getSystemProperty("java.version")) + "</p>" +
|
---|
[6901] | 98 | "<p style='font-size:50%'></p>" +
|
---|
| 99 | "</html>");
|
---|
[13781] | 100 | info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 10));
|
---|
[8510] | 101 | info.add(new JLabel(tr("Homepage")), GBC.std().insets(10, 0, 10, 0));
|
---|
[14119] | 102 | info.add(new UrlLabel(Config.getUrls().getJOSMWebsite(), 2), GBC.eol());
|
---|
[13781] | 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());
|
---|
[13782] | 107 | logos.add(createImageLink("OpenStreetMap", /* ICON(dialogs/about/) */ "openstreetmap",
|
---|
| 108 | "https://www.openstreetmap.org/user/josmeditor/diary"));
|
---|
| 109 | logos.add(createImageLink("Twitter", /* ICON(dialogs/about/) */ "twitter", "https://twitter.com/josmeditor"));
|
---|
| 110 | logos.add(createImageLink("Facebook", /* ICON(dialogs/about/) */ "facebook", "https://www.facebook.com/josmeditor"));
|
---|
[14107] | 111 | logos.add(createImageLink("GitHub", /* ICON(dialogs/about/) */ "github", "https://github.com/JOSM"));
|
---|
[13781] | 112 | info.add(logos, GBC.eol().insets(0, 10, 0, 0));
|
---|
[8510] | 113 | info.add(GBC.glue(0, 5), GBC.eol());
|
---|
[626] | 114 |
|
---|
[1169] | 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));
|
---|
[1802] | 119 | about.addTab(tr("License"), createScrollPane(license));
|
---|
[1326] | 120 | about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
|
---|
[626] | 121 |
|
---|
[13783] | 122 | // Get the list of Launchpad contributors using customary msgid “translator-credits”
|
---|
| 123 | String translators = tr("translator-credits");
|
---|
[13824] | 124 | if (translators != null && !translators.isEmpty() && !"translator-credits".equals(translators)) {
|
---|
[13783] | 125 | about.addTab(tr("Translators"), createScrollPane(new JosmTextArea(translators)));
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[5493] | 128 | // Intermediate panel to allow proper optionPane resizing
|
---|
| 129 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
[10062] | 130 | panel.setPreferredSize(new Dimension(890, 300));
|
---|
[10428] | 131 | panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
|
---|
[10062] | 132 | JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
|
---|
[5493] | 133 | panel.add(about, GBC.std().fill());
|
---|
[6069] | 134 |
|
---|
[5493] | 135 | GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
|
---|
[14153] | 136 | int ret = new ExtendedDialog(MainApplication.getMainFrame(), tr("About JOSM..."), tr("OK"), tr("Report bug"))
|
---|
[12279] | 137 | .setButtonIcons("ok", "bug")
|
---|
[10062] | 138 | .setContent(panel, false)
|
---|
| 139 | .showDialog().getValue();
|
---|
| 140 | if (2 == ret) {
|
---|
[12643] | 141 | MainApplication.getMenu().reportbug.actionPerformed(null);
|
---|
[10062] | 142 | }
|
---|
[1169] | 143 | }
|
---|
[626] | 144 |
|
---|
[13781] | 145 | private static JLabel createImageLink(String tooltip, String icon, final String link) {
|
---|
| 146 | JLabel label = new JLabel(ImageProvider.get("dialogs/about", icon, ImageSizes.LARGEICON));
|
---|
| 147 | label.setToolTipText(tooltip);
|
---|
| 148 | label.addMouseListener(new MouseAdapter() {
|
---|
| 149 | @Override
|
---|
| 150 | public void mouseClicked(MouseEvent e) {
|
---|
| 151 | OpenBrowser.displayUrl(link);
|
---|
| 152 | }
|
---|
| 153 | });
|
---|
| 154 | return label;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[9019] | 157 | /**
|
---|
| 158 | * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text
|
---|
| 159 | * into the {@link JTextArea} given by the {@code ta}-attribute.
|
---|
| 160 | * @param ta the {@link JTextArea} to put the files contents into
|
---|
| 161 | * @param filePath the path where the resource file to read resides
|
---|
| 162 | */
|
---|
| 163 | private void setTextFromResourceFile(JTextArea ta, String filePath) {
|
---|
[14480] | 164 | InputStream is = Utils.getResourceAsStream(getClass(), filePath);
|
---|
[9019] | 165 | if (is == null) {
|
---|
| 166 | displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
|
---|
| 167 | } else {
|
---|
[10234] | 168 | try (InputStreamReader reader = new InputStreamReader(is, "UTF-8");
|
---|
| 169 | BufferedReader br = new BufferedReader(reader)) {
|
---|
[9019] | 170 | String line;
|
---|
| 171 | while ((line = br.readLine()) != null) {
|
---|
| 172 | ta.append(line+'\n');
|
---|
| 173 | }
|
---|
| 174 | } catch (IOException e) {
|
---|
[12620] | 175 | Logging.warn(e);
|
---|
[9019] | 176 | displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString()));
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | private static void displayErrorMessage(JTextArea ta, String msg) {
|
---|
[12620] | 182 | Logging.warn(msg);
|
---|
[9019] | 183 | ta.setForeground(new Color(200, 0, 0));
|
---|
| 184 | ta.setText(msg);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[8870] | 187 | private static JScrollPane createScrollPane(JosmTextArea area) {
|
---|
[8510] | 188 | area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
[1169] | 189 | area.setOpaque(false);
|
---|
| 190 | JScrollPane sp = new JScrollPane(area);
|
---|
| 191 | sp.setBorder(null);
|
---|
| 192 | sp.setOpaque(false);
|
---|
| 193 | return sp;
|
---|
| 194 | }
|
---|
[626] | 195 | }
|
---|