changeset 877:1a693a82850e

RT-19589: ComboBox : cannot access to the current string editor
author jgiles
date Thu, 26 Apr 2012 16:47:57 +1200
parents 5bf85e72593a
children d86de2e536a0
files javafx-ui-controls/src/com/sun/javafx/scene/control/FocusableTextField.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java javafx-ui-controls/src/javafx/scene/control/ComboBox.java
diffstat 3 files changed, 79 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/FocusableTextField.java	Thu Apr 26 16:47:57 2012 +1200
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.javafx.scene.control;
+
+import com.sun.javafx.event.EventDispatchChainImpl;
+import javafx.event.EventDispatchChain;
+import javafx.scene.control.TextField;
+
+/**
+ * Used by ComboBox - makes it possible to call setFocused from external classes.
+ */
+public final class FocusableTextField extends TextField {
+    
+    public void setFakeFocus(boolean focus) {
+        setFocused(focus);
+    }
+
+    @Override
+    public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
+        EventDispatchChain chain = new EventDispatchChainImpl();
+        chain.append(getEventDispatcher());
+        return chain;
+    }
+}
\ No newline at end of file
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Apr 26 16:04:40 2012 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Apr 26 16:47:57 2012 +1200
@@ -26,6 +26,7 @@
 package com.sun.javafx.scene.control.skin;
 
 import com.sun.javafx.event.EventDispatchChainImpl;
+import com.sun.javafx.scene.control.FocusableTextField;
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import javafx.scene.control.ComboBox;
 import com.sun.javafx.scene.control.behavior.ComboBoxListViewBehavior;
@@ -36,8 +37,6 @@
 import javafx.beans.value.ObservableValue;
 import javafx.collections.ListChangeListener;
 import javafx.collections.ObservableList;
-import javafx.event.Event;
-import javafx.event.EventDispatchChain;
 import javafx.event.EventHandler;
 import javafx.event.EventTarget;
 import javafx.scene.Node;
@@ -61,7 +60,7 @@
     private final ComboBox<T> comboBox;
     
     private ListCell<T> listCellLabel;
-    private FocusableTextField textField;
+    private TextField textField;
     
     private final ListView<T> listView;
     
@@ -77,7 +76,8 @@
         comboBox.focusedProperty().addListener(new ChangeListener<Boolean>() {
             @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                 if (textField == null) return;
-                textField.setFakeFocus(comboBox.isFocused());
+                if (! (textField instanceof FocusableTextField)) return;
+                ((FocusableTextField)textField).setFakeFocus(comboBox.isFocused());
             }
         });
         
@@ -202,10 +202,10 @@
         return displayNode;
     }
     
-    private FocusableTextField getEditableInputNode() {
+    private TextField getEditableInputNode() {
         if (textField != null) return textField;
         
-        textField = new FocusableTextField();
+        textField = comboBox.getEditor();
         textField.setFocusTraversable(true);
         textField.promptTextProperty().bind(comboBox.promptTextProperty());
         
@@ -452,19 +452,4 @@
     public ListView<T> getListView() {
         return listView;
     }
-    
-    
-    private final class FocusableTextField extends TextField {
-    
-        public void setFakeFocus(boolean focus) {
-            setFocused(focus);
-        }
-
-        @Override
-        public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
-            EventDispatchChain chain = new EventDispatchChainImpl();
-            chain.append(textField.getEventDispatcher());
-            return chain;
-        }
-    }
 }
--- a/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Thu Apr 26 16:04:40 2012 +1200
+++ b/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Thu Apr 26 16:47:57 2012 +1200
@@ -25,19 +25,13 @@
 
 package javafx.scene.control;
 
-import com.sun.javafx.css.StyleManager;
+import com.sun.javafx.event.EventDispatchChainImpl;
+import com.sun.javafx.scene.control.FocusableTextField;
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin;
-import com.sun.javafx.scene.control.skin.ListViewSkin;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
-import javafx.beans.property.IntegerProperty;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleIntegerProperty;
-import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.*;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.beans.value.WeakChangeListener;
@@ -45,11 +39,8 @@
 import javafx.collections.ListChangeListener;
 import javafx.collections.ListChangeListener.Change;
 import javafx.collections.ObservableList;
+import javafx.event.EventDispatchChain;
 import javafx.scene.Node;
-import javafx.scene.control.*;
-import javafx.scene.paint.Color;
-import javafx.scene.shape.Rectangle;
-import javafx.scene.text.Text;
 import javafx.util.Callback;
 import javafx.util.StringConverter;
 
@@ -335,7 +326,25 @@
     public final IntegerProperty visibleRowCountProperty() { return visibleRowCount; }
     
     
-
+    // --- Editor
+    /**
+     * The editor for the ComboBox. The editor is null if the ComboBox is not
+     * {@link #editableProperty() editable}.
+     */
+    private ReadOnlyObjectWrapper<TextField> editor;
+    public final TextField getEditor() { 
+        return editorProperty().get(); 
+    }
+    public final ReadOnlyObjectProperty<TextField> editorProperty() { 
+        if (editor == null) {
+            TextField textField = isEditable() ? new FocusableTextField() : null;
+            editor = new ReadOnlyObjectWrapper<TextField>(this, "editor", textField);
+        }
+        return editor.getReadOnlyProperty(); 
+    }
+    
+    
+    
     /***************************************************************************
      *                                                                         *
      * Callbacks and Events                                                    *
@@ -458,4 +467,8 @@
             return items == null ? 0 : items.size();
         }
     }
+    
+    
+    
+    
 }