From 9837f6421b3602e461df742878666736d832298e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Dec 2009 07:06:07 +0100 Subject: [PATCH] Create radio buttons from actions. --- src/de/todesbaum/jsite/gui/PreferencesPage.java | 52 +++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/de/todesbaum/jsite/gui/PreferencesPage.java b/src/de/todesbaum/jsite/gui/PreferencesPage.java index a2a13b0..03910eb 100644 --- a/src/de/todesbaum/jsite/gui/PreferencesPage.java +++ b/src/de/todesbaum/jsite/gui/PreferencesPage.java @@ -46,6 +46,12 @@ import de.todesbaum.util.swing.TWizardPage; */ public class PreferencesPage extends TWizardPage { + /** Select default temp directory action. */ + private Action selectDefaultTempDirectoryAction; + + /** Select custom temp directory action. */ + private Action selectCustomTempDirectoryAction; + /** Action that chooses a new temp directory. */ private Action chooseTempDirectoryAction; @@ -121,6 +127,28 @@ public class PreferencesPage extends TWizardPage { * Creates all actions. */ private void createActions() { + selectDefaultTempDirectoryAction = new AbstractAction(I18n.getMessage("jsite.preferences.temp-directory.default")) { + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + selectDefaultTempDirectory(); + } + }; + selectCustomTempDirectoryAction = new AbstractAction(I18n.getMessage("jsite.preferences.temp-directory.custom")) { + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + selectCustomTempDirectory(); + } + }; chooseTempDirectoryAction = new AbstractAction(I18n.getMessage("jsite.preferences.temp-directory.choose")) { @Override @@ -135,6 +163,8 @@ public class PreferencesPage extends TWizardPage { @Override @SuppressWarnings("synthetic-access") public void run() { + selectDefaultTempDirectoryAction.putValue(Action.NAME, I18n.getMessage("jsite.preferences.temp-directory.default")); + selectCustomTempDirectoryAction.putValue(Action.NAME, I18n.getMessage("jsite.preferences.temp-directory.custom")); chooseTempDirectoryAction.putValue(Action.NAME, I18n.getMessage("jsite.preferences.temp-directory.choose")); } }); @@ -154,10 +184,10 @@ public class PreferencesPage extends TWizardPage { final JLabel tempDirectoryLabel = new JLabel("" + I18n.getMessage("jsite.preferences.temp-directory") + ""); tempDirectoryPanel.add(tempDirectoryLabel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - final JRadioButton defaultTempDirectory = new JRadioButton(I18n.getMessage("jsite.preferences.temp-directory.default")); + final JRadioButton defaultTempDirectory = new JRadioButton(selectDefaultTempDirectoryAction); tempDirectoryPanel.add(defaultTempDirectory, new GridBagConstraints(0, 1, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 18, 0, 0), 0, 0)); - final JRadioButton customTempDirectory = new JRadioButton(I18n.getMessage("jsite.preferences.temp-directory.custom")); + final JRadioButton customTempDirectory = new JRadioButton(selectCustomTempDirectoryAction); tempDirectoryPanel.add(customTempDirectory, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 18, 0, 0), 0, 0)); ButtonGroup tempDirectoryButtonGroup = new ButtonGroup(); @@ -178,8 +208,6 @@ public class PreferencesPage extends TWizardPage { @Override public void run() { tempDirectoryLabel.setText("" + I18n.getMessage("jsite.preferences.temp-directory") + ""); - defaultTempDirectory.setText(I18n.getMessage("jsite.preferences.temp-directory.default")); - customTempDirectory.setText(I18n.getMessage("jsite.preferences.temp-directory.custom")); } }); @@ -187,6 +215,22 @@ public class PreferencesPage extends TWizardPage { } /** + * Activates the default temp directory radio button. + */ + private void selectDefaultTempDirectory() { + tempDirectoryTextField.setEnabled(false); + chooseTempDirectoryAction.setEnabled(false); + } + + /** + * Activates the custom temp directory radio button. + */ + private void selectCustomTempDirectory() { + tempDirectoryTextField.setEnabled(true); + chooseTempDirectoryAction.setEnabled(true); + } + + /** * Lets the user choose a new temp directory. */ private void chooseTempDirectory() { -- 2.7.4