From 08de64294b855fe7abab3b5520be1b151af7f135 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 25 Apr 2008 00:00:56 +0000 Subject: [PATCH] enhance configuration dialog with font selection git-svn-id: http://trooper/svn/projects/jSite/trunk@762 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../jsite/gui/ConfigurationDialog.java | 128 +++++++++++++++++++-- .../pterodactylus/jsite/gui/SwingInterface.java | 62 +++++++--- 2 files changed, 163 insertions(+), 27 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java index a64e845..4444868 100644 --- a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java +++ b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java @@ -1,10 +1,14 @@ /** * © 2008 INA Service GmbH */ + package net.pterodactylus.jsite.gui; import java.awt.BorderLayout; import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.event.ActionEvent; import javax.swing.BorderFactory; @@ -23,7 +27,7 @@ import net.pterodactylus.util.swing.SwingUtils; /** * The configuration dialog. - * + * * @author David Roden * @version $Id$ */ @@ -38,15 +42,33 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** The “beautify GUI” action. */ private I18nAction beautifyAction; + /** The “use custom control font” action. */ + private I18nAction useCustomControlFontAction; + + /** The “use custom user font” action. */ + private I18nAction useCustomUserFontAction; + /** The “beautify” checkbox. */ private JCheckBox beautifyCheckBox; + /** The “use custom” fonts checkbox. */ + private JCheckBox useCustomControlFontCheckBox; + + /** The control font list. */ + private FontComboBox controlFontList; + + /** The checkbox for “use same as control font”. */ + private JCheckBox useCustomUserFontCheckBox; + + /** The user font list. */ + private FontComboBox userFontList; + /** Whether the dialog was cancelled. */ private boolean cancelled; /** * Creates a new configuration dialog. - * + * * @param swingInterface * The Swing interface */ @@ -66,7 +88,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** * 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 */ @@ -78,7 +100,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { * 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 */ @@ -88,12 +110,62 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** * Sets the state of the “beautify” checkbox. - * + * * @param beautify * The state of the checkbox */ public void setBeautify(boolean beautify) { beautifyCheckBox.setSelected(beautify); + useCustomControlFontCheckBox.setEnabled(beautify); + controlFontList.setEnabled(beautify && useCustomControlFontCheckBox.isSelected()); + useCustomUserFontCheckBox.setEnabled(beautify); + userFontList.setEnabled(beautify && useCustomUserFontCheckBox.isSelected()); + } + + /** + * Returns the font for the controls. + * + * @return The control font, or null if no custom control + * font is to be used + */ + public String getControlFont() { + return (String) ((beautifyCheckBox.isSelected() && useCustomControlFontCheckBox.isSelected()) ? controlFontList.getSelectedItem() : null); + } + + /** + * Sets the font for the controls. + * + * @param controlFont + * The control font, or null if no custom control + * font is to be used + */ + public void setControlFont(String controlFont) { + useCustomControlFontCheckBox.setSelected(controlFont != null); + controlFontList.setEnabled(beautifyCheckBox.isSelected() && (controlFont != null)); + controlFontList.setSelectedItem(controlFont); + } + + /** + * Returns the font for user input. + * + * @return The font for user input, or null if no custom user + * input font is to be used + */ + public String getUserFont() { + return (String) ((beautifyCheckBox.isSelected() && useCustomUserFontCheckBox.isSelected()) ? userFontList.getSelectedItem() : null); + } + + /** + * Sets the font for user input. + * + * @param userFont + * The font for user input, or null if no custom + * user input font is to be used + */ + public void setUserFont(String userFont) { + useCustomUserFontCheckBox.setSelected(userFont != null); + userFontList.setEnabled(beautifyCheckBox.isSelected() && (userFont != null)); + userFontList.setSelectedItem(userFont); } // @@ -105,6 +177,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { */ private void initActions() { okayAction = new I18nAction("general.button.okay") { + /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @@ -114,6 +187,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { } }; cancelAction = new I18nAction("general.button.cancel") { + /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @@ -123,11 +197,33 @@ public class ConfigurationDialog extends JDialog implements I18nable { } }; beautifyAction = new I18nAction("configurationDialog.page.interface.item.beautify") { + /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - /* don't do anything. */ + setBeautify(beautifyCheckBox.isSelected()); + } + }; + useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent e) { + controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected()); + } + }; + useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent e) { + userFontList.setEnabled(useCustomUserFontCheckBox.isSelected()); } }; } @@ -158,15 +254,29 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** * Creates the panel for the interface configuration. - * + * * @return The interface configuration panel */ private JComponent createInterfaceConfig() { - JPanel interfaceConfigPanel = new JPanel(new BorderLayout(12, 12)); + JPanel interfaceConfigPanel = new JPanel(new GridBagLayout()); interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); beautifyCheckBox = new JCheckBox(beautifyAction); - interfaceConfigPanel.add(beautifyCheckBox, BorderLayout.PAGE_START); + interfaceConfigPanel.add(beautifyCheckBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + + useCustomControlFontCheckBox = new JCheckBox(useCustomControlFontAction); + interfaceConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 18, 0, 0), 0, 0)); + + controlFontList = new FontComboBox(); + interfaceConfigPanel.add(controlFontList, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + + useCustomUserFontCheckBox = new JCheckBox(useCustomUserFontAction); + interfaceConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); + + userFontList = new FontComboBox(); + interfaceConfigPanel.add(userFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + + interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return interfaceConfigPanel; } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index d00ebe1..09205bc 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -41,7 +41,7 @@ import net.pterodactylus.util.io.Closer; /** * The Swing user interface. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ @@ -108,9 +108,15 @@ public class SwingInterface implements CoreListener { /** Whether to beautify the GUI. */ private boolean beautify; + /** The control font. */ + private String controlFont; + + /** The user font. */ + private String userFont; + /** * Creates a new swing interface. - * + * * @param core * The core to operate on * @param configDirectory @@ -123,8 +129,12 @@ public class SwingInterface implements CoreListener { loadConfig(); if (beautify) { System.setProperty("swing.aatext", "true"); - System.setProperty("swing.plaf.metal.controlFont", "Tahoma"); - System.setProperty("swing.plaf.metal.userFont", "Tahoma"); + if (controlFont != null) { + System.setProperty("swing.plaf.metal.controlFont", controlFont); + } + if (userFont != null) { + System.setProperty("swing.plaf.metal.userFont", userFont); + } } initActions(); initDialogs(); @@ -136,7 +146,7 @@ public class SwingInterface implements CoreListener { /** * Returns the core that is controlled by the Swing interface. - * + * * @return The core */ Core getCore() { @@ -145,7 +155,7 @@ public class SwingInterface implements CoreListener { /** * Returns the main window of the Swing interface. - * + * * @return The main window */ MainWindow getMainWindow() { @@ -154,7 +164,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “configure” action. - * + * * @return The “configure” action */ I18nAction getConfigureAction() { @@ -163,7 +173,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “import config” action. - * + * * @return The “import config” action */ I18nAction getImportConfigAction() { @@ -172,7 +182,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “quit” action. - * + * * @return The “quit” action */ I18nAction getQuitAction() { @@ -181,7 +191,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “manage nodes” action. - * + * * @return The “manage nodes” action */ I18nAction getManageNodesAction() { @@ -190,7 +200,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “connect to node” action. - * + * * @return The “connect to node” action */ I18nAction getNodeConnectAction() { @@ -199,7 +209,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “disconnect from node” action. - * + * * @return The “disconnect from node” action */ I18nAction getNodeDisconnectAction() { @@ -208,7 +218,7 @@ public class SwingInterface implements CoreListener { /** * Returns all language actions. - * + * * @return All language actions */ List getLanguageActions() { @@ -217,7 +227,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “about” action. - * + * * @return The “about” action */ I18nAction getHelpAboutAction() { @@ -226,7 +236,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “add project” action. - * + * * @return The “add project” action */ I18nAction getAddProjectAction() { @@ -235,7 +245,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “clone project” action. - * + * * @return The “clone project” action */ I18nAction getCloneProjectAction() { @@ -244,7 +254,7 @@ public class SwingInterface implements CoreListener { /** * Returns the “delete project” action. - * + * * @return The “delete project” action */ I18nAction getDeleteProjectAction() { @@ -295,6 +305,12 @@ public class SwingInterface implements CoreListener { if (configProperties.containsKey("beautify")) { beautify = Boolean.valueOf(configProperties.getProperty("beautify")); } + if (configProperties.containsKey("controlFont")) { + controlFont = configProperties.getProperty("controlFont"); + } + if (configProperties.containsKey("userFont")) { + userFont = configProperties.getProperty("userFont"); + } } /** @@ -315,6 +331,12 @@ public class SwingInterface implements CoreListener { File configFile = new File(configDirectory, "swing-interface.properties"); Properties configProperties = new Properties(); configProperties.setProperty("beautify", String.valueOf(beautify)); + if (controlFont != null) { + configProperties.setProperty("controlFont", controlFont); + } + if (userFont != null) { + configProperties.setProperty("userFont", userFont); + } FileOutputStream configOutputStream = null; try { configOutputStream = new FileOutputStream(configFile); @@ -463,9 +485,13 @@ public class SwingInterface implements CoreListener { */ private void configure() { configurationDialog.setBeautify(beautify); + configurationDialog.setControlFont(controlFont); + configurationDialog.setUserFont(userFont); configurationDialog.setVisible(true); if (!configurationDialog.wasCancelled()) { beautify = configurationDialog.getBeautify(); + controlFont = configurationDialog.getControlFont(); + userFont = configurationDialog.getUserFont(); saveConfig(); } } @@ -508,7 +534,7 @@ public class SwingInterface implements CoreListener { /** * Changes the language of the interface. This method also disables the * action for the newly set language and enables all others. - * + * * @param newLocale * The new language * @param languageAction -- 2.7.4