Source for org.jfree.ui.about.AboutDialog

   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: AboutDialog.java,v 1.4 2008/12/18 09:57:32 mungady Exp $
  36:  *
  37:  * Changes (from 26-Nov-2001)
  38:  * --------------------------
  39:  * 30-Jan-2006 : Version 1, based on the AboutFrame (TM);
  40:  * 18-Dec-2008 : Use ResourceBundleWrapper (DG);
  41:  *
  42:  */
  43: 
  44: package org.jfree.ui.about;
  45: 
  46: import java.awt.BorderLayout;
  47: import java.awt.Dialog;
  48: import java.awt.Dimension;
  49: import java.awt.Frame;
  50: import java.awt.Image;
  51: import java.util.List;
  52: import java.util.ResourceBundle;
  53: 
  54: import javax.swing.BorderFactory;
  55: import javax.swing.JDialog;
  56: import javax.swing.JPanel;
  57: import javax.swing.JScrollPane;
  58: import javax.swing.JTabbedPane;
  59: import javax.swing.JTextArea;
  60: import javax.swing.border.Border;
  61: 
  62: import org.jfree.util.ResourceBundleWrapper;
  63: 
  64: /**
  65:  * A dialog that displays information about the demonstration application.
  66:  *
  67:  * @author David Gilbert
  68:  */
  69: public class AboutDialog extends JDialog {
  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
  76:             = BorderFactory.createEmptyBorder(5, 5, 5, 5);
  77: 
  78:     /** Localised resources. */
  79:     private ResourceBundle resources;
  80: 
  81:     /** The application name. */
  82:     private String application;
  83: 
  84:     /** The application version. */
  85:     private String version;
  86: 
  87:     /** The copyright string. */
  88:     private String copyright;
  89: 
  90:     /** Other info about the application. */
  91:     private String info;
  92: 
  93:     /** The project logo. */
  94:     private Image logo;
  95: 
  96:     /** A list of contributors. */
  97:     private List contributors;
  98: 
  99:     /** 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: }