    001    /* ========================================================================
    002     * JCommon : a free general purpose class library for the Java(tm) platform
    003     * ========================================================================
    004     *
    005     * (C) Copyright 2000-2005, 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-2004, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * $Id: AboutFrame.java,v 1.6 2006/03/23 19:47:05 taqua Exp $
    036     *
    037     * Changes (from 26-Nov-2001)
    038     * --------------------------
    039     * 26-Nov-2001 : Version 1, based on code from JFreeChart demo application (DG);
    040     * 27-Nov-2001 : Added getPreferredSize() method (DG);
    041     * 08-Feb-2002 : List of developers is now optional (DG);
    042     * 15-Mar-2002 : Modified to use a ResourceBundle for elements that require localisation (DG);
    043     * 25-Mar-2002 : Added new constructor (DG);
    044     * 26-Jun-2002 : Removed redundant code (DG);
    045     * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
    046     *
    047     */
    048
    049    package org.jfree.ui.about;
    050
    051    import java.awt.BorderLayout;
    052    import java.awt.Dimension;
    053    import java.awt.Image;
    054    import java.util.List;
    055    import java.util.ResourceBundle;
    056    import javax.swing.BorderFactory;
    057    import javax.swing.JFrame;
    058    import javax.swing.JPanel;
    059    import javax.swing.JScrollPane;
    060    import javax.swing.JTabbedPane;
    061    import javax.swing.JTextArea;
    062    import javax.swing.border.Border;
    063
    064    /**
    065     * A frame that displays information about the demonstration application.
    066     *
    067     * @author David Gilbert
    068     */
    069    public class AboutFrame extends JFrame {
    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 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    076
    077        /** Localised resources. */
    078        private ResourceBundle resources;
    079
    080        /** The application name. */
    081        private String application;
    082
    083        /** The application version. */
    084        private String version;
    085
    086        /** The copyright string. */
    087        private String copyright;
    088
    089        /** Other info about the application. */
    090        private String info;
    091
    092        /** The project logo. */
    093        private Image logo;
    094
    095        /** A list of contributors. */
    096        private List contributors;
    097
    098        /** The licence. */
    099        private String licence;
    100
    101        /**
    102         * Constructs an about frame.
    103         *
    104         * @param title  the frame title.
    105         * @param project  information about the project.
    106         */
    107        public AboutFrame(final String title, final ProjectInfo project) {
    108
    109            this(title,
    110                 project.getName(),
    111                 "Version " + project.getVersion(),
    112                 project.getInfo(),
    113                 project.getLogo(),
    114                 project.getCopyright(),
    115                 project.getLicenceText(),
    116                 project.getContributors(),
    117                 project);
    118
    119        }
    120
    121        /**
    122         * Constructs an 'About' frame.
    123         *
    124         * @param title  the frame title.
    125         * @param application  the application name.
    126         * @param version  the version.
    127         * @param info  other info.
    128         * @param logo  an optional logo.
    129         * @param copyright  the copyright notice.
    130         * @param licence  the licence.
    131         * @param contributors  a list of developers/contributors.
    132         * @param libraries  a list of libraries.
    133         */
    134        public AboutFrame(final String title,
    135                          final String application, final String version, final String info,
    136                          final Image logo,
    137                          final String copyright, final String licence,
    138                          final List contributors,
    139                          final ProjectInfo project) {
    140
    141            super(title);
    142
    143            this.application = application;
    144            this.version = version;
    145            this.copyright = copyright;
    146            this.info = info;
    147            this.logo = logo;
    148            this.contributors = contributors;
    149            this.licence = licence;
    150
    151            final String baseName = "org.jfree.ui.about.resources.AboutResources";
    152            this.resources = ResourceBundle.getBundle(baseName);
    153
    154            final JPanel content = new JPanel(new BorderLayout());
    155            content.setBorder(STANDARD_BORDER);
    156
    157            final JTabbedPane tabs = createTabs(project);
    158            content.add(tabs);
    159            setContentPane(content);
    160
    161            pack();
    162
    163        }
    164
    165        /**
    166         * Returns the preferred size for the about frame.
    167         *
    168         * @return the preferred size.
    169         */
    170        public Dimension getPreferredSize() {
    171            return PREFERRED_SIZE;
    172        }
    173
    174        /**
    175         * Creates a tabbed pane containing an about panel and a system properties panel.
    176         *
    177         * @return a tabbed pane.
    178         * @param project
    179         */
    180        private JTabbedPane createTabs(final ProjectInfo project) {
    181
    182            final JTabbedPane tabs = new JTabbedPane();
    183
    184            final JPanel aboutPanel = createAboutPanel(project);
    185            aboutPanel.setBorder(AboutFrame.STANDARD_BORDER);
    186            final String aboutTab = this.resources.getString("about-frame.tab.about");
    187            tabs.add(aboutTab, aboutPanel);
    188
    189            final JPanel systemPanel = new SystemPropertiesPanel();
    190            systemPanel.setBorder(AboutFrame.STANDARD_BORDER);
    191            final String systemTab = this.resources.getString("about-frame.tab.system");
    192            tabs.add(systemTab, systemPanel);
    193
    194            return tabs;
    195
    196        }
    197
    198        /**
    199         * Creates a panel showing information about the application, including the name, version,
    200         * copyright notice, URL for further information, and a list of contributors.
    201         *
    202         * @return a panel.
    203         * @param project
    204         */
    205        private JPanel createAboutPanel(final ProjectInfo project) {
    206
    207            final JPanel about = new JPanel(new BorderLayout());
    208
    209            final JPanel details = new AboutPanel(this.application, this.version, this.copyright, this.info,
    210                                            this.logo);
    211
    212            boolean includetabs = false;
    213            final JTabbedPane tabs = new JTabbedPane();
    214
    215            if (this.contributors != null) {
    216                final JPanel contributorsPanel = new ContributorsPanel(this.contributors);
    217                contributorsPanel.setBorder(AboutFrame.STANDARD_BORDER);
    218                final String contributorsTab = this.resources.getString("about-frame.tab.contributors");
    219                tabs.add(contributorsTab, contributorsPanel);
    220                includetabs = true;
    221            }
    222
    223            if (this.licence != null) {
    224                final JPanel licencePanel = createLicencePanel();
    225                licencePanel.setBorder(STANDARD_BORDER);
    226                final String licenceTab = this.resources.getString("about-frame.tab.licence");
    227                tabs.add(licenceTab, licencePanel);
    228                includetabs = true;
    229            }
    230
    231            if (project != null) {
    232                final JPanel librariesPanel = new LibraryPanel(project);
    233                librariesPanel.setBorder(AboutFrame.STANDARD_BORDER);
    234                final String librariesTab = this.resources.getString("about-frame.tab.libraries");
    235                tabs.add(librariesTab, librariesPanel);
    236                includetabs = true;
    237            }
    238
    239            about.add(details, BorderLayout.NORTH);
    240            if (includetabs) {
    241                about.add(tabs);
    242            }
    243
    244            return about;
    245
    246        }
    247
    248        /**
    249         * Creates a panel showing the licence.
    250         *
    251         * @return a panel.
    252         */
    253        private JPanel createLicencePanel() {
    254
    255            final JPanel licencePanel = new JPanel(new BorderLayout());
    256            final JTextArea area = new JTextArea(this.licence);
    257            area.setLineWrap(true);
    258            area.setWrapStyleWord(true);
    259            area.setCaretPosition(0);
    260            area.setEditable(false);
    261            licencePanel.add(new JScrollPane(area));
    262            return licencePanel;
    263
    264        }
    265
    266
    267    }