package net.pterodactylus.jsite.gui;
import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
+import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import net.pterodactylus.jsite.i18n.I18n;
+import net.pterodactylus.jsite.i18n.I18nable;
+import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.i18n.gui.I18nLabel;
+import net.pterodactylus.jsite.main.Version;
+import net.pterodactylus.util.io.StreamCopier;
+import net.pterodactylus.util.swing.SwingUtils;
/**
* An “about” dialog.
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
-public class AboutDialog extends JDialog {
+public class AboutDialog extends JDialog implements I18nable {
/** A list of all contributors. */
private static final List<Contributor> CONTRIBUTORS = new ArrayList<Contributor>();
CONTRIBUTORS.add(new Contributor("David ‘Bombe’ Roden", "bombe@freenetproject.org", "Main code"));
}
+ /** The “okay” button action. */
+ private I18nAction okayAction;
+
+ /** The contributors label. */
+ private I18nLabel contributorsLabel;
+
+ /** The i18n maintainer label. */
+ private I18nLabel i18nMaintainerLabel;
+
+ /** The i18n maintainer’s name label. */
+ private JLabel i18nMaintainerNameLabel;
+
+ /** The license header. */
+ private I18nLabel licenseHeaderLabel;
+
/**
* Creates a new “about” dialog.
*
* The Swing interface
*/
public AboutDialog(SwingInterface swingInterface) {
- super(swingInterface.getMainWindow());
+ super(swingInterface.getMainWindow(), I18n.get("aboutDialog.title"));
+ initActions();
initComponents();
+ pack();
+ SwingUtils.center(this);
+ I18n.registerI18nable(this);
}
//
//
/**
+ * Initializes all actions.
+ */
+ private void initActions() {
+ okayAction = new I18nAction("general.button.okay") {
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent e) {
+ actionOkay();
+ }
+ };
+ }
+
+ /**
* Initiliazes all components of the dialog.
*/
private void initComponents() {
tabbedPane.setToolTipTextAt(0, I18n.get("aboutDialog.page.about.shortDescription"));
tabbedPane.addTab(I18n.get("aboutDialog.page.license.title"), createLicensePage());
tabbedPane.setToolTipTextAt(1, I18n.get("aboutDialog.page.license.shortDescription"));
+
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
+ contentPane.add(buttonPanel, BorderLayout.PAGE_END);
+ buttonPanel.add(new JButton(okayAction));
}
/**
* @return The “about” page
*/
private JComponent createAboutPage() {
- return new JPanel();
+ JPanel aboutPanel = new JPanel(new BorderLayout(12, 12));
+ aboutPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+ /* the about page consists of an image to the left and text to right. */
+ JComponent textPanel = new Box(BoxLayout.PAGE_AXIS);
+ aboutPanel.add(textPanel, BorderLayout.CENTER);
+
+ JLabel jSiteHeaderLabel = new JLabel("jSite " + Version.getVersion());
+ textPanel.add(jSiteHeaderLabel);
+ textPanel.add(Box.createVerticalStrut(24));
+ Font jSiteHeaderLabelFont = jSiteHeaderLabel.getFont();
+ jSiteHeaderLabel.setFont(jSiteHeaderLabelFont.deriveFont(jSiteHeaderLabelFont.getSize2D() * 2).deriveFont(Font.BOLD));
+
+ contributorsLabel = new I18nLabel("aboutDialog.page.about.label.contributor");
+ textPanel.add(contributorsLabel);
+ textPanel.add(Box.createVerticalStrut(12));
+ contributorsLabel.setFont(contributorsLabel.getFont().deriveFont(Font.BOLD));
+
+ for (Contributor contributor: CONTRIBUTORS) {
+ JLabel contributorLabel = new JLabel(contributor.getName() + " <" + contributor.getEmail() + "> (" + contributor.getPart() + ")");
+ textPanel.add(contributorLabel);
+ }
+ textPanel.add(Box.createVerticalStrut(24));
+
+ i18nMaintainerLabel = new I18nLabel("aboutDialog.page.about.label.i18nMaintainer");
+ textPanel.add(i18nMaintainerLabel);
+ textPanel.add(Box.createVerticalStrut(12));
+ i18nMaintainerLabel.setFont(i18nMaintainerLabel.getFont().deriveFont(Font.BOLD));
+
+ i18nMaintainerNameLabel = new JLabel(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
+ textPanel.add(i18nMaintainerNameLabel);
+
+ return aboutPanel;
}
/**
* @return The “license” page
*/
private JComponent createLicensePage() {
- return new JPanel();
+ JPanel licensePanel = new JPanel(new BorderLayout(12, 12));
+ licensePanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+ licenseHeaderLabel = new I18nLabel("aboutDialog.page.license.header", Version.getVersion());
+ licensePanel.add(licenseHeaderLabel, BorderLayout.PAGE_START);
+ licenseHeaderLabel.setAlignmentX(0.5f);
+
+ String licenseText = loadLicenseText();
+ JTextArea licenseArea = new JTextArea(licenseText, 25, 80);
+ licensePanel.add(new JScrollPane(licenseArea), BorderLayout.CENTER);
+ licenseArea.setFont(new Font("Courier", Font.PLAIN, licenseArea.getFont().getSize()));
+ licenseArea.setEditable(false);
+
+ return licensePanel;
+ }
+
+ /**
+ * Loads the license text.
+ *
+ * @return The license text
+ */
+ private String loadLicenseText() {
+ InputStream licenseInputStream = getClass().getResourceAsStream("/LICENSE");
+ if (licenseInputStream == null) {
+ return "Could not load LICENSE, check your installation.";
+ }
+ ByteArrayOutputStream licenseOutputStream = new ByteArrayOutputStream(20000);
+ try {
+ StreamCopier.copy(licenseInputStream, licenseOutputStream);
+ } catch (IOException e) {
+ return "Could not load LICENSE, check your installation.";
+ }
+ String licenseText;
+ try {
+ licenseText = new String(licenseOutputStream.toByteArray(), "ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ licenseText = new String(licenseOutputStream.toByteArray());
+ }
+ return licenseText;
+ }
+
+ //
+ // PRIVATE ACTIONS
+ //
+
+ /**
+ * Closes the dialog.
+ */
+ private void actionOkay() {
+ setVisible(false);
+ }
+
+ //
+ // INTERFACE I18nable
+ //
+
+ /**
+ * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
+ */
+ public void updateI18n() {
+ contributorsLabel.updateI18n();
+ licenseHeaderLabel.updateI18n();
+ i18nMaintainerLabel.updateI18n();
+ i18nMaintainerNameLabel.setText(I18n.get("i18n.maintainer.name") + " <" + I18n.get("i18n.maintainer.email") + ">");
+ okayAction.updateI18n();
+ setTitle(I18n.get("aboutDialog.title"));
+ SwingUtils.repackCentered(this);
}
/**