modules/controls/src/main/java/javafx/scene/control/SkinBase.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 1,7 ****
/*
! * Copyright (c) 2012, 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) 2012, 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
*** 23,36 ****
--- 23,43 ----
* questions.
*/
package javafx.scene.control;
+ import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;
+ import com.sun.javafx.scene.control.behavior.BehaviorBase;
+ import javafx.application.ConditionalFeature;
+ import javafx.application.Platform;
+ import javafx.beans.value.ObservableValue;
import javafx.css.CssMetaData;
import javafx.css.PseudoClass;
import java.util.Collections;
import java.util.List;
+ import java.util.function.Consumer;
+
import javafx.collections.ObservableList;
import javafx.css.Styleable;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
*** 68,77 ****
--- 75,91 ----
/**
* A local field that directly refers to the children list inside the Control.
*/
private ObservableList<Node> children;
+ /**
+ * This is part of the workaround introduced during delomboking. We probably will
+ * want to adjust the way listeners are added rather than continuing to use this
+ * map (although it doesn't really do much harm).
+ */
+ private LambdaMultiplePropertyChangeListenerHandler lambdaChangeListenerHandler;
+
/***************************************************************************
* *
* Event Handlers / Listeners *
*** 137,146 ****
--- 151,165 ----
/** {@inheritDoc} */
@Override public void dispose() {
// control.removeEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, contextMenuHandler);
+ // unhook listeners
+ if (lambdaChangeListenerHandler != null) {
+ lambdaChangeListenerHandler.dispose();
+ }
+
this.control = null;
}
*** 181,190 ****
--- 200,222 ----
control.removeEventHandler(MouseEvent.ANY, mouseEventConsumer);
}
}
+ /**
+ * Subclasses can invoke this method to register that we want to listen to
+ * property change events for the given property.
+ */
+ protected final void registerChangeListener(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) {
+ if (lambdaChangeListenerHandler == null) {
+ lambdaChangeListenerHandler = new LambdaMultiplePropertyChangeListenerHandler();
+ }
+ lambdaChangeListenerHandler.registerChangeListener(property, consumer);
+ }
+
+
+
/***************************************************************************
* *
* Public Layout-related API *
* *
*** 719,740 ****
* Specialization of CSS handling code *
* *
**************************************************************************/
private static class StyleableProperties {
-
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
static {
STYLEABLES = Collections.unmodifiableList(Control.getClassCssMetaData());
}
}
/**
! * @return The CssMetaData associated with this class, which may include the
* CssMetaData of its super classes.
! */ public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return SkinBase.StyleableProperties.STYLEABLES;
}
/**
* This method should delegate to {@link Node#getClassCssMetaData()} so that
--- 751,772 ----
* Specialization of CSS handling code *
* *
**************************************************************************/
private static class StyleableProperties {
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
static {
STYLEABLES = Collections.unmodifiableList(Control.getClassCssMetaData());
}
}
/**
! * Returns the CssMetaData associated with this class, which may include the
* CssMetaData of its super classes.
! */
! public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return SkinBase.StyleableProperties.STYLEABLES;
}
/**
* This method should delegate to {@link Node#getClassCssMetaData()} so that
*** 744,754 ****
*/
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
return getClassCssMetaData();
}
! /** @see Node#pseudoClassStateChanged */
public final void pseudoClassStateChanged(PseudoClass pseudoClass, boolean active) {
Control ctl = getSkinnable();
if (ctl != null) {
ctl.pseudoClassStateChanged(pseudoClass, active);
}
--- 776,815 ----
*/
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
return getClassCssMetaData();
}
! /**
! * Used to specify that a pseudo-class of this Node has changed. If the
! * pseudo-class is used in a CSS selector that matches this Node, CSS will
! * be reapplied. Typically, this method is called from the {@code invalidated}
! * method of a property that is used as a pseudo-class. For example:
! * <code><pre>
! *
! * private static final PseudoClass MY_PSEUDO_CLASS_STATE = PseudoClass.getPseudoClass("my-state");
! *
! * BooleanProperty myPseudoClassState = new BooleanPropertyBase(false) {
! *
! * {@literal @}Override public void invalidated() {
! * pseudoClassStateChanged(MY_PSEUDO_CLASS_STATE, get());
! * }
! *
! * {@literal @}Override public Object getBean() {
! * return MyControl.this;
! * }
! *
! * {@literal @}Override public String getName() {
! * return "myPseudoClassState";
! * }
! * };
! * </pre><code>
! *
! * @see Node#pseudoClassStateChanged
! * @param pseudoClass the pseudo-class that has changed state
! * @param active whether or not the state is active
! * @since JavaFX 8.0
! */
public final void pseudoClassStateChanged(PseudoClass pseudoClass, boolean active) {
Control ctl = getSkinnable();
if (ctl != null) {
ctl.pseudoClassStateChanged(pseudoClass, active);
}
*** 759,774 ****
* *
* Accessibility handling *
* *
**************************************************************************/
! /** @see Node#queryAccessibleAttribute */
protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
return null;
}
! /** @see Node#executeAccessibleAction */
protected void executeAccessibleAction(AccessibleAction action, Object... parameters) {
}
/***************************************************************************
* *
--- 820,870 ----
* *
* Accessibility handling *
* *
**************************************************************************/
! /**
! * This method is called by the assistive technology to request
! * the value for an attribute.
! * <p>
! * This method is commonly overridden by subclasses to implement
! * attributes that are required for a specific role.<br>
! * If a particular attribute is not handled, the super class implementation
! * must be called.
! * </p>
! *
! * @param attribute the requested attribute
! * @param parameters optional list of parameters
! * @return the value for the requested attribute
! *
! * @see AccessibleAttribute
! * @see Node#queryAccessibleAttribute
! *
! * @since JavaFX 8u40
! */
protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
return null;
}
! /**
! * This method is called by the assistive technology to request the action
! * indicated by the argument should be executed.
! * <p>
! * This method is commonly overridden by subclasses to implement
! * action that are required for a specific role.<br>
! * If a particular action is not handled, the super class implementation
! * must be called.
! * </p>
! *
! * @param action the action to execute
! * @param parameters optional list of parameters
! *
! * @see AccessibleAction
! * @see Node#executeAccessibleAction
! *
! * @since JavaFX 8u40
! */
protected void executeAccessibleAction(AccessibleAction action, Object... parameters) {
}
/***************************************************************************
* *