/**
* © 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;
/**
* The configuration dialog.
- *
+ *
* @author <a href="mailto:dr@ina-germany.de">David Roden</a>
* @version $Id$
*/
/** 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
*/
/**
* 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
*/
* 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
*/
/**
* 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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);
}
//
*/
private void initActions() {
okayAction = new I18nAction("general.button.okay") {
+
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
}
};
cancelAction = new I18nAction("general.button.cancel") {
+
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
}
};
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());
}
};
}
/**
* 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;
}
/**
* The Swing user interface.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/** 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
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();
/**
* Returns the core that is controlled by the Swing interface.
- *
+ *
* @return The core
*/
Core getCore() {
/**
* Returns the main window of the Swing interface.
- *
+ *
* @return The main window
*/
MainWindow getMainWindow() {
/**
* Returns the “configure” action.
- *
+ *
* @return The “configure” action
*/
I18nAction getConfigureAction() {
/**
* Returns the “import config” action.
- *
+ *
* @return The “import config” action
*/
I18nAction getImportConfigAction() {
/**
* Returns the “quit” action.
- *
+ *
* @return The “quit” action
*/
I18nAction getQuitAction() {
/**
* Returns the “manage nodes” action.
- *
+ *
* @return The “manage nodes” action
*/
I18nAction getManageNodesAction() {
/**
* Returns the “connect to node” action.
- *
+ *
* @return The “connect to node” action
*/
I18nAction getNodeConnectAction() {
/**
* Returns the “disconnect from node” action.
- *
+ *
* @return The “disconnect from node” action
*/
I18nAction getNodeDisconnectAction() {
/**
* Returns all language actions.
- *
+ *
* @return All language actions
*/
List<I18nAction> getLanguageActions() {
/**
* Returns the “about” action.
- *
+ *
* @return The “about” action
*/
I18nAction getHelpAboutAction() {
/**
* Returns the “add project” action.
- *
+ *
* @return The “add project” action
*/
I18nAction getAddProjectAction() {
/**
* Returns the “clone project” action.
- *
+ *
* @return The “clone project” action
*/
I18nAction getCloneProjectAction() {
/**
* Returns the “delete project” action.
- *
+ *
* @return The “delete project” action
*/
I18nAction getDeleteProjectAction() {
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");
+ }
}
/**
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);
*/
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();
}
}
/**
* 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