add configuration dialog
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Apr 2008 11:01:24 +0000 (11:01 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Apr 2008 11:01:24 +0000 (11:01 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@641 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/gui/ConfigurationDialog.java [new file with mode: 0644]
src/net/pterodactylus/jsite/gui/SwingInterface.java

diff --git a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java
new file mode 100644 (file)
index 0000000..a64e845
--- /dev/null
@@ -0,0 +1,208 @@
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.jsite.gui;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+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.util.swing.SwingUtils;
+
+/**
+ * The configuration dialog.
+ * 
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class ConfigurationDialog extends JDialog implements I18nable {
+
+       /** The “okay” action. */
+       private I18nAction okayAction;
+
+       /** The “cancel” action. */
+       private I18nAction cancelAction;
+
+       /** The “beautify GUI” action. */
+       private I18nAction beautifyAction;
+
+       /** The “beautify” checkbox. */
+       private JCheckBox beautifyCheckBox;
+
+       /** Whether the dialog was cancelled. */
+       private boolean cancelled;
+
+       /**
+        * Creates a new configuration dialog.
+        * 
+        * @param swingInterface
+        *            The Swing interface
+        */
+       public ConfigurationDialog(SwingInterface swingInterface) {
+               super(swingInterface.getMainWindow(), I18n.get("configurationDialog.title"), true);
+               initActions();
+               initComponents();
+               pack();
+               SwingUtils.center(this);
+               I18n.registerI18nable(this);
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns whether the dialog was cancelled or confirmed. If the dialog was
+        * cancelled, no further processing should be done.
+        * 
+        * @return <code>true</code> if the dialog was cancelled,
+        *         <code>false</code> otherwise
+        */
+       public boolean wasCancelled() {
+               return cancelled;
+       }
+
+       /**
+        * Returns whether the “beautify” checkbox has been selected. The result of
+        * this method should not be used if {@link #wasCancelled()} returned
+        * <code>true</code>!
+        * 
+        * @return <code>true</code> if the checkbox was selected,
+        *         <code>false</code> otherwise
+        */
+       public boolean getBeautify() {
+               return beautifyCheckBox.isSelected();
+       }
+
+       /**
+        * Sets the state of the “beautify” checkbox.
+        * 
+        * @param beautify
+        *            The state of the checkbox
+        */
+       public void setBeautify(boolean beautify) {
+               beautifyCheckBox.setSelected(beautify);
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
+        * Creates 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 actionEvent) {
+                               actionOkay();
+                       }
+               };
+               cancelAction = new I18nAction("general.button.cancel") {
+                       /**
+                        * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               actionCancel();
+                       }
+               };
+               beautifyAction = new I18nAction("configurationDialog.page.interface.item.beautify") {
+                       /**
+                        * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+                        */
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               /* don't do anything. */
+                       }
+               };
+       }
+
+       /**
+        * Creates all internal components.
+        */
+       private void initComponents() {
+               JPanel contentPane = new JPanel(new BorderLayout(12, 12));
+               contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+               JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
+               contentPane.add(tabbedPane, BorderLayout.CENTER);
+
+               JComponent interfaceConfig = createInterfaceConfig();
+               tabbedPane.add("Swing Interface", interfaceConfig);
+
+               JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
+               contentPane.add(buttonPanel, BorderLayout.PAGE_END);
+               buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
+               buttonPanel.add(new JButton(cancelAction));
+               JButton okayButton = new JButton(okayAction);
+               buttonPanel.add(okayButton);
+               getRootPane().setDefaultButton(okayButton);
+
+               getContentPane().add(contentPane, BorderLayout.CENTER);
+       }
+
+       /**
+        * Creates the panel for the interface configuration.
+        * 
+        * @return The interface configuration panel
+        */
+       private JComponent createInterfaceConfig() {
+               JPanel interfaceConfigPanel = new JPanel(new BorderLayout(12, 12));
+               interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+               beautifyCheckBox = new JCheckBox(beautifyAction);
+               interfaceConfigPanel.add(beautifyCheckBox, BorderLayout.PAGE_START);
+
+               return interfaceConfigPanel;
+       }
+
+       //
+       // PRIVATE ACTIONS
+       //
+
+       /**
+        * Called when the “okay” button is clicked.
+        */
+       private void actionOkay() {
+               cancelled = false;
+               setVisible(false);
+       }
+
+       /**
+        * Called when the “cancel” button is clicked.
+        */
+       private void actionCancel() {
+               cancelled = true;
+               setVisible(false);
+       }
+
+       //
+       // INTERFACE I18nable
+       //
+
+       /**
+        * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
+        */
+       public void updateI18n() {
+               okayAction.updateI18n();
+               cancelAction.updateI18n();
+               beautifyAction.updateI18n();
+               SwingUtils.repackCentered(this);
+       }
+
+}
index e98fa80..1f41af1 100644 (file)
@@ -79,9 +79,19 @@ public class SwingInterface implements CoreListener {
        /** The “about” dialog. */
        private AboutDialog aboutDialog;
 
+       /** The configuration dialog. */
+       private ConfigurationDialog configurationDialog;
+
        /** The list of all defined nodes. */
        private List<Node> nodeList;
 
+       //
+       // CONFIGURATION
+       //
+
+       /** Whether to beautify the GUI. */
+       private boolean beautify;
+
        /**
         * Creates a new swing interface.
         * 
@@ -91,9 +101,12 @@ public class SwingInterface implements CoreListener {
        public SwingInterface(Core core) {
                this.core = core;
                I18n.setLocale(Locale.ENGLISH); /* TODO - load config */
-               System.setProperty("swing.aatext", "true");
-               System.setProperty("swing.plaf.metal.controlFont", "Tahoma");
-               System.setProperty("swing.plaf.metal.userFont", "Tahoma");
+               loadConfig();
+               if (beautify) {
+                       System.setProperty("swing.aatext", "true");
+                       System.setProperty("swing.plaf.metal.controlFont", "Tahoma");
+                       System.setProperty("swing.plaf.metal.userFont", "Tahoma");
+               }
                initActions();
                initDialogs();
        }
@@ -221,6 +234,13 @@ public class SwingInterface implements CoreListener {
        //
 
        /**
+        * Loads the configuration of the interface.
+        */
+       private void loadConfig() {
+               beautify = true;
+       }
+
+       /**
         * Initializes all actions.
         */
        private void initActions() {
@@ -325,6 +345,7 @@ public class SwingInterface implements CoreListener {
        private void initDialogs() {
                manageNodesDialog = new ManageNodesDialog(this);
                aboutDialog = new AboutDialog(this);
+               configurationDialog = new ConfigurationDialog(this);
        }
 
        //
@@ -335,6 +356,11 @@ public class SwingInterface implements CoreListener {
         * Shows the configuration dialog.
         */
        private void configure() {
+               configurationDialog.setBeautify(beautify);
+               configurationDialog.setVisible(true);
+               if (!configurationDialog.wasCancelled()) {
+                       beautify = configurationDialog.getBeautify();
+               }
        }
 
        /**