modules/controls/src/main/java/javafx/scene/control/skin/ButtonBarSkin.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 1,7 ****
/*
! * Copyright (c) 2014, 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
--- 1,7 ----
/*
! * Copyright (c) 2014, 2015, 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
*** 20,54 ****
*
* 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 com.sun.javafx.scene.control.skin;
import java.util.ArrayList;
- import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.beans.InvalidationListener;
import javafx.beans.property.ObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
! import com.sun.javafx.scene.control.behavior.BehaviorBase;
! import com.sun.javafx.scene.control.behavior.KeyBinding;
!
! public class ButtonBarSkin extends BehaviorSkinBase<ButtonBar, BehaviorBase<ButtonBar>> {
/**************************************************************************
*
* Static fields
*
--- 20,60 ----
*
* 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.skin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+ import com.sun.javafx.scene.control.Properties;
+ import com.sun.javafx.scene.control.behavior.BehaviorBase;
import javafx.beans.InvalidationListener;
import javafx.beans.property.ObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonBar.ButtonData;
+ import javafx.scene.control.Control;
+ import javafx.scene.control.SkinBase;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
! /**
! * Default skin implementation for the {@link ButtonBar} control.
! *
! * @see ButtonBar
! * @since 9
! */
! public class ButtonBarSkin extends SkinBase<ButtonBar> {
/**************************************************************************
*
* Static fields
*
*** 56,71 ****
private static final double GAP_SIZE = 10;
private static final String CATEGORIZED_TYPES = "LRHEYNXBIACO"; //$NON-NLS-1$
- // represented as a ButtonData
- public static final String BUTTON_DATA_PROPERTY = "javafx.scene.control.ButtonBar.ButtonData"; //$NON-NLS-1$
-
- // allows to exclude button from uniform resizing
- public static final String BUTTON_SIZE_INDEPENDENCE = "javafx.scene.control.ButtonBar.independentSize"; //$NON-NLS-1$
-
// pick an arbitrary number
private static final double DO_NOT_CHANGE_SIZE = Double.MAX_VALUE - 100;
/**************************************************************************
--- 62,71 ----
*** 73,99 ****
* fields
*
**************************************************************************/
private HBox layout;
-
private InvalidationListener buttonDataListener = o -> layoutButtons();
/**************************************************************************
*
* Constructors
*
**************************************************************************/
public ButtonBarSkin(final ButtonBar control) {
! super(control, new BehaviorBase<>(control, Collections.<KeyBinding> emptyList()));
this.layout = new HBox(GAP_SIZE) {
! @Override
! protected void layoutChildren() {
// has to be called first or layout is not correct sometimes
resizeButtons();
super.layoutChildren();
}
};
--- 73,105 ----
* fields
*
**************************************************************************/
private HBox layout;
private InvalidationListener buttonDataListener = o -> layoutButtons();
/**************************************************************************
*
* Constructors
*
**************************************************************************/
+ /**
+ * Creates a new ButtonBarSkin instance, installing the necessary child
+ * nodes into the Control {@link Control#getChildren() children} list, as
+ * well as the necessary {@link Node#getInputMap() input mappings} for
+ * handling key, mouse, etc events.
+ *
+ * @param control The control that this skin should be installed onto.
+ */
public ButtonBarSkin(final ButtonBar control) {
! super(control);
this.layout = new HBox(GAP_SIZE) {
! @Override protected void layoutChildren() {
// has to be called first or layout is not correct sometimes
resizeButtons();
super.layoutChildren();
}
};
*** 110,129 ****
updateButtonListeners(c.getAddedSubList(), true);
}
layoutButtons();
});
! registerChangeListener(control.buttonOrderProperty(), "BUTTON_ORDER"); //$NON-NLS-1$
! registerChangeListener(control.buttonMinWidthProperty(), "BUTTON_MIN_WIDTH"); //$NON-NLS-1$
}
private void updateButtonListeners(List<? extends Node> list, boolean buttonsAdded) {
if (list != null) {
for (Node n : list) {
final Map<Object, Object> properties = n.getProperties();
! if (properties.containsKey(ButtonBarSkin.BUTTON_DATA_PROPERTY)) {
! ObjectProperty<ButtonData> property = (ObjectProperty<ButtonData>) properties.get(ButtonBarSkin.BUTTON_DATA_PROPERTY);
if (property != null) {
if (buttonsAdded) {
property.addListener(buttonDataListener);
} else {
property.removeListener(buttonDataListener);
--- 116,143 ----
updateButtonListeners(c.getAddedSubList(), true);
}
layoutButtons();
});
! registerChangeListener(control.buttonOrderProperty(), e -> layoutButtons());
! registerChangeListener(control.buttonMinWidthProperty(), e -> resizeButtons());
}
+
+
+ /**************************************************************************
+ *
+ * Implementation
+ *
+ **************************************************************************/
+
private void updateButtonListeners(List<? extends Node> list, boolean buttonsAdded) {
if (list != null) {
for (Node n : list) {
final Map<Object, Object> properties = n.getProperties();
! if (properties.containsKey(Properties.BUTTON_DATA_PROPERTY)) {
! ObjectProperty<ButtonData> property = (ObjectProperty<ButtonData>) properties.get(Properties.BUTTON_DATA_PROPERTY);
if (property != null) {
if (buttonsAdded) {
property.addListener(buttonDataListener);
} else {
property.removeListener(buttonDataListener);
*** 132,167 ****
}
}
}
}
-
- /**************************************************************************
- *
- * Overriding public API
- *
- **************************************************************************/
-
- @Override protected void handleControlPropertyChanged(String p) {
- super.handleControlPropertyChanged(p);
-
- if ("BUTTON_ORDER".equals(p)) { //$NON-NLS-1$
- layoutButtons();
- } else if ("BUTTON_MIN_WIDTH".equals(p)) { //$NON-NLS-1$
- // layoutButtons();
- resizeButtons();
- }
- }
-
-
-
- /**************************************************************************
- *
- * Implementation
- *
- **************************************************************************/
-
private void layoutButtons() {
final ButtonBar buttonBar = getSkinnable();
final List<? extends Node> buttons = buttonBar.getButtons();
final double buttonMinWidth = buttonBar.getButtonMinWidth();
--- 146,155 ----