complete about dialog
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Apr 2008 10:02:02 +0000 (10:02 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Apr 2008 10:02:02 +0000 (10:02 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@639 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/gui/AboutDialog.java

index 2d69b46..3601733 100644 (file)
 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.
@@ -38,7 +57,7 @@ import net.pterodactylus.jsite.i18n.I18n;
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  * @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>();
@@ -47,6 +66,21 @@ public class AboutDialog extends JDialog {
                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.
         * 
@@ -54,8 +88,12 @@ public class AboutDialog extends JDialog {
         *            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);
        }
 
        //
@@ -63,6 +101,21 @@ public class AboutDialog extends JDialog {
        //
 
        /**
+        * 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() {
@@ -77,6 +130,10 @@ public class AboutDialog extends JDialog {
                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));
        }
 
        /**
@@ -85,7 +142,39 @@ public class AboutDialog extends JDialog {
         * @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;
        }
 
        /**
@@ -94,7 +183,73 @@ public class AboutDialog extends JDialog {
         * @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);
        }
 
        /**