add configuration dialog
[jSite2.git] / src / net / pterodactylus / jsite / gui / ConfigurationDialog.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);
+       }
+
+}