17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.control.skin;
27
28 import com.sun.javafx.scene.control.FakeFocusTextField;
29 import com.sun.javafx.scene.control.Properties;
30 import com.sun.javafx.scene.input.ExtendedInputMethodRequests;
31 import com.sun.javafx.scene.traversal.Algorithm;
32 import com.sun.javafx.scene.traversal.Direction;
33 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
34 import com.sun.javafx.scene.traversal.TraversalContext;
35 import javafx.beans.InvalidationListener;
36 import javafx.beans.value.ObservableValue;
37 import javafx.css.PseudoClass;
38 import javafx.css.Styleable;
39 import javafx.event.EventHandler;
40 import javafx.geometry.Bounds;
41 import javafx.geometry.HPos;
42 import javafx.geometry.Point2D;
43 import javafx.geometry.VPos;
44 import javafx.scene.AccessibleAttribute;
45 import javafx.scene.Node;
46 import javafx.scene.control.ComboBoxBase;
47 import javafx.scene.control.PopupControl;
48 import javafx.scene.control.Skin;
49 import javafx.scene.control.Skinnable;
50 import javafx.scene.control.TextField;
51 import javafx.scene.input.DragEvent;
52 import javafx.scene.input.KeyCode;
53 import javafx.scene.input.KeyEvent;
54 import javafx.scene.input.MouseEvent;
55 import javafx.scene.layout.Region;
56 import javafx.stage.WindowEvent;
57 import javafx.util.StringConverter;
120 */
121 public ComboBoxPopupControl(ComboBoxBase<T> control) {
122 super(control);
123 this.comboBoxBase = control;
124
125 // editable input node
126 this.textField = getEditor() != null ? getEditableInputNode() : null;
127
128 // Fix for RT-29565. Without this the textField does not have a correct
129 // pref width at startup, as it is not part of the scenegraph (and therefore
130 // has no pref width until after the first measurements have been taken).
131 if (this.textField != null) {
132 getChildren().add(textField);
133 }
134
135 // move fake focus in to the textfield if the comboBox is editable
136 comboBoxBase.focusedProperty().addListener((ov, t, hasFocus) -> {
137 if (getEditor() != null) {
138 // Fix for the regression noted in a comment in RT-29885.
139 ((FakeFocusTextField)textField).setFakeFocus(hasFocus);
140 }
141 });
142
143 comboBoxBase.addEventFilter(KeyEvent.ANY, ke -> {
144 if (textField == null || getEditor() == null) {
145 handleKeyEvent(ke, false);
146 } else {
147 // This prevents a stack overflow from our rebroadcasting of the
148 // event to the textfield that occurs in the final else statement
149 // of the conditions below.
150 if (ke.getTarget().equals(textField)) return;
151
152 switch (ke.getCode()) {
153 case ESCAPE:
154 case F10:
155 // Allow to bubble up.
156 break;
157
158 case ENTER:
159 handleKeyEvent(ke, true);
563 }
564 }
565
566
567
568 /***************************************************************************
569 * *
570 * Support classes *
571 * *
572 **************************************************************************/
573
574
575
576
577
578 /***************************************************************************
579 * *
580 * Stylesheet Handling *
581 * *
582 **************************************************************************/
583
584 private static PseudoClass CONTAINS_FOCUS_PSEUDOCLASS_STATE = PseudoClass.getPseudoClass("contains-focus");
585
586 }
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.control.skin;
27
28 import com.sun.javafx.scene.control.FakeFocusTextField;
29 import com.sun.javafx.scene.control.Properties;
30 import com.sun.javafx.scene.input.ExtendedInputMethodRequests;
31 import com.sun.javafx.scene.traversal.Algorithm;
32 import com.sun.javafx.scene.traversal.Direction;
33 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
34 import com.sun.javafx.scene.traversal.TraversalContext;
35 import javafx.beans.InvalidationListener;
36 import javafx.beans.value.ObservableValue;
37 import javafx.css.Styleable;
38 import javafx.event.EventHandler;
39 import javafx.geometry.Bounds;
40 import javafx.geometry.HPos;
41 import javafx.geometry.Point2D;
42 import javafx.geometry.VPos;
43 import javafx.scene.AccessibleAttribute;
44 import javafx.scene.Node;
45 import javafx.scene.control.ComboBoxBase;
46 import javafx.scene.control.PopupControl;
47 import javafx.scene.control.Skin;
48 import javafx.scene.control.Skinnable;
49 import javafx.scene.control.TextField;
50 import javafx.scene.input.DragEvent;
51 import javafx.scene.input.KeyCode;
52 import javafx.scene.input.KeyEvent;
53 import javafx.scene.input.MouseEvent;
54 import javafx.scene.layout.Region;
55 import javafx.stage.WindowEvent;
56 import javafx.util.StringConverter;
119 */
120 public ComboBoxPopupControl(ComboBoxBase<T> control) {
121 super(control);
122 this.comboBoxBase = control;
123
124 // editable input node
125 this.textField = getEditor() != null ? getEditableInputNode() : null;
126
127 // Fix for RT-29565. Without this the textField does not have a correct
128 // pref width at startup, as it is not part of the scenegraph (and therefore
129 // has no pref width until after the first measurements have been taken).
130 if (this.textField != null) {
131 getChildren().add(textField);
132 }
133
134 // move fake focus in to the textfield if the comboBox is editable
135 comboBoxBase.focusedProperty().addListener((ov, t, hasFocus) -> {
136 if (getEditor() != null) {
137 // Fix for the regression noted in a comment in RT-29885.
138 ((FakeFocusTextField)textField).setFakeFocus(hasFocus);
139
140 // JDK-8120120 (aka RT-21454) and JDK-8136838
141 if (!hasFocus) {
142 setTextFromTextFieldIntoComboBoxValue();
143 }
144 }
145 });
146
147 comboBoxBase.addEventFilter(KeyEvent.ANY, ke -> {
148 if (textField == null || getEditor() == null) {
149 handleKeyEvent(ke, false);
150 } else {
151 // This prevents a stack overflow from our rebroadcasting of the
152 // event to the textfield that occurs in the final else statement
153 // of the conditions below.
154 if (ke.getTarget().equals(textField)) return;
155
156 switch (ke.getCode()) {
157 case ESCAPE:
158 case F10:
159 // Allow to bubble up.
160 break;
161
162 case ENTER:
163 handleKeyEvent(ke, true);
567 }
568 }
569
570
571
572 /***************************************************************************
573 * *
574 * Support classes *
575 * *
576 **************************************************************************/
577
578
579
580
581
582 /***************************************************************************
583 * *
584 * Stylesheet Handling *
585 * *
586 **************************************************************************/
587
588 }
|