Ver código fonte

Fixes issue 2665 (Adds an optional integer prefs component)

Moves colour dialogs to a separate package

Change-Id: Id0aa4294fdc5f33139a5d14c47afa778346cd6bf
Reviewed-on: http://gerrit.dmdirc.com/100
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3b1
Gregory Holmes 14 anos atrás
pai
commit
a0ceaf14cc

+ 1
- 1
src/com/dmdirc/addons/nickcolours/NickColourInputDialog.java Ver arquivo

@@ -25,7 +25,7 @@ package com.dmdirc.addons.nickcolours;
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.addons.ui_swing.MainFrame;
27 27
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
28
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
28
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
29 29
 
30 30
 import java.awt.event.ActionEvent;
31 31
 import java.awt.event.ActionListener;

+ 62
- 3
src/com/dmdirc/addons/ui_swing/PrefsComponentFactory.java Ver arquivo

@@ -24,14 +24,17 @@ package com.dmdirc.addons.ui_swing;
24 24
 
25 25
 import com.dmdirc.config.prefs.PreferencesSetting;
26 26
 import com.dmdirc.config.prefs.validator.NumericalValidator;
27
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
27
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
28 28
 import com.dmdirc.addons.ui_swing.components.FontPicker;
29
-import com.dmdirc.addons.ui_swing.components.OptionalColourChooser;
29
+import com.dmdirc.addons.ui_swing.components.OptionalJSpinner;
30
+import com.dmdirc.addons.ui_swing.components.colours.OptionalColourChooser;
30 31
 import com.dmdirc.addons.ui_swing.components.durationeditor.DurationDisplay;
31 32
 import com.dmdirc.addons.ui_swing.components.durationeditor.DurationListener;
32 33
 import com.dmdirc.addons.ui_swing.components.renderers.MapEntryRenderer;
33 34
 import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
34 35
 
36
+import com.dmdirc.config.prefs.validator.OptionalValidator;
37
+import com.dmdirc.config.prefs.validator.Validator;
35 38
 import java.awt.Dimension;
36 39
 import java.awt.Font;
37 40
 import java.awt.event.ActionEvent;
@@ -87,6 +90,9 @@ public final class PrefsComponentFactory {
87 90
             case INTEGER:
88 91
                 option = getIntegerOption(setting);
89 92
                 break;
93
+            case OPTIONALINTEGER:
94
+                option = getOptionalIntegerOption(setting);
95
+                break;
90 96
             case DURATION:
91 97
                 option = getDurationOption(setting);
92 98
                 break;
@@ -207,7 +213,7 @@ public final class PrefsComponentFactory {
207 213
         }
208 214
 
209 215
         option.addChangeListener(new ChangeListener() {
210
-            
216
+
211 217
             /** {@inheritDoc} */
212 218
             @Override
213 219
             public void stateChanged(final ChangeEvent e) {
@@ -219,6 +225,59 @@ public final class PrefsComponentFactory {
219 225
         return option;
220 226
     }
221 227
 
228
+    /**
229
+     * Initialises and returns a JSpinner for the specified setting.
230
+     *
231
+     * @param setting The setting to create the component for
232
+     * @return A JComponent descendent for the specified setting
233
+     */
234
+    private static JComponent getOptionalIntegerOption(final PreferencesSetting setting) {
235
+        final boolean state = setting.getValue() != null
236
+                && !setting.getValue().startsWith("false:");
237
+        final String integer = setting.getValue() == null ? "0" : setting.getValue().
238
+                substring(1 + setting.getValue().indexOf(':'));
239
+        
240
+        OptionalJSpinner option;
241
+        Validator optionalValidator = setting.getValidator();
242
+        Validator numericalValidator = null;
243
+        if (optionalValidator instanceof OptionalValidator) {
244
+            numericalValidator = ((OptionalValidator) setting.getValidator()).
245
+                    getValidator();
246
+            if (!(numericalValidator instanceof NumericalValidator)) {
247
+                numericalValidator = null;
248
+            }
249
+        }
250
+
251
+        try {
252
+            if (numericalValidator != null) {
253
+                option = new OptionalJSpinner(
254
+                        new SpinnerNumberModel(Integer.parseInt(integer),
255
+                        ((NumericalValidator) numericalValidator).getMin(),
256
+                        ((NumericalValidator) numericalValidator).getMax(),
257
+                        1), state);
258
+            } else {
259
+                option = new OptionalJSpinner(new SpinnerNumberModel());
260
+                option.setValue(Integer.parseInt(integer));
261
+                option.setSelected(state);
262
+            }
263
+        } catch (NumberFormatException ex) {
264
+            option = new OptionalJSpinner(new SpinnerNumberModel(), state);
265
+        }
266
+
267
+        option.addChangeListener(new ChangeListener() {
268
+
269
+            /** {@inheritDoc} */
270
+            @Override
271
+            public void stateChanged(final ChangeEvent e) {
272
+                setting.setValue(((OptionalJSpinner) e.getSource()).isSelected() + ":" +
273
+                        ((OptionalJSpinner) e.getSource()).getValue().
274
+                        toString());
275
+            }
276
+        });
277
+
278
+        return option;
279
+    }
280
+
222 281
     /**
223 282
      * Initialises and returns a DurationDisplay for the specified setting.
224 283
      *

+ 217
- 0
src/com/dmdirc/addons/ui_swing/components/OptionalJSpinner.java Ver arquivo

@@ -0,0 +1,217 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.components;
25
+
26
+import com.dmdirc.util.ListenerList;
27
+
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
31
+import javax.swing.JCheckBox;
32
+import javax.swing.JPanel;
33
+import javax.swing.JSpinner;
34
+import javax.swing.SpinnerModel;
35
+import javax.swing.SpinnerNumberModel;
36
+import javax.swing.event.ChangeEvent;
37
+import javax.swing.event.ChangeListener;
38
+
39
+import net.miginfocom.swing.MigLayout;
40
+
41
+/**
42
+ * Optional JSpinner component.  Composite JSpinner, JCheckbox component.
43
+ */
44
+public class OptionalJSpinner extends JPanel implements ActionListener,
45
+        ChangeListener {
46
+
47
+    private static final long serialVersionUID = -2867331420063503447L;
48
+    private final JSpinner spinner;
49
+    private final JCheckBox checkbox;
50
+    private final ListenerList listeners;
51
+
52
+    /**
53
+     * Creates a new optional JSpinner with a default number model.
54
+     */
55
+    public OptionalJSpinner() {
56
+        this(new SpinnerNumberModel());
57
+    }
58
+
59
+    /**
60
+     * Creates a new optional JSpinner with a default number model.
61
+     *
62
+     * @param enabled Initial selected state
63
+     */
64
+    public OptionalJSpinner(final boolean enabled) {
65
+        this(new SpinnerNumberModel(), enabled);
66
+    }
67
+
68
+    /**
69
+     * Creates a new optional SPinner with a default number model.
70
+     *
71
+     * @param model Model to show
72
+     */
73
+    public OptionalJSpinner(final SpinnerModel model) {
74
+        this(model, true);
75
+    }
76
+
77
+    /**
78
+     * Creates a new optional SPinner with a default number model.
79
+     *
80
+     * @param model Model to show
81
+     * @param enabled Initial selected state
82
+     */
83
+    public OptionalJSpinner(final SpinnerModel model, final boolean enabled) {
84
+        checkbox = new JCheckBox("", enabled);
85
+        spinner = new JSpinner(model);
86
+        listeners = new ListenerList();
87
+
88
+        spinner.setEnabled(enabled);
89
+
90
+        spinner.addChangeListener(this);
91
+        checkbox.addActionListener(this);
92
+
93
+        setLayout(new MigLayout("fill"));
94
+
95
+        add(checkbox, "");
96
+        add(spinner, "growx, pushx");
97
+    }
98
+
99
+    /**
100
+     * Returns the state of the button. True if the toggle button is selected,
101
+     * false if it's not.
102
+     *
103
+     * @return true if the toggle button is selected, otherwise false
104
+     */
105
+    public boolean isSelected() {
106
+        return checkbox.isSelected();
107
+    }
108
+
109
+    /**
110
+     * Sets the state of the button.
111
+     *
112
+     * @param selected true if the button is selected, otherwise false
113
+     */
114
+    public void setSelected(final boolean selected) {
115
+        checkbox.setSelected(selected);
116
+    }
117
+
118
+    /**
119
+     * Returns the current value of the model, typically this value is
120
+     * displayed by the editor. If the user has changed the value displayed
121
+     * by the editor it is possible for the model's value to differ from that
122
+     * of the editor, refer to the class level javadoc for examples of how to
123
+     * deal with this.
124
+     *
125
+     * This method simply delegates to the model. It is equivalent to:
126
+     * 
127
+     * getModel().getValue()
128
+     *
129
+     * @return The current value
130
+     */
131
+    public Object getValue() {
132
+        return spinner.getValue();
133
+    }
134
+
135
+    /**
136
+     * Changes current value of the model, typically this value is displayed
137
+     * by the editor. If the SpinnerModel implementation doesn't support
138
+     * the specified value then an IllegalArgumentException is thrown.
139
+     * This method simply delegates to the model. It is equivalent to:
140
+     *
141
+     * getModel().setValue(value)
142
+     *
143
+     * @param value Value to set
144
+     */
145
+    public void setValue(final Object value) {
146
+        spinner.setValue(value);
147
+    }
148
+
149
+    /**
150
+     * Returns the SpinnerModel that defines this spinners sequence of values.
151
+     *
152
+     * @return the value of the model property
153
+     */
154
+    public SpinnerModel getModel() {
155
+        return spinner.getModel();
156
+    }
157
+
158
+    /**
159
+     * Changes the model that represents the value of this spinner. If the
160
+     * editor property has not been explicitly set, the editor property
161
+     * is (implicitly) set after the "model" PropertyChangeEvent has been
162
+     * fired. The editor property is set to the value returned by createEditor,
163
+     * as in:
164
+     *
165
+     * setEditor(createEditor(model));
166
+     *
167
+     * @param model the new SpinnerModel
168
+     */
169
+    public void setModel(final SpinnerModel model) {
170
+        spinner.setModel(model);
171
+    }
172
+
173
+    /**
174
+     * Adds a change listener to this optional spinner.
175
+     *
176
+     * @param listener Listener to add
177
+     */
178
+    public void addChangeListener(final ChangeListener listener) {
179
+        synchronized (listeners) {
180
+            listeners.add(ChangeListener.class, listener);
181
+        }
182
+    }
183
+
184
+    /**
185
+     * Removes a change listener from this optional spinner.
186
+     *
187
+     * @param listener Listener to remove
188
+     */
189
+    public void removeChangeListener(final ChangeListener listener) {
190
+        synchronized (listeners) {
191
+            listeners.remove(ChangeListener.class, listener);
192
+        }
193
+    }
194
+
195
+    private void fireChangeListener() {
196
+        for (ChangeListener listener : listeners.get(ChangeListener.class)) {
197
+            listener.stateChanged(new ChangeEvent(this));
198
+        }
199
+    }
200
+
201
+    /** {@inheritDoc} */
202
+    @Override
203
+    public void stateChanged(final ChangeEvent e) {
204
+        fireChangeListener();
205
+    }
206
+
207
+    /**
208
+     * {@inheritDoc}
209
+     *
210
+     * @param e Action event
211
+     */
212
+    @Override
213
+    public void actionPerformed(final ActionEvent e) {
214
+        fireChangeListener();
215
+        spinner.setEnabled(checkbox.isSelected());
216
+    }
217
+}

+ 1
- 0
src/com/dmdirc/addons/ui_swing/components/SwingInputField.java Ver arquivo

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components;
24 24
 
25
+import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
25 26
 import com.dmdirc.ui.IconManager;
26 27
 import com.dmdirc.config.IdentityManager;
27 28
 import com.dmdirc.ui.interfaces.InputField;

+ 1
- 0
src/com/dmdirc/addons/ui_swing/components/TextAreaInputField.java Ver arquivo

@@ -21,6 +21,7 @@
21 21
  */
22 22
 package com.dmdirc.addons.ui_swing.components;
23 23
 
24
+import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
24 25
 import com.dmdirc.config.IdentityManager;
25 26
 import com.dmdirc.ui.interfaces.InputField;
26 27
 

src/com/dmdirc/addons/ui_swing/components/ColourChooser.java → src/com/dmdirc/addons/ui_swing/components/colours/ColourChooser.java Ver arquivo

@@ -20,8 +20,9 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.components;
23
+package com.dmdirc.addons.ui_swing.components.colours;
24 24
 
25
+import com.dmdirc.addons.ui_swing.components.*;
25 26
 import com.dmdirc.ui.messages.ColourManager;
26 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
27 28
 

src/com/dmdirc/addons/ui_swing/components/ColourPickerDialog.java → src/com/dmdirc/addons/ui_swing/components/colours/ColourPickerDialog.java Ver arquivo

@@ -20,10 +20,9 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.components;
23
+package com.dmdirc.addons.ui_swing.components.colours;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
26
-import com.dmdirc.addons.ui_swing.SwingController;
27 26
 
28 27
 import java.awt.Window;
29 28
 import java.awt.event.ActionListener;

src/com/dmdirc/addons/ui_swing/components/ColourPickerPanel.java → src/com/dmdirc/addons/ui_swing/components/colours/ColourPickerPanel.java Ver arquivo

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.components;
23
+package com.dmdirc.addons.ui_swing.components.colours;
24 24
 
25 25
 import com.dmdirc.ui.messages.ColourManager;
26 26
 

src/com/dmdirc/addons/ui_swing/components/OptionalColourChooser.java → src/com/dmdirc/addons/ui_swing/components/colours/OptionalColourChooser.java Ver arquivo

@@ -20,8 +20,9 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.components;
23
+package com.dmdirc.addons.ui_swing.components.colours;
24 24
 
25
+import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
25 26
 import com.dmdirc.ui.messages.ColourManager;
26 27
 import com.dmdirc.util.ListenerList;
27 28
 import com.dmdirc.addons.ui_swing.UIUtilities;

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/expandingsettings/AddOptionPanel.java Ver arquivo

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components.expandingsettings;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.components.renderers.AddOptionCellRenderer;
26
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
26
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
27 27
 import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel.OptionType;
28 28
 import com.dmdirc.addons.ui_swing.UIUtilities;
29 29
 import com.dmdirc.addons.ui_swing.components.FontPicker;

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/expandingsettings/CurrentOptionsPanel.java Ver arquivo

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components.expandingsettings;
24 24
 
25 25
 import com.dmdirc.ui.IconManager;
26
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
26
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
27 27
 import com.dmdirc.addons.ui_swing.components.ImageButton;
28 28
 import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel.OptionType;
29 29
 import com.dmdirc.addons.ui_swing.UIUtilities;

+ 2
- 2
src/com/dmdirc/addons/ui_swing/components/frames/InputTextFrame.java Ver arquivo

@@ -351,10 +351,10 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
351 351
             final String inputFieldText = getInputField().getText();
352 352
             final String text = inputFieldText.substring(0, caretPosition) + clipboard + inputFieldText.substring(caretPosition);
353 353
             //check the limit
354
-            final int pasteTrigger = getConfigManager().getOptionInt("ui",
354
+            final Integer pasteTrigger = getConfigManager().getOptionInt("ui",
355 355
                     "pasteProtectionLimit");
356 356
             //check whether the number of lines is over the limit
357
-            if (getContainer().getNumLines(text) > pasteTrigger) {
357
+            if (pasteTrigger != null && getContainer().getNumLines(text) > pasteTrigger) {
358 358
                 //show the multi line paste dialog
359 359
                 new PasteDialog(this, text, getController().getMainFrame()).setVisible(true);
360 360
                 inputField.setText("");

+ 2
- 2
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java Ver arquivo

@@ -25,8 +25,8 @@ package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
25 25
 import com.dmdirc.actions.ActionGroup;
26 26
 import com.dmdirc.config.prefs.PreferencesSetting;
27 27
 import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
28
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
29
-import com.dmdirc.addons.ui_swing.components.OptionalColourChooser;
28
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
29
+import com.dmdirc.addons.ui_swing.components.colours.OptionalColourChooser;
30 30
 import com.dmdirc.addons.ui_swing.components.durationeditor.DurationDisplay;
31 31
 
32 32
 import java.awt.Window;

+ 3
- 3
src/com/dmdirc/addons/ui_swing/dialogs/prefs/PrefsCategoryLoader.java Ver arquivo

@@ -26,10 +26,10 @@ package com.dmdirc.addons.ui_swing.dialogs.prefs;
26 26
 import com.dmdirc.addons.ui_swing.Apple;
27 27
 import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
28 28
 import com.dmdirc.addons.ui_swing.UIUtilities;
29
-import com.dmdirc.addons.ui_swing.components.ColourChooser;
30
-import com.dmdirc.addons.ui_swing.components.OptionalColourChooser;
31
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29
+import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
30
+import com.dmdirc.addons.ui_swing.components.colours.OptionalColourChooser;
32 31
 import com.dmdirc.addons.ui_swing.components.durationeditor.DurationDisplay;
32
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
33 33
 import com.dmdirc.config.prefs.PreferencesCategory;
34 34
 import com.dmdirc.config.prefs.PreferencesSetting;
35 35
 

+ 21
- 3
src/com/dmdirc/config/ConfigSource.java Ver arquivo

@@ -210,11 +210,29 @@ public abstract class ConfigSource {
210 210
      *
211 211
      * @param domain The domain of the option
212 212
      * @param option The name of the option
213
+     * @param fallbacks An ordered array of further domains and options
214
+     * (in pairs) to try if the specified domain/option isn't found
213 215
      * @throws NumberFormatException If the setting can't be parsed
214
-     * @return The integer representation of the option
216
+     * @return The integer representation of the option or null if optional
217
+     * setting is false
215 218
      */
216
-    public int getOptionInt(final String domain, final String option) {
217
-        return Integer.parseInt(getOption(domain, option).trim());
219
+    public Integer getOptionInt(final String domain, final String option,
220
+            final String ... fallbacks) {
221
+        String value;
222
+
223
+        if (!hasOption(domain, option) || (value = getOption(domain, option))
224
+                .startsWith("false:")) {
225
+            return fallbacks.length >= 2 ? getOptionInt(fallbacks[0], fallbacks[1],
226
+                    Arrays.copyOfRange(fallbacks, 2, fallbacks.length)) : null;
227
+        }
228
+        if (value.startsWith("true:")) {
229
+            return Integer.parseInt(getOption(domain, option).trim().substring(
230
+                    5));
231
+        } else if (value.startsWith("false:")) {
232
+            return null;
233
+        } else {
234
+            return Integer.parseInt(getOption(domain, option).trim());
235
+        }
218 236
     }
219 237
 
220 238
 }

+ 1
- 1
src/com/dmdirc/config/defaults/default/defaults Ver arquivo

@@ -157,7 +157,7 @@ ui:
157 157
   nickListAltBackgroundColour=false:f0f0f0
158 158
   nicklistbackgroundcolour=false:0
159 159
   nicklistforegroundcolour=false:1
160
-  pasteProtectionLimit=1
160
+  pasteProtectionLimit=true:1
161 161
   quickCopy=false
162 162
   shownickcoloursinnicklist=true
163 163
   shownickcoloursintext=false

+ 3
- 2
src/com/dmdirc/config/prefs/PreferencesManager.java Ver arquivo

@@ -25,6 +25,7 @@ import com.dmdirc.Main;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.config.prefs.validator.NumericalValidator;
28
+import com.dmdirc.config.prefs.validator.OptionalValidator;
28 29
 import com.dmdirc.plugins.PluginManager;
29 30
 import com.dmdirc.plugins.Service;
30 31
 import com.dmdirc.util.ListenerList;
@@ -165,8 +166,8 @@ public class PreferencesManager {
165 166
         category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
166 167
                 "ui", "awayindicator", "Away indicator",
167 168
                 "Shows an indicator in windows when you are marked as away"));
168
-        category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
169
-                new NumericalValidator(0, 100), "ui", "pasteProtectionLimit",
169
+        category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
170
+                new OptionalValidator(new NumericalValidator(0, 100)), "ui", "pasteProtectionLimit",
170 171
                 "Paste protection trigger", "Confirm pasting of text that " +
171 172
                 "contains more than this many lines."));
172 173
         

+ 2
- 0
src/com/dmdirc/config/prefs/PreferencesType.java Ver arquivo

@@ -32,6 +32,8 @@ public enum PreferencesType {
32 32
     TEXT,
33 33
     /** A free-form integer preference. */
34 34
     INTEGER,
35
+    /** A optional free-form integer preference. */
36
+    OPTIONALINTEGER,
35 37
     /** A boolean preference. */
36 38
     BOOLEAN,
37 39
     /** A colour preference. */

+ 70
- 0
src/com/dmdirc/config/prefs/validator/OptionalValidator.java Ver arquivo

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.config.prefs.validator;
23
+
24
+/**
25
+ * Validates an optional setting in tandem with another validator.
26
+ */
27
+public class OptionalValidator implements Validator<String> {
28
+    
29
+    /** The minimum value for this number. */
30
+    protected final Validator<String> validator;
31
+
32
+    /**
33
+     * Creates a new Optional validator
34
+     * @param validator 
35
+     */
36
+    public OptionalValidator(Validator<String> validator) {
37
+        this.validator = validator;
38
+    }
39
+
40
+    /**
41
+     * Gets the secondary validator.
42
+     *
43
+     * @return Secondary validator
44
+     */
45
+    public Validator getValidator() {
46
+        return validator;
47
+    }
48
+    
49
+    /** {@inheritDoc} */
50
+    @Override
51
+    public ValidationResponse validate(final String object) {
52
+        String booleanv;
53
+        String otherv;
54
+        int colonIndex = object.indexOf(":");
55
+
56
+        if (colonIndex == -1) {
57
+            return new ValidationResponse("Must contain boolean int seperator.");
58
+        }
59
+
60
+        booleanv = object.substring(0, colonIndex);
61
+        otherv = object.substring(colonIndex + 1);
62
+
63
+        if (!"true".equals(booleanv) && !"false".equals(booleanv)) {
64
+            return new ValidationResponse("Must be true or false.");
65
+        }
66
+
67
+        return validator.validate(otherv);
68
+    }
69
+
70
+}

Carregando…
Cancelar
Salvar