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>
60 public class AboutDialog extends JDialog implements I18nable {
62 /** A list of all contributors. */
63 private static final List<Contributor> CONTRIBUTORS = new ArrayList<Contributor>();
66 CONTRIBUTORS.add(new Contributor("David ‘Bombe’ Roden", "bombe@freenetproject.org", "Main code"));
69 /** The “okay” button action. */
70 private I18nAction okayAction;
72 /** The contributors label. */
73 private I18nLabel contributorsLabel;
75 /** The i18n maintainer label. */
76 private I18nLabel i18nMaintainerLabel;
78 /** The i18n maintainer’s name label. */
79 private JLabel i18nMaintainerNameLabel;
81 /** The license header. */
82 private I18nLabel licenseHeaderLabel;
85 * Creates a new “about” dialog.
87 * @param swingInterface
90 public AboutDialog(SwingInterface swingInterface) {
91 super(swingInterface.getMainWindow(), I18n.get("aboutDialog.title"));
95 SwingUtils.center(this);
96 I18n.registerI18nable(this);
104 * Initializes all actions.
106 private void initActions() {
107 okayAction = new I18nAction("general.button.okay") {
109 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
111 @SuppressWarnings("synthetic-access")
112 public void actionPerformed(ActionEvent e) {
119 * Initiliazes all components of the dialog.
121 private void initComponents() {
122 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
123 getContentPane().add(contentPane, BorderLayout.CENTER);
124 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
126 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
127 contentPane.add(tabbedPane, BorderLayout.CENTER);
129 tabbedPane.addTab(I18n.get("aboutDialog.page.about.title"), createAboutPage());
130 tabbedPane.setToolTipTextAt(0, I18n.get("aboutDialog.page.about.shortDescription"));
131 tabbedPane.addTab(I18n.get("aboutDialog.page.license.title"), createLicensePage());
132 tabbedPane.setToolTipTextAt(1, I18n.get("aboutDialog.page.license.shortDescription"));
134 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
135 contentPane.add(buttonPanel, BorderLayout.PAGE_END);
136 buttonPanel.add(new JButton(okayAction));
140 * Creates the “about” page.
142 * @return The “about” page
144 private JComponent createAboutPage() {
145 JPanel aboutPanel = new JPanel(new BorderLayout(12, 12));
146 aboutPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
148 /* the about page consists of an image to the left and text to right. */
149 JComponent textPanel = new Box(BoxLayout.PAGE_AXIS);
150 aboutPanel.add(textPanel, BorderLayout.CENTER);
152 JLabel jSiteHeaderLabel = new JLabel("jSite " + Version.getVersion());
153 textPanel.add(jSiteHeaderLabel);
154 textPanel.add(Box.createVerticalStrut(24));
155 Font jSiteHeaderLabelFont = jSiteHeaderLabel.getFont();
156 jSiteHeaderLabel.setFont(jSiteHeaderLabelFont.deriveFont(jSiteHeaderLabelFont.getSize2D() * 2).deriveFont(Font.BOLD));
158 contributorsLabel = new I18nLabel("aboutDialog.page.about.label.contributor");
159 textPanel.add(contributorsLabel);
160 textPanel.add(Box.createVerticalStrut(12));
161 contributorsLabel.setFont(contributorsLabel.getFont().deriveFont(Font.BOLD));
163 for (Contributor contributor: CONTRIBUTORS) {
164 JLabel contributorLabel = new JLabel(contributor.getName() + " <" + contributor.getEmail() + "> (" + contributor.getPart() + ")");
165 textPanel.add(contributorLabel);
167 textPanel.add(Box.createVerticalStrut(24));
169 i18nMaintainerLabel = new I18nLabel("aboutDialog.page.about.label.i18nMaintainer");
170 textPanel.add(i18nMaintainerLabel);
171 textPanel.add(Box.createVerticalStrut(12));
172 i18nMaintainerLabel.setFont(i18nMaintainerLabel.getFont().deriveFont(Font.BOLD));
174 i18nMaintainerNameLabel = new JLabel(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
175 textPanel.add(i18nMaintainerNameLabel);
181 * Creates the “license” page.
183 * @return The “license” page
185 private JComponent createLicensePage() {
186 JPanel licensePanel = new JPanel(new BorderLayout(12, 12));
187 licensePanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
189 licenseHeaderLabel = new I18nLabel("aboutDialog.page.license.header", Version.getVersion());
190 licensePanel.add(licenseHeaderLabel, BorderLayout.PAGE_START);
191 licenseHeaderLabel.setAlignmentX(0.5f);
193 String licenseText = loadLicenseText();
194 JTextArea licenseArea = new JTextArea(licenseText, 25, 80);
195 licensePanel.add(new JScrollPane(licenseArea), BorderLayout.CENTER);
196 licenseArea.setFont(new Font("Courier", Font.PLAIN, licenseArea.getFont().getSize()));
197 licenseArea.setEditable(false);
203 * Loads the license text.
205 * @return The license text
207 private String loadLicenseText() {
208 InputStream licenseInputStream = getClass().getResourceAsStream("/LICENSE");
209 if (licenseInputStream == null) {
210 return "Could not load LICENSE, check your installation.";
212 ByteArrayOutputStream licenseOutputStream = new ByteArrayOutputStream(20000);
214 StreamCopier.copy(licenseInputStream, licenseOutputStream);
215 } catch (IOException e) {
216 return "Could not load LICENSE, check your installation.";
220 licenseText = new String(licenseOutputStream.toByteArray(), "ISO-8859-1");
221 } catch (UnsupportedEncodingException e) {
222 licenseText = new String(licenseOutputStream.toByteArray());
234 private void actionOkay() {
239 // INTERFACE I18nable
243 * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
245 public void updateI18n() {
246 contributorsLabel.updateI18n();
247 licenseHeaderLabel.updateI18n();
248 i18nMaintainerLabel.updateI18n();
249 i18nMaintainerNameLabel.setText(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
250 okayAction.updateI18n();
251 setTitle(I18n.get("aboutDialog.title"));
252 SwingUtils.repackCentered(this);
256 * Container for a contributor.
258 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
261 private static class Contributor {
263 /** The name of the contributor. */
264 private final String name;
266 /** The email address of the contributor. */
267 private final String email;
269 /** The parts where the contributor helped. */
270 private final String part;
273 * Creates a new contributor.
276 * The name of the contributor
278 * The email address of the contributor
280 * The parts where the contributor helped
282 public Contributor(String name, String email, String part) {
289 * Returns the name of the contributor.
291 * @return The name of the contributor
298 * Returns the email address of the contributor.
300 * @return The email address of the contributor
307 * Returns the parts where the contributor helped.
309 * @return The parts where the contributor helped