Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/settings
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv19238/src/games/stendhal/client/gui/settings
Modified Files:
GeneralSettings.java
Log Message:
Added a selector for default font size
Index: GeneralSettings.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/settings/GeneralSettings.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** GeneralSettings.java 12 Nov 2012 20:38:32 -0000 1.10
--- GeneralSettings.java 1 Dec 2012 08:10:26 -0000 1.11
***************
*** 18,22 ****
--- 18,24 ----
import games.stendhal.client.gui.styled.Style;
import games.stendhal.client.gui.styled.StyleUtil;
+ import games.stendhal.client.gui.styled.StyledLookAndFeel;
import games.stendhal.client.gui.wt.core.WtWindowManager;
+ import games.stendhal.common.MathHelper;
import games.stendhal.common.NotificationType;
***************
*** 32,46 ****
import javax.swing.JComponent;
import javax.swing.JLabel;
class GeneralSettings {
-
private static final String GAMESCREEN_BLOOD = "gamescreen.blood";
private static final String GAMESCREEN_AUTORAISECORPSE = "gamescreen.autoraisecorpse";
! /** Default decorative font */
private static final String DEFAULT_FONT = "BlackChancery";
! /** Property used for the decorative font */
private static final String FONT_PROPERTY = "ui.logfont";
! /** Property used for the double click setting */
private static final String DOUBLE_CLICK_PROPERTY = "ui.doubleclick";
--- 34,56 ----
import javax.swing.JComponent;
import javax.swing.JLabel;
+ import javax.swing.LookAndFeel;
+ import javax.swing.UIManager;
+ /**
+ * Page for general settings.
+ */
class GeneralSettings {
private static final String GAMESCREEN_BLOOD = "gamescreen.blood";
private static final String GAMESCREEN_AUTORAISECORPSE = "gamescreen.autoraisecorpse";
! /** Default decorative font. */
private static final String DEFAULT_FONT = "BlackChancery";
! /** Default font size. */
! private static final int DEFAULT_FONT_SIZE = 12;
! /** Property used for the decorative font. */
private static final String FONT_PROPERTY = "ui.logfont";
! /** Property used for the decorative font. */
! private static final String FONT_SIZE_PROPERTY = "ui.font_size";
! /** Property used for the double click setting. */
private static final String DOUBLE_CLICK_PROPERTY = "ui.doubleclick";
***************
*** 53,59 ****
private static final String SCALE_SCREEN_PROPERTY = "ui.scale_screen";
! /** Container for the setting components */
private final JComponent page;
GeneralSettings() {
int pad = SBoxLayout.COMMON_PADDING;
--- 63,72 ----
private static final String SCALE_SCREEN_PROPERTY = "ui.scale_screen";
! /** Container for the setting components. */
private final JComponent page;
+ /**
+ * Create new GeneralSettings.
+ */
GeneralSettings() {
int pad = SBoxLayout.COMMON_PADDING;
***************
*** 98,115 ****
boolean enabled = (e.getStateChange() == ItemEvent.SELECTED);
String tmp = enabled ? "enabled" : "disabled";
! String msg = "Lighting effects are now " + tmp +
! ". You may need to change map or relogin for it to take effect.";
ClientSingletonRepository.getUserInterface().addEventLine(new EventLine("", msg, NotificationType.CLIENT));
}
});
! JCheckBox scaleScreenToggle = SettingsComponentFactory.createSettingsToggle(SCALE_SCREEN_PROPERTY,
"true", "Scale view to fit window", "<html>If selected, the game view will scale to fit the available space,<br>otherwise the default sized graphics are used.</html>");
page.add(scaleScreenToggle);
!
page.add(createFontSelector(), SBoxLayout.constraint(SLayout.EXPAND_X));
}
/**
* Create selector for the font used in the quest log and achievements.
*
--- 111,171 ----
boolean enabled = (e.getStateChange() == ItemEvent.SELECTED);
String tmp = enabled ? "enabled" : "disabled";
! String msg = "Lighting effects are now " + tmp
! + ". You may need to change map or relogin for it to take effect.";
ClientSingletonRepository.getUserInterface().addEventLine(new EventLine("", msg, NotificationType.CLIENT));
}
});
! final JCheckBox scaleScreenToggle = SettingsComponentFactory.createSettingsToggle(SCALE_SCREEN_PROPERTY,
"true", "Scale view to fit window", "<html>If selected, the game view will scale to fit the available space,<br>otherwise the default sized graphics are used.</html>");
page.add(scaleScreenToggle);
! page.add(createFontSizeSelector());
page.add(createFontSelector(), SBoxLayout.constraint(SLayout.EXPAND_X));
}
/**
+ * Create selector for the default font size.
+ *
+ * @return component containing the selector
+ */
+ private JComponent createFontSizeSelector() {
+ JComponent container = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
+ container.add(new JLabel("Text size"));
+
+ final JComboBox selector = new JComboBox();
+
+ // Fill the selector, and set current size as the selection
+ int current = WtWindowManager.getInstance().getPropertyInt(FONT_SIZE_PROPERTY, DEFAULT_FONT_SIZE);
+ selector.addItem("default (12)");
+ for (int size = 8; size <= 20; size += 2) {
+ Integer obj = size;
+ selector.addItem(obj);
+ if ((size == current) && (size != DEFAULT_FONT_SIZE)) {
+ selector.setSelectedItem(obj);
+ }
+ }
+
+ selector.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Object selected = selector.getSelectedItem();
+ if ("default (12)".equals(selected)) {
+ selected = "12";
+ }
+ WtWindowManager.getInstance().setProperty(FONT_SIZE_PROPERTY, selected.toString());
+
+ LookAndFeel look = UIManager.getLookAndFeel();
+ if (look instanceof StyledLookAndFeel) {
+ int size = MathHelper.parseIntDefault(selected.toString(), DEFAULT_FONT_SIZE);
+ ((StyledLookAndFeel) look).setDefaultFontSize(size);
+ }
+ }
+ });
+ container.add(selector);
+ container.setToolTipText("Common text size");
+ return container;
+ }
+
+ /**
* Create selector for the font used in the quest log and achievements.
*
|