KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > 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 JavaDoc;
46 import java.awt.Dialog JavaDoc;
47 import java.awt.Dimension JavaDoc;
48 import java.awt.Frame JavaDoc;
49 import java.awt.Image JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.ResourceBundle JavaDoc;
52 import javax.swing.BorderFactory JavaDoc;
53 import javax.swing.JDialog JavaDoc;
54 import javax.swing.JPanel JavaDoc;
55 import javax.swing.JScrollPane JavaDoc;
56 import javax.swing.JTabbedPane JavaDoc;
57 import javax.swing.JTextArea JavaDoc;
58 import javax.swing.border.Border JavaDoc;
59
60 /**
61  * A dialog that displays information about the demonstration application.
62  *
63  * @author David Gilbert
64  */

65 public class AboutDialog extends JDialog JavaDoc {
66
67     /** The preferred size for the frame. */
68     public static final Dimension JavaDoc PREFERRED_SIZE = new Dimension JavaDoc(560, 360);
69
70     /** The default border for the panels in the tabbed pane. */
71     public static final Border JavaDoc STANDARD_BORDER = BorderFactory.createEmptyBorder(5, 5, 5, 5);
72
73     /** Localised resources. */
74     private ResourceBundle JavaDoc resources;
75
76     /** The application name. */
77     private String JavaDoc application;
78
79     /** The application version. */
80     private String JavaDoc version;
81
82     /** The copyright string. */
83     private String JavaDoc copyright;
84
85     /** Other info about the application. */
86     private String JavaDoc info;
87
88     /** The project logo. */
89     private Image JavaDoc logo;
90
91     /** A list of contributors. */
92     private List JavaDoc contributors;
93
94     /** The licence. */
95     private String JavaDoc 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 JavaDoc 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 JavaDoc owner,
124                      final String JavaDoc 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 JavaDoc owner,
146                      final String JavaDoc 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 JavaDoc title,
175                        final String JavaDoc application,
176                        final String JavaDoc version,
177                        final String JavaDoc info,
178                        final Image JavaDoc logo,
179                        final String JavaDoc copyright,
180                        final String JavaDoc licence,
181                        final List JavaDoc 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 JavaDoc baseName = "org.jfree.ui.about.resources.AboutResources";
195         this.resources = ResourceBundle.getBundle(baseName);
196
197         final JPanel JavaDoc content = new JPanel JavaDoc(new BorderLayout JavaDoc());
198         content.setBorder(STANDARD_BORDER);
199
200         final JTabbedPane JavaDoc 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 JavaDoc 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 JavaDoc createTabs(final ProjectInfo info) {
223
224         final JTabbedPane JavaDoc tabs = new JTabbedPane JavaDoc();
225
226         final JPanel JavaDoc aboutPanel = createAboutPanel(info);
227         aboutPanel.setBorder(AboutDialog.STANDARD_BORDER);
228         final String JavaDoc aboutTab = this.resources.getString("about-frame.tab.about");
229         tabs.add(aboutTab, aboutPanel);
230
231         final JPanel JavaDoc systemPanel = new SystemPropertiesPanel();
232         systemPanel.setBorder(AboutDialog.STANDARD_BORDER);
233         final String JavaDoc 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 JavaDoc createAboutPanel(final ProjectInfo info) {
247
248         final JPanel JavaDoc about = new JPanel JavaDoc(new BorderLayout JavaDoc());
249
250         final JPanel JavaDoc details = new AboutPanel(this.application, this.version, this.copyright, this.info,
251                                         this.logo);
252
253         boolean includetabs = false;
254         final JTabbedPane JavaDoc tabs = new JTabbedPane JavaDoc();
255
256         if (this.contributors != null) {
257             final JPanel JavaDoc contributorsPanel = new ContributorsPanel(this.contributors);
258             contributorsPanel.setBorder(AboutDialog.STANDARD_BORDER);
259             final String JavaDoc 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 JavaDoc licencePanel = createLicencePanel();
266             licencePanel.setBorder(STANDARD_BORDER);
267             final String JavaDoc 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 JavaDoc librariesPanel = new LibraryPanel(info);
274             librariesPanel.setBorder(AboutDialog.STANDARD_BORDER);
275             final String JavaDoc 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 JavaDoc createLicencePanel() {
295
296         final JPanel JavaDoc licencePanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
297         final JTextArea JavaDoc area = new JTextArea JavaDoc(this.licence);
298         area.setLineWrap(true);
299         area.setWrapStyleWord(true);
300         area.setCaretPosition(0);
301         area.setEditable(false);
302         licencePanel.add(new JScrollPane JavaDoc(area));
303         return licencePanel;
304
305     }
306
307
308 }
309
Popular Tags