X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FConfigurationDialog.java;h=a8d212c9c5522645969840ae1a598491997c5abd;hb=f42b615dcbe440d9908385754948d6448a3b67ff;hp=c512c469def4e2a8a19db9520fbd4202f2b27630;hpb=aa72bfe9c0d91f7339a70218aa50824e2b321780;p=jSite2.git
diff --git a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java
index c512c46..a8d212c 100644
--- a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java
+++ b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java
@@ -6,30 +6,40 @@ package net.pterodactylus.jsite.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
+import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
+import javax.swing.LookAndFeel;
+import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.I18nable;
import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.i18n.gui.I18nLabel;
import net.pterodactylus.util.swing.SwingUtils;
/**
* The configuration dialog.
- *
+ *
* @author David Roden
- * @version $Id$
*/
public class ConfigurationDialog extends JDialog implements I18nable {
@@ -39,6 +49,12 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/** The âcancelâ action. */
private I18nAction cancelAction;
+ /** The âadvanced modeâ action. */
+ private I18nAction advancedModeAction;
+
+ /** The âadvanced modeâ checkbox. */
+ private JCheckBox advancedModeCheckBox;
+
/** The âbeautify GUIâ action. */
private I18nAction antialiasAction;
@@ -48,6 +64,12 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/** The âuse custom user fontâ action. */
private I18nAction useCustomUserFontAction;
+ /** The âuse custom L&Fâ action. */
+ private I18nAction useCustomLAFAction;
+
+ /** The ârestart requiredâ warning label. */
+ private I18nLabel restartRequiredLabel;
+
/** The âbeautifyâ checkbox. */
private JCheckBox antialiasCheckBox;
@@ -57,18 +79,30 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/** The control font list. */
private FontComboBox controlFontList;
+ /** The control font size spinner. */
+ private JSpinner controlFontSizeSpinner;
+
/** The checkbox for âuse same as control fontâ. */
private JCheckBox useCustomUserFontCheckBox;
/** The user font list. */
private FontComboBox userFontList;
+ /** The user font size spinner. */
+ private JSpinner userFontSizeSpinner;
+
+ /** The checkbox for custom L&F. */
+ private JCheckBox useCustomLAFCheckBox;
+
+ /** The combo box for the L&Fs. */
+ private JComboBox customLAFComboBox;
+
/** Whether the dialog was cancelled. */
private boolean cancelled;
/**
* Creates a new configuration dialog.
- *
+ *
* @param swingInterface
* The Swing interface
*/
@@ -88,7 +122,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
*/
@@ -97,10 +131,31 @@ public class ConfigurationDialog extends JDialog implements I18nable {
}
/**
+ * Returns whether the advanced mode is selected.
+ *
+ * @return true
if the advanced mode is selected,
+ * false
otherwise
+ */
+ public boolean isAdvancedMode() {
+ return advancedModeCheckBox.isSelected();
+ }
+
+ /**
+ * Sets whether the advanced mode is selected.
+ *
+ * @param advancedMode
+ * true
if the advanced mode is selected,
+ * false
otherwise
+ */
+ public void setAdvancedMode(boolean advancedMode) {
+ advancedModeCheckBox.setSelected(advancedMode);
+ }
+
+ /**
* 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
*/
@@ -110,7 +165,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/**
* Sets the state of the âantialiasâ checkbox.
- *
+ *
* @param antialias
* The state of the checkbox
*/
@@ -120,48 +175,104 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/**
* 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) (useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() : null);
+ return useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() + "-" + controlFontSizeSpinner.getValue() : 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(controlFont != null);
- controlFontList.setSelectedItem(controlFont);
+ boolean hasControlFont = controlFont != null;
+ useCustomControlFontCheckBox.setSelected(hasControlFont);
+ controlFontList.setEnabled(hasControlFont);
+ controlFontSizeSpinner.setEnabled(hasControlFont);
+ if (hasControlFont) {
+ Font font = Font.decode(controlFont);
+ controlFontSizeSpinner.setValue(font.getSize());
+ controlFontList.setSelectedItem(font.getName());
+ } else {
+ controlFontSizeSpinner.setValue(12);
+ controlFontList.setSelectedItem(null);
+ }
}
/**
* 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) (useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() : null);
+ return useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() + "-" + userFontSizeSpinner.getValue() : 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(userFont != null);
- userFontList.setSelectedItem(userFont);
+ boolean hasUserFont = userFont != null;
+ useCustomUserFontCheckBox.setSelected(hasUserFont);
+ userFontList.setEnabled(hasUserFont);
+ userFontSizeSpinner.setEnabled(hasUserFont);
+ if (hasUserFont) {
+ Font font = Font.decode(userFont);
+ userFontSizeSpinner.setValue(font.getSize());
+ userFontList.setSelectedItem(font.getName());
+ } else {
+ userFontSizeSpinner.setValue(12);
+ userFontList.setSelectedItem(null);
+ }
+ }
+
+ /**
+ * Returns the class name of the selected look and feel, if a custom look
+ * and feel is selected.
+ *
+ * @return The class name of the look and feel to load, or null
+ * if no special look and feel should be used
+ */
+ public String getLookAndFeel() {
+ if (!useCustomLAFCheckBox.isSelected()) {
+ return null;
+ }
+ return ((LookAndFeelWrapper) customLAFComboBox.getSelectedItem()).getClassName();
+ }
+
+ /**
+ * Sets the given look and feel.
+ *
+ * @param lookAndFeel
+ * The class name of the look and feel, or null
to
+ * not select a custom look and feel
+ */
+ public void setLookAndFeel(String lookAndFeel) {
+ useCustomLAFCheckBox.setSelected(false);
+ customLAFComboBox.setEnabled(false);
+ if (lookAndFeel == null) {
+ return;
+ }
+ for (int lookAndFeelIndex = 0; lookAndFeelIndex < customLAFComboBox.getItemCount(); lookAndFeelIndex++) {
+ LookAndFeelWrapper lookAndFeelWrapper = (LookAndFeelWrapper) customLAFComboBox.getItemAt(lookAndFeelIndex);
+ if (lookAndFeelWrapper.getClassName().equals(lookAndFeel)) {
+ customLAFComboBox.setSelectedIndex(lookAndFeelIndex);
+ customLAFComboBox.setEnabled(true);
+ useCustomLAFCheckBox.setSelected(true);
+ break;
+ }
+ }
}
//
@@ -192,7 +303,16 @@ public class ConfigurationDialog extends JDialog implements I18nable {
actionCancel();
}
};
- antialiasAction = new I18nAction("configurationDialog.page.interface.item.beautify") {
+ advancedModeAction = new I18nAction("configurationDialog.page.interface.item.advancedMode") {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void actionPerformed(ActionEvent e) {
+ /* do nothing. */
+ }
+ };
+ antialiasAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.antialias") {
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
@@ -201,24 +321,38 @@ public class ConfigurationDialog extends JDialog implements I18nable {
/* do nothing. */
}
};
- useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") {
+ useCustomControlFontAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomControlFont") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent e) {
+ boolean selected = useCustomControlFontCheckBox.isSelected();
+ controlFontList.setEnabled(selected);
+ controlFontSizeSpinner.setEnabled(selected);
+ }
+ };
+ useCustomUserFontAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomUserFont") {
/**
* {@inheritDoc}
*/
@SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent e) {
- controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected());
+ boolean selected = useCustomUserFontCheckBox.isSelected();
+ userFontList.setEnabled(selected);
+ userFontSizeSpinner.setEnabled(selected);
}
};
- useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") {
+ useCustomLAFAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomLAF") {
/**
* {@inheritDoc}
*/
@SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent e) {
- userFontList.setEnabled(useCustomUserFontCheckBox.isSelected());
+ customLAFComboBox.setEnabled(useCustomLAFCheckBox.isSelected());
}
};
}
@@ -236,6 +370,9 @@ public class ConfigurationDialog extends JDialog implements I18nable {
JComponent interfaceConfig = createInterfaceConfig();
tabbedPane.add(I18n.get("configurationDialog.page.interface.name"), interfaceConfig);
+ JComponent interfaceTweaksConfig = createInterfaceTweaksConfig();
+ tabbedPane.add(I18n.get("configurationDialog.page.interfaceTweaks.name"), interfaceTweaksConfig);
+
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
contentPane.add(buttonPanel, BorderLayout.PAGE_END);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
@@ -248,32 +385,68 @@ public class ConfigurationDialog extends JDialog implements I18nable {
}
/**
- * Creates the panel for the interface configuration.
- *
+ * Creates the interface configuration panel.
+ *
* @return The interface configuration panel
*/
private JComponent createInterfaceConfig() {
JPanel interfaceConfigPanel = new JPanel(new GridBagLayout());
interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+ advancedModeCheckBox = new JCheckBox(advancedModeAction);
+ interfaceConfigPanel.add(advancedModeCheckBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+ interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+ return interfaceConfigPanel;
+ }
+
+ /**
+ * Creates the panel for the interface tweaks configuration.
+ *
+ * @return The interface tweaks configuration panel
+ */
+ private JComponent createInterfaceTweaksConfig() {
+ JPanel interfaceTweaksConfigPanel = new JPanel(new GridBagLayout());
+ interfaceTweaksConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+ restartRequiredLabel = new I18nLabel("configurationDialog.page.interfaceTweaks.item.restartRequired");
+ interfaceTweaksConfigPanel.add(restartRequiredLabel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
+
antialiasCheckBox = new JCheckBox(antialiasAction);
- interfaceConfigPanel.add(antialiasCheckBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+ interfaceTweaksConfigPanel.add(antialiasCheckBox, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(18, 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, 0, 0, 0), 0, 0));
+ interfaceTweaksConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 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));
+ interfaceTweaksConfigPanel.add(controlFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
+
+ controlFontSizeSpinner = new JSpinner(new SpinnerNumberModel(12, 6, 80, 1));
+ interfaceTweaksConfigPanel.add(controlFontSizeSpinner, new GridBagConstraints(2, 2, 1, 1, 0.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, 0, 0, 0), 0, 0));
+ interfaceTweaksConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 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));
+ interfaceTweaksConfigPanel.add(userFontList, new GridBagConstraints(1, 3, 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));
+ userFontSizeSpinner = new JSpinner(new SpinnerNumberModel(12, 6, 80, 1));
+ interfaceTweaksConfigPanel.add(userFontSizeSpinner, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
- return interfaceConfigPanel;
+ useCustomLAFCheckBox = new JCheckBox(useCustomLAFAction);
+ interfaceTweaksConfigPanel.add(useCustomLAFCheckBox, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
+
+ LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
+ List lookAndFeelWrappers = new ArrayList();
+ for (LookAndFeelInfo lookAndFeelInfo: lookAndFeelInfos) {
+ lookAndFeelWrappers.add(new LookAndFeelWrapper(lookAndFeelInfo.getClassName(), lookAndFeelInfo.getName()));
+ }
+ customLAFComboBox = new JComboBox(lookAndFeelWrappers.toArray(new LookAndFeelWrapper[0]));
+ interfaceTweaksConfigPanel.add(customLAFComboBox, new GridBagConstraints(1, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
+
+ interfaceTweaksConfigPanel.add(new JPanel(), new GridBagConstraints(0, 5, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+ return interfaceTweaksConfigPanel;
}
//
@@ -284,6 +457,18 @@ public class ConfigurationDialog extends JDialog implements I18nable {
* Called when the âokayâ button is clicked.
*/
private void actionOkay() {
+ if (useCustomControlFontCheckBox.isSelected()) {
+ if (controlFontList.getSelectedItem() == null) {
+ JOptionPane.showMessageDialog(this, I18n.get("configurationDialog.error.noControlFontSelected.message"), I18n.get("configurationDialog.error.noControlFontSelected.title"), JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ }
+ if (useCustomUserFontCheckBox.isSelected()) {
+ if (userFontList.getSelectedItem() == null) {
+ JOptionPane.showMessageDialog(this, I18n.get("configurationDialog.error.noUserFontSelected.message"), I18n.get("configurationDialog.error.noUserFontSelected.title"), JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ }
cancelled = false;
setVisible(false);
}
@@ -306,10 +491,59 @@ public class ConfigurationDialog extends JDialog implements I18nable {
public void updateI18n() {
okayAction.updateI18n();
cancelAction.updateI18n();
+ advancedModeAction.updateI18n();
+ restartRequiredLabel.updateI18n();
antialiasAction.updateI18n();
useCustomControlFontAction.updateI18n();
useCustomUserFontAction.updateI18n();
+ useCustomLAFAction.updateI18n();
SwingUtils.repackCentered(this);
}
+ /**
+ * Wrapper around class name and name of a {@link LookAndFeel}.
+ *
+ * @author David âBombeâ Roden <bombe@freenetproject.org>
+ */
+ private static class LookAndFeelWrapper {
+
+ /** The class name of the look and feel. */
+ private final String className;
+
+ /** The name of a look and feel. */
+ private final String lookAndFeelName;
+
+ /**
+ * Creates a new wrapper around the given class name and name of a look
+ * and feel.
+ *
+ * @param className
+ * The class name of the look and feel
+ * @param lookAndFeelName
+ * The name of the look and feel
+ */
+ public LookAndFeelWrapper(String className, String lookAndFeelName) {
+ this.className = className;
+ this.lookAndFeelName = lookAndFeelName;
+ }
+
+ /**
+ * Returns the class name of the look and feel.
+ *
+ * @return The class name of the look and feel
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return lookAndFeelName;
+ }
+
+ }
+
}