diff --git a/modules/controls/src/main/java/javafx/scene/control/skin/ColorPickerSkin.java b/modules/controls/src/main/java/javafx/scene/control/skin/ColorPickerSkin.java --- a/modules/controls/src/main/java/javafx/scene/control/skin/ColorPickerSkin.java +++ b/modules/controls/src/main/java/javafx/scene/control/skin/ColorPickerSkin.java @@ -56,6 +56,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; import javafx.scene.control.ColorPicker; import javafx.scene.control.TextField; @@ -330,8 +331,8 @@ } /** {@inheritDoc} */ - @Override ComboBoxBaseBehavior getBehavior() { - return behavior; + @Override Optional getBehavior() { + return Optional.of(behavior); } private void updateComboBoxMode() { diff --git a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxBaseSkin.java b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxBaseSkin.java --- a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxBaseSkin.java +++ b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxBaseSkin.java @@ -36,6 +36,8 @@ import javafx.scene.layout.StackPane; import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; /** * An abstract class intended to be used as the base skin for ComboBox-like @@ -105,10 +107,10 @@ // arrowButton behaves like a button. // This is strongly tied to the implementation in ComboBoxBaseBehavior. // - arrowButton.addEventHandler(MouseEvent.MOUSE_ENTERED, (e) -> getBehavior().mouseEntered(e)); - arrowButton.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> { getBehavior().mousePressed(e); e.consume(); }); - arrowButton.addEventHandler(MouseEvent.MOUSE_RELEASED, (e) -> { getBehavior().mouseReleased(e); e.consume();}); - arrowButton.addEventHandler(MouseEvent.MOUSE_EXITED, (e) -> getBehavior().mouseExited(e)); + arrowButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> executeBehavior(b -> b.mouseEntered(e))); + arrowButton.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> executeBehavior(b -> { b.mousePressed(e); e.consume(); })); + arrowButton.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> executeBehavior(b -> { b.mouseReleased(e); e.consume();})); + arrowButton.addEventHandler(MouseEvent.MOUSE_EXITED, e -> executeBehavior(b -> b.mouseExited(e))); } getChildren().add(arrowButton); @@ -251,8 +253,12 @@ * * **************************************************************************/ - ComboBoxBaseBehavior getBehavior() { - return null; + void executeBehavior(Consumer consumer) { + getBehavior().ifPresent(consumer); + } + + Optional getBehavior() { + return Optional.empty(); } void focusLost() { diff --git a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java --- a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java +++ b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java @@ -30,6 +30,7 @@ import com.sun.javafx.scene.control.behavior.ComboBoxListViewBehavior; import java.util.List; +import java.util.Optional; import javafx.beans.InvalidationListener; import javafx.beans.WeakInvalidationListener; @@ -363,8 +364,8 @@ } /** {@inheritDoc} */ - @Override ComboBoxBaseBehavior getBehavior() { - return behavior; + @Override Optional getBehavior() { + return Optional.of(behavior); } private void updateComboBoxItems() { diff --git a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java --- a/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java +++ b/modules/controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java @@ -461,13 +461,13 @@ popup.setAutoHide(true); popup.setAutoFix(true); popup.setHideOnEscape(true); - popup.setOnAutoHide(e -> getBehavior().onAutoHide(popup)); + popup.setOnAutoHide(e -> executeBehavior(b -> b.onAutoHide(popup))); popup.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> { // RT-18529: We listen to mouse input that is received by the popup // but that is not consumed, and assume that this is due to the mouse // clicking outside of the node, but in areas such as the // dropshadow. - getBehavior().onAutoHide(popup); + executeBehavior(b -> b.onAutoHide(popup)); }); popup.addEventHandler(WindowEvent.WINDOW_HIDDEN, t -> { // Make sure the accessibility focus returns to the combo box diff --git a/modules/controls/src/main/java/javafx/scene/control/skin/DatePickerSkin.java b/modules/controls/src/main/java/javafx/scene/control/skin/DatePickerSkin.java --- a/modules/controls/src/main/java/javafx/scene/control/skin/DatePickerSkin.java +++ b/modules/controls/src/main/java/javafx/scene/control/skin/DatePickerSkin.java @@ -28,6 +28,7 @@ import java.time.LocalDate; import java.time.YearMonth; import java.time.chrono.HijrahChronology; +import java.util.Optional; import com.sun.javafx.scene.control.DatePickerContent; import com.sun.javafx.scene.control.DatePickerHijrahContent; @@ -230,7 +231,8 @@ } /** {@inheritDoc} */ - @Override ComboBoxBaseBehavior getBehavior() { - return behavior; + @Override + Optional getBehavior() { + return Optional.of(behavior); } }