< prev index next >

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

Print this page




  74      * @param graphic a null graphic is acceptable
  75      */
  76     public ButtonBase(String text, Node graphic) {
  77         super(text, graphic);
  78     }
  79 
  80 
  81     /***************************************************************************
  82      *                                                                         *
  83      * Properties                                                              *
  84      *                                                                         *
  85      **************************************************************************/
  86 
  87     /**
  88      * Indicates that the button has been "armed" such that a mouse release
  89      * will cause the button's action to be invoked. This is subtly different
  90      * from pressed. Pressed indicates that the mouse has been
  91      * pressed on a Node and has not yet been released. {@code arm} however
  92      * also takes into account whether the mouse is actually over the
  93      * button and pressed.

  94      */
  95     public final ReadOnlyBooleanProperty armedProperty() { return armed.getReadOnlyProperty(); }
  96     private void setArmed(boolean value) { armed.set(value); }
  97     public final boolean isArmed() { return armedProperty().get(); }
  98     private ReadOnlyBooleanWrapper armed = new ReadOnlyBooleanWrapper() {
  99         @Override protected void invalidated() {
 100             pseudoClassStateChanged(ARMED_PSEUDOCLASS_STATE, get());
 101         }
 102 
 103         @Override
 104         public Object getBean() {
 105             return ButtonBase.this;
 106         }
 107 
 108         @Override
 109         public String getName() {
 110             return "armed";
 111         }
 112     };
 113 
 114     /**
 115      * The button's action, which is invoked whenever the button is fired. This
 116      * may be due to the user clicking on the button with the mouse, or by
 117      * a touch event, or by a key press, or if the developer programmatically
 118      * invokes the {@link #fire()} method.


 119      */
 120     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }
 121     public final void setOnAction(EventHandler<ActionEvent> value) { onActionProperty().set(value); }
 122     public final EventHandler<ActionEvent> getOnAction() { return onActionProperty().get(); }
 123     private ObjectProperty<EventHandler<ActionEvent>> onAction = new ObjectPropertyBase<EventHandler<ActionEvent>>() {
 124         @Override protected void invalidated() {
 125             setEventHandler(ActionEvent.ACTION, get());
 126         }
 127 
 128         @Override
 129         public Object getBean() {
 130             return ButtonBase.this;
 131         }
 132 
 133         @Override
 134         public String getName() {
 135             return "onAction";
 136         }
 137     };
 138 
 139 
 140     /***************************************************************************
 141      *                                                                         *
 142      * Methods                                                                 *
 143      *                                                                         *
 144      **************************************************************************/
 145 
 146     /**
 147      * Arms the button. An armed button will fire an action (whether that be
 148      * the action of a {@link Button} or toggling selection on a
 149      * {@link CheckBox} or some other behavior) on the next expected UI
 150      * gesture.
 151      *
 152      * @expert This function is intended to be used by experts, primarily
 153      *         by those implementing new Skins or Behaviors. It is not common
 154      *         for developers or designers to access this function directly.
 155      */
 156     public void arm() {
 157         setArmed(true);
 158     }
 159 
 160     /**
 161      * Disarms the button. See {@link #arm()}.
 162      *
 163      * @expert This function is intended to be used by experts, primarily
 164      *         by those implementing new Skins or Behaviors. It is not common
 165      *         for developers or designers to access this function directly.
 166      */
 167     public void disarm() {
 168         setArmed(false);
 169     }
 170 
 171     /**
 172      * Invoked when a user gesture indicates that an event for this
 173      * {@code ButtonBase} should occur.
 174      * <p>
 175      * If invoked, this method will be executed regardless of the status of
 176      * {@link #arm}.
 177      * </p>
 178      */
 179     public abstract void fire();
 180 
 181 
 182     /***************************************************************************
 183      *                                                                         *




  74      * @param graphic a null graphic is acceptable
  75      */
  76     public ButtonBase(String text, Node graphic) {
  77         super(text, graphic);
  78     }
  79 
  80 
  81     /***************************************************************************
  82      *                                                                         *
  83      * Properties                                                              *
  84      *                                                                         *
  85      **************************************************************************/
  86 
  87     /**
  88      * Indicates that the button has been "armed" such that a mouse release
  89      * will cause the button's action to be invoked. This is subtly different
  90      * from pressed. Pressed indicates that the mouse has been
  91      * pressed on a Node and has not yet been released. {@code arm} however
  92      * also takes into account whether the mouse is actually over the
  93      * button and pressed.
  94      * @return the property to indicate that the button has been "armed"
  95      */
  96     public final ReadOnlyBooleanProperty armedProperty() { return armed.getReadOnlyProperty(); }
  97     private void setArmed(boolean value) { armed.set(value); }
  98     public final boolean isArmed() { return armedProperty().get(); }
  99     private ReadOnlyBooleanWrapper armed = new ReadOnlyBooleanWrapper() {
 100         @Override protected void invalidated() {
 101             pseudoClassStateChanged(ARMED_PSEUDOCLASS_STATE, get());
 102         }
 103 
 104         @Override
 105         public Object getBean() {
 106             return ButtonBase.this;
 107         }
 108 
 109         @Override
 110         public String getName() {
 111             return "armed";
 112         }
 113     };
 114 
 115     /**
 116      * The button's action, which is invoked whenever the button is fired. This
 117      * may be due to the user clicking on the button with the mouse, or by
 118      * a touch event, or by a key press, or if the developer programmatically
 119      * invokes the {@link #fire()} method.
 120      * @return the property to represent the button's action, which is invoked
 121      * whenever the button is fired
 122      */
 123     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }
 124     public final void setOnAction(EventHandler<ActionEvent> value) { onActionProperty().set(value); }
 125     public final EventHandler<ActionEvent> getOnAction() { return onActionProperty().get(); }
 126     private ObjectProperty<EventHandler<ActionEvent>> onAction = new ObjectPropertyBase<EventHandler<ActionEvent>>() {
 127         @Override protected void invalidated() {
 128             setEventHandler(ActionEvent.ACTION, get());
 129         }
 130 
 131         @Override
 132         public Object getBean() {
 133             return ButtonBase.this;
 134         }
 135 
 136         @Override
 137         public String getName() {
 138             return "onAction";
 139         }
 140     };
 141 
 142 
 143     /***************************************************************************
 144      *                                                                         *
 145      * Methods                                                                 *
 146      *                                                                         *
 147      **************************************************************************/
 148 
 149     /**
 150      * Arms the button. An armed button will fire an action (whether that be
 151      * the action of a {@link Button} or toggling selection on a
 152      * {@link CheckBox} or some other behavior) on the next expected UI
 153      * gesture.
 154      *
 155      * Note: This function is intended to be used by experts, primarily
 156      *       by those implementing new Skins or Behaviors. It is not common
 157      *       for developers or designers to access this function directly.
 158      */
 159     public void arm() {
 160         setArmed(true);
 161     }
 162 
 163     /**
 164      * Disarms the button. See {@link #arm()}.
 165      *
 166      * Note: This function is intended to be used by experts, primarily
 167      *       by those implementing new Skins or Behaviors. It is not common
 168      *       for developers or designers to access this function directly.
 169      */
 170     public void disarm() {
 171         setArmed(false);
 172     }
 173 
 174     /**
 175      * Invoked when a user gesture indicates that an event for this
 176      * {@code ButtonBase} should occur.
 177      * <p>
 178      * If invoked, this method will be executed regardless of the status of
 179      * {@link #arm}.
 180      * </p>
 181      */
 182     public abstract void fire();
 183 
 184 
 185     /***************************************************************************
 186      *                                                                         *


< prev index next >