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: AboutDialog.java,v 1.3 2008/09/10 09:18:13 mungady Exp $ 036 * 037 * Changes (from 26-Nov-2001) 038 * -------------------------- 039 * 30-Jan-2006 : Version 1, based on the AboutFrame (TM); 040 * 041 */ 042 043 package org.jfree.ui.about; 044 045 import java.awt.BorderLayout; 046 import java.awt.Dialog; 047 import java.awt.Dimension; 048 import java.awt.Frame; 049 import java.awt.Image; 050 import java.util.List; 051 import java.util.ResourceBundle; 052 import javax.swing.BorderFactory; 053 import javax.swing.JDialog; 054 import javax.swing.JPanel; 055 import javax.swing.JScrollPane; 056 import javax.swing.JTabbedPane; 057 import javax.swing.JTextArea; 058 import javax.swing.border.Border; 059 060 /** 061 * A dialog that displays information about the demonstration application. 062 * 063 * @author David Gilbert 064 */ 065 public class AboutDialog extends JDialog { 066 067 /** The preferred size for the frame. */ 068 public static final Dimension PREFERRED_SIZE = new Dimension(560, 360); 069 070 /** The default border for the panels in the tabbed pane. */ 071 public static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(5, 5, 5, 5); 072 073 /** Localised resources. */ 074 private ResourceBundle resources; 075 076 /** The application name. */ 077 private String application; 078 079 /** The application version. */ 080 private String version; 081 082 /** The copyright string. */ 083 private String copyright; 084 085 /** Other info about the application. */ 086 private String info; 087 088 /** The project logo. */ 089 private Image logo; 090 091 /** A list of contributors. */ 092 private List contributors; 093 094 /** The licence. */ 095 private String licence; 096 097 /** 098 * Constructs an about frame. 099 * 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 * @param title the title, 123 * @param project the project. 124 */ 125 public AboutDialog(final Frame owner, 126 final String title, 127 final ProjectInfo project) 128 { 129 super(owner); 130 init(title, 131 project.getName(), 132 "Version " + project.getVersion(), 133 project.getInfo(), 134 project.getLogo(), 135 project.getCopyright(), 136 project.getLicenceText(), 137 project.getContributors(), 138 project); 139 } 140 141 /** 142 * Creates a non-modal dialog without a title with the specifed 143 * <code>Dialog</code> as its owner. 144 * 145 * @param owner the <code>Dialog</code> from which the dialog is displayed. 146 * @param title the title. 147 * @param project the project. 148 */ 149 public AboutDialog(final Dialog owner, 150 final String title, 151 final ProjectInfo project) 152 { 153 super(owner); 154 init(title, 155 project.getName(), 156 "Version " + project.getVersion(), 157 project.getInfo(), 158 project.getLogo(), 159 project.getCopyright(), 160 project.getLicenceText(), 161 project.getContributors(), 162 project); 163 } 164 165 /** 166 * Constructs an 'About' frame. 167 * 168 * @param title the frame title. 169 * @param application the application name. 170 * @param version the version. 171 * @param info other info. 172 * @param logo an optional logo. 173 * @param copyright the copyright notice. 174 * @param licence the licence. 175 * @param contributors a list of developers/contributors. 176 * @param libraries a list of libraries. 177 */ 178 private void init (final String title, 179 final String application, 180 final String version, 181 final String info, 182 final Image logo, 183 final String copyright, 184 final String licence, 185 final List contributors, 186 final ProjectInfo libraries) { 187 188 setTitle(title); 189 190 this.application = application; 191 this.version = version; 192 this.copyright = copyright; 193 this.info = info; 194 this.logo = logo; 195 this.contributors = contributors; 196 this.licence = licence; 197 198 final String baseName = "org.jfree.ui.about.resources.AboutResources"; 199 this.resources = ResourceBundle.getBundle(baseName); 200 201 final JPanel content = new JPanel(new BorderLayout()); 202 content.setBorder(STANDARD_BORDER); 203 204 final JTabbedPane tabs = createTabs(libraries); 205 content.add(tabs); 206 setContentPane(content); 207 208 pack(); 209 210 } 211 212 /** 213 * Returns the preferred size for the about frame. 214 * 215 * @return the preferred size. 216 */ 217 public Dimension getPreferredSize() { 218 return PREFERRED_SIZE; 219 } 220 221 /** 222 * Creates a tabbed pane containing an about panel and a system properties panel. 223 * 224 * @param info project information. 225 * 226 * @return a tabbed pane. 227 */ 228 private JTabbedPane createTabs(final ProjectInfo info) { 229 230 final JTabbedPane tabs = new JTabbedPane(); 231 232 final JPanel aboutPanel = createAboutPanel(info); 233 aboutPanel.setBorder(AboutDialog.STANDARD_BORDER); 234 final String aboutTab = this.resources.getString("about-frame.tab.about"); 235 tabs.add(aboutTab, aboutPanel); 236 237 final JPanel systemPanel = new SystemPropertiesPanel(); 238 systemPanel.setBorder(AboutDialog.STANDARD_BORDER); 239 final String systemTab = this.resources.getString("about-frame.tab.system"); 240 tabs.add(systemTab, systemPanel); 241 242 return tabs; 243 244 } 245 246 /** 247 * Creates a panel showing information about the application, including the name, version, 248 * copyright notice, URL for further information, and a list of contributors. 249 * 250 * @param info project info. 251 * 252 * @return a panel. 253 */ 254 private JPanel createAboutPanel(final ProjectInfo info) { 255 256 final JPanel about = new JPanel(new BorderLayout()); 257 258 final JPanel details = new AboutPanel(this.application, this.version, this.copyright, this.info, 259 this.logo); 260 261 boolean includetabs = false; 262 final JTabbedPane tabs = new JTabbedPane(); 263 264 if (this.contributors != null) { 265 final JPanel contributorsPanel = new ContributorsPanel(this.contributors); 266 contributorsPanel.setBorder(AboutDialog.STANDARD_BORDER); 267 final String contributorsTab = this.resources.getString("about-frame.tab.contributors"); 268 tabs.add(contributorsTab, contributorsPanel); 269 includetabs = true; 270 } 271 272 if (this.licence != null) { 273 final JPanel licencePanel = createLicencePanel(); 274 licencePanel.setBorder(STANDARD_BORDER); 275 final String licenceTab = this.resources.getString("about-frame.tab.licence"); 276 tabs.add(licenceTab, licencePanel); 277 includetabs = true; 278 } 279 280 if (info != null) { 281 final JPanel librariesPanel = new LibraryPanel(info); 282 librariesPanel.setBorder(AboutDialog.STANDARD_BORDER); 283 final String librariesTab = this.resources.getString("about-frame.tab.libraries"); 284 tabs.add(librariesTab, librariesPanel); 285 includetabs = true; 286 } 287 288 about.add(details, BorderLayout.NORTH); 289 if (includetabs) { 290 about.add(tabs); 291 } 292 293 return about; 294 295 } 296 297 /** 298 * Creates a panel showing the licence. 299 * 300 * @return a panel. 301 */ 302 private JPanel createLicencePanel() { 303 304 final JPanel licencePanel = new JPanel(new BorderLayout()); 305 final JTextArea area = new JTextArea(this.licence); 306 area.setLineWrap(true); 307 area.setWrapStyleWord(true); 308 area.setCaretPosition(0); 309 area.setEditable(false); 310 licencePanel.add(new JScrollPane(area)); 311 return licencePanel; 312 313 } 314 315 316 }