< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/ComboBoxBase.java

Print this page




 126                 if (change.getKey() == "FOCUSED") {
 127                     setFocused((Boolean)change.getValueAdded());
 128                     getProperties().remove("FOCUSED");
 129                 }
 130             }
 131         });
 132         // End of fix for RT-29885
 133     }
 134 
 135     /***************************************************************************
 136      *                                                                         *
 137      * Properties                                                              *
 138      *                                                                         *
 139      **************************************************************************/
 140 
 141     // --- value
 142     /**
 143      * The value of this ComboBox is defined as the selected item if the input
 144      * is not editable, or if it is editable, the most recent user action:
 145      * either the value input by the user, or the last selected item.

 146      */
 147     public ObjectProperty<T> valueProperty() { return value; }
 148     private ObjectProperty<T> value = new SimpleObjectProperty<T>(this, "value");
 149 
 150     public final void setValue(T value) { valueProperty().set(value); }
 151     public final T getValue() { return valueProperty().get(); }
 152 
 153 
 154     // --- editable
 155     /**
 156      * Specifies whether the ComboBox allows for user input. When editable is
 157      * true, the ComboBox has a text input area that a user may type in to. This
 158      * input is then available via the {@link #valueProperty() value} property.
 159      *
 160      * <p>Note that when the editable property changes, the value property is
 161      * reset, along with any other relevant state.

 162      */
 163     public BooleanProperty editableProperty() { return editable; }
 164     public final void setEditable(boolean value) { editableProperty().set(value); }
 165     public final boolean isEditable() { return editableProperty().get(); }
 166     private BooleanProperty editable = new SimpleBooleanProperty(this, "editable", false) {
 167         @Override protected void invalidated() {
 168             pseudoClassStateChanged(PSEUDO_CLASS_EDITABLE, get());
 169         }
 170     };
 171 
 172 
 173     // --- showing
 174     /**
 175      * Represents the current state of the ComboBox popup, and whether it is
 176      * currently visible on screen (although it may be hidden behind other windows).
 177      */
 178     private ReadOnlyBooleanWrapper showing;
 179     public ReadOnlyBooleanProperty showingProperty() { return showingPropertyImpl().getReadOnlyProperty(); }
 180     public final boolean isShowing() { return showingPropertyImpl().get(); }
 181     private void setShowing(boolean value) {


 224             String txt = get();
 225             if (txt != null && txt.contains("\n")) {
 226                 txt = txt.replace("\n", "");
 227                 set(txt);
 228             }
 229         }
 230     };
 231     public final StringProperty promptTextProperty() { return promptText; }
 232     public final String getPromptText() { return promptText.get(); }
 233     public final void setPromptText(String value) { promptText.set(value); }
 234 
 235 
 236     // --- armed
 237     /**
 238      * Indicates that the ComboBox has been "armed" such that a mouse release
 239      * will cause the ComboBox {@link #show()} method to be invoked. This is
 240      * subtly different from pressed. Pressed indicates that the mouse has been
 241      * pressed on a Node and has not yet been released. {@code arm} however
 242      * also takes into account whether the mouse is actually over the
 243      * ComboBox and pressed.

 244      */
 245     public BooleanProperty armedProperty() { return armed; }
 246     private final void setArmed(boolean value) { armedProperty().set(value); }
 247     public final boolean isArmed() { return armedProperty().get(); }
 248     private BooleanProperty armed = new SimpleBooleanProperty(this, "armed", false) {
 249         @Override protected void invalidated() {
 250             pseudoClassStateChanged(PSEUDO_CLASS_ARMED, get());
 251         }
 252     };
 253 
 254 
 255     // --- On Action
 256     /**
 257      * The ComboBox action, which is invoked whenever the ComboBox
 258      * {@link #valueProperty() value} property is changed. This
 259      * may be due to the value property being programmatically changed, when the
 260      * user selects an item in a popup list or dialog, or, in the case of
 261      * {@link #editableProperty() editable} ComboBoxes, it may be when the user
 262      * provides their own input (be that via a {@link TextField} or some other
 263      * input mechanism.

 264      */
 265     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }
 266     public final void setOnAction(EventHandler<ActionEvent> value) { onActionProperty().set(value); }
 267     public final EventHandler<ActionEvent> getOnAction() { return onActionProperty().get(); }
 268     private ObjectProperty<EventHandler<ActionEvent>> onAction = new ObjectPropertyBase<EventHandler<ActionEvent>>() {
 269         @Override protected void invalidated() {
 270             setEventHandler(ActionEvent.ACTION, get());
 271         }
 272 
 273         @Override
 274         public Object getBean() {
 275             return ComboBoxBase.this;
 276         }
 277 
 278         @Override
 279         public String getName() {
 280             return "onAction";
 281         }
 282     };
 283 


 388      */
 389     public void show() {
 390         if (!isDisabled()) {
 391             setShowing(true);
 392         }
 393     }
 394 
 395     /**
 396      * Closes the popup / dialog that was shown when {@link #show()} was called.
 397      */
 398     public void hide() {
 399         if (isShowing()) {
 400             setShowing(false);
 401         }
 402     }
 403 
 404     /**
 405      * Arms the ComboBox. An armed ComboBox will show a popup list on the next
 406      * expected UI gesture.
 407      *
 408      * @expert This function is intended to be used by experts, primarily
 409      *         by those implementing new Skins or Behaviors. It is not common
 410      *         for developers or designers to access this function directly.
 411      */
 412     public void arm() {
 413         if (! armedProperty().isBound()) {
 414             setArmed(true);
 415         }
 416     }
 417 
 418     /**
 419      * Disarms the ComboBox. See {@link #arm()}.
 420      *
 421      * @expert This function is intended to be used by experts, primarily
 422      *         by those implementing new Skins or Behaviors. It is not common
 423      *         for developers or designers to access this function directly.
 424      */
 425     public void disarm() {
 426         if (! armedProperty().isBound()) {
 427             setArmed(false);
 428         }
 429     }
 430 
 431 
 432     /***************************************************************************
 433      *                                                                         *
 434      * Stylesheet Handling                                                     *
 435      *                                                                         *
 436      **************************************************************************/
 437 
 438     private static final String DEFAULT_STYLE_CLASS = "combo-box-base";
 439 
 440     private static final PseudoClass PSEUDO_CLASS_EDITABLE =
 441             PseudoClass.getPseudoClass("editable");




 126                 if (change.getKey() == "FOCUSED") {
 127                     setFocused((Boolean)change.getValueAdded());
 128                     getProperties().remove("FOCUSED");
 129                 }
 130             }
 131         });
 132         // End of fix for RT-29885
 133     }
 134 
 135     /***************************************************************************
 136      *                                                                         *
 137      * Properties                                                              *
 138      *                                                                         *
 139      **************************************************************************/
 140 
 141     // --- value
 142     /**
 143      * The value of this ComboBox is defined as the selected item if the input
 144      * is not editable, or if it is editable, the most recent user action:
 145      * either the value input by the user, or the last selected item.
 146      * @return the value property
 147      */
 148     public ObjectProperty<T> valueProperty() { return value; }
 149     private ObjectProperty<T> value = new SimpleObjectProperty<T>(this, "value");
 150 
 151     public final void setValue(T value) { valueProperty().set(value); }
 152     public final T getValue() { return valueProperty().get(); }
 153 
 154 
 155     // --- editable
 156     /**
 157      * Specifies whether the ComboBox allows for user input. When editable is
 158      * true, the ComboBox has a text input area that a user may type in to. This
 159      * input is then available via the {@link #valueProperty() value} property.
 160      *
 161      * <p>Note that when the editable property changes, the value property is
 162      * reset, along with any other relevant state.
 163      * @return the editable property
 164      */
 165     public BooleanProperty editableProperty() { return editable; }
 166     public final void setEditable(boolean value) { editableProperty().set(value); }
 167     public final boolean isEditable() { return editableProperty().get(); }
 168     private BooleanProperty editable = new SimpleBooleanProperty(this, "editable", false) {
 169         @Override protected void invalidated() {
 170             pseudoClassStateChanged(PSEUDO_CLASS_EDITABLE, get());
 171         }
 172     };
 173 
 174 
 175     // --- showing
 176     /**
 177      * Represents the current state of the ComboBox popup, and whether it is
 178      * currently visible on screen (although it may be hidden behind other windows).
 179      */
 180     private ReadOnlyBooleanWrapper showing;
 181     public ReadOnlyBooleanProperty showingProperty() { return showingPropertyImpl().getReadOnlyProperty(); }
 182     public final boolean isShowing() { return showingPropertyImpl().get(); }
 183     private void setShowing(boolean value) {


 226             String txt = get();
 227             if (txt != null && txt.contains("\n")) {
 228                 txt = txt.replace("\n", "");
 229                 set(txt);
 230             }
 231         }
 232     };
 233     public final StringProperty promptTextProperty() { return promptText; }
 234     public final String getPromptText() { return promptText.get(); }
 235     public final void setPromptText(String value) { promptText.set(value); }
 236 
 237 
 238     // --- armed
 239     /**
 240      * Indicates that the ComboBox has been "armed" such that a mouse release
 241      * will cause the ComboBox {@link #show()} method to be invoked. This is
 242      * subtly different from pressed. Pressed indicates that the mouse has been
 243      * pressed on a Node and has not yet been released. {@code arm} however
 244      * also takes into account whether the mouse is actually over the
 245      * ComboBox and pressed.
 246      * @return the armed property
 247      */
 248     public BooleanProperty armedProperty() { return armed; }
 249     private final void setArmed(boolean value) { armedProperty().set(value); }
 250     public final boolean isArmed() { return armedProperty().get(); }
 251     private BooleanProperty armed = new SimpleBooleanProperty(this, "armed", false) {
 252         @Override protected void invalidated() {
 253             pseudoClassStateChanged(PSEUDO_CLASS_ARMED, get());
 254         }
 255     };
 256 
 257 
 258     // --- On Action
 259     /**
 260      * The ComboBox action, which is invoked whenever the ComboBox
 261      * {@link #valueProperty() value} property is changed. This
 262      * may be due to the value property being programmatically changed, when the
 263      * user selects an item in a popup list or dialog, or, in the case of
 264      * {@link #editableProperty() editable} ComboBoxes, it may be when the user
 265      * provides their own input (be that via a {@link TextField} or some other
 266      * input mechanism.
 267      * @return the on action property
 268      */
 269     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }
 270     public final void setOnAction(EventHandler<ActionEvent> value) { onActionProperty().set(value); }
 271     public final EventHandler<ActionEvent> getOnAction() { return onActionProperty().get(); }
 272     private ObjectProperty<EventHandler<ActionEvent>> onAction = new ObjectPropertyBase<EventHandler<ActionEvent>>() {
 273         @Override protected void invalidated() {
 274             setEventHandler(ActionEvent.ACTION, get());
 275         }
 276 
 277         @Override
 278         public Object getBean() {
 279             return ComboBoxBase.this;
 280         }
 281 
 282         @Override
 283         public String getName() {
 284             return "onAction";
 285         }
 286     };
 287 


 392      */
 393     public void show() {
 394         if (!isDisabled()) {
 395             setShowing(true);
 396         }
 397     }
 398 
 399     /**
 400      * Closes the popup / dialog that was shown when {@link #show()} was called.
 401      */
 402     public void hide() {
 403         if (isShowing()) {
 404             setShowing(false);
 405         }
 406     }
 407 
 408     /**
 409      * Arms the ComboBox. An armed ComboBox will show a popup list on the next
 410      * expected UI gesture.
 411      *
 412      * Note: This function is intended to be used by experts, primarily
 413      *       by those implementing new Skins or Behaviors. It is not common
 414      *       for developers or designers to access this function directly.
 415      */
 416     public void arm() {
 417         if (! armedProperty().isBound()) {
 418             setArmed(true);
 419         }
 420     }
 421 
 422     /**
 423      * Disarms the ComboBox. See {@link #arm()}.
 424      *
 425      * Note: This function is intended to be used by experts, primarily
 426      *       by those implementing new Skins or Behaviors. It is not common
 427      *       for developers or designers to access this function directly.
 428      */
 429     public void disarm() {
 430         if (! armedProperty().isBound()) {
 431             setArmed(false);
 432         }
 433     }
 434 
 435 
 436     /***************************************************************************
 437      *                                                                         *
 438      * Stylesheet Handling                                                     *
 439      *                                                                         *
 440      **************************************************************************/
 441 
 442     private static final String DEFAULT_STYLE_CLASS = "combo-box-base";
 443 
 444     private static final PseudoClass PSEUDO_CLASS_EDITABLE =
 445             PseudoClass.getPseudoClass("editable");


< prev index next >