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-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: AboutDialog.java,v 1.2 2006/03/23 19:47:05 taqua Exp $
  36:  *
  37:  * Changes (from 26-Nov-2001)
  38:  * --------------------------
  39:  * 30-Jan-2006 : Version 1, based on the AboutFrame (TM);
  40:  *
  41:  */
  42: 
  43: package org.jfree.ui.about;
  44: 
  45: import java.awt.BorderLayout;
  46: import java.awt.Dialog;
  47: import java.awt.Dimension;
  48: import java.awt.Frame;
  49: import java.awt.Image;
  50: import java.util.List;
  51: import java.util.ResourceBundle;
  52: import javax.swing.BorderFactory;
  53: import javax.swing.JDialog;
  54: import javax.swing.JPanel;
  55: import javax.swing.JScrollPane;
  56: import javax.swing.JTabbedPane;
  57: import javax.swing.JTextArea;
  58: import javax.swing.border.Border;
  59: 
  60: /**
  61:  * A dialog that displays information about the demonstration application.
  62:  *
  63:  * @author David Gilbert
  64:  */
  65: public class AboutDialog extends JDialog {
  66: 
  67:     /** The preferred size for the frame. */
  68:     public static final Dimension PREFERRED_SIZE = new Dimension(560, 360);
  69: 
  70:     /** The default border for the panels in the tabbed pane. */
  71:     public static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(5, 5, 5, 5);
  72: 
  73:     /** Localised resources. */
  74:     private ResourceBundle resources;
  75: 
  76:     /** The application name. */
  77:     private String application;
  78: 
  79:     /** The application version. */
  80:     private String version;
  81: 
  82:     /** The copyright string. */
  83:     private String copyright;
  84: 
  85:     /** Other info about the application. */
  86:     private String info;
  87: 
  88:     /** The project logo. */
  89:     private Image logo;
  90: 
  91:     /** A list of contributors. */
  92:     private List contributors;
  93: 
  94:     /** The licence. */
  95:     private String licence;
  96: 
  97:     /**
  98:      * Constructs an about frame.
  99:      *
 100:      * @param title  the frame title.
 101:      * @param project  information about the project.
 102:      */
 103:     public AboutDialog(final String title, final ProjectInfo project) {
 104: 
 105:         init(title,
 106:              project.getName(),
 107:              "Version " + project.getVersion(),
 108:              project.getInfo(),
 109:              project.getLogo(),
 110:              project.getCopyright(),
 111:              project.getLicenceText(),
 112:              project.getContributors(),
 113:              project);
 114: 
 115:     }
 116: 
 117:   /**
 118:    * Creates a non-modal dialog without a title with the specifed
 119:    * <code>Frame</code> as its owner.
 120:    *
 121:    * @param owner the <code>Frame</code> from which the dialog is displayed
 122:    */
 123:   public AboutDialog(final Frame owner,
 124:                      final String title,
 125:                      final ProjectInfo project)
 126:   {
 127:     super(owner);
 128:     init(title,
 129:          project.getName(),
 130:          "Version " + project.getVersion(),
 131:          project.getInfo(),
 132:          project.getLogo(),
 133:          project.getCopyright(),
 134:          project.getLicenceText(),
 135:          project.getContributors(),
 136:          project);
 137:   }
 138: 
 139:   /**
 140:    * Creates a non-modal dialog without a title with the specifed
 141:    * <code>Dialog</code> as its owner.
 142:    *
 143:    * @param owner the <code>Dialog</code> from which the dialog is displayed
 144:    */
 145:   public AboutDialog(final Dialog owner,
 146:                      final String title,
 147:                      final ProjectInfo project)
 148:   {
 149:     super(owner);
 150:     init(title,
 151:          project.getName(),
 152:          "Version " + project.getVersion(),
 153:          project.getInfo(),
 154:          project.getLogo(),
 155:          project.getCopyright(),
 156:          project.getLicenceText(),
 157:          project.getContributors(),
 158:          project);
 159:   }
 160: 
 161:   /**
 162:      * Constructs an 'About' frame.
 163:      *
 164:      * @param title  the frame title.
 165:      * @param application  the application name.
 166:      * @param version  the version.
 167:      * @param info  other info.
 168:      * @param logo  an optional logo.
 169:      * @param copyright  the copyright notice.
 170:      * @param licence  the licence.
 171:      * @param contributors  a list of developers/contributors.
 172:      * @param libraries  a list of libraries.
 173:      */
 174:     private void init (final String title,
 175:                        final String application,
 176:                        final String version,
 177:                        final String info,
 178:                        final Image logo,
 179:                        final String copyright,
 180:                        final String licence,
 181:                        final List contributors,
 182:                        final ProjectInfo libraries) {
 183: 
 184:         setTitle(title);
 185: 
 186:         this.application = application;
 187:         this.version = version;
 188:         this.copyright = copyright;
 189:         this.info = info;
 190:         this.logo = logo;
 191:         this.contributors = contributors;
 192:         this.licence = licence;
 193: 
 194:         final String baseName = "org.jfree.ui.about.resources.AboutResources";
 195:         this.resources = ResourceBundle.getBundle(baseName);
 196: 
 197:         final JPanel content = new JPanel(new BorderLayout());
 198:         content.setBorder(STANDARD_BORDER);
 199: 
 200:         final JTabbedPane tabs = createTabs(libraries);
 201:         content.add(tabs);
 202:         setContentPane(content);
 203: 
 204:         pack();
 205: 
 206:     }
 207: 
 208:     /**
 209:      * Returns the preferred size for the about frame.
 210:      *
 211:      * @return the preferred size.
 212:      */
 213:     public Dimension getPreferredSize() {
 214:         return PREFERRED_SIZE;
 215:     }
 216: 
 217:     /**
 218:      * Creates a tabbed pane containing an about panel and a system properties panel.
 219:      *
 220:      * @return a tabbed pane.
 221:      */
 222:     private JTabbedPane createTabs(final ProjectInfo info) {
 223: 
 224:         final JTabbedPane tabs = new JTabbedPane();
 225: 
 226:         final JPanel aboutPanel = createAboutPanel(info);
 227:         aboutPanel.setBorder(AboutDialog.STANDARD_BORDER);
 228:         final String aboutTab = this.resources.getString("about-frame.tab.about");
 229:         tabs.add(aboutTab, aboutPanel);
 230: 
 231:         final JPanel systemPanel = new SystemPropertiesPanel();
 232:         systemPanel.setBorder(AboutDialog.STANDARD_BORDER);
 233:         final String systemTab = this.resources.getString("about-frame.tab.system");
 234:         tabs.add(systemTab, systemPanel);
 235: 
 236:         return tabs;
 237: 
 238:     }
 239: 
 240:     /**
 241:      * Creates a panel showing information about the application, including the name, version,
 242:      * copyright notice, URL for further information, and a list of contributors.
 243:      *
 244:      * @return a panel.
 245:      */
 246:     private JPanel createAboutPanel(final ProjectInfo info) {
 247: 
 248:         final JPanel about = new JPanel(new BorderLayout());
 249: 
 250:         final JPanel details = new AboutPanel(this.application, this.version, this.copyright, this.info,
 251:                                         this.logo);
 252: 
 253:         boolean includetabs = false;
 254:         final JTabbedPane tabs = new JTabbedPane();
 255: 
 256:         if (this.contributors != null) {
 257:             final JPanel contributorsPanel = new ContributorsPanel(this.contributors);
 258:             contributorsPanel.setBorder(AboutDialog.STANDARD_BORDER);
 259:             final String contributorsTab = this.resources.getString("about-frame.tab.contributors");
 260:             tabs.add(contributorsTab, contributorsPanel);
 261:             includetabs = true;
 262:         }
 263: 
 264:         if (this.licence != null) {
 265:             final JPanel licencePanel = createLicencePanel();
 266:             licencePanel.setBorder(STANDARD_BORDER);
 267:             final String licenceTab = this.resources.getString("about-frame.tab.licence");
 268:             tabs.add(licenceTab, licencePanel);
 269:             includetabs = true;
 270:         }
 271: 
 272:         if (info != null) {
 273:             final JPanel librariesPanel = new LibraryPanel(info);
 274:             librariesPanel.setBorder(AboutDialog.STANDARD_BORDER);
 275:             final String librariesTab = this.resources.getString("about-frame.tab.libraries");
 276:             tabs.add(librariesTab, librariesPanel);
 277:             includetabs = true;
 278:         }
 279: 
 280:         about.add(details, BorderLayout.NORTH);
 281:         if (includetabs) {
 282:             about.add(tabs);
 283:         }
 284: 
 285:         return about;
 286: 
 287:     }
 288: 
 289:     /**
 290:      * Creates a panel showing the licence.
 291:      *
 292:      * @return a panel.
 293:      */
 294:     private JPanel createLicencePanel() {
 295: 
 296:         final JPanel licencePanel = new JPanel(new BorderLayout());
 297:         final JTextArea area = new JTextArea(this.licence);
 298:         area.setLineWrap(true);
 299:         area.setWrapStyleWord(true);
 300:         area.setCaretPosition(0);
 301:         area.setEditable(false);
 302:         licencePanel.add(new JScrollPane(area));
 303:         return licencePanel;
 304: 
 305:     }
 306: 
 307: 
 308: }