    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.4 2005/10/18 13:19:13 mungady 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.Arrays;
    055    import java.util.List;
    056    import java.util.ResourceBundle;
    057
    058    import javax.swing.BorderFactory;
    059    import javax.swing.JFrame;
    060    import javax.swing.JPanel;
    061    import javax.swing.JScrollPane;
    062    import javax.swing.JTabbedPane;
    063    import javax.swing.JTextArea;
    064    import javax.swing.border.Border;
    065
    066    /**
    067     * A frame that displays information about the demonstration application.
    068     *
    069     * @author David Gilbert
    070     */
    071    public class AboutFrame extends JFrame {
    072
    073        /** The preferred size for the frame. */
    074        public static final Dimension PREFERRED_SIZE = new Dimension(560, 360);
    075
    076        /** The default border for the panels in the tabbed pane. */
    077        public static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    078
    079        /** Localised resources. */
    080        private ResourceBundle resources;
    081
    082        /** The application name. */
    083        private String application;
    084
    085        /** The application version. */
    086        private String version;
    087
    088        /** The copyright string. */
    089        private String copyright;
    090
    091        /** Other info about the application. */
    092        private String info;
    093
    094        /** The project logo. */
    095        private Image logo;
    096
    097        /** A list of contributors. */
    098        private List contributors;
    099
    100        /** The licence. */
    101        private String licence;
    102
    103        /** A list of libraries. */
    104        private List libraries;
    105
    106        /**
    107         * Constructs an about frame.
    108         *
    109         * @param title  the frame title.
    110         * @param project  information about the project.
    111         */
    112        public AboutFrame(final String title, final ProjectInfo project) {
    113
    114            this(title,
    115                 project.getName(),
    116                 "Version " + project.getVersion(),
    117                 project.getInfo(),
    118                 project.getLogo(),
    119                 project.getCopyright(),
    120                 project.getLicenceText(),
    121                 project.getContributors(),
    122                 Arrays.asList(project.getLibraries()));
    123
    124        }
    125
    126        /**
    127         * Constructs an 'About' frame.
    128         *
    129         * @param title  the frame title.
    130         * @param application  the application name.
    131         * @param version  the version.
    132         * @param info  other info.
    133         * @param logo  an optional logo.
    134         * @param copyright  the copyright notice.
    135         * @param licence  the licence.
    136         * @param contributors  a list of developers/contributors.
    137         * @param libraries  a list of libraries.
    138         */
    139        public AboutFrame(final String title,
    140                          final String application, final String version, final String info,
    141                          final Image logo,
    142                          final String copyright, final String licence,
    143                          final List contributors,
    144                          final List libraries) {
    145
    146            super(title);
    147
    148            this.application = application;
    149            this.version = version;
    150            this.copyright = copyright;
    151            this.info = info;
    152            this.logo = logo;
    153            this.contributors = contributors;
    154            this.licence = licence;
    155            this.libraries = libraries;
    156
    157            final String baseName = "org.jfree.ui.about.resources.AboutResources";
    158            this.resources = ResourceBundle.getBundle(baseName);
    159
    160            final JPanel content = new JPanel(new BorderLayout());
    161            content.setBorder(STANDARD_BORDER);
    162
    163            final JTabbedPane tabs = createTabs();
    164            content.add(tabs);
    165            setContentPane(content);
    166
    167            pack();
    168
    169        }
    170
    171        /**
    172         * Returns the preferred size for the about frame.
    173         *
    174         * @return the preferred size.
    175         */
    176        public Dimension getPreferredSize() {
    177            return PREFERRED_SIZE;
    178        }
    179
    180        /**
    181         * Creates a tabbed pane containing an about panel and a system properties panel.
    182         *
    183         * @return a tabbed pane.
    184         */
    185        private JTabbedPane createTabs() {
    186
    187            final JTabbedPane tabs = new JTabbedPane();
    188
    189            final JPanel aboutPanel = createAboutPanel();
    190            aboutPanel.setBorder(AboutFrame.STANDARD_BORDER);
    191            final String aboutTab = this.resources.getString("about-frame.tab.about");
    192            tabs.add(aboutTab, aboutPanel);
    193
    194            final JPanel systemPanel = new SystemPropertiesPanel();
    195            systemPanel.setBorder(AboutFrame.STANDARD_BORDER);
    196            final String systemTab = this.resources.getString("about-frame.tab.system");
    197            tabs.add(systemTab, systemPanel);
    198
    199            return tabs;
    200
    201        }
    202
    203        /**
    204         * Creates a panel showing information about the application, including the name, version,
    205         * copyright notice, URL for further information, and a list of contributors.
    206         *
    207         * @return a panel.
    208         */
    209        private JPanel createAboutPanel() {
    210
    211            final JPanel about = new JPanel(new BorderLayout());
    212
    213            final JPanel details = new AboutPanel(this.application, this.version, this.copyright, this.info,
    214                                            this.logo);
    215
    216            boolean includetabs = false;
    217            final JTabbedPane tabs = new JTabbedPane();
    218
    219            if (this.contributors != null) {
    220                final JPanel contributorsPanel = new ContributorsPanel(this.contributors);
    221                contributorsPanel.setBorder(AboutFrame.STANDARD_BORDER);
    222                final String contributorsTab = this.resources.getString("about-frame.tab.contributors");
    223                tabs.add(contributorsTab, contributorsPanel);
    224                includetabs = true;
    225            }
    226
    227            if (this.licence != null) {
    228                final JPanel licencePanel = createLicencePanel();
    229                licencePanel.setBorder(STANDARD_BORDER);
    230                final String licenceTab = this.resources.getString("about-frame.tab.licence");
    231                tabs.add(licenceTab, licencePanel);
    232                includetabs = true;
    233            }
    234
    235            if (this.libraries != null) {
    236                final JPanel librariesPanel = new LibraryPanel(this.libraries);
    237                librariesPanel.setBorder(AboutFrame.STANDARD_BORDER);
    238                final String librariesTab = this.resources.getString("about-frame.tab.libraries");
    239                tabs.add(librariesTab, librariesPanel);
    240                includetabs = true;
    241            }
    242
    243            about.add(details, BorderLayout.NORTH);
    244            if (includetabs) {
    245                about.add(tabs);
    246            }
    247
    248            return about;
    249
    250        }
    251
    252        /**
    253         * Creates a panel showing the licence.
    254         *
    255         * @return a panel.
    256         */
    257        private JPanel createLicencePanel() {
    258
    259            final JPanel licencePanel = new JPanel(new BorderLayout());
    260            final JTextArea area = new JTextArea(this.licence);
    261            area.setLineWrap(true);
    262            area.setWrapStyleWord(true);
    263            area.setCaretPosition(0);
    264            area.setEditable(false);
    265            licencePanel.add(new JScrollPane(area));
    266            return licencePanel;
    267
    268        }
    269
    270
    271    }