You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/04/21 01:54:54 UTC

svn commit: r936116 - in /pivot/trunk: wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java wtk/src/org/apache/pivot/wtk/TextInput.java wtk/src/org/apache/pivot/wtk/TextInputListener.java

Author: gbrown
Date: Tue Apr 20 23:54:54 2010
New Revision: 936116

URL: http://svn.apache.org/viewvc?rev=936116&view=rev
Log:
Resolve PIVOT-443.

Modified:
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=936116&r1=936115&r2=936116&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Tue Apr 20 23:54:54 2010
@@ -138,7 +138,6 @@ public class TerraTextInputSkin extends 
     private Color borderColor;
     private Color disabledBorderColor;
     private Insets padding;
-    private boolean strictValidation;
 
     private Color selectionColor;
     private Color selectionBackgroundColor;
@@ -168,7 +167,6 @@ public class TerraTextInputSkin extends 
         borderColor = theme.getColor(7);
         disabledBorderColor = theme.getColor(7);
         padding = new Insets(2);
-        strictValidation = false;
 
         selectionColor = theme.getColor(4);
         selectionBackgroundColor = theme.getColor(13);
@@ -916,14 +914,6 @@ public class TerraTextInputSkin extends 
         setPadding(Insets.decode(padding));
     }
 
-    public boolean getStrictValidation() {
-        return strictValidation;
-    }
-
-    public void setStrictValidation(boolean strictValidation) {
-        this.strictValidation = strictValidation;
-    }
-
     @Override
     public boolean mouseMove(Component component, int x, int y) {
         boolean consumed = super.mouseMove(component, x, y);
@@ -1062,6 +1052,7 @@ public class TerraTextInputSkin extends 
                     Toolkit.getDefaultToolkit().beep();
                 } else {
                     Validator validator = textInput.getValidator();
+                    boolean strictValidation = textInput.isStrictValidation();
 
                     if (validator != null
                         && strictValidation) {
@@ -1098,6 +1089,7 @@ public class TerraTextInputSkin extends 
                 boolean backspace = (keyCode == Keyboard.KeyCode.DELETE ? false : true);
 
                 Validator validator = textInput.getValidator();
+                boolean strictValidation = textInput.isStrictValidation();
 
                 if (validator != null
                     && strictValidation) {
@@ -1349,12 +1341,17 @@ public class TerraTextInputSkin extends 
     }
 
     @Override
-    public void textValidChanged(TextInput textInput) {
+    public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
         repaintComponent();
     }
 
     @Override
-    public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
+    public void strictValidationChanged(TextInput textInput) {
+        // No-op
+    }
+
+    @Override
+    public void textValidChanged(TextInput textInput) {
         repaintComponent();
     }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=936116&r1=936115&r2=936116&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Tue Apr 20 23:54:54 2010
@@ -118,16 +118,22 @@ public class TextInput extends Component
         }
 
         @Override
-        public void textValidChanged(TextInput textInput) {
+        public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
             for (TextInputListener listener : this) {
-                listener.textValidChanged(textInput);
+                listener.textValidatorChanged(textInput, previousValidator);
+            }
+        }
+
+        public void strictValidationChanged(TextInput textInput) {
+            for (TextInputListener listener : this) {
+                listener.strictValidationChanged(textInput);
             }
         }
 
         @Override
-        public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
+        public void textValidChanged(TextInput textInput) {
             for (TextInputListener listener : this) {
-                listener.textValidatorChanged(textInput, previousValidator);
+                listener.textValidChanged(textInput);
             }
         }
     }
@@ -212,6 +218,8 @@ public class TextInput extends Component
     private TextBindMapping textBindMapping = null;
 
     private Validator validator = null;
+    private boolean strictValidation = false;
+
     private boolean textValid = true;
 
     private NodeListener textNodeListener = new NodeListener() {
@@ -834,15 +842,6 @@ public class TextInput extends Component
     }
 
     /**
-     * Tells whether or not this text input's text is currently valid as
-     * defined by its validator. If there is no validator associated with this
-     * text input, the text is assumed to always be valid.
-     */
-    public boolean isTextValid() {
-        return textValid;
-    }
-
-    /**
      * Gets the validator associated with this text input.
      */
     public Validator getValidator() {
@@ -866,12 +865,40 @@ public class TextInput extends Component
     }
 
     /**
+     * Returns the text input's strict validation flag.
+     */
+    public boolean isStrictValidation() {
+        return strictValidation;
+    }
+
+    /**
+     * Sets the text input's strict validation flag. When enabled, only valid text will be
+     * accepted by the text input.
+     *
+     * @param strictValidation
+     */
+    public void setStrictValidation(boolean strictValidation) {
+        if (this.strictValidation != strictValidation) {
+            this.strictValidation = strictValidation;
+            textInputListeners.strictValidationChanged(this);
+        }
+    }
+
+    /**
+     * Tells whether or not this text input's text is currently valid as
+     * defined by its validator. If there is no validator associated with this
+     * text input, the text is assumed to always be valid.
+     */
+    public boolean isTextValid() {
+        return textValid;
+    }
+
+    /**
      * Updates the valid state after the text or the validator has changed.
      */
     private void validateText() {
         String text = getText();
-        boolean textValid = (validator == null
-            || text == null) ? true : validator.isValid(text);
+        boolean textValid = (validator == null || text == null) ? true : validator.isValid(text);
 
         if (textValid != this.textValid) {
             this.textValid = textValid;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java?rev=936116&r1=936115&r2=936116&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInputListener.java Tue Apr 20 23:54:54 2010
@@ -48,11 +48,15 @@ public interface TextInputListener {
         }
 
         @Override
-        public void textValidChanged(TextInput textInput) {
+        public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
         }
 
         @Override
-        public void textValidatorChanged(TextInput textInput, Validator previousValidator) {
+        public void strictValidationChanged(TextInput textInput) {
+        }
+
+        @Override
+        public void textValidChanged(TextInput textInput) {
         }
     }
 
@@ -99,17 +103,24 @@ public interface TextInputListener {
     public void promptChanged(TextInput textInput, String previousPrompt);
 
     /**
-     * Called when the text changes validity.
+     * Called when the validator changes.
      *
      * @param textInput
+     * @param previousValidator
      */
-    public void textValidChanged(TextInput textInput);
+    public void textValidatorChanged(TextInput textInput, Validator previousValidator);
 
     /**
-     * Called when the validator changes.
+     * Called when a text input's strict validation flag has changed.
      *
      * @param textInput
-     * @param previousValidator
      */
-    public void textValidatorChanged(TextInput textInput, Validator previousValidator);
+    public void strictValidationChanged(TextInput textInput);
+
+    /**
+     * Called when the text changes validity.
+     *
+     * @param textInput
+     */
+    public void textValidChanged(TextInput textInput);
 }