Hi Noel,

As I mentioned in my reply to Chris's message, I have applied the patch and it 
works great. Nice work.

FYI, I did tweak the Javadoc a bit, to tie validation less specifically to 
TextInput. I'm thinking there may be other use cases for it in the future.

Greg


On Thursday, March 26, 2009, at 11:50AM, "Noel Grandin" <[email protected]> 
wrote:
>Hi
>
>Patch attached.
>
>Regards, Noel.
>
>Greg Brown wrote:
>> Hi Noel,
>>
>> While attempting to add a validator example to the Kitchen Sink demo, I 
>> noticed a couple of things that still need a bit more work:
>>
>> 1) The validation classes need more Javadoc. I'll admit that we're pretty 
>> lax about method Javadoc a lot of the time, but we do try to make sure that 
>> every class has at least a minimal description. Otherwise, the documentation 
>> tends to look a bit unprofessional.
>>
>> 2) Each concrete validator should have a no-arg constructor and bean 
>> properties for configuring its behavior so it can be used in WTKX. For 
>> example, RegexTextValidator should have a "pattern" property:
>>
>> Pattern getPattern()
>> void setPattern(Pattern pattern)
>> void setPattern(String pattern)
>>
>> The string setter allows us to use it from WTKX like this:
>>
>> <TextInput>
>>     <validator>
>>         <validation:RegexTextValidator pattern="[0-9]"/>
>>     </validator>
>> </TextInput>
>>
>> WTKX automatically handles setters for primitive types (via BeanDictionary), 
>> so you don't need to provide String overloads for those. However, any 
>> non-primitive setters will require a String overload.
>>
>> We'd very much like to get these updates in before we release version 1.1. 
>> Do you think you will have time to do it in the very near future?
>>
>> Thanks,
>> Greg
>>
>>
>>   
>
>
>Index: wtk/src/pivot/wtk/text/validation/DecimalValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/DecimalValidator.java    (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/DecimalValidator.java    (working copy)
>@@ -18,10 +18,12 @@
> import java.text.ParseException;
> 
> /**
>- *
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for decimal values.
>+ *  
>  * @author Noel Grandin
>  */
> public abstract class DecimalValidator extends 
> FormattedValidator<NumberFormat> {
>+    
>     protected DecimalValidator(DecimalFormat format) {
>         super(format);
>     }
>Index: wtk/src/pivot/wtk/text/validation/DoubleRangeValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/DoubleRangeValidator.java        
>(revision 758676)
>+++ wtk/src/pivot/wtk/text/validation/DoubleRangeValidator.java        
>(working copy)
>@@ -14,17 +14,39 @@
> package pivot.wtk.text.validation;
> 
> /**
>- *
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a double value 
>limited to a range.
>+ * 
>  * @author Noel Grandin
>  */
> public class DoubleRangeValidator extends DoubleValidator {
>-    private final double minValue, maxValue;
>+    private double minValue, maxValue;
> 
>+    public DoubleRangeValidator() {
>+        this.minValue = 0;
>+        this.maxValue = 1;
>+    }
>+    
>     public DoubleRangeValidator(double minValue, double maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
> 
>+    public double getMinimum() {
>+        return minValue;
>+    }
>+
>+    public void setMinimum(double minValue) {
>+        this.minValue = minValue;
>+    }
>+
>+    public double getMaximum() {
>+        return maxValue;
>+    }
>+
>+    public void setMaximum(double maxValue) {
>+        this.maxValue = maxValue;
>+    }
>+
>     @Override
>     public boolean isValid(String text) {
>         boolean valid = false;
>Index: wtk/src/pivot/wtk/text/validation/DoubleValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/DoubleValidator.java     (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/DoubleValidator.java     (working copy)
>@@ -14,6 +14,7 @@
> package pivot.wtk.text.validation;
> 
> /**
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a double value.
>  *
>  * @author Noel Grandin
>  */
>Index: wtk/src/pivot/wtk/text/validation/FloatRangeValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/FloatRangeValidator.java (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/FloatRangeValidator.java (working copy)
>@@ -14,17 +14,39 @@
> package pivot.wtk.text.validation;
> 
> /**
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a float value 
>limited to a range.
>  *
>  * @author Noel Grandin
>  */
> public class FloatRangeValidator extends FloatValidator {
>-    private final float minValue, maxValue;
>+    private float minValue, maxValue;
> 
>+    public FloatRangeValidator() {
>+        this.minValue = 0;
>+        this.maxValue = 1;
>+    }
>+    
>     public FloatRangeValidator(float minValue, float maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
> 
>+    public float getMinimum() {
>+        return minValue;
>+    }
>+
>+    public void setMinimum(float minValue) {
>+        this.minValue = minValue;
>+    }
>+
>+    public float getMaximum() {
>+        return maxValue;
>+    }
>+
>+    public void setMaximum(float maxValue) {
>+        this.maxValue = maxValue;
>+    }
>+    
>     @Override
>     public boolean isValid(String text) {
>         boolean valid = false;
>Index: wtk/src/pivot/wtk/text/validation/FloatValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/FloatValidator.java      (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/FloatValidator.java      (working copy)
>@@ -14,6 +14,7 @@
> package pivot.wtk.text.validation;
> 
> /**
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a float value.
>  *
>  * @author Noel Grandin
>  */
>Index: wtk/src/pivot/wtk/text/validation/FormattedValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/FormattedValidator.java  (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/FormattedValidator.java  (working copy)
>@@ -16,12 +16,15 @@
> import java.text.ParsePosition;
> 
> /**
>- *
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a {...@link 
>java.text.Format}'ed value.
>+ * 
>+ * This class is mostly intended to be a base-class for other validators.
>+ * 
>  * @author Noel Grandin
>  */
> public abstract class FormattedValidator<TFormat extends java.text.Format> 
> implements Validator {
>     protected final TFormat format;
>-
>+    
>     protected FormattedValidator(TFormat format) {
>         this.format = format;
>     }
>Index: wtk/src/pivot/wtk/text/validation/IntRangeValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/IntRangeValidator.java   (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/IntRangeValidator.java   (working copy)
>@@ -14,17 +14,39 @@
> package pivot.wtk.text.validation;
> 
> /**
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for an int value 
>limited to a range.
>  *
>  * @author Noel Grandin
>  */
> public class IntRangeValidator extends IntValidator {
>-    private final int minValue, maxValue;
>+    private int minValue, maxValue;
> 
>+    public IntRangeValidator() {
>+        this.minValue = 0;
>+        this.maxValue = 1;
>+    }
>+    
>     public IntRangeValidator(int minValue, int maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
> 
>+    public int getMinimum() {
>+        return minValue;
>+    }
>+
>+    public void setMinimum(int minValue) {
>+        this.minValue = minValue;
>+    }
>+
>+    public int getMaximum() {
>+        return maxValue;
>+    }
>+
>+    public void setMaximum(int maxValue) {
>+        this.maxValue = maxValue;
>+    }
>+    
>     @Override
>     public boolean isValid(String text) {
>         boolean valid = false;
>Index: wtk/src/pivot/wtk/text/validation/IntValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/IntValidator.java        (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/IntValidator.java        (working copy)
>@@ -14,6 +14,7 @@
> package pivot.wtk.text.validation;
> 
> /**
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for an int value.
>  *
>  * @author Noel Grandin
>  */
>Index: wtk/src/pivot/wtk/text/validation/RegexTextValidator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/RegexTextValidator.java  (revision 
>758676)
>+++ wtk/src/pivot/wtk/text/validation/RegexTextValidator.java  (working copy)
>@@ -14,13 +14,19 @@
> package pivot.wtk.text.validation;
> 
> import java.util.regex.Pattern;
>+import java.util.regex.PatternSyntaxException;
> 
> /**
>- *
>+ * A {...@link pivot.wtk.TextInput} {...@link Validator} for a regular 
>expression.
>+ * 
>+ * @see Pattern
>  * @author Noel Grandin
>  */
> public class RegexTextValidator implements Validator {
>-    private final Pattern p;
>+    private Pattern p;
>+
>+    public RegexTextValidator() {
>+    }
> 
>     public RegexTextValidator(Pattern p) {
>         this.p = p;
>@@ -30,6 +36,22 @@
>         this.p = Pattern.compile(regexPattern);
>     }
> 
>+    public Pattern getPattern() {
>+        return p;
>+    }
>+
>+    public void setPattern(Pattern pattern) {
>+        this.p = pattern;
>+    }
>+
>+    /**
>+     * @throws PatternSyntaxException
>+     *             If the expression's syntax is invalid
>+     */
>+    public void setPattern(String regexPattern) {
>+        this.p = Pattern.compile(regexPattern);
>+    }
>+
>     public boolean isValid(String text) {
>         return p.matcher(text).matches();
>     }
>Index: wtk/src/pivot/wtk/text/validation/Validator.java
>===================================================================
>--- wtk/src/pivot/wtk/text/validation/Validator.java   (revision 758676)
>+++ wtk/src/pivot/wtk/text/validation/Validator.java   (working copy)
>@@ -14,8 +14,15 @@
> package pivot.wtk.text.validation;
> 
> /**
>- * Validation interface for TextInput widget.
>- *
>+ * Validation interface for {...@link pivot.wtk.TextInput} widget.
>+ * 
>+ * Allows the programmer to specify various constraints on the data in the
>+ * TextInput.
>+ * 
>+ * This is indicated visually to the user (a red background would be typical),
>+ * and events are fired by the TextInput if the programmer wishes to take
>+ * further action.
>+ * 
>  * @author Noel Grandin
>  */
> public interface Validator {
>
>

Reply via email to