- java.lang.Object
-
- javafx.scene.control.SkinBase<T>
-
- javafx.scene.control.skin.TextInputControlSkin<TextField>
-
- javafx.scene.control.skin.TextFieldSkin
-
- All Implemented Interfaces:
Skin<T>
public class TextFieldSkin extends TextInputControlSkin<TextField>
Default skin implementation for theTextField
control.- Since:
- 9
- See Also:
TextField
-
-
Property Summary
-
Properties inherited from class javafx.scene.control.skin.TextInputControlSkin
forwardBias, highlightFill, highlightTextFill, promptTextFill, textFill
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javafx.scene.control.skin.TextInputControlSkin
TextInputControlSkin.Direction, TextInputControlSkin.TextUnit
-
-
Constructor Summary
Constructors Constructor Description TextFieldSkin(TextField control)
Creates a new TextFieldSkin instance, installing the necessary child nodes into the Controlchildren
list, as well as the necessary input mappings for handling key, mouse, etc events.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addHighlight(List<? extends Node> nodes, int start)
Adds highlight for composed text from Input Method.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
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
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
.void
deleteChar(boolean previous)
Deletes the character that follows or precedes the current caret position from the text if there is no selection, or deletes the selection if there is one.void
dispose()
Called by a Skinnable when the Skin is replaced on the Skinnable.Rectangle2D
getCharacterBounds(int index)
Returns the bounds of the character at a given index.HitInfo
getIndex(double x, double y)
Performs a hit test, mapping point to index in the content.Point2D
getMenuPosition()
Returns the position to be used for a context menu, based on the location of the caret handle or selection handles.protected PathElement[]
getRangeShape(int start, int end)
protected PathElement[]
getUnderlineShape(int start, int end)
protected void
layoutChildren(double x, double y, double w, double h)
Called during the layout pass of the scenegraph.protected String
maskText(String txt)
This method may be overridden by subclasses to replace the displayed characters without affecting the actual text content.void
moveCaret(TextInputControlSkin.TextUnit unit, TextInputControlSkin.Direction dir, boolean select)
Moves the caret by one of the given text unit, in the given direction.void
positionCaret(HitInfo hit, boolean select)
Moves the caret to the specified position.protected Object
queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
This method is called by the assistive technology to request the value for an attribute.protected void
removeHighlight(List<? extends Node> nodes)
Removes highlight for composed text from Input Method.void
replaceText(int start, int end, String txt)
Replaces a range of characters with the given text.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from class javafx.scene.control.SkinBase
computeMaxWidth, computeMinWidth, consumeMouseEvents, getChildren, getNode, getSkinnable, layoutInArea, layoutInArea, layoutInArea, positionInArea, positionInArea, pseudoClassStateChanged, registerChangeListener, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, unregisterChangeListeners
-
Methods inherited from class javafx.scene.control.skin.TextInputControlSkin
executeAccessibleAction, forwardBiasProperty, getClassCssMetaData, getCssMetaData, getHighlightFill, getHighlightTextFill, getInsertionPoint, getPromptTextFill, getTextFill, handleInputMethodEvent, highlightFillProperty, highlightTextFillProperty, invalidateMetrics, isForwardBias, promptTextFillProperty, scrollCharacterToVisible, setCaretAnimating, setForwardBias, setHighlightFill, setHighlightTextFill, setPromptTextFill, setTextFill, textFillProperty, updateHighlightFill, updateHighlightTextFill, updateTextFill
-
-
-
-
Constructor Detail
-
TextFieldSkin
public TextFieldSkin(TextField control)
Creates a new TextFieldSkin instance, installing the necessary child nodes into the Controlchildren
list, as well as the necessary input mappings for handling key, mouse, etc events.- Parameters:
control
- The control that this skin should be installed onto.
-
-
Method Detail
-
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.
-
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.- Overrides:
computePrefWidth
in classSkinBase<TextField>
- 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
-
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.- Overrides:
computeMinHeight
in classSkinBase<TextField>
- 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.
-
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.- Overrides:
computePrefHeight
in classSkinBase<TextField>
- 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
-
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.- Overrides:
computeMaxHeight
in classSkinBase<TextField>
- 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.
-
computeBaselineOffset
public 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, returnsNode.getBaselineOffset()
.- Overrides:
computeBaselineOffset
in classSkinBase<TextField>
- 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
-
replaceText
public void replaceText(int start, int end, String txt)
Replaces a range of characters with the given text. Call this implementation from behavior classes instead of the one provided on TextInputControl to ensure that the text scrolls as needed.- Parameters:
start
- The starting index in the range, inclusive. This must be >= 0 and < the end.end
- The ending index in the range, exclusive. This is one-past the last character to delete (consistent with the String manipulation methods). This must be > the start, and <= the length of the text.txt
- The text that is to replace the range. This must not be null.- See Also:
TextInputControl.replaceText(int, int, String)
-
deleteChar
public void deleteChar(boolean previous)
Deletes the character that follows or precedes the current caret position from the text if there is no selection, or deletes the selection if there is one. Call this implementation from behavior classes instead of the one provided on TextInputControl to ensure that the text scrolls as needed.- Parameters:
previous
- whether to delete the preceding character.
-
getIndex
public HitInfo getIndex(double x, double y)
Performs a hit test, mapping point to index in the content.- Parameters:
x
- the x coordinate of the point.y
- the y coordinate of the point.- Returns:
- a
HitInfo
object describing the index and forward bias.
-
positionCaret
public void positionCaret(HitInfo hit, boolean select)
Moves the caret to the specified position.- Parameters:
hit
- the new position and forward bias of the caret.select
- whether to extend selection to the new position.
-
getCharacterBounds
public Rectangle2D getCharacterBounds(int index)
Returns the bounds of the character at a given index.- Overrides:
getCharacterBounds
in classTextInputControlSkin<TextField>
- Parameters:
index
- the index- Returns:
- the bounds of the character at a given index
-
getUnderlineShape
protected PathElement[] getUnderlineShape(int start, int end)
- Specified by:
getUnderlineShape
in classTextInputControlSkin<TextField>
- Parameters:
start
- the startend
- the end- Returns:
- the path elements describing the shape of the underline for the given range.
-
getRangeShape
protected PathElement[] getRangeShape(int start, int end)
- Specified by:
getRangeShape
in classTextInputControlSkin<TextField>
- Parameters:
start
- the startend
- the end- Returns:
- the path elements describing the bounding rectangles for the given range of text.
-
addHighlight
protected void addHighlight(List<? extends Node> nodes, int start)
Adds highlight for composed text from Input Method.- Specified by:
addHighlight
in classTextInputControlSkin<TextField>
- Parameters:
nodes
- the list of nodesstart
- the start
-
removeHighlight
protected void removeHighlight(List<? extends Node> nodes)
Removes highlight for composed text from Input Method.- Specified by:
removeHighlight
in classTextInputControlSkin<TextField>
- Parameters:
nodes
- the list of nodes
-
moveCaret
public void moveCaret(TextInputControlSkin.TextUnit unit, TextInputControlSkin.Direction dir, boolean select)
Moves the caret by one of the given text unit, in the given direction. Note that only certain combinations are valid, depending on the implementing subclass.- Specified by:
moveCaret
in classTextInputControlSkin<TextField>
- Parameters:
unit
- the unit of text to move by.dir
- the direction of movement.select
- whether to extends the selection to the new posititon.
-
layoutChildren
protected void layoutChildren(double x, double y, double w, double h)
Called during the layout pass of the scenegraph.- Overrides:
layoutChildren
in classSkinBase<TextField>
- Parameters:
x
- the x positiony
- the y positionw
- the widthh
- the height
-
getMenuPosition
public Point2D getMenuPosition()
Returns the position to be used for a context menu, based on the location of the caret handle or selection handles. This is supported only on touch displays and does not use the location of the mouse.- Overrides:
getMenuPosition
in classTextInputControlSkin<TextField>
- Returns:
- the position to be used for this context menu
-
maskText
protected String maskText(String txt)
This method may be overridden by subclasses to replace the displayed characters without affecting the actual text content. This is used to display bullet characters in PasswordField.- Overrides:
maskText
in classTextInputControlSkin<TextField>
- Parameters:
txt
- the content that may need to be masked.- Returns:
- the replacement string. This may just be the input string, or may be a string of replacement characters with the same length as the input string.
-
queryAccessibleAttribute
protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
This method is called by the assistive technology to request the value for an attribute.This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.- Overrides:
queryAccessibleAttribute
in classSkinBase<TextField>
- Parameters:
attribute
- the requested attributeparameters
- optional list of parameters- Returns:
- the value for the requested attribute
- See Also:
AccessibleAttribute
,Node.queryAccessibleAttribute(javafx.scene.AccessibleAttribute, java.lang.Object...)
-
-