/* * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.scene.control; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javafx.beans.DefaultProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.value.WritableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Orientation; import javafx.scene.AccessibleRole; import javafx.scene.Node; import javafx.css.StyleableObjectProperty; import javafx.css.CssMetaData; import javafx.css.PseudoClass; import javafx.css.converter.EnumConverter; import javafx.scene.control.skin.ToolBarSkin; import javafx.css.Styleable; import javafx.css.StyleableProperty; /** *
* A ToolBar is a control which displays items horizontally * or vertically. The most common items to place within a {@code ToolBar} * are {@link Button Buttons}, {@link ToggleButton ToggleButtons} and * {@link Separator Separators}, but you are not restricted to just these, and * can insert any {@link Node} into them. *
* *If there are too many items to fit in the ToolBar an overflow button will appear. * The overflow button allows you to select items that are not currently visible in the toolbar. *
** ToolBar sets focusTraversable to false. *
* ** Example of a horizontal ToolBar with eight buttons separated with two vertical separators. *
*
* ToolBar toolBar = new ToolBar(
* new Button("New"),
* new Button("Open"),
* new Button("Save"),
* new Separator(true),
* new Button("Clean"),
* new Button("Compile"),
* new Button("Run"),
* new Separator(true),
* new Button("Debug"),
* new Button("Profile")
* );
*
*
* @since JavaFX 2.0
*/
@DefaultProperty("items")
public class ToolBar extends Control {
/***************************************************************************
* *
* Constructors *
* *
**************************************************************************/
/**
* Creates an empty tool bar.
*/
public ToolBar() {
initialize();
}
/**
* Creates a tool bar populated with the specified nodes. None of the items
* can be null.
*
* @param items the items to add
*/
public ToolBar(Node... items) {
initialize();
this.items.addAll(items);
}
private void initialize() {
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.TOOL_BAR);
// 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 set on the
// CssMetaData ensures that css will be able to override the value.
((StyleableProperty