Source for org.jfree.ui.about.AboutFrame

   1: /* ========================================================================
   2:  * JCommon : a free general purpose class library for the Java(tm) platform
   3:  * ========================================================================
   4:  *
   5:  * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jcommon/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it
  10:  * under the terms of the GNU Lesser General Public License as published by
  11:  * the Free Software Foundation; either version 2.1 of the License, or
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
  22:  * USA.
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  25:  * in the United States and other countries.]
  26:  *
  27:  * ---------------
  28:  * AboutFrame.java
  29:  * ---------------
  30:  * (C) Copyright 2001-2008, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: AboutFrame.java,v 1.8 2008/12/18 09:57:32 mungady Exp $
  36:  *
  37:  * Changes (from 26-Nov-2001)
  38:  * --------------------------
  39:  * 26-Nov-2001 : Version 1, based on code from JFreeChart demo application (DG);
  40:  * 27-Nov-2001 : Added getPreferredSize() method (DG);
  41:  * 08-Feb-2002 : List of developers is now optional (DG);
  42:  * 15-Mar-2002 : Modified to use a ResourceBundle for elements that require
  43:  *               localisation (DG);
  44:  * 25-Mar-2002 : Added new constructor (DG);
  45:  * 26-Jun-2002 : Removed redundant code (DG);
  46:  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  47:  * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
  48:  *               Jess Thrysoee (DG);
  49:  *
  50:  */
  51: 
  52: package org.jfree.ui.about;
  53: 
  54: import java.awt.BorderLayout;
  55: import java.awt.Dimension;
  56: import java.awt.Image;
  57: import java.util.List;
  58: import java.util.ResourceBundle;
  59: 
  60: import javax.swing.BorderFactory;
  61: import javax.swing.JFrame;
  62: import javax.swing.JPanel;
  63: import javax.swing.JScrollPane;
  64: import javax.swing.JTabbedPane;
  65: import javax.swing.JTextArea;
  66: import javax.swing.border.Border;
  67: 
  68: import org.jfree.util.ResourceBundleWrapper;
  69: 
  70: /**
  71:  * A frame that displays information about the demonstration application.
  72:  *
  73:  * @author David Gilbert
  74:  */
  75: public class AboutFrame extends JFrame {
  76: 
  77:     /** The preferred size for the frame. */
  78:     public static final Dimension PREFERRED_SIZE = new Dimension(560, 360);
  79: 
  80:     /** The default border for the panels in the tabbed pane. */
  81:     public static final Border STANDARD_BORDER
  82:             = BorderFactory.createEmptyBorder(5, 5, 5, 5);
  83: 
  84:     /** Localised resources. */
  85:     private ResourceBundle resources;
  86: 
  87:     /** The application name. */
  88:     private String application;
  89: 
  90:     /** The application version. */
  91:     private String version;
  92: 
  93:     /** The copyright string. */
  94:     private String copyright;
  95: 
  96:     /** Other info about the application. */
  97:     private String info;
  98: 
  99:     /** The project logo. */
 100:     private Image logo;
 101: 
 102:     /** A list of contributors. */
 103:     private List contributors;
 104: 
 105:     /** The licence. */
 106:     private String licence;
 107: 
 108:     /**
 109:      * Constructs an about frame.
 110:      *
 111:      * @param title  the frame title.
 112:      * @param project  information about the project.
 113:      */
 114:     public AboutFrame(final String title, final ProjectInfo project) {
 115: 
 116:         this(title,
 117:              project.getName(),
 118:              "Version " + project.getVersion(),
 119:              project.getInfo(),
 120:              project.getLogo(),
 121:              project.getCopyright(),
 122:              project.getLicenceText(),
 123:              project.getContributors(),
 124:              project);
 125: 
 126:     }
 127: 
 128:     /**
 129:      * Constructs an 'About' frame.
 130:      *
 131:      * @param title  the frame title.
 132:      * @param application  the application name.
 133:      * @param version  the version.
 134:      * @param info  other info.
 135:      * @param logo  an optional logo.
 136:      * @param copyright  the copyright notice.
 137:      * @param licence  the licence.
 138:      * @param contributors  a list of developers/contributors.
 139:      * @param project  info about the project.
 140:      */
 141:     public AboutFrame(final String title,
 142:                       final String application, final String version,
 143:                       final String info,
 144:                       final Image logo,
 145:                       final String copyright, final String licence,
 146:                       final List contributors,
 147:                       final ProjectInfo project) {
 148: 
 149:         super(title);
 150: 
 151:         this.application = application;
 152:         this.version = version;
 153:         this.copyright = copyright;
 154:         this.info = info;
 155:         this.logo = logo;
 156:         this.contributors = contributors;
 157:         this.licence = licence;
 158: 
 159:         final String baseName = "org.jfree.ui.about.resources.AboutResources";
 160:         this.resources = ResourceBundleWrapper.getBundle(baseName);
 161: 
 162:         final JPanel content = new JPanel(new BorderLayout());
 163:         content.setBorder(STANDARD_BORDER);
 164: 
 165:         final JTabbedPane tabs = createTabs(project);
 166:         content.add(tabs);
 167:         setContentPane(content);
 168: 
 169:         pack();
 170: 
 171:     }
 172: 
 173:     /**
 174:      * Returns the preferred size for the about frame.
 175:      *
 176:      * @return the preferred size.
 177:      */
 178:     public Dimension getPreferredSize() {
 179:         return PREFERRED_SIZE;
 180:     }
 181: 
 182:     /**
 183:      * Creates a tabbed pane containing an about panel and a system properties
 184:      * panel.
 185:      *
 186:      * @return a tabbed pane.
 187:      * @param project
 188:      */
 189:     private JTabbedPane createTabs(final ProjectInfo project) {
 190: 
 191:         final JTabbedPane tabs = new JTabbedPane();
 192: 
 193:         final JPanel aboutPanel = createAboutPanel(project);
 194:         aboutPanel.setBorder(AboutFrame.STANDARD_BORDER);
 195:         final String aboutTab = this.resources.getString(
 196:                 "about-frame.tab.about");
 197:         tabs.add(aboutTab, aboutPanel);
 198: 
 199:         final JPanel systemPanel = new SystemPropertiesPanel();
 200:         systemPanel.setBorder(AboutFrame.STANDARD_BORDER);
 201:         final String systemTab = this.resources.getString(
 202:                 "about-frame.tab.system");
 203:         tabs.add(systemTab, systemPanel);
 204: 
 205:         return tabs;
 206: 
 207:     }
 208: 
 209:     /**
 210:      * Creates a panel showing information about the application, including the
 211:      * name, version, copyright notice, URL for further information, and a list
 212:      * of contributors.
 213: 
 214:      * @param project
 215:      *
 216:      * @return a panel.
 217:      */
 218:     private JPanel createAboutPanel(final ProjectInfo project) {
 219: 
 220:         final JPanel about = new JPanel(new BorderLayout());
 221: 
 222:         final JPanel details = new AboutPanel(this.application, this.version,
 223:                 this.copyright, this.info, this.logo);
 224: 
 225:         boolean includetabs = false;
 226:         final JTabbedPane tabs = new JTabbedPane();
 227: 
 228:         if (this.contributors != null) {
 229:             final JPanel contributorsPanel = new ContributorsPanel(
 230:                     this.contributors);
 231:             contributorsPanel.setBorder(AboutFrame.STANDARD_BORDER);
 232:             final String contributorsTab = this.resources.getString(
 233:                     "about-frame.tab.contributors");
 234:             tabs.add(contributorsTab, contributorsPanel);
 235:             includetabs = true;
 236:         }
 237: 
 238:         if (this.licence != null) {
 239:             final JPanel licencePanel = createLicencePanel();
 240:             licencePanel.setBorder(STANDARD_BORDER);
 241:             final String licenceTab = this.resources.getString(
 242:                     "about-frame.tab.licence");
 243:             tabs.add(licenceTab, licencePanel);
 244:             includetabs = true;
 245:         }
 246: 
 247:         if (project != null) {
 248:             final JPanel librariesPanel = new LibraryPanel(project);
 249:             librariesPanel.setBorder(AboutFrame.STANDARD_BORDER);
 250:             final String librariesTab = this.resources.getString(
 251:                     "about-frame.tab.libraries");
 252:             tabs.add(librariesTab, librariesPanel);
 253:             includetabs = true;
 254:         }
 255: 
 256:         about.add(details, BorderLayout.NORTH);
 257:         if (includetabs) {
 258:             about.add(tabs);
 259:         }
 260: 
 261:         return about;
 262: 
 263:     }
 264: 
 265:     /**
 266:      * Creates a panel showing the licence.
 267:      *
 268:      * @return a panel.
 269:      */
 270:     private JPanel createLicencePanel() {
 271: 
 272:         final JPanel licencePanel = new JPanel(new BorderLayout());
 273:         final JTextArea area = new JTextArea(this.licence);
 274:         area.setLineWrap(true);
 275:         area.setWrapStyleWord(true);
 276:         area.setCaretPosition(0);
 277:         area.setEditable(false);
 278:         licencePanel.add(new JScrollPane(area));
 279:         return licencePanel;
 280: 
 281:     }
 282: 
 283: 
 284: }