From: David ‘Bombe’ Roden Date: Sat, 26 Apr 2008 10:41:58 +0000 (+0000) Subject: add size selector for fonts X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d20f7a1d2ca77ada5408ac73926d64725685b6a5;p=jSite2.git add size selector for fonts git-svn-id: http://trooper/svn/projects/jSite/trunk@767 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java index a65947d..ee8e471 100644 --- a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java +++ b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java @@ -6,6 +6,7 @@ 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; @@ -17,7 +18,9 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; +import javax.swing.JSpinner; import javax.swing.JTabbedPane; +import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; import net.pterodactylus.jsite.i18n.I18n; @@ -61,12 +64,18 @@ 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; + /** Whether the dialog was cancelled. */ private boolean cancelled; @@ -129,7 +138,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { * font is to be used */ public String getControlFont() { - return (String) (useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() : null); + return useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() + "-" + controlFontSizeSpinner.getValue() : null; } /** @@ -140,9 +149,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { * 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); + } } /** @@ -152,7 +170,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { * input font is to be used */ public String getUserFont() { - return (String) (useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() : null); + return useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() + "-" + userFontSizeSpinner.getValue() : null; } /** @@ -163,9 +181,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { * 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); + } } // @@ -212,7 +239,9 @@ public class ConfigurationDialog extends JDialog implements I18nable { */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { - controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected()); + boolean selected = useCustomControlFontCheckBox.isSelected(); + controlFontList.setEnabled(selected); + controlFontSizeSpinner.setEnabled(selected); } }; useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") { @@ -222,7 +251,9 @@ public class ConfigurationDialog extends JDialog implements I18nable { */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { - userFontList.setEnabled(useCustomUserFontCheckBox.isSelected()); + boolean selected = useCustomUserFontCheckBox.isSelected(); + userFontList.setEnabled(selected); + userFontSizeSpinner.setEnabled(selected); } }; } @@ -261,10 +292,10 @@ public class ConfigurationDialog extends JDialog implements I18nable { interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); restartRequiredLabel = new I18nLabel("configurationDialog.page.interface.item.restartRequired"); - interfaceConfigPanel.add(restartRequiredLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + interfaceConfigPanel.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, 1, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(18, 0, 0, 0), 0, 0)); + interfaceConfigPanel.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, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); @@ -272,13 +303,19 @@ public class ConfigurationDialog extends JDialog implements I18nable { controlFontList = new FontComboBox(); interfaceConfigPanel.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)); + interfaceConfigPanel.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, 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, 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, 4, 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)); + interfaceConfigPanel.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)); + + interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return interfaceConfigPanel; }