001package apps.swing;
002
003import java.awt.*;
004import java.util.Locale;
005
006import javax.swing.*;
007
008import jmri.*;
009import jmri.jmrix.ConnectionConfig;
010import jmri.jmrix.ConnectionConfigManager;
011import jmri.swing.ConnectionLabel;
012import jmri.util.FileUtil;
013
014import org.slf4j.Logger;
015import org.slf4j.LoggerFactory;
016
017/**
018 * About dialog.
019 *
020 * @author Randall Wood Copyright (C) 2012
021 */
022public final class AboutDialog extends JDialog {
023
024    // this should probably be changed to a JmriAbstractAction that opens a JmriJOptionPane with the contents and an OK button instead.
025    public AboutDialog(JFrame frame, boolean modal) {
026
027        super(frame, modal);
028
029        log.debug("Start UI");
030
031        JPanel pane = new JPanel();
032        pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
033        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
034        pane.add(namePane());
035        pane.add(infoPane());
036        this.add(pane);
037        this.pack();
038        this.setResizable(false);
039        this.setLocationRelativeTo(null); // center on screen
040        this.setTitle(Bundle.getMessage("TitleAbout", Application.getApplicationName()));
041        log.debug("End constructor");
042    }
043
044    protected JPanel namePane() {
045        String logo = Application.getLogo();
046        JPanel pane = new JPanel();
047        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
048        if (log.isDebugEnabled()) {
049            log.debug("Fetch main logo: {} ({})", logo, FileUtil.findURL(logo, FileUtil.Location.INSTALLED));
050        }
051        addCenteredComponent(new JLabel(new ImageIcon(getToolkit().getImage(FileUtil.findURL(logo, FileUtil.Location.INSTALLED)), "JMRI logo"), JLabel.CENTER), pane);
052        pane.add(Box.createRigidArea(new Dimension(0, 15)));
053        String name = Application.getApplicationName();
054        name = checkCopyright(name);
055        JLabel appName = new JLabel(name, JLabel.CENTER);
056        appName.setFont(pane.getFont().deriveFont(Font.BOLD, pane.getFont().getSize() * 1.2f));
057        addCenteredComponent(appName, pane);
058        addCenteredComponent(new JLabel(Application.getURL(), JLabel.CENTER), pane);
059        pane.add(Box.createRigidArea(new Dimension(0, 15)));
060        pane.setAlignmentX(Component.CENTER_ALIGNMENT);
061        return pane;
062    }
063
064    protected String checkCopyright(String name) {
065        if (name.toUpperCase().equals("DECODERPRO")) {
066            name = name + "\u00ae";
067        }
068        return name;
069    }
070
071    protected JPanel infoPane() {
072        JPanel pane1 = new JPanel();
073        pane1.setLayout(new BoxLayout(pane1, BoxLayout.Y_AXIS));
074
075        log.debug("start labels");
076
077        // add listener for Com port updates
078        for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
079            if (!conn.getDisabled()) {
080                pane1.add(new ConnectionLabel(conn));
081            }
082        }
083        pane1.add(Box.createRigidArea(new Dimension(0, 15)));
084
085        pane1.add(new JLabel(Bundle.getMessage("DefaultVersionCredit", Version.name())));
086        pane1.add(new JLabel(Version.getCopyright()));
087        pane1.add(new JLabel(Bundle.getMessage("JavaVersionCredit",
088                System.getProperty("java.version", "<unknown>"),
089                Locale.getDefault().toString())));
090        pane1.setAlignmentX(Component.CENTER_ALIGNMENT);
091        return pane1;
092    }
093
094    protected void addCenteredComponent(JComponent c, JPanel p) {
095        c.setAlignmentX(Component.CENTER_ALIGNMENT); // doesn't work
096        p.add(c);
097    }
098
099    private static final Logger log = LoggerFactory.getLogger(AboutDialog.class);
100}