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-2005, 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-2004, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: AboutFrame.java,v 1.6 2006/03/23 19:47:05 taqua 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 localisation (DG);
  43:  * 25-Mar-2002 : Added new constructor (DG);
  44:  * 26-Jun-2002 : Removed redundant code (DG);
  45:  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  46:  *
  47:  */
  48: 
  49: package org.jfree.ui.about;
  50: 
  51: import java.awt.BorderLayout;
  52: import java.awt.Dimension;
  53: import java.awt.Image;
  54: import java.util.List;
  55: import java.util.ResourceBundle;
  56: import javax.swing.BorderFactory;
  57: import javax.swing.JFrame;
  58: import javax.swing.JPanel;
  59: import javax.swing.JScrollPane;
  60: import javax.swing.JTabbedPane;
  61: import javax.swing.JTextArea;
  62: import javax.swing.border.Border;
  63: 
  64: /**
  65:  * A frame that displays information about the demonstration application.
  66:  *
  67:  * @author David Gilbert
  68:  */
  69: public class AboutFrame extends JFrame {
  70: 
  71:     /** The preferred size for the frame. */
  72:     public static final Dimension PREFERRED_SIZE = new Dimension(560, 360);
  73: 
  74:     /** The default border for the panels in the tabbed pane. */
  75:     public static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(5, 5, 5, 5);
  76: 
  77:     /** Localised resources. */
  78:     private ResourceBundle resources;
  79: 
  80:     /** The application name. */
  81:     private String application;
  82: 
  83:     /** The application version. */
  84:     private String version;
  85: 
  86:     /** The copyright string. */
  87:     private String copyright;
  88: 
  89:     /** Other info about the application. */
  90:     private String info;
  91: 
  92:     /** The project logo. */
  93:     private Image logo;
  94: 
  95:     /** A list of contributors. */
  96:     private List contributors;
  97: 
  98:     /** The licence. */
  99:     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: }