changeset 4139:35d3fe04f57e

RT-31340: TextInputControl pseudo class state "readonly" is being set for editable fields
author jgiles
date Wed, 03 Jul 2013 11:54:51 +1200
parents 4ae1706251da
children 7526766c86f5
files modules/controls/src/main/java/javafx/scene/control/TextInputControl.java modules/controls/src/test/java/javafx/scene/control/TextFieldTest.java
diffstat 2 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/TextInputControl.java	Wed Jul 03 09:08:37 2013 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/TextInputControl.java	Wed Jul 03 11:54:51 2013 +1200
@@ -291,7 +291,7 @@
      */
     private BooleanProperty editable = new SimpleBooleanProperty(this, "editable", true) {
         @Override protected void invalidated() {
-            pseudoClassStateChanged(PSEUDO_CLASS_READONLY, get());
+            pseudoClassStateChanged(PSEUDO_CLASS_READONLY, ! get());
         }
     };
     public final boolean isEditable() { return editable.getValue(); }
--- a/modules/controls/src/test/java/javafx/scene/control/TextFieldTest.java	Wed Jul 03 09:08:37 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TextFieldTest.java	Wed Jul 03 11:54:51 2013 +1200
@@ -25,10 +25,13 @@
 
 package javafx.scene.control;
 
+import com.sun.javafx.scene.control.infrastructure.StageLoader;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.property.SimpleStringProperty;
 import javafx.beans.property.StringProperty;
+import javafx.collections.ObservableSet;
+import javafx.css.PseudoClass;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.scene.Scene;
@@ -39,10 +42,6 @@
 import static com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*;
 import static org.junit.Assert.*;
 
-/**
- *
- * @author srikalyc
- */
 public class TextFieldTest {
     private TextField txtField;//Empty string
     private TextField dummyTxtField;//With string value
@@ -141,6 +140,34 @@
         assertEquals(100, txtField.getPrefColumnCount(), 0);
     }
 
+    @Test public void pseudoClassState_isReadOnly() {
+        new StageLoader(txtField);
+        txtField.impl_processCSS(true);
+
+        txtField.setEditable(false);
+        ObservableSet<PseudoClass> pcSet = txtField.getPseudoClassStates();
+        boolean match = false;
+        for (PseudoClass pc : pcSet) {
+            if (match) break;
+            match = "readonly".equals(pc.getPseudoClassName());
+        }
+        assertTrue(match);
+    }
+
+    @Test public void pseudoClassState_isNotReadOnly() {
+        new StageLoader(txtField);
+        txtField.impl_processCSS(true);
+
+        txtField.setEditable(true);
+        ObservableSet<PseudoClass> pcSet = txtField.getPseudoClassStates();
+        boolean match = false;
+        for (PseudoClass pc : pcSet) {
+            if (match) break;
+            match = "readonly".equals(pc.getPseudoClassName());
+        }
+        assertFalse(match);
+    }
+
     /*********************************************************************
      * Tests for property binding                                        *
      ********************************************************************/