From e2ea5a1eac8809b3a3d0c4e48dad26c9cae14961 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 7 Apr 2008 11:01:24 +0000 Subject: [PATCH] add configuration dialog git-svn-id: http://trooper/svn/projects/jSite/trunk@641 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../jsite/gui/ConfigurationDialog.java | 208 +++++++++++++++++++++ .../pterodactylus/jsite/gui/SwingInterface.java | 32 +++- 2 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 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 index 0000000..a64e845 --- /dev/null +++ b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java @@ -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 David Roden + * @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 true if the dialog was cancelled, + * false 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 + * true! + * + * @return true if the checkbox was selected, + * false 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); + } + +} diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index e98fa80..1f41af1 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -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 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(); + } } /** -- 2.7.4