Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.control; 027 028import javafx.event.ActionEvent; 029import com.sun.javafx.scene.control.skin.SplitMenuButtonSkin; 030 031/** 032 * The SplitMenuButton, like the {@link MenuButton} is closely associated with 033 * the concept of selecting a {@link MenuItem} from a menu. Unlike {@link MenuButton}, 034 * the SplitMenuButton is broken into two pieces, the "action" area and the 035 * "menu open" area. 036 * <p> 037 * If the user clicks in the action area, the SplitMenuButton will act similarly 038 * to a {@link javafx.scene.control.Button Button}, firing whatever is 039 * associated with the {@link #onAction} property. 040 * <p> 041 * The menu open area of the control will show a menu if clicked. When the user 042 * selects an item from the menu, it is executed. 043 * <p> 044 * Note that the SplitMenuButton does not automatically assign whatever was last 045 * selected in the menu to be the action should the action region be clicked. 046 * 047 * <p>Example:</p> 048 * <pre> 049 * SplitMenuButton m = new SplitMenuButton(); 050 * m.setText("Shutdown"); 051 * m.getItems().addAll(new MenuItem("Logout"), new MenuItem("Sleep")); 052 * m.setOnAction(new EventHandler<ActionEvent>() { 053 * @Override public void handle(ActionEvent e) { 054 * System.out.println("Shutdown"); 055 * } 056 * }); 057 * </pre> 058 * <p> 059 * 060 * <p> 061 * MnemonicParsing is enabled by default for SplitMenuButton. 062 * </p> 063 * 064 * @see MenuItem 065 * @see Menu 066 */ 067 068public class SplitMenuButton extends MenuButton { 069 070 /*************************************************************************** 071 * * 072 * Constructors * 073 * * 074 **************************************************************************/ 075 076 /** 077 * Creates a new empty split menu button. Use {@link #setText(String)}, 078 * {@link #setGraphic(Node)} and {@link #getItems()} to set the content. 079 */ 080 public SplitMenuButton() { 081 this((MenuItem[])null); 082 } 083 084 /** 085 * Creates a new split menu button with the given list of menu items. 086 * 087 * @param items The items to show within this button's menu 088 */ 089 public SplitMenuButton(MenuItem... items) { 090 if (items != null) { 091 getItems().addAll(items); 092 } 093 094 getStyleClass().setAll(DEFAULT_STYLE_CLASS); 095 setMnemonicParsing(true); // enable mnemonic auto-parsing by default 096 } 097 098 /*************************************************************************** 099 * * 100 * Properties * 101 * * 102 **************************************************************************/ 103 /** 104 * Call the action when button is pressed. 105 */ 106 @Override public void fire() { 107 fireEvent(new ActionEvent()); 108 } 109 110 /*************************************************************************** 111 * * 112 * Methods * 113 * * 114 **************************************************************************/ 115 116 /** {@inheritDoc} */ 117 @Override protected Skin<?> createDefaultSkin() { 118 return new SplitMenuButtonSkin(this); 119 } 120 121 /*************************************************************************** 122 * * 123 * Stylesheet Handling * 124 * * 125 **************************************************************************/ 126 127 private static final String DEFAULT_STYLE_CLASS = "split-menu-button"; 128 129 // SplitMenuButton adds no new CSS keys. 130}