modules/controls/src/main/java/javafx/scene/control/skin/SeparatorSkin.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

*** 21,84 **** * 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 javafx.geometry.Orientation; import javafx.scene.control.Separator; import javafx.scene.layout.Region; import java.util.Collections; - import com.sun.javafx.scene.control.behavior.BehaviorBase; /** * */ ! public class SeparatorSkin extends BehaviorSkinBase<Separator, BehaviorBase<Separator>> { /** * Separator's have no intrinsic length, so we need to hard code some sort * of default preferred size when a separator is not otherwise being resized. * This is the default length to use (height when vertical, width when horizontal) * for computing the preferred width/height. */ private static final double DEFAULT_LENGTH = 10; /** * The region to use for rendering the line. The line is specified via * CSS. By default we use a single stroke to render the line, but the * programmer could use images or whatnot from CSS instead. */ private final Region line; /** ! * Create a new SeparatorSkin. Just specify the separator, thanks very much. ! * @param separator not null */ ! public SeparatorSkin(Separator separator) { // There is no behavior for the separator, so we just create a // dummy behavior base instead, since SkinBase will complain // about it being null. ! super(separator, new BehaviorBase<>(separator, Collections.emptyList())); line = new Region(); line.getStyleClass().setAll("line"); getChildren().add(line); ! registerChangeListener(separator.orientationProperty(), "ORIENTATION"); ! registerChangeListener(separator.halignmentProperty(), "HALIGNMENT"); ! registerChangeListener(separator.valignmentProperty(), "VALIGNMENT"); } ! @Override protected void handleControlPropertyChanged(String p) { ! super.handleControlPropertyChanged(p); ! if ("ORIENTATION".equals(p) || "HALIGNMENT".equals(p) || "VALIGNMENT".equals(p)) { ! getSkinnable().requestLayout(); ! } ! } /** * We only need to deal with the single "line" child region. The important * thing here is that we want a horizontal separator to have a line which is * as wide as the separator (less the left/right padding), but as thin as --- 21,117 ---- * 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 javafx.geometry.Orientation; + import javafx.scene.Node; + import javafx.scene.control.Accordion; + import javafx.scene.control.Control; import javafx.scene.control.Separator; + import javafx.scene.control.SkinBase; import javafx.scene.layout.Region; import java.util.Collections; /** + * Default skin implementation for the {@link Separator} control. * + * @see Separator + * @since 9 */ ! public class SeparatorSkin extends SkinBase<Separator> { ! ! /*************************************************************************** ! * * ! * Static fields * ! * * ! **************************************************************************/ /** * Separator's have no intrinsic length, so we need to hard code some sort * of default preferred size when a separator is not otherwise being resized. * This is the default length to use (height when vertical, width when horizontal) * for computing the preferred width/height. */ private static final double DEFAULT_LENGTH = 10; + + + /*************************************************************************** + * * + * Private fields * + * * + **************************************************************************/ + /** * The region to use for rendering the line. The line is specified via * CSS. By default we use a single stroke to render the line, but the * programmer could use images or whatnot from CSS instead. */ private final Region line; + + + /*************************************************************************** + * * + * Constructors * + * * + **************************************************************************/ + /** ! * Creates a new SeparatorSkin 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 SeparatorSkin(Separator control) { // There is no behavior for the separator, so we just create a // dummy behavior base instead, since SkinBase will complain // about it being null. ! super(control); line = new Region(); line.getStyleClass().setAll("line"); getChildren().add(line); ! registerChangeListener(control.orientationProperty(), e -> getSkinnable().requestLayout()); ! registerChangeListener(control.halignmentProperty(), e -> getSkinnable().requestLayout()); ! registerChangeListener(control.valignmentProperty(), e -> getSkinnable().requestLayout()); } ! ! ! /*************************************************************************** ! * * ! * Public API * ! * * ! **************************************************************************/ /** * We only need to deal with the single "line" child region. The important * thing here is that we want a horizontal separator to have a line which is * as wide as the separator (less the left/right padding), but as thin as
*** 103,137 **** --- 136,176 ---- // Now that the line has been sized, simply position it positionInArea(line, x, y, w, h, 0, sep.getHalignment(), sep.getValignment()); } + /** {@inheritDoc} */ @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { return computePrefWidth(height, topInset, rightInset, bottomInset, leftInset); } + /** {@inheritDoc} */ @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { return computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); } + /** {@inheritDoc} */ @Override protected double computePrefWidth(double h, double topInset, double rightInset, double bottomInset, double leftInset) { final Separator sep = getSkinnable(); double w = sep.getOrientation() == Orientation.VERTICAL ? line.prefWidth(-1) : DEFAULT_LENGTH; return w + leftInset + rightInset; } + /** {@inheritDoc} */ @Override protected double computePrefHeight(double w, double topInset, double rightInset, double bottomInset, double leftInset) { final Separator sep = getSkinnable(); double h = sep.getOrientation() == Orientation.VERTICAL ? DEFAULT_LENGTH : line.prefHeight(-1); return h + topInset + bottomInset; } + /** {@inheritDoc} */ @Override protected double computeMaxWidth(double h, double topInset, double rightInset, double bottomInset, double leftInset) { final Separator sep = getSkinnable(); return sep.getOrientation() == Orientation.VERTICAL ? sep.prefWidth(h) : Double.MAX_VALUE; } + /** {@inheritDoc} */ @Override protected double computeMaxHeight(double w, double topInset, double rightInset, double bottomInset, double leftInset) { final Separator sep = getSkinnable(); return sep.getOrientation() == Orientation.VERTICAL ? Double.MAX_VALUE : sep.prefHeight(w); } }