< prev index next >

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

Print this page




   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.ContextMenuContent;
  29 import com.sun.javafx.scene.control.ControlAcceleratorSupport;
  30 import com.sun.javafx.scene.control.LabeledImpl;
  31 import com.sun.javafx.scene.control.skin.Utils;
  32 import javafx.application.Platform;
  33 import javafx.collections.ListChangeListener;
  34 import javafx.event.ActionEvent;
  35 import javafx.scene.control.ContextMenu;
  36 import javafx.scene.control.MenuButton;
  37 import javafx.scene.control.MenuItem;
  38 import javafx.scene.control.SkinBase;
  39 import javafx.scene.input.MouseEvent;
  40 import javafx.scene.layout.Region;
  41 import javafx.scene.layout.StackPane;
  42 import com.sun.javafx.scene.control.behavior.MenuButtonBehaviorBase;
  43 
  44 /**
  45  * Base class for MenuButtonSkin and SplitMenuButtonSkin. It consists of the
  46  * label, the arrowButton with its arrow shape, and the popup.
  47  *


 169             // Handle tabbing away from an open MenuButton
 170             if (!getSkinnable().isFocused() && getSkinnable().isShowing()) {
 171                 hide();
 172             }
 173             if (!getSkinnable().isFocused() && popup.isShowing()) {
 174                 hide();
 175             }
 176         });
 177         registerChangeListener(control.mnemonicParsingProperty(), e -> {
 178             label.setMnemonicParsing(getSkinnable().isMnemonicParsing());
 179             getSkinnable().requestLayout();
 180         });
 181         registerChangeListener(popup.showingProperty(), e -> {
 182             if (!popup.isShowing() && getSkinnable().isShowing()) {
 183                 // Popup was dismissed. Maybe user clicked outside or typed ESCAPE.
 184                 // Make sure button is in sync.
 185                 getSkinnable().hide();
 186             }
 187 
 188             if (popup.isShowing()) {
 189                 Utils.addMnemonics(popup, getSkinnable().getScene(), getSkinnable().impl_isShowMnemonics());
 190             } else {
 191                 // we wrap this in a runLater so that mnemonics are not removed
 192                 // before all key events are fired (because KEY_PRESSED might have
 193                 // been used to hide the menu, but KEY_TYPED and KEY_RELEASED
 194                 // events are still to be fired, and shouldn't miss out on going
 195                 // through the mnemonics code (especially in case they should be
 196                 // consumed to prevent them being used elsewhere).
 197                 // See JBS-8090026 for more detail.
 198                 Platform.runLater(() -> Utils.removeMnemonics(popup, getSkinnable().getScene()));
 199             }
 200         });
 201     }
 202 
 203 
 204 
 205     /***************************************************************************
 206      *                                                                         *
 207      * Private implementation                                                  *
 208      *                                                                         *
 209      **************************************************************************/




   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.NodeHelper;
  29 import com.sun.javafx.scene.control.ContextMenuContent;
  30 import com.sun.javafx.scene.control.ControlAcceleratorSupport;
  31 import com.sun.javafx.scene.control.LabeledImpl;
  32 import com.sun.javafx.scene.control.skin.Utils;
  33 import javafx.application.Platform;
  34 import javafx.collections.ListChangeListener;
  35 import javafx.event.ActionEvent;
  36 import javafx.scene.control.ContextMenu;
  37 import javafx.scene.control.MenuButton;
  38 import javafx.scene.control.MenuItem;
  39 import javafx.scene.control.SkinBase;
  40 import javafx.scene.input.MouseEvent;
  41 import javafx.scene.layout.Region;
  42 import javafx.scene.layout.StackPane;
  43 import com.sun.javafx.scene.control.behavior.MenuButtonBehaviorBase;
  44 
  45 /**
  46  * Base class for MenuButtonSkin and SplitMenuButtonSkin. It consists of the
  47  * label, the arrowButton with its arrow shape, and the popup.
  48  *


 170             // Handle tabbing away from an open MenuButton
 171             if (!getSkinnable().isFocused() && getSkinnable().isShowing()) {
 172                 hide();
 173             }
 174             if (!getSkinnable().isFocused() && popup.isShowing()) {
 175                 hide();
 176             }
 177         });
 178         registerChangeListener(control.mnemonicParsingProperty(), e -> {
 179             label.setMnemonicParsing(getSkinnable().isMnemonicParsing());
 180             getSkinnable().requestLayout();
 181         });
 182         registerChangeListener(popup.showingProperty(), e -> {
 183             if (!popup.isShowing() && getSkinnable().isShowing()) {
 184                 // Popup was dismissed. Maybe user clicked outside or typed ESCAPE.
 185                 // Make sure button is in sync.
 186                 getSkinnable().hide();
 187             }
 188 
 189             if (popup.isShowing()) {
 190                 Utils.addMnemonics(popup, getSkinnable().getScene(), NodeHelper.isShowMnemonics(getSkinnable()));
 191             } else {
 192                 // we wrap this in a runLater so that mnemonics are not removed
 193                 // before all key events are fired (because KEY_PRESSED might have
 194                 // been used to hide the menu, but KEY_TYPED and KEY_RELEASED
 195                 // events are still to be fired, and shouldn't miss out on going
 196                 // through the mnemonics code (especially in case they should be
 197                 // consumed to prevent them being used elsewhere).
 198                 // See JBS-8090026 for more detail.
 199                 Platform.runLater(() -> Utils.removeMnemonics(popup, getSkinnable().getScene()));
 200             }
 201         });
 202     }
 203 
 204 
 205 
 206     /***************************************************************************
 207      *                                                                         *
 208      * Private implementation                                                  *
 209      *                                                                         *
 210      **************************************************************************/


< prev index next >