001//License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.Dimension;
007import java.awt.GridBagLayout;
008import java.awt.event.ActionEvent;
009import java.awt.event.KeyEvent;
010
011import javax.swing.BorderFactory;
012import javax.swing.JLabel;
013import javax.swing.JOptionPane;
014import javax.swing.JPanel;
015import javax.swing.JScrollPane;
016import javax.swing.JTabbedPane;
017
018import org.openstreetmap.josm.Main;
019import org.openstreetmap.josm.data.Version;
020import org.openstreetmap.josm.gui.util.GuiHelper;
021import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
022import org.openstreetmap.josm.gui.widgets.JosmTextArea;
023import org.openstreetmap.josm.gui.widgets.UrlLabel;
024import org.openstreetmap.josm.plugins.PluginHandler;
025import org.openstreetmap.josm.tools.BugReportExceptionHandler;
026import org.openstreetmap.josm.tools.GBC;
027import org.openstreetmap.josm.tools.ImageProvider;
028import org.openstreetmap.josm.tools.Shortcut;
029import org.openstreetmap.josm.tools.Utils;
030
031/**
032 * Nice about screen. I guess every application need one these days.. *sigh*
033 *
034 * The REVISION resource is read and if present, it shows the revision
035 * information of the jar-file.
036 *
037 * @author imi
038 */
039public class AboutAction extends JosmAction {
040
041    /**
042     * Constructs a new {@code AboutAction}.
043     */
044    public AboutAction() {
045        super(tr("About"), "logo", tr("Display the about screen."),
046            Shortcut.registerShortcut("system:about", tr("About"),
047            KeyEvent.VK_F1, Shortcut.SHIFT), true);
048    }
049
050    @Override
051    public void actionPerformed(ActionEvent e) {
052        final JTabbedPane about = new JTabbedPane();
053
054        Version version = Version.getInstance();
055
056        JosmTextArea readme = new JosmTextArea();
057        readme.setEditable(false);
058        readme.setText(Version.loadResourceFile(Main.class.getResource("/README")));
059        readme.setCaretPosition(0);
060
061        JosmTextArea revision = new JosmTextArea();
062        revision.setEditable(false);
063        revision.setText(version.getReleaseAttributes());
064        revision.setCaretPosition(0);
065
066        JosmTextArea contribution = new JosmTextArea();
067        contribution.setEditable(false);
068        contribution.setText(Version.loadResourceFile(Main.class.getResource("/CONTRIBUTION")));
069        contribution.setCaretPosition(0);
070
071        JosmTextArea license = new JosmTextArea();
072        license.setEditable(false);
073        license.setText(Version.loadResourceFile(Main.class.getResource("/LICENSE")));
074        license.setCaretPosition(0);
075
076        JPanel info = new JPanel(new GridBagLayout());
077        final JMultilineLabel label = new JMultilineLabel("<html>" +
078                "<h1>" + "JOSM ? " + tr("Java OpenStreetMap Editor") + "</h1>" +
079                "<p style='font-size:75%'></p>" +
080                "<p>" + tr("Version {0}", version.getVersionString()) + "</p>" +
081                "<p style='font-size:50%'></p>" +
082                "<p>" + tr("Last change at {0}", version.getTime()) + "</p>" +
083                "<p style='font-size:50%'></p>" +
084                "<p>" + tr("Java Version {0}", System.getProperty("java.version")) + "</p>" +
085                "<p style='font-size:50%'></p>" +
086                "</html>");
087        info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
088        info.add(new JLabel(tr("Homepage")), GBC.std().insets(10,0,10,0));
089        info.add(new UrlLabel(Main.getJOSMWebsite(),2), GBC.eol().fill(GBC.HORIZONTAL));
090        info.add(GBC.glue(0,5), GBC.eol());
091        info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10,0,10,0));
092        info.add(BugReportExceptionHandler.getBugReportUrlLabel(Utils.strip(ShowStatusReportAction.getReportHeader())), GBC.eol().fill(GBC.HORIZONTAL));
093
094        about.addTab(tr("Info"), info);
095        about.addTab(tr("Readme"), createScrollPane(readme));
096        about.addTab(tr("Revision"), createScrollPane(revision));
097        about.addTab(tr("Contribution"), createScrollPane(contribution));
098        about.addTab(tr("License"), createScrollPane(license));
099        about.addTab(tr("Plugins"), new JScrollPane(PluginHandler.getInfoPanel()));
100
101        // Intermediate panel to allow proper optionPane resizing
102        JPanel panel = new JPanel(new GridBagLayout());
103        panel.setPreferredSize(new Dimension(600, 300));
104        panel.add(about, GBC.std().fill());
105
106        GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
107        JOptionPane.showMessageDialog(Main.parent, panel, tr("About JOSM..."),
108                JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo"));
109    }
110
111    private JScrollPane createScrollPane(JosmTextArea area) {
112        area.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
113        area.setOpaque(false);
114        JScrollPane sp = new JScrollPane(area);
115        sp.setBorder(null);
116        sp.setOpaque(false);
117        return sp;
118    }
119}