modules/controls/src/main/java/javafx/scene/control/skin/SplitMenuButtonSkin.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 com.sun.javafx.scene.control.skin;
  27 






  28 import javafx.scene.control.SplitMenuButton;
  29 import javafx.scene.input.MouseEvent;
  30 
  31 import com.sun.javafx.scene.control.behavior.SplitMenuButtonBehavior;
  32 
  33 /**
  34  * Skin for SplitMenuButton Control.



  35  */
  36 public class SplitMenuButtonSkin extends MenuButtonSkinBase<SplitMenuButton, SplitMenuButtonBehavior> {










  37 
  38     /***************************************************************************
  39      *                                                                         *
  40      * Constructors                                                            *
  41      *                                                                         *
  42      **************************************************************************/
  43     
  44     /**
  45      * Creates a new SplitMenuButtonSkin for the given SplitMenu.


  46      * 
  47      * @param splitMenuButton the SplitMenuButton
  48      */
  49     public SplitMenuButtonSkin(final SplitMenuButton splitMenuButton) {
  50         super(splitMenuButton, new SplitMenuButtonBehavior(splitMenuButton));




  51 
  52         /*
  53          * The arrow button is the only thing that acts like a MenuButton on
  54          * this control.
  55          */
  56         behaveLikeButton = true;
  57         // TODO: do we need to consume all mouse events?
  58         // they only bubble to the skin which consumes them by default
  59         arrowButton.addEventHandler(MouseEvent.ANY, event -> {
  60             event.consume();
  61         });
  62         arrowButton.setOnMousePressed(e -> {
  63             getBehavior().mousePressed(e, false);
  64             e.consume();
  65         });
  66         arrowButton.setOnMouseReleased(e -> {
  67             getBehavior().mouseReleased(e, false);
  68             e.consume();
  69         });
  70 
  71         label.setLabelFor(splitMenuButton);





























  72     }
  73 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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.skin;
  27 
  28 import com.sun.javafx.scene.control.behavior.BehaviorBase;
  29 import com.sun.javafx.scene.control.behavior.MenuButtonBehavior;
  30 import javafx.scene.Node;
  31 import javafx.scene.control.Accordion;
  32 import javafx.scene.control.Button;
  33 import javafx.scene.control.Control;
  34 import javafx.scene.control.SplitMenuButton;
  35 import javafx.scene.input.MouseEvent;
  36 
  37 import com.sun.javafx.scene.control.behavior.SplitMenuButtonBehavior;
  38 
  39 /**
  40  * Default skin implementation for the {@link SplitMenuButton} control.
  41  *
  42  * @see SplitMenuButton
  43  * @since 9
  44  */
  45 public class SplitMenuButtonSkin extends MenuButtonSkinBase<SplitMenuButton> {
  46 
  47     /***************************************************************************
  48      *                                                                         *
  49      * Private fields                                                          *
  50      *                                                                         *
  51      **************************************************************************/
  52 
  53     private final SplitMenuButtonBehavior behavior;
  54 
  55 
  56 
  57     /***************************************************************************
  58      *                                                                         *
  59      * Constructors                                                            *
  60      *                                                                         *
  61      **************************************************************************/
  62 
  63     /**
  64      * Creates a new SplitMenuButtonSkin instance, installing the necessary child
  65      * nodes into the Control {@link Control#getChildren() children} list, as
  66      * well as the necessary input mappings for handling key, mouse, etc events.
  67      *
  68      * @param control The control that this skin should be installed onto.
  69      */
  70     public SplitMenuButtonSkin(final SplitMenuButton control) {
  71         super(control);
  72 
  73         // install default input map for the MenuButton-like controls
  74         this.behavior = new SplitMenuButtonBehavior(control);
  75 //        setInputMap(control, behavior.getInputMap());
  76 
  77         /*
  78          * The arrow button is the only thing that acts like a MenuButton on
  79          * this control.
  80          */
  81         behaveLikeButton = true;
  82         // TODO: do we need to consume all mouse events?
  83         // they only bubble to the skin which consumes them by default
  84         arrowButton.addEventHandler(MouseEvent.ANY, event -> event.consume());


  85         arrowButton.setOnMousePressed(e -> {
  86             getBehavior().mousePressed(e, false);
  87             e.consume();
  88         });
  89         arrowButton.setOnMouseReleased(e -> {
  90             getBehavior().mouseReleased(e, false);
  91             e.consume();
  92         });
  93 
  94         label.setLabelFor(control);
  95     }
  96 
  97 
  98 
  99     /***************************************************************************
 100      *                                                                         *
 101      * Public API                                                              *
 102      *                                                                         *
 103      **************************************************************************/
 104 
 105     /** {@inheritDoc} */
 106     @Override public void dispose() {
 107         super.dispose();
 108 
 109         if (behavior != null) {
 110             behavior.dispose();
 111         }
 112     }
 113 
 114 
 115 
 116     /***************************************************************************
 117      *                                                                         *
 118      * Private implementation                                                  *
 119      *                                                                         *
 120      **************************************************************************/
 121 
 122     @Override SplitMenuButtonBehavior getBehavior() {
 123         return behavior;
 124     }
 125 }