/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javafx.scene.control;
import com.sun.javafx.css.converters.BooleanConverter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javafx.beans.DefaultProperty;
import javafx.beans.property.BooleanProperty;
import javafx.beans.value.WritableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.css.CssMetaData;
import javafx.css.StyleableBooleanProperty;
import com.sun.javafx.scene.control.skin.MenuBarSkin;
import javafx.css.Styleable;
import javafx.css.StyleableProperty;
import javafx.scene.AccessibleRole;
/**
*
* A MenuBar control traditionally is placed at the very top of the user
* interface, and embedded within it are {@link Menu Menus}. To add a menu to
* a menubar, you add it to the {@link #getMenus() menus} ObservableList.
* By default, for each menu added to the menubar, it will be
* represented as a button with the Menu {@link MenuItem#textProperty() text} value displayed.
*
* MenuBar sets focusTraversable to false.
*
*
* To create and populate a {@code MenuBar}, you may do what is shown below.
* Please refer to the {@link Menu} API page for more information on how to
* configure it.
*
* final Menu menu1 = new Menu("File");
* final Menu menu2 = new Menu("Options");
* final Menu menu3 = new Menu("Help");
*
* MenuBar menuBar = new MenuBar();
* menuBar.getMenus().addAll(menu1, menu2, menu3);
*
*
* @see Menu
* @see MenuItem
* @since JavaFX 2.0
*/
@DefaultProperty("menus")
public class MenuBar extends Control {
/***************************************************************************
* *
* Constructors *
* *
**************************************************************************/
/**
* Creates a new empty MenuBar.
*/
public MenuBar() {
this((Menu[])null);
}
/**
* Creates a new MenuBar populated with the given menus.
*
* @param menus The menus to place inside the MenuBar
* @since JavaFX 8u40
*/
public MenuBar(Menu... menus) {
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.MENU_BAR);
if (menus != null) {
getMenus().addAll(menus);
}
// focusTraversable is styleable through css. Calling setFocusTraversable
// makes it look to css like the user set the value and css will not
// override. Initializing focusTraversable by calling applyStyle with null
// StyleOrigin ensures that css will be able to override the value.
((StyleableProperty)(WritableValue)focusTraversableProperty()).applyStyle(null, Boolean.FALSE);
}
/***************************************************************************
* *
* Instance variables *
* *
**************************************************************************/
private ObservableList