2 * jSite2 - AboutDialog.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.FlowLayout;
25 import java.awt.event.ActionEvent;
26 import java.io.ByteArrayOutputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.UnsupportedEncodingException;
30 import java.util.ArrayList;
31 import java.util.List;
33 import javax.swing.BorderFactory;
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.JButton;
37 import javax.swing.JComponent;
38 import javax.swing.JDialog;
39 import javax.swing.JLabel;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.JTabbedPane;
43 import javax.swing.JTextArea;
44 import javax.swing.SwingConstants;
46 import net.pterodactylus.jsite.i18n.I18n;
47 import net.pterodactylus.jsite.i18n.I18nable;
48 import net.pterodactylus.jsite.i18n.gui.I18nAction;
49 import net.pterodactylus.jsite.i18n.gui.I18nLabel;
50 import net.pterodactylus.jsite.main.Version;
51 import net.pterodactylus.util.io.StreamCopier;
52 import net.pterodactylus.util.swing.SwingUtils;
57 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
59 public class AboutDialog extends JDialog implements I18nable {
61 /** A list of all contributors. */
62 private static final List<Contributor> CONTRIBUTORS = new ArrayList<Contributor>();
64 /** A list of all code usages. */
65 private static final List<CodeUsage> CODE_USAGES = new ArrayList<CodeUsage>();
68 CONTRIBUTORS.add(new Contributor("David ‘Bombe’ Roden", "bombe@freenetproject.org", "Main code"));
69 CODE_USAGES.add(new CodeUsage("Tango Desktop Project", "http://tango.freedesktop.org/", "Creative Commons Attribution-Share Alike 2.5", "Icons"));
72 /** The “okay” button action. */
73 private I18nAction okayAction;
75 /** The contributors label. */
76 private I18nLabel contributorsLabel;
78 /** The i18n maintainer label. */
79 private I18nLabel i18nMaintainerLabel;
81 /** The i18n maintainer’s name label. */
82 private JLabel i18nMaintainerNameLabel;
84 /** The “other people’s code used” label. */
85 private I18nLabel codeUsageLabel;
87 /** The license header. */
88 private I18nLabel licenseHeaderLabel;
90 /** The tabbed pane with all the pages. */
91 private JTabbedPane pagesPane;
94 * Creates a new “about” dialog.
96 * @param swingInterface
99 public AboutDialog(SwingInterface swingInterface) {
100 super(swingInterface.getMainWindow(), I18n.get("aboutDialog.title"));
104 SwingUtils.center(this);
105 I18n.registerI18nable(this);
113 * Initializes all actions.
115 private void initActions() {
116 okayAction = new I18nAction("general.button.okay") {
119 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
121 @SuppressWarnings("synthetic-access")
122 public void actionPerformed(ActionEvent e) {
129 * Initiliazes all components of the dialog.
131 private void initComponents() {
132 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
133 getContentPane().add(contentPane, BorderLayout.CENTER);
134 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
136 pagesPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
137 contentPane.add(pagesPane, BorderLayout.CENTER);
139 pagesPane.addTab(I18n.get("aboutDialog.page.about.title"), createAboutPage());
140 pagesPane.setToolTipTextAt(0, I18n.get("aboutDialog.page.about.shortDescription"));
141 pagesPane.addTab(I18n.get("aboutDialog.page.license.title"), createLicensePage());
142 pagesPane.setToolTipTextAt(1, I18n.get("aboutDialog.page.license.shortDescription"));
144 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
145 contentPane.add(buttonPanel, BorderLayout.PAGE_END);
146 buttonPanel.add(new JButton(okayAction));
150 * Creates the “about” page.
152 * @return The “about” page
154 private JComponent createAboutPage() {
155 JPanel aboutPanel = new JPanel(new BorderLayout(12, 12));
156 aboutPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
158 /* the about page consists of an image to the left and text to right. */
159 JComponent textPanel = new Box(BoxLayout.PAGE_AXIS);
160 aboutPanel.add(textPanel, BorderLayout.CENTER);
162 JLabel jSiteHeaderLabel = new JLabel("jSite " + Version.getVersion());
163 textPanel.add(jSiteHeaderLabel);
164 textPanel.add(Box.createVerticalStrut(24));
165 Font jSiteHeaderLabelFont = jSiteHeaderLabel.getFont();
166 jSiteHeaderLabel.setFont(jSiteHeaderLabelFont.deriveFont(jSiteHeaderLabelFont.getSize2D() * 2).deriveFont(Font.BOLD));
168 contributorsLabel = new I18nLabel("aboutDialog.page.about.label.contributor");
169 textPanel.add(contributorsLabel);
170 textPanel.add(Box.createVerticalStrut(12));
171 contributorsLabel.setFont(contributorsLabel.getFont().deriveFont(Font.BOLD));
173 for (Contributor contributor: CONTRIBUTORS) {
174 JLabel contributorLabel = new JLabel(contributor.getName() + " <" + contributor.getEmail() + "> (" + contributor.getPart() + ")");
175 textPanel.add(contributorLabel);
177 textPanel.add(Box.createVerticalStrut(24));
179 i18nMaintainerLabel = new I18nLabel("aboutDialog.page.about.label.i18nMaintainer");
180 textPanel.add(i18nMaintainerLabel);
181 textPanel.add(Box.createVerticalStrut(12));
182 i18nMaintainerLabel.setFont(i18nMaintainerLabel.getFont().deriveFont(Font.BOLD));
184 i18nMaintainerNameLabel = new JLabel(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
185 textPanel.add(i18nMaintainerNameLabel);
186 textPanel.add(Box.createVerticalStrut(24));
188 codeUsageLabel = new I18nLabel("aboutDialog.page.about.label.codeUsage");
189 codeUsageLabel.setFont(codeUsageLabel.getFont().deriveFont(Font.BOLD));
190 textPanel.add(codeUsageLabel);
191 textPanel.add(Box.createVerticalStrut(12));
193 for (CodeUsage codeUsage: CODE_USAGES) {
194 JLabel usageLabel = new JLabel(codeUsage.getName() + " (" + codeUsage.getURL() + ", " + codeUsage.getLicense() + ")");
195 textPanel.add(usageLabel);
202 * Creates the “license” page.
204 * @return The “license” page
206 private JComponent createLicensePage() {
207 JPanel licensePanel = new JPanel(new BorderLayout(12, 12));
208 licensePanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
210 JPanel licenseHeaderPanel = new JPanel(new FlowLayout());
211 licensePanel.add(licenseHeaderPanel, BorderLayout.PAGE_START);
213 licenseHeaderLabel = new I18nLabel("aboutDialog.page.license.header", Version.getVersion());
214 licenseHeaderPanel.add(licenseHeaderLabel);
215 licenseHeaderLabel.setAlignmentX(0.5f);
217 String licenseText = loadLicenseText();
218 JTextArea licenseArea = new JTextArea(licenseText, 25, 80);
219 licensePanel.add(new JScrollPane(licenseArea), BorderLayout.CENTER);
220 licenseArea.setFont(new Font("Courier", Font.PLAIN, licenseArea.getFont().getSize()));
221 licenseArea.setEditable(false);
227 * Loads the license text.
229 * @return The license text
231 private String loadLicenseText() {
232 InputStream licenseInputStream = getClass().getResourceAsStream("/LICENSE");
233 if (licenseInputStream == null) {
234 return "Could not load LICENSE, check your installation.";
236 ByteArrayOutputStream licenseOutputStream = new ByteArrayOutputStream(20000);
238 StreamCopier.copy(licenseInputStream, licenseOutputStream);
239 } catch (IOException e) {
240 return "Could not load LICENSE, check your installation.";
244 licenseText = new String(licenseOutputStream.toByteArray(), "ISO-8859-1");
245 } catch (UnsupportedEncodingException e) {
246 licenseText = new String(licenseOutputStream.toByteArray());
258 private void actionOkay() {
263 // INTERFACE I18nable
267 * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
269 public void updateI18n() {
270 contributorsLabel.updateI18n();
271 licenseHeaderLabel.updateI18n();
272 i18nMaintainerLabel.updateI18n();
273 codeUsageLabel.updateI18n();
274 i18nMaintainerNameLabel.setText(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
275 okayAction.updateI18n();
276 setTitle(I18n.get("aboutDialog.title"));
277 pagesPane.setTitleAt(0, I18n.get("aboutDialog.page.about.title"));
278 pagesPane.setToolTipTextAt(0, I18n.get("aboutDialog.page.about.shortDescription"));
279 pagesPane.setTitleAt(1, I18n.get("aboutDialog.page.license.title"));
280 pagesPane.setToolTipTextAt(1, I18n.get("aboutDialog.page.license.shortDescription"));
281 SwingUtils.repackCentered(this);
285 * Container for a contributor.
287 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
289 private static class Contributor {
291 /** The name of the contributor. */
292 private final String name;
294 /** The email address of the contributor. */
295 private final String email;
297 /** The parts where the contributor helped. */
298 private final String part;
301 * Creates a new contributor.
304 * The name of the contributor
306 * The email address of the contributor
308 * The parts where the contributor helped
310 public Contributor(String name, String email, String part) {
317 * Returns the name of the contributor.
319 * @return The name of the contributor
326 * Returns the email address of the contributor.
328 * @return The email address of the contributor
335 * Returns the parts where the contributor helped.
337 * @return The parts where the contributor helped
346 * A code usage object describes code or other resources that have been
347 * taken from other projects.
349 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
351 private static class CodeUsage {
353 /** The name of the project. */
354 private final String name;
356 /** The URL of the project. */
357 private final String url;
359 /** The license of the project. */
360 private final String license;
362 /** The part that is used. */
363 private final String part;
366 * Creates a new code usage object.
369 * The name of the project
371 * The URL of the project
373 * The license of the used code
375 * The part that is used
377 public CodeUsage(String name, String url, String license, String part) {
380 this.license = license;
385 * Returns the name of the project.
387 * @return The name of the project
389 public String getName() {
394 * Returns the URL of the project.
396 * @return The URL of the project
398 public String getURL() {
403 * Returns the license of the used part.
405 * @return The license of the used part
407 public String getLicense() {
412 * Returns the used part.
414 * @return The used part
416 public String getPart() {