    001/* ========================================================================
    002 * JCommon : a free general purpose class library for the Java(tm) platform
    003 * ========================================================================
    004 *
    005 * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
    006 *
    007 * Project Info:  http://www.jfree.org/jcommon/index.html
    008 *
    009 * This library is free software; you can redistribute it and/or modify it
    010 * under the terms of the GNU Lesser General Public License as published by
    011 * the Free Software Foundation; either version 2.1 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This library is distributed in the hope that it will be useful, but
    015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    017 * License for more details.
    018 *
    019 * You should have received a copy of the GNU Lesser General Public
    020 * License along with this library; if not, write to the Free Software
    021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    022 * USA.
    023 *
    024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
    025 * in the United States and other countries.]
    026 *
    027 * ---------------
    028 * AboutFrame.java
    029 * ---------------
    030 * (C) Copyright 2001-2008, by Object Refinery Limited.
    031 *
    032 * Original Author:  David Gilbert (for Object Refinery Limited);
    033 * Contributor(s):   -;
    034 *
    035 * $Id: AboutDialog.java,v 1.4 2008/12/18 09:57:32 mungady Exp $
    036 *
    037 * Changes (from 26-Nov-2001)
    038 * --------------------------
    039 * 30-Jan-2006 : Version 1, based on the AboutFrame (TM);
    040 * 18-Dec-2008 : Use ResourceBundleWrapper (DG);
    041 *
    042 */
    043
    044package org.jfree.ui.about;
    045
    046import java.awt.BorderLayout;
    047import java.awt.Dialog;
    048import java.awt.Dimension;
    049import java.awt.Frame;
    050import java.awt.Image;
    051import java.util.List;
    052import java.util.ResourceBundle;
    053
    054import javax.swing.BorderFactory;
    055import javax.swing.JDialog;
    056import javax.swing.JPanel;
    057import javax.swing.JScrollPane;
    058import javax.swing.JTabbedPane;
    059import javax.swing.JTextArea;
    060import javax.swing.border.Border;
    061
    062import org.jfree.util.ResourceBundleWrapper;
    063
    064/**
    065 * A dialog that displays information about the demonstration application.
    066 *
    067 * @author David Gilbert
    068 */
    069public class AboutDialog extends JDialog {
    070
    071    /** The preferred size for the frame. */
    072    public static final Dimension PREFERRED_SIZE = new Dimension(560, 360);
    073
    074    /** The default border for the panels in the tabbed pane. */
    075    public static final Border STANDARD_BORDER
    076            = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    077
    078    /** Localised resources. */
    079    private ResourceBundle resources;
    080
    081    /** The application name. */
    082    private String application;
    083
    084    /** The application version. */
    085    private String version;
    086
    087    /** The copyright string. */
    088    private String copyright;
    089
    090    /** Other info about the application. */
    091    private String info;
    092
    093    /** The project logo. */
    094    private Image logo;
    095
    096    /** A list of contributors. */
    097    private List contributors;
    098
    099    /** The licence. */
    100    private String licence;
    101
    102    /**
    103     * Constructs an about frame.
    104     *
    105     * @param title  the frame title.
    106     * @param project  information about the project.
    107     */
    108    public AboutDialog(final String title, final ProjectInfo project) {
    109
    110        init(title,
    111             project.getName(),
    112             "Version " + project.getVersion(),
    113             project.getInfo(),
    114             project.getLogo(),
    115             project.getCopyright(),
    116             project.getLicenceText(),
    117             project.getContributors(),
    118             project);
    119
    120    }
    121
    122  /**
    123   * Creates a non-modal dialog without a title with the specifed
    124   * <code>Frame</code> as its owner.
    125   *
    126   * @param owner the <code>Frame</code> from which the dialog is displayed.
    127   * @param title  the title,
    128   * @param project  the project.
    129   */
    130  public AboutDialog(final Frame owner,
    131                     final String title,
    132                     final ProjectInfo project)
    133  {
    134    super(owner);
    135    init(title,
    136         project.getName(),
    137         "Version " + project.getVersion(),
    138         project.getInfo(),
    139         project.getLogo(),
    140         project.getCopyright(),
    141         project.getLicenceText(),
    142         project.getContributors(),
    143         project);
    144  }
    145
    146  /**
    147   * Creates a non-modal dialog without a title with the specifed
    148   * <code>Dialog</code> as its owner.
    149   *
    150   * @param owner the <code>Dialog</code> from which the dialog is displayed.
    151   * @param title  the title.
    152   * @param project  the project.
    153   */
    154  public AboutDialog(final Dialog owner,
    155                     final String title,
    156                     final ProjectInfo project)
    157  {
    158    super(owner);
    159    init(title,
    160         project.getName(),
    161         "Version " + project.getVersion(),
    162         project.getInfo(),
    163         project.getLogo(),
    164         project.getCopyright(),
    165         project.getLicenceText(),
    166         project.getContributors(),
    167         project);
    168  }
    169
    170  /**
    171     * Constructs an 'About' frame.
    172     *
    173     * @param title  the frame title.
    174     * @param application  the application name.
    175     * @param version  the version.
    176     * @param info  other info.
    177     * @param logo  an optional logo.
    178     * @param copyright  the copyright notice.
    179     * @param licence  the licence.
    180     * @param contributors  a list of developers/contributors.
    181     * @param libraries  a list of libraries.
    182     */
    183    private void init (final String title,
    184                       final String application,
    185                       final String version,
    186                       final String info,
    187                       final Image logo,
    188                       final String copyright,
    189                       final String licence,
    190                       final List contributors,
    191                       final ProjectInfo libraries) {
    192
    193        setTitle(title);
    194
    195        this.application = application;
    196        this.version = version;
    197        this.copyright = copyright;
    198        this.info = info;
    199        this.logo = logo;
    200        this.contributors = contributors;
    201        this.licence = licence;
    202
    203        final String baseName = "org.jfree.ui.about.resources.AboutResources";
    204        this.resources = ResourceBundleWrapper.getBundle(baseName);
    205
    206        final JPanel content = new JPanel(new BorderLayout());
    207        content.setBorder(STANDARD_BORDER);
    208
    209        final JTabbedPane tabs = createTabs(libraries);
    210        content.add(tabs);
    211        setContentPane(content);
    212
    213        pack();
    214
    215    }
    216
    217    /**
    218     * Returns the preferred size for the about frame.
    219     *
    220     * @return the preferred size.
    221     */
    222    public Dimension getPreferredSize() {
    223        return PREFERRED_SIZE;
    224    }
    225
    226    /**
    227     * Creates a tabbed pane containing an about panel and a system properties
    228     * panel.
    229     *
    230     * @param info  project information.
    231     *
    232     * @return a tabbed pane.
    233     */
    234    private JTabbedPane createTabs(final ProjectInfo info) {
    235
    236        final JTabbedPane tabs = new JTabbedPane();
    237
    238        final JPanel aboutPanel = createAboutPanel(info);
    239        aboutPanel.setBorder(AboutDialog.STANDARD_BORDER);
    240        final String aboutTab = this.resources.getString(
    241                "about-frame.tab.about");
    242        tabs.add(aboutTab, aboutPanel);
    243
    244        final JPanel systemPanel = new SystemPropertiesPanel();
    245        systemPanel.setBorder(AboutDialog.STANDARD_BORDER);
    246        final String systemTab = this.resources.getString(
    247                "about-frame.tab.system");
    248        tabs.add(systemTab, systemPanel);
    249
    250        return tabs;
    251
    252    }
    253
    254    /**
    255     * Creates a panel showing information about the application, including the
    256     * name, version, copyright notice, URL for further information, and a list
    257     * of contributors.
    258     *
    259     * @param info  project info.
    260     *
    261     * @return a panel.
    262     */
    263    private JPanel createAboutPanel(final ProjectInfo info) {
    264
    265        final JPanel about = new JPanel(new BorderLayout());
    266
    267        final JPanel details = new AboutPanel(this.application, this.version,
    268                this.copyright, this.info, this.logo);
    269
    270        boolean includetabs = false;
    271        final JTabbedPane tabs = new JTabbedPane();
    272
    273        if (this.contributors != null) {
    274            final JPanel contributorsPanel = new ContributorsPanel(
    275                    this.contributors);
    276            contributorsPanel.setBorder(AboutDialog.STANDARD_BORDER);
    277            final String contributorsTab = this.resources.getString(
    278                    "about-frame.tab.contributors");
    279            tabs.add(contributorsTab, contributorsPanel);
    280            includetabs = true;
    281        }
    282
    283        if (this.licence != null) {
    284            final JPanel licencePanel = createLicencePanel();
    285            licencePanel.setBorder(STANDARD_BORDER);
    286            final String licenceTab = this.resources.getString(
    287                    "about-frame.tab.licence");
    288            tabs.add(licenceTab, licencePanel);
    289            includetabs = true;
    290        }
    291
    292        if (info != null) {
    293            final JPanel librariesPanel = new LibraryPanel(info);
    294            librariesPanel.setBorder(AboutDialog.STANDARD_BORDER);
    295            final String librariesTab = this.resources.getString(
    296                    "about-frame.tab.libraries");
    297            tabs.add(librariesTab, librariesPanel);
    298            includetabs = true;
    299        }
    300
    301        about.add(details, BorderLayout.NORTH);
    302        if (includetabs) {
    303            about.add(tabs);
    304        }
    305
    306        return about;
    307
    308    }
    309
    310    /**
    311     * Creates a panel showing the licence.
    312     *
    313     * @return a panel.
    314     */
    315    private JPanel createLicencePanel() {
    316
    317        final JPanel licencePanel = new JPanel(new BorderLayout());
    318        final JTextArea area = new JTextArea(this.licence);
    319        area.setLineWrap(true);
    320        area.setWrapStyleWord(true);
    321        area.setCaretPosition(0);
    322        area.setEditable(false);
    323        licencePanel.add(new JScrollPane(area));
    324        return licencePanel;
    325
    326    }
    327
    328
    329}