Class SkinBase<C extends Control>
- All Implemented Interfaces:
Skin<C>
- Direct Known Subclasses:
BehaviorSkinBase
,FxControlPeerSkin
,ProgressIndicatorSkin
,SeparatorSkin
,SplitPaneSkin
skin
.
A user interface control is abstracted behind the Skinnable
interface.- Since:
- JavaFX 8.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected double
computeBaselineOffset
(double topInset, double rightInset, double bottomInset, double leftInset) Calculates the baseline offset based on the first managed child.protected double
computeMaxHeight
(double width, double topInset, double rightInset, double bottomInset, double leftInset) Computes the maximum allowable height of the Skin, based on the provided width.protected double
computeMaxWidth
(double height, double topInset, double rightInset, double bottomInset, double leftInset) Computes the maximum allowable width of the Skin, based on the provided height.protected double
computeMinHeight
(double width, double topInset, double rightInset, double bottomInset, double leftInset) Computes the minimum allowable height of the Skin, based on the provided width.protected double
computeMinWidth
(double height, double topInset, double rightInset, double bottomInset, double leftInset) Computes the minimum allowable width of the Skin, based on the provided height.protected double
computePrefHeight
(double width, double topInset, double rightInset, double bottomInset, double leftInset) Calculates the preferred height of thisSkinBase
.protected double
computePrefWidth
(double height, double topInset, double rightInset, double bottomInset, double leftInset) Calculates the preferred width of thisSkinBase
.protected final void
consumeMouseEvents
(boolean value) Determines whether all mouse events should be automatically consumed.void
dispose()
Called by a Skinnable when the Skin is replaced on the Skinnable.final ObservableList<Node>
Returns the children of the skin.final Node
getNode()
Gets the Node which represents this Skin.final C
Gets the Skinnable to which this Skin is assigned.protected void
layoutChildren
(double contentX, double contentY, double contentWidth, double contentHeight) Called during the layout pass of the scenegraph.protected void
layoutInArea
(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.protected void
layoutInArea
(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, boolean fillWidth, boolean fillHeight, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.protected void
layoutInArea
(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.protected void
positionInArea
(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, HPos halignment, VPos valignment) Utility method which positions the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.protected void
positionInArea
(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, HPos halignment, VPos valignment) Utility method which positions the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.protected final void
registerChangeListener
(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) Subclasses can invoke this method to register that they want to listen to property change events for the given property.protected double
Utility method to get the bottom inset which includes padding and border inset.protected double
Utility method to get the left inset which includes padding and border inset.protected double
Utility method to get the right inset which includes padding and border inset.protected double
Utility method to get the top inset which includes padding and border inset.protected double
snapPosition
(double value) If this region's snapToPixel property is true, returns a value rounded to the nearest pixel, else returns the same value.protected double
snapSize
(double value) If this region's snapToPixel property is true, returns a value ceiled to the nearest pixel, else returns the same value.protected double
snapSizeX
(double value) Convenience method for accessing thesnapSizeX()
method on the skinnable.protected double
snapSizeY
(double value) Convenience method for accessing thesnapSizeY()
method on the skinnable.protected double
snapSpace
(double value) If this region's snapToPixel property is true, returns a value rounded to the nearest pixel, else returns the same value.protected double
snapSpaceX
(double value) Convenience method for accessing thesnapSpaceX()
method on the skinnable.protected double
snapSpaceY
(double value) Convenience method for accessing thesnapSpaceY()
method on the skinnable.protected final Consumer<ObservableValue<?>>
unregisterChangeListeners
(ObservableValue<?> property) Unregisters all change listeners that have been registered usingregisterChangeListener(ObservableValue, Consumer)
for the given property.
-
Constructor Details
-
SkinBase
Constructor for all SkinBase instances.- Parameters:
control
- The control for which this Skin should attach to.
-
-
Method Details
-
getSkinnable
Gets the Skinnable to which this Skin is assigned. A Skin must be created for one and only one Skinnable. This value will only ever go from a non-null to null value when the Skin is removed from the Skinnable, and only as a consequence of a call toSkin.dispose()
.The caller who constructs a Skinnable must also construct a Skin and properly establish the relationship between the Control and its Skin.
- Specified by:
getSkinnable
in interfaceSkin<C extends Control>
- Returns:
- A non-null Skinnable, or null value if disposed.
-
getNode
Gets the Node which represents this Skin. This must never be null, except after a call toSkin.dispose()
, and must never change except when changing to null. -
dispose
public void dispose()Called by a Skinnable when the Skin is replaced on the Skinnable. This method allows a Skin to implement any logic necessary to clean up itself after the Skin is no longer needed. It may be used to release native resources. The methodsSkin.getSkinnable()
andSkin.getNode()
should return null following a call to dispose. Calling dispose twice has no effect. -
getChildren
Returns the children of the skin. -
layoutChildren
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) Called during the layout pass of the scenegraph. -
consumeMouseEvents
protected final void consumeMouseEvents(boolean value) Determines whether all mouse events should be automatically consumed. -
registerChangeListener
protected final void registerChangeListener(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) Subclasses can invoke this method to register that they want to listen to property change events for the given property. RegisteredConsumer
instances will be executed in the order in which they are registered.- Parameters:
property
- the propertyconsumer
- the consumer
-
unregisterChangeListeners
Unregisters all change listeners that have been registered usingregisterChangeListener(ObservableValue, Consumer)
for the given property. The end result is that the given property is no longer observed by any of the change listeners, but it may still have additional listeners registered on it through means outside ofregisterChangeListener(ObservableValue, Consumer)
.- Parameters:
property
- The property for which all listeners should be removed.- Returns:
- A single chained
Consumer
consisting of allconsumers
registered throughregisterChangeListener(ObservableValue, Consumer)
. If no consumers have been registered on this property, null will be returned. - Since:
- 9
-
computeMinWidth
protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) Computes the minimum allowable width of the Skin, based on the provided height.- Parameters:
height
- The height of the Skin, in case this value might dictate the minimum width.topInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- A double representing the minimum width of this Skin.
-
computeMinHeight
protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) Computes the minimum allowable height of the Skin, based on the provided width.- Parameters:
width
- The width of the Skin, in case this value might dictate the minimum height.topInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- A double representing the minimum height of this Skin.
-
computeMaxWidth
protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) Computes the maximum allowable width of the Skin, based on the provided height.- Parameters:
height
- The height of the Skin, in case this value might dictate the maximum width.topInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- A double representing the maximum width of this Skin.
-
computeMaxHeight
protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) Computes the maximum allowable height of the Skin, based on the provided width.- Parameters:
width
- The width of the Skin, in case this value might dictate the maximum height.topInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- A double representing the maximum height of this Skin.
-
computePrefWidth
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) Calculates the preferred width of thisSkinBase
. The default implementation calculates this width as the width of the area occupied by its managed children when they are positioned at their current positions at their preferred widths.- Parameters:
height
- the height that should be used if preferred width depends on ittopInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- the calculated preferred width
-
computePrefHeight
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) Calculates the preferred height of thisSkinBase
. The default implementation calculates this height as the height of the area occupied by its managed children when they are positioned at their current positions at their preferred heights.- Parameters:
width
- the width that should be used if preferred height depends on ittopInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- the calculated preferred height
-
computeBaselineOffset
protected double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset) Calculates the baseline offset based on the first managed child. If there is no such child, returnsINode.getBaselineOffset()
.- Parameters:
topInset
- the pixel snapped top insetrightInset
- the pixel snapped right insetbottomInset
- the pixel snapped bottom insetleftInset
- the pixel snapped left inset- Returns:
- baseline offset
-
snappedTopInset
protected double snappedTopInset()Utility method to get the top inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.- Returns:
- Rounded up insets top
-
snappedBottomInset
protected double snappedBottomInset()Utility method to get the bottom inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.- Returns:
- Rounded up insets bottom
-
snappedLeftInset
protected double snappedLeftInset()Utility method to get the left inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.- Returns:
- Rounded up insets left
-
snappedRightInset
protected double snappedRightInset()Utility method to get the right inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.- Returns:
- Rounded up insets right
-
snapSpace
protected double snapSpace(double value) If this region's snapToPixel property is true, returns a value rounded to the nearest pixel, else returns the same value.- Parameters:
value
- the space value to be snapped- Returns:
- value rounded to nearest pixel
-
snapSpaceX
protected double snapSpaceX(double value) Convenience method for accessing thesnapSpaceX()
method on the skinnable. It is equivalent to callinggetSkinnable().snapSpaceX(value)
.- Parameters:
value
- the space value to be snapped- Returns:
- value rounded to nearest pixel
- Since:
- 9
- See Also:
-
snapSpaceY
protected double snapSpaceY(double value) Convenience method for accessing thesnapSpaceY()
method on the skinnable. It is equivalent to callinggetSkinnable().snapSpaceY(value)
.- Parameters:
value
- the space value to be snapped- Returns:
- value rounded to nearest pixel
- Since:
- 9
- See Also:
-
snapSize
protected double snapSize(double value) If this region's snapToPixel property is true, returns a value ceiled to the nearest pixel, else returns the same value.- Parameters:
value
- the size value to be snapped- Returns:
- value ceiled to nearest pixel
-
snapSizeX
protected double snapSizeX(double value) Convenience method for accessing thesnapSizeX()
method on the skinnable. It is equivalent to callinggetSkinnable().snapSizeX(value)
.- Parameters:
value
- the size value to be snapped- Returns:
- value ceiled to nearest pixel
- Since:
- 9
- See Also:
-
snapSizeY
protected double snapSizeY(double value) Convenience method for accessing thesnapSizeY()
method on the skinnable. It is equivalent to callinggetSkinnable().snapSizeY(value)
.- Parameters:
value
- the size value to be snapped- Returns:
- value ceiled to nearest pixel
- Since:
- 9
- See Also:
-
snapPosition
protected double snapPosition(double value) If this region's snapToPixel property is true, returns a value rounded to the nearest pixel, else returns the same value.- Parameters:
value
- the position value to be snapped- Returns:
- value rounded to nearest pixel
-
positionInArea
protected void positionInArea(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, HPos halignment, VPos valignment) Utility method which positions the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.This function does not resize the node and uses the node's layout bounds width and height to determine how it should be positioned within the area.
If the vertical alignment is
VPos.BASELINE
then it will position the node so that its own baseline aligns with the passed inbaselineOffset
, otherwise the baseline parameter is ignored.If
snapToPixel
istrue
for this skin, then the x/y position values will be rounded to their nearest pixel boundaries.- Parameters:
child
- the child being positioned within this skinareaX
- the horizontal offset of the layout area relative to this skinareaY
- the vertical offset of the layout area relative to this skinareaWidth
- the width of the layout areaareaHeight
- the height of the layout areaareaBaselineOffset
- the baseline offset to be used if VPos is BASELINEhalignment
- the horizontal alignment for the child within the areavalignment
- the vertical alignment for the child within the area
-
positionInArea
protected void positionInArea(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, HPos halignment, VPos valignment) Utility method which positions the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.This function does not resize the node and uses the node's layout bounds width and height to determine how it should be positioned within the area.
If the vertical alignment is
VPos.BASELINE
then it will position the node so that its own baseline aligns with the passed inbaselineOffset
, otherwise the baseline parameter is ignored.If
snapToPixel
istrue
for this skin, then the x/y position values will be rounded to their nearest pixel boundaries.If
margin
is non-null, then that space will be allocated around the child within the layout area. margin may be null.- Parameters:
child
- the child being positioned within this skinareaX
- the horizontal offset of the layout area relative to this skinareaY
- the vertical offset of the layout area relative to this skinareaWidth
- the width of the layout areaareaHeight
- the height of the layout areaareaBaselineOffset
- the baseline offset to be used if VPos is BASELINEmargin
- the margin of space to be allocated around the childhalignment
- the horizontal alignment for the child within the areavalignment
- the vertical alignment for the child within the area- Since:
- JavaFX 8.0
-
layoutInArea
protected void layoutInArea(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.If the child is resizable, this method will resize it to fill the specified area unless the node's maximum size prevents it. If the node's maximum size preference is less than the area size, the maximum size will be used. If node's maximum is greater than the area size, then the node will be resized to fit within the area, unless its minimum size prevents it.
If the child has a non-null contentBias, then this method will use it when resizing the child. If the contentBias is horizontal, it will set its width first to the area's width (up to the child's max width limit) and then pass that value to compute the child's height. If child's contentBias is vertical, then it will set its height to the area height (up to child's max height limit) and pass that height to compute the child's width. If the child's contentBias is null, then it's width and height have no dependencies on each other.
If the child is not resizable (Shape, Group, etc) then it will only be positioned and not resized.
If the child's resulting size differs from the area's size (either because it was not resizable or it's sizing preferences prevented it), then this function will align the node relative to the area using horizontal and vertical alignment values. If valignment is
VPos.BASELINE
then the node's baseline will be aligned with the area baseline offset parameter, otherwise the baseline parameter is ignored.If
snapToPixel
istrue
for this skin, then the resulting x,y values will be rounded to their nearest pixel boundaries and the width/height values will be ceiled to the next pixel boundary.- Parameters:
child
- the child being positioned within this skinareaX
- the horizontal offset of the layout area relative to this skinareaY
- the vertical offset of the layout area relative to this skinareaWidth
- the width of the layout areaareaHeight
- the height of the layout areaareaBaselineOffset
- the baseline offset to be used if VPos is BASELINEhalignment
- the horizontal alignment for the child within the areavalignment
- the vertical alignment for the child within the area
-
layoutInArea
protected void layoutInArea(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.If the child is resizable, this method will resize it to fill the specified area unless the node's maximum size prevents it. If the node's maximum size preference is less than the area size, the maximum size will be used. If node's maximum is greater than the area size, then the node will be resized to fit within the area, unless its minimum size prevents it.
If the child has a non-null contentBias, then this method will use it when resizing the child. If the contentBias is horizontal, it will set its width first to the area's width (up to the child's max width limit) and then pass that value to compute the child's height. If child's contentBias is vertical, then it will set its height to the area height (up to child's max height limit) and pass that height to compute the child's width. If the child's contentBias is null, then it's width and height have no dependencies on each other.
If the child is not resizable (Shape, Group, etc) then it will only be positioned and not resized.
If the child's resulting size differs from the area's size (either because it was not resizable or it's sizing preferences prevented it), then this function will align the node relative to the area using horizontal and vertical alignment values. If valignment is
VPos.BASELINE
then the node's baseline will be aligned with the area baseline offset parameter, otherwise the baseline parameter is ignored.If
margin
is non-null, then that space will be allocated around the child within the layout area. margin may be null.If
snapToPixel
istrue
for this skin, then the resulting x,y values will be rounded to their nearest pixel boundaries and the width/height values will be ceiled to the next pixel boundary.- Parameters:
child
- the child being positioned within this skinareaX
- the horizontal offset of the layout area relative to this skinareaY
- the vertical offset of the layout area relative to this skinareaWidth
- the width of the layout areaareaHeight
- the height of the layout areaareaBaselineOffset
- the baseline offset to be used if VPos is BASELINEmargin
- the margin of space to be allocated around the childhalignment
- the horizontal alignment for the child within the areavalignment
- the vertical alignment for the child within the area
-
layoutInArea
protected void layoutInArea(Node child, double areaX, double areaY, double areaWidth, double areaHeight, double areaBaselineOffset, Insets margin, boolean fillWidth, boolean fillHeight, HPos halignment, VPos valignment) Utility method which lays out the child within an area of this skin defined byareaX
,areaY
,areaWidth
xareaHeight
, with a baseline offset relative to that area.If the child is resizable, this method will use
fillWidth
andfillHeight
to determine whether to resize it to fill the area or keep the child at its preferred dimension. If fillWidth/fillHeight are true, then this method will only resize the child up to its max size limits. If the node's maximum size preference is less than the area size, the maximum size will be used. If node's maximum is greater than the area size, then the node will be resized to fit within the area, unless its minimum size prevents it.If the child has a non-null contentBias, then this method will use it when resizing the child. If the contentBias is horizontal, it will set its width first and then pass that value to compute the child's height. If child's contentBias is vertical, then it will set its height first and pass that value to compute the child's width. If the child's contentBias is null, then it's width and height have no dependencies on each other.
If the child is not resizable (Shape, Group, etc) then it will only be positioned and not resized.
If the child's resulting size differs from the area's size (either because it was not resizable or it's sizing preferences prevented it), then this function will align the node relative to the area using horizontal and vertical alignment values. If valignment is
VPos.BASELINE
then the node's baseline will be aligned with the area baseline offset parameter, otherwise the baseline parameter is ignored.If
margin
is non-null, then that space will be allocated around the child within the layout area. margin may be null.If
snapToPixel
istrue
for this skin, then the resulting x,y values will be rounded to their nearest pixel boundaries and the width/height values will be ceiled to the next pixel boundary.- Parameters:
child
- the child being positioned within this skinareaX
- the horizontal offset of the layout area relative to this skinareaY
- the vertical offset of the layout area relative to this skinareaWidth
- the width of the layout areaareaHeight
- the height of the layout areaareaBaselineOffset
- the baseline offset to be used if VPos is BASELINEmargin
- the margin of space to be allocated around the childfillWidth
- whether or not the child should be resized to fill the area width or kept to its preferred widthfillHeight
- whether or not the child should e resized to fill the area height or kept to its preferred heighthalignment
- the horizontal alignment for the child within the areavalignment
- the vertical alignment for the child within the area
-