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, 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 */
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 }