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.2 2006/03/23 19:47:05 taqua 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,
069: 360);
070:
071: /** The default border for the panels in the tabbed pane. */
072: public static final Border STANDARD_BORDER = BorderFactory
073: .createEmptyBorder(5, 5, 5, 5);
074:
075: /** Localised resources. */
076: private ResourceBundle resources;
077:
078: /** The application name. */
079: private String application;
080:
081: /** The application version. */
082: private String version;
083:
084: /** The copyright string. */
085: private String copyright;
086:
087: /** Other info about the application. */
088: private String info;
089:
090: /** The project logo. */
091: private Image logo;
092:
093: /** A list of contributors. */
094: private List contributors;
095:
096: /** The licence. */
097: private String licence;
098:
099: /**
100: * Constructs an about frame.
101: *
102: * @param title the frame title.
103: * @param project information about the project.
104: */
105: public AboutDialog(final String title, final ProjectInfo project) {
106:
107: init(title, project.getName(), "Version "
108: + project.getVersion(), project.getInfo(), project
109: .getLogo(), project.getCopyright(), project
110: .getLicenceText(), project.getContributors(), project);
111:
112: }
113:
114: /**
115: * Creates a non-modal dialog without a title with the specifed
116: * <code>Frame</code> as its owner.
117: *
118: * @param owner the <code>Frame</code> from which the dialog is displayed
119: */
120: public AboutDialog(final Frame owner, final String title,
121: final ProjectInfo project) {
122: super (owner);
123: init(title, project.getName(), "Version "
124: + project.getVersion(), project.getInfo(), project
125: .getLogo(), project.getCopyright(), project
126: .getLicenceText(), project.getContributors(), project);
127: }
128:
129: /**
130: * Creates a non-modal dialog without a title with the specifed
131: * <code>Dialog</code> as its owner.
132: *
133: * @param owner the <code>Dialog</code> from which the dialog is displayed
134: */
135: public AboutDialog(final Dialog owner, final String title,
136: final ProjectInfo project) {
137: super (owner);
138: init(title, project.getName(), "Version "
139: + project.getVersion(), project.getInfo(), project
140: .getLogo(), project.getCopyright(), project
141: .getLicenceText(), project.getContributors(), project);
142: }
143:
144: /**
145: * Constructs an 'About' frame.
146: *
147: * @param title the frame title.
148: * @param application the application name.
149: * @param version the version.
150: * @param info other info.
151: * @param logo an optional logo.
152: * @param copyright the copyright notice.
153: * @param licence the licence.
154: * @param contributors a list of developers/contributors.
155: * @param libraries a list of libraries.
156: */
157: private void init(final String title, final String application,
158: final String version, final String info, final Image logo,
159: final String copyright, final String licence,
160: final List contributors, final ProjectInfo libraries) {
161:
162: setTitle(title);
163:
164: this .application = application;
165: this .version = version;
166: this .copyright = copyright;
167: this .info = info;
168: this .logo = logo;
169: this .contributors = contributors;
170: this .licence = licence;
171:
172: final String baseName = "org.jfree.ui.about.resources.AboutResources";
173: this .resources = ResourceBundle.getBundle(baseName);
174:
175: final JPanel content = new JPanel(new BorderLayout());
176: content.setBorder(STANDARD_BORDER);
177:
178: final JTabbedPane tabs = createTabs(libraries);
179: content.add(tabs);
180: setContentPane(content);
181:
182: pack();
183:
184: }
185:
186: /**
187: * Returns the preferred size for the about frame.
188: *
189: * @return the preferred size.
190: */
191: public Dimension getPreferredSize() {
192: return PREFERRED_SIZE;
193: }
194:
195: /**
196: * Creates a tabbed pane containing an about panel and a system properties panel.
197: *
198: * @return a tabbed pane.
199: */
200: private JTabbedPane createTabs(final ProjectInfo info) {
201:
202: final JTabbedPane tabs = new JTabbedPane();
203:
204: final JPanel aboutPanel = createAboutPanel(info);
205: aboutPanel.setBorder(AboutDialog.STANDARD_BORDER);
206: final String aboutTab = this .resources
207: .getString("about-frame.tab.about");
208: tabs.add(aboutTab, aboutPanel);
209:
210: final JPanel systemPanel = new SystemPropertiesPanel();
211: systemPanel.setBorder(AboutDialog.STANDARD_BORDER);
212: final String systemTab = this .resources
213: .getString("about-frame.tab.system");
214: tabs.add(systemTab, systemPanel);
215:
216: return tabs;
217:
218: }
219:
220: /**
221: * Creates a panel showing information about the application, including the name, version,
222: * copyright notice, URL for further information, and a list of contributors.
223: *
224: * @return a panel.
225: */
226: private JPanel createAboutPanel(final ProjectInfo info) {
227:
228: final JPanel about = new JPanel(new BorderLayout());
229:
230: final JPanel details = new AboutPanel(this .application,
231: this .version, this .copyright, this .info, this .logo);
232:
233: boolean includetabs = false;
234: final JTabbedPane tabs = new JTabbedPane();
235:
236: if (this .contributors != null) {
237: final JPanel contributorsPanel = new ContributorsPanel(
238: this .contributors);
239: contributorsPanel.setBorder(AboutDialog.STANDARD_BORDER);
240: final String contributorsTab = this .resources
241: .getString("about-frame.tab.contributors");
242: tabs.add(contributorsTab, contributorsPanel);
243: includetabs = true;
244: }
245:
246: if (this .licence != null) {
247: final JPanel licencePanel = createLicencePanel();
248: licencePanel.setBorder(STANDARD_BORDER);
249: final String licenceTab = this .resources
250: .getString("about-frame.tab.licence");
251: tabs.add(licenceTab, licencePanel);
252: includetabs = true;
253: }
254:
255: if (info != null) {
256: final JPanel librariesPanel = new LibraryPanel(info);
257: librariesPanel.setBorder(AboutDialog.STANDARD_BORDER);
258: final String librariesTab = this .resources
259: .getString("about-frame.tab.libraries");
260: tabs.add(librariesTab, librariesPanel);
261: includetabs = true;
262: }
263:
264: about.add(details, BorderLayout.NORTH);
265: if (includetabs) {
266: about.add(tabs);
267: }
268:
269: return about;
270:
271: }
272:
273: /**
274: * Creates a panel showing the licence.
275: *
276: * @return a panel.
277: */
278: private JPanel createLicencePanel() {
279:
280: final JPanel licencePanel = new JPanel(new BorderLayout());
281: final JTextArea area = new JTextArea(this .licence);
282: area.setLineWrap(true);
283: area.setWrapStyleWord(true);
284: area.setCaretPosition(0);
285: area.setEditable(false);
286: licencePanel.add(new JScrollPane(area));
287: return licencePanel;
288:
289: }
290:
291: }
|