/** * Saves the settings to a file. * * @param file The file we're saving to * @throws IOException if the file could not be saved. */ public void save(File file) throws IOException { PrintStream out = new PrintStream(new FileOutputStream(file)); out.println("font.size=" + fontSize); out.println("font.bold=" + bold); out.println("font.italic=" + italic); out.println(); out.println("pad.top=" + paddingTop); out.println("pad.right=" + paddingRight); out.println("pad.bottom=" + paddingBottom); out.println("pad.left=" + paddingLeft); out.println("pad.advance.x=" + paddingAdvanceX); out.println("pad.advance.y=" + paddingAdvanceY); out.println(); out.println("glyph.page.width=" + glyphPageWidth); out.println("glyph.page.height=" + glyphPageHeight); out.println(); for (Iterator iter = effects.iterator(); iter.hasNext();) { ConfigurableEffect effect = (ConfigurableEffect)iter.next(); out.println("effect.class=" + effect.getClass().getName()); for (Iterator iter2 = effect.getValues().iterator(); iter2.hasNext();) { Value value = (Value)iter2.next(); out.println("effect." + value.getName() + "=" + value.getString()); } out.println(); } out.close(); }
/** * Prompts the user for a colour value * * @param name Thename of the value being configured * @param currentValue The default value that should be selected * @return The value selected */ static public Value colorValue(String name, Color currentValue) { return new DefaultValue(name, EffectUtil.toString(currentValue)) { public void showDialog () { Color newColor = JColorChooser.showDialog(null, "Choose a color", EffectUtil.fromString(value)); if (newColor != null) value = EffectUtil.toString(newColor); } public Object getObject () { return EffectUtil.fromString(value); } }; }
/** * Prompts the user for int value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @return The value selected by the user */ static public Value intValue (String name, final int currentValue, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JSpinner spinner = new JSpinner(new SpinnerNumberModel(currentValue, Short.MIN_VALUE, Short.MAX_VALUE, 1)); if (showValueDialog(spinner, description)) value = String.valueOf(spinner.getValue()); } public Object getObject () { return Integer.valueOf(value); } }; }
/** * Prompts the user for float value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @param min The minimum value to allow * @param max The maximum value to allow * @return The value selected by the user */ static public Value floatValue (String name, final float currentValue, final float min, final float max, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JSpinner spinner = new JSpinner(new SpinnerNumberModel(currentValue, min, max, 0.1f)); if (showValueDialog(spinner, description)) value = String.valueOf(((Double)spinner.getValue()).floatValue()); } public Object getObject () { return Float.valueOf(value); } }; }
/** * Prompts the user for boolean value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @return The value selected by the user */ static public Value booleanValue (String name, final boolean currentValue, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JCheckBox checkBox = new JCheckBox(); checkBox.setSelected(currentValue); if (showValueDialog(checkBox, description)) value = String.valueOf(checkBox.isSelected()); } public Object getObject () { return Boolean.valueOf(value); } }; }
public void updateValues () { prefs.put("foreground", EffectUtil.toString(colorEffect.getColor())); valuesPanel.removeAll(); values = effect.getValues(); for (Iterator iter = values.iterator(); iter.hasNext();) addValue((Value)iter.next()); }
/** * Saves the settings to a file. * * @param file The file we're saving to * @throws IOException if the file could not be saved. * @throws SlickException if effect from effects is not ConfigurableEffect */ public void save(@Nonnull File file) throws SlickException, IOException { try( final FileOutputStream fileOutputStream = new FileOutputStream(file); final PrintStream out = new PrintStream(fileOutputStream) ) { out.println("font.size=" + fontSize); out.println("font.bold=" + bold); out.println("font.italic=" + italic); out.println(); out.println("pad.top=" + paddingTop); out.println("pad.right=" + paddingRight); out.println("pad.bottom=" + paddingBottom); out.println("pad.left=" + paddingLeft); out.println("pad.advance.x=" + paddingAdvanceX); out.println("pad.advance.y=" + paddingAdvanceY); out.println(); out.println("glyph.page.width=" + glyphPageWidth); out.println("glyph.page.height=" + glyphPageHeight); out.println(); for (Iterator<Effect> iter = effects.iterator(); iter.hasNext();) { if(!(iter.next() instanceof ConfigurableEffect)) { throw new SlickException("Effect is not org.newdawn.slick.font.effects.ConfigurableEffect"); } ConfigurableEffect effect = (ConfigurableEffect) iter.next(); out.println("effect.class=" + effect.getClass().getName()); for (Value value : effect.getValues()) { out.println("effect." + value.getName() + "=" + value.getString()); } out.println(); } } }
/** * Prompts the user for a colour value * * @param name Thename of the value being configured * @param currentValue The default value that should be selected * @return The value selected */ @Nullable static public Value colorValue(String name, @Nullable Color currentValue) { return new DefaultValue(name, EffectUtil.toString(currentValue)) { public void showDialog () { Color newColor = JColorChooser.showDialog(null, "Choose a color", EffectUtil.fromString(value)); if (newColor != null) value = EffectUtil.toString(newColor); } public Object getObject () { return EffectUtil.fromString(value); } }; }
/** * Prompts the user for int value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @return The value selected by the user */ @Nonnull static public Value intValue (String name, final int currentValue, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JSpinner spinner = new JSpinner(new SpinnerNumberModel(currentValue, Short.MIN_VALUE, Short.MAX_VALUE, 1)); if (showValueDialog(spinner, description)) value = String.valueOf(spinner.getValue()); } public Object getObject () { return Integer.valueOf(value); } }; }
/** * Prompts the user for float value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @param min The minimum value to allow * @param max The maximum value to allow * @return The value selected by the user */ @Nonnull static public Value floatValue (String name, final float currentValue, final float min, final float max, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JSpinner spinner = new JSpinner(new SpinnerNumberModel(currentValue, min, max, 0.1f)); if (showValueDialog(spinner, description)) value = String.valueOf(((Double)spinner.getValue()).floatValue()); } public Object getObject () { return Float.valueOf(value); } }; }
/** * Prompts the user for boolean value * * @param name The name of the dialog to show * @param currentValue The current value to be displayed * @param description The help text to provide * @return The value selected by the user */ @Nonnull static public Value booleanValue (String name, final boolean currentValue, final String description) { return new DefaultValue(name, String.valueOf(currentValue)) { public void showDialog () { JCheckBox checkBox = new JCheckBox(); checkBox.setSelected(currentValue); if (showValueDialog(checkBox, description)) value = String.valueOf(checkBox.isSelected()); } public Object getObject () { return Boolean.valueOf(value); } }; }