< prev index next >

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

Print this page




  15  * accompanied this code).
  16  *
  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;
  27 
  28 import javafx.css.PseudoClass;
  29 import javafx.beans.property.ObjectProperty;
  30 import javafx.beans.property.ObjectPropertyBase;
  31 import javafx.collections.FXCollections;
  32 import javafx.collections.ObservableList;
  33 import javafx.event.ActionEvent;
  34 import javafx.event.Event;

  35 import javafx.event.EventType;
  36 import javafx.geometry.Side;
  37 import javafx.scene.AccessibleAction;
  38 import javafx.scene.AccessibleRole;
  39 import javafx.scene.Node;
  40 import javafx.scene.control.skin.MenuButtonSkin;
  41 import javafx.beans.property.ReadOnlyBooleanProperty;
  42 import javafx.beans.property.ReadOnlyBooleanWrapper;
  43 
  44 /**
  45  * MenuButton is a button which, when clicked or pressed, will show a
  46  * {@link ContextMenu}. A MenuButton shares a very similar API to the {@link Menu}
  47  * control, insofar that you set the items that should be shown in the
  48  * {@link #getItems() items} ObservableList, and there is a {@link #textProperty() text} property to specify the
  49  * label shown within the MenuButton.
  50  * <p>
  51  * As mentioned, like the Menu API itself, you'll find an {@link #getItems() items} ObservableList
  52  * within which you can provide anything that extends from {@link MenuItem}.
  53  * There are several useful subclasses of {@link MenuItem} including
  54  * {@link RadioMenuItem}, {@link CheckMenuItem}, {@link Menu},


 251             popupSide = new ObjectPropertyBase<Side>(Side.BOTTOM) {
 252                 @Override protected void invalidated() {
 253                     final Side side = get();
 254                     final boolean active = (side == Side.TOP) || (side == Side.BOTTOM);
 255                     pseudoClassStateChanged(PSEUDO_CLASS_OPENVERTICALLY, active);
 256                 }
 257 
 258                 @Override
 259                 public Object getBean() {
 260                     return MenuButton.this;
 261                 }
 262 
 263                 @Override
 264                 public String getName() {
 265                     return "popupSide";
 266                 }
 267             };
 268         }
 269         return popupSide;
 270     }

























































































 271 
 272     /***************************************************************************
 273      *                                                                         *
 274      * Control methods                                                         *
 275      *                                                                         *
 276      **************************************************************************/
 277 
 278     /**
 279      * Shows the {@link ContextMenu}, assuming this MenuButton is not disabled.
 280      *
 281      * @see #isDisabled()
 282      * @see #isShowing()
 283      */
 284     public void show() {
 285         // TODO: isBound check is probably unnecessary here
 286         if (!isDisabled() && !showing.isBound()) {
 287             setShowing(true);
 288         }
 289     }
 290 




  15  * accompanied this code).
  16  *
  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;
  27 
  28 import javafx.css.PseudoClass;
  29 import javafx.beans.property.ObjectProperty;
  30 import javafx.beans.property.ObjectPropertyBase;
  31 import javafx.collections.FXCollections;
  32 import javafx.collections.ObservableList;
  33 import javafx.event.ActionEvent;
  34 import javafx.event.Event;
  35 import javafx.event.EventHandler;
  36 import javafx.event.EventType;
  37 import javafx.geometry.Side;
  38 import javafx.scene.AccessibleAction;
  39 import javafx.scene.AccessibleRole;
  40 import javafx.scene.Node;
  41 import javafx.scene.control.skin.MenuButtonSkin;
  42 import javafx.beans.property.ReadOnlyBooleanProperty;
  43 import javafx.beans.property.ReadOnlyBooleanWrapper;
  44 
  45 /**
  46  * MenuButton is a button which, when clicked or pressed, will show a
  47  * {@link ContextMenu}. A MenuButton shares a very similar API to the {@link Menu}
  48  * control, insofar that you set the items that should be shown in the
  49  * {@link #getItems() items} ObservableList, and there is a {@link #textProperty() text} property to specify the
  50  * label shown within the MenuButton.
  51  * <p>
  52  * As mentioned, like the Menu API itself, you'll find an {@link #getItems() items} ObservableList
  53  * within which you can provide anything that extends from {@link MenuItem}.
  54  * There are several useful subclasses of {@link MenuItem} including
  55  * {@link RadioMenuItem}, {@link CheckMenuItem}, {@link Menu},


 252             popupSide = new ObjectPropertyBase<Side>(Side.BOTTOM) {
 253                 @Override protected void invalidated() {
 254                     final Side side = get();
 255                     final boolean active = (side == Side.TOP) || (side == Side.BOTTOM);
 256                     pseudoClassStateChanged(PSEUDO_CLASS_OPENVERTICALLY, active);
 257                 }
 258 
 259                 @Override
 260                 public Object getBean() {
 261                     return MenuButton.this;
 262                 }
 263 
 264                 @Override
 265                 public String getName() {
 266                     return "popupSide";
 267                 }
 268             };
 269         }
 270         return popupSide;
 271     }
 272 
 273     /**
 274      * Called just prior to the {@code ContextMenu} being shown.
 275      * @return the on showing property
 276      * @since 10
 277      */
 278     public final ObjectProperty<EventHandler<Event>> onShowingProperty() { return onShowing; }
 279     public final void setOnShowing(EventHandler<Event> value) { onShowingProperty().set(value); }
 280     public final EventHandler<Event> getOnShowing() { return onShowingProperty().get(); }
 281     private ObjectProperty<EventHandler<Event>> onShowing = new ObjectPropertyBase<EventHandler<Event>>() {
 282         @Override protected void invalidated() {
 283             setEventHandler(ON_SHOWING, get());
 284         }
 285 
 286         @Override public Object getBean() {
 287             return MenuButton.this;
 288         }
 289 
 290         @Override public String getName() {
 291             return "onShowing";
 292         }
 293     };
 294 
 295     /**
 296      * Called just after the {@code ContextMenu} is shown.
 297      * @return the on shown property
 298      * @since 10
 299      */
 300     public final ObjectProperty<EventHandler<Event>> onShownProperty() { return onShown; }
 301     public final void setOnShown(EventHandler<Event> value) { onShownProperty().set(value); }
 302     public final EventHandler<Event> getOnShown() { return onShownProperty().get(); }
 303     private ObjectProperty<EventHandler<Event>> onShown = new ObjectPropertyBase<EventHandler<Event>>() {
 304         @Override protected void invalidated() {
 305             setEventHandler(ON_SHOWN, get());
 306         }
 307 
 308         @Override public Object getBean() {
 309             return MenuButton.this;
 310         }
 311 
 312         @Override public String getName() {
 313             return "onShown";
 314         }
 315     };
 316 
 317     /**
 318      * Called just prior to the {@code ContextMenu} being hidden.
 319      * @return the on hiding property
 320      * @since 10
 321      */
 322     public final ObjectProperty<EventHandler<Event>> onHidingProperty() { return onHiding; }
 323     public final void setOnHiding(EventHandler<Event> value) { onHidingProperty().set(value); }
 324     public final EventHandler<Event> getOnHiding() { return onHidingProperty().get(); }
 325     private ObjectProperty<EventHandler<Event>> onHiding = new ObjectPropertyBase<EventHandler<Event>>() {
 326         @Override protected void invalidated() {
 327             setEventHandler(ON_HIDING, get());
 328         }
 329 
 330         @Override public Object getBean() {
 331             return MenuButton.this;
 332         }
 333 
 334         @Override public String getName() {
 335             return "onHiding";
 336         }
 337     };
 338 
 339     /**
 340      * Called just after the {@code ContextMenu} has been hidden.
 341      * @return the on hidden property
 342      * @since 10
 343      */
 344     public final ObjectProperty<EventHandler<Event>> onHiddenProperty() { return onHidden; }
 345     public final void setOnHidden(EventHandler<Event> value) { onHiddenProperty().set(value); }
 346     public final EventHandler<Event> getOnHidden() { return onHiddenProperty().get(); }
 347     private ObjectProperty<EventHandler<Event>> onHidden = new ObjectPropertyBase<EventHandler<Event>>() {
 348         @Override protected void invalidated() {
 349             setEventHandler(ON_HIDDEN, get());
 350         }
 351 
 352         @Override public Object getBean() {
 353             return MenuButton.this;
 354         }
 355 
 356         @Override public String getName() {
 357             return "onHidden";
 358         }
 359     };
 360 
 361 
 362     /***************************************************************************
 363      *                                                                         *
 364      * Control methods                                                         *
 365      *                                                                         *
 366      **************************************************************************/
 367 
 368     /**
 369      * Shows the {@link ContextMenu}, assuming this MenuButton is not disabled.
 370      *
 371      * @see #isDisabled()
 372      * @see #isShowing()
 373      */
 374     public void show() {
 375         // TODO: isBound check is probably unnecessary here
 376         if (!isDisabled() && !showing.isBound()) {
 377             setShowing(true);
 378         }
 379     }
 380 


< prev index next >