diff --git a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TitledPaneSkin.java b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TitledPaneSkin.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TitledPaneSkin.java +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TitledPaneSkin.java @@ -25,6 +25,7 @@ package com.sun.javafx.scene.control.skin; +import com.sun.javafx.css.converters.SizeConverter; import javafx.animation.Animation.Status; import javafx.animation.Interpolator; import javafx.animation.KeyFrame; @@ -32,7 +33,9 @@ import javafx.animation.Timeline; import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoublePropertyBase; +import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.SimpleDoubleProperty; +import javafx.css.*; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Bounds; @@ -41,8 +44,7 @@ import javafx.geometry.VPos; import javafx.scene.Cursor; import javafx.scene.Node; -import javafx.scene.control.ContentDisplay; -import javafx.scene.control.TitledPane; +import javafx.scene.control.*; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; @@ -55,15 +57,16 @@ import com.sun.javafx.scene.traversal.TraverseListener; import javafx.beans.binding.DoubleBinding; import javafx.geometry.Insets; -import javafx.scene.control.Accordion; -import javafx.scene.control.Labeled; -import javafx.scene.control.ContextMenu; import javafx.scene.input.MouseButton; import javafx.scene.text.Font; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class TitledPaneSkin extends LabeledSkinBase { - public static final int MIN_HEADER_HEIGHT = 22; + private static final int DEFAULT_HEADER_HEIGHT = 22; public static final Duration TRANSITION_DURATION = new Duration(350.0); private final TitleRegion titleRegion; @@ -200,6 +203,48 @@ return transition; } + private DoubleProperty headerHeight; + + public final double getHeaderHeight() { + return headerHeight == null ? DEFAULT_HEADER_HEIGHT : headerHeight.get(); + } + + public final ReadOnlyDoubleProperty headerHeightProperty() { + return (ReadOnlyDoubleProperty)headerHeightPropertyImpl(); + } + + private DoubleProperty headerHeightPropertyImpl() { + if (headerHeight == null) { + headerHeight = new StyleableDoubleProperty(DEFAULT_HEADER_HEIGHT) { + + @Override + public void applyStyle(StyleOrigin origin, Number value) { + double size = value == null ? DEFAULT_HEADER_HEIGHT : value.doubleValue(); + // guard against a 0 or negative size + super.applyStyle(origin, size <= 0 ? DEFAULT_HEADER_HEIGHT : size); + } + + @Override public void set(double value) { + super.set(value); + getSkinnable().requestLayout(); + } + + @Override public Object getBean() { + return TitledPaneSkin.this; + } + + @Override public String getName() { + return "cellSize"; + } + + @Override public CssMetaData getCssMetaData() { + return StyleableProperties.HEADER_HEIGHT; + } + }; + } + return headerHeight; + } + private boolean isInsideAccordion() { return getSkinnable().getParent() != null && getSkinnable().getParent() instanceof Accordion; } @@ -208,7 +253,7 @@ final double w, final double h) { // header - double headerHeight = Math.max(MIN_HEADER_HEIGHT, snapSize(titleRegion.prefHeight(-1))); + double headerHeight = Math.max(getHeaderHeight(), snapSize(titleRegion.prefHeight(-1))); titleRegion.resize(w, headerHeight); positionInArea(titleRegion, x, y, @@ -235,7 +280,7 @@ } @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { - return Math.max(MIN_HEADER_HEIGHT, snapSize(titleRegion.prefHeight(-1))); + return Math.max(getHeaderHeight(), snapSize(titleRegion.prefHeight(-1))); } @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { @@ -245,7 +290,7 @@ } @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { - double headerHeight = Math.max(MIN_HEADER_HEIGHT, snapSize(titleRegion.prefHeight(-1))); + double headerHeight = Math.max(getHeaderHeight(), snapSize(titleRegion.prefHeight(-1))); double contentHeight = contentContainer.prefHeight(-1) * getTransition(); return headerHeight + snapSize(contentHeight) + topInset + bottomInset; } @@ -260,7 +305,7 @@ } double getTitledPaneHeightForAccordion() { - double headerHeight = Math.max(MIN_HEADER_HEIGHT, snapSize(titleRegion.prefHeight(-1))); + double headerHeight = Math.max(getHeaderHeight(), snapSize(titleRegion.prefHeight(-1))); double contentHeight = (prefHeightFromAccordion - headerHeight) * getTransition(); return headerHeight + snapSize(contentHeight) + snappedTopInset() + snappedBottomInset(); } @@ -563,4 +608,59 @@ return content; } } + + + /*************************************************************************** + * * + * Stylesheet Handling * + * * + **************************************************************************/ + + /** + * Super-lazy instantiation pattern from Bill Pugh. + * @treatAsPrivate implementation detail + */ + private static class StyleableProperties { + private final static CssMetaData HEADER_HEIGHT = + new CssMetaData("-fx-header-height", + SizeConverter.getInstance(), DEFAULT_HEADER_HEIGHT) { + + @Override + public boolean isSettable(TitledPane n) { + final TitledPaneSkin skin = (TitledPaneSkin) n.getSkin(); + return skin.headerHeight == null || !skin.headerHeight.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(TitledPane n) { + final TitledPaneSkin skin = (TitledPaneSkin) n.getSkin(); + return (StyleableProperty)skin.headerHeightPropertyImpl(); + } + }; + + private static final List> STYLEABLES; + static { + final List> styleables = + new ArrayList<>(SkinBase.getClassCssMetaData()); + styleables.add(HEADER_HEIGHT); + STYLEABLES = Collections.unmodifiableList(styleables); + + } + } + + /** + * @return The CssMetaData associated with this class, which may include the + * CssMetaData of its super classes. + */ + public static List> getClassCssMetaData() { + return StyleableProperties.STYLEABLES; + } + + /** + * {@inheritDoc} + */ + @Override + public List> getCssMetaData() { + return getClassCssMetaData(); + } }