Package snap.view
Class TextField
java.lang.Object
snap.props.PropObject
snap.view.View
snap.view.ParentView
snap.view.TextField
- All Implemented Interfaces:
PropChange.DoChange
,XMLArchiver.Archivable
An view subclass for editing a single line of text.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class snap.view.ParentView
_children, Child_Prop, NeedsLayout_Prop
Fields inherited from class snap.view.View
_align, _borderRadius, _effect, _font, _margin, _padding, _repaintRect, _showing, _spacing, _vertical, Action, Align_Prop, Border_Prop, BorderRadius_Prop, Clip_Prop, Cursor_Prop, DEFAULT_ALIGN, DEFAULT_MARGIN, DEFAULT_PADDING, DEFAULT_SPACING, Disabled_Prop, DragEvents, Effect_Prop, Fill_Prop, Focusable_Prop, Focused_Prop, FocusWhenPressed_Prop, Font_Prop, GrowHeight_Prop, GrowWidth_Prop, Height_Prop, KeyEvents, KeyPress, KeyRelease, KeyType, LeanX_Prop, LeanY_Prop, Managed_Prop, Margin_Prop, MaxHeight_Prop, MaxWidth_Prop, MinHeight_Prop, MinWidth_Prop, MouseDrag, MouseEnter, MouseEvents, MouseExit, MouseMove, MousePress, MouseRelease, Name_Prop, Opacity_Prop, Padding_Prop, Paintable_Prop, Parent_Prop, Pickable_Prop, PrefHeight_Prop, PrefWidth_Prop, Rotate_Prop, ScaleX_Prop, ScaleY_Prop, Scroll, Showing_Prop, Spacing_Prop, Text_Prop, ToolTip_Prop, TransX_Prop, TransY_Prop, Vertical_Prop, Visible_Prop, Width_Prop, X_Prop, Y_Prop
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int anIndex) Returns the individual character at given index.void
clear()
Clears the text.void
copy()
Copies the current selection onto the clipboard.void
cut()
Copies the current selection onto the clip board, then deletes the current selection.void
delete()
Deletes the current selection.void
delete
(int aStart, int anEnd, boolean doUpdateSel) Deletes the given range of chars.void
Deletes the character before of the insertion point.void
Deletes the character after of the insertion point.void
Deletes the characters from the insertion point to the end of the line.void
Called when escape key is pressed to cancels editing in TextField.protected void
fireActionEvent
(ViewEvent anEvent) Override to reset FocusedGainedVal.void
fromXMLView
(XMLArchiver anArchiver, XMLElement anElement) XML unarchival.int
getCharIndexAt
(double anX) Returns the char index for given point in text coordinate space.int
Returns the column count.Returns the default border.Override to return white.getLabel()
Returns the label in the background.protected double
getPrefHeightImpl
(double aW) Calculates the preferred height.protected double
getPrefWidthImpl
(double aH) Calculates the preferred width.Returns the prompt text.Returns the selection bounds.int
Returns the character index of the end of the text selection.int
Returns the character index of the start of the text selection.Returns the selection string.getText()
Returns the plain string of the text being edited.getTextBounds
(boolean inBounds) Returns the text bounds.Returns the text fill.double
Returns the text height.double
Returns the text width.Returns a mapped property name.double
getXForChar
(int anIndex) Returns the char index for given point in text coordinate space.void
Hides the cursor.protected void
Override to customize for this class.boolean
isEdited()
Returns whether text has been edited since last focus (while focused).boolean
Returns whether text view fires action on focus lost (if text changed).boolean
Returns whether the selection is empty.protected void
keyPressed
(ViewEvent anEvent) Called when a key is pressed.protected void
keyReleased
(ViewEvent anEvent) Called when a key is released.protected void
Called when a key is typed.protected void
Layout children.int
length()
Returns the number of characters in the text string.protected void
mouseDragged
(ViewEvent anEvent) Handles mouse dragged.protected void
mouseMoved
(ViewEvent anEvent) Handle MouseMoved.protected void
mousePressed
(ViewEvent anEvent) Handles mouse pressed.protected void
mouseReleased
(ViewEvent anEvent) Handles mouse released.protected void
paintFront
(Painter aPntr) Paints TextField.protected void
Paints TextField Selection.void
paste()
Pasts the current clipboard data over the current selection.protected void
processActionEvent
(ViewEvent anEvent) Called when action event is received.protected void
processEvent
(ViewEvent anEvent) Process event.void
replaceChars
(String aString) Replaces the current selection with the given string.void
replaceChars
(String aString, int aStart, int anEnd, boolean doUpdateSel) Replaces the current selection with the given string.void
Selects all the characters in the text editor.void
selectBackward
(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range).void
selectForward
(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range).void
Moves the insertion point to next newline or text end.void
Moves the insertion point to the beginning of line.static void
setBackLabelAlignAnimatedOnFocused
(TextField aTextField, boolean aValue) Sets the given TextField to animate background label alignment from center to left when focused.void
setColCount
(int aValue) Sets the column count.void
setCompletionText
(String aString) Sets text that represents a completion of current text.protected void
setEdited
(boolean aValue) Sets whether text has been edited since last focus (while focused).void
setFireActionOnFocusLost
(boolean aValue) Sets whether text area sends action on focus lost (if text changed).protected void
setFocused
(boolean aValue) Override to track FocusGainedValue.void
setPromptText
(String aStr) Sets the prompt text.void
setSel
(int newStartEnd) Sets the character index of the text cursor.void
setSel
(int aStart, int anEnd) Sets the character index of the start and end of the text selection.void
setSelEnd
(int aValue) Sets the selection end.void
setSelStart
(int aValue) Sets the selection start.protected void
setShowing
(boolean aValue) Override to check caret animation and scrollSelToVisible when showing.void
Set text string of text editor.void
setTextFill
(Paint aPaint) Sets the text fill.void
Shows the cursor.protected void
Override to update Prompt label.toString()
Standard toString implementation.toXMLView
(XMLArchiver anArchiver) XML archival.Methods inherited from class snap.view.ParentView
addChild, addChild, addDeepChangeListener, childDidDeepChange, childDidPropChange, fromXML, fromXMLChildren, getChild, getChildAt, getChildAt, getChildCount, getChildCountManaged, getChildForClass, getChildForName, getChildLast, getChildren, getChildrenForClass, getChildrenInPaintOrder, getChildrenManaged, getFocusNext, getFocusPrev, getPropValue, getViewList, getViewProxy, indexOfChild, intersectsShape, isInLayout, isNeedsLayout, isNeedsLayoutDeep, isNeedsRepaintDeep, layout, layoutDeep, layoutDeepImpl, layoutFloatingViews, paintAbove, paintAll, paintChildren, parentFontChanged, processPropChange, relayout, removeChild, removeChild, removeChildren, removeDeepChangeListener, setChildren, setFont, setNeedsLayout, setNeedsLayoutDeep, setNeedsRepaintDeep, setOwner, setOwnerChildren, setPropValue, themeChanged, toXML, toXMLChildren
Methods inherited from class snap.view.View
addBinding, addEventFilter, addEventHandler, clone, contains, contains, containsShape, createActionEvent, disableEvents, enableEvents, getAlign, getAlignX, getAlignY, getAnim, getAnimCleared, getAnimTimeDeep, getBestHeight, getBestSize, getBestWidth, getBinding, getBinding, getBindingCount, getBindings, getBorder, getBorderRadius, getBounds, getBoundsLocal, getBoundsParent, getBoundsShape, getBoundsShapeParent, getClip, getClipAll, getClipAllBounds, getClipBounds, getClippedRect, getCursor, getDefaultFont, getEffect, getEnv, getEventAdapter, getFill, getFillColor, getFocusNext, getFocusPrev, getFont, getHeight, getHost, getInsetsAll, getLean, getLeanX, getLeanY, getLocalToParent, getLocalToParent, getMargin, getMaxHeight, getMaxSize, getMaxWidth, getMaxX, getMaxY, getMidX, getMidY, getMinHeight, getMinHeightImpl, getMinSize, getMinWidth, getMinWidthImpl, getName, getOpacity, getOpacityAll, getOwner, getOwner, getPadding, getParent, getParent, getParentCount, getParentToLocal, getParentToLocal, getPhysics, getPhysics, getPrefHeight, getPrefHeight, getPrefSize, getPrefWidth, getPrefWidth, getProp, getPropDefault, getProps, getRealClassName, getRepaintRect, getRepaintRectExpanded, getRootView, getRotate, getScale, getScaleX, getScaleY, getSize, getSpacing, getToolTip, getToolTip, getTransX, getTransY, getUpdater, getVisRect, getWidth, getWindow, getX, getXY, getY, indexInHost, indexInParent, isActionable, isAncestor, isClipToBounds, isDisabled, isEnabled, isFocusable, isFocused, isFocusKeysEnabled, isFocusPainted, isFocusWhenPressed, isFontSet, isGrowHeight, isGrowWidth, isGuest, isHorizontal, isLocalToParentSimple, isManaged, isManagedVisible, isMaxHeightSet, isMaxWidthSet, isMinHeightSet, isMinWidthSet, isMouseDown, isMouseOver, isNeedsRepaint, isPaintable, isPickable, isPickableVisible, isPrefHeightSet, isPrefWidthSet, isShowing, isToolTipEnabled, isVertical, isVisible, localToParent, localToParent, localToParent, localToParent, localToScreen, paintBack, parentToLocal, parentToLocal, parentToLocal, parentToLocal, playAnimDeep, processEventAll, processEventFilters, processEventHandlers, relayoutParent, removeBinding, removeBinding, removeEventFilter, removeEventHandler, repaint, repaint, repaint, repaintInParent, requestFocus, runDelayed, runIntervals, runLater, scrollToVisible, setActionable, setAlign, setAlignX, setAlignY, setAnimProps, setAnimString, setAnimTimeDeep, setBorder, setBorder, setBorderRadius, setBounds, setBounds, setBoundsLocal, setClip, setClipToBounds, setCursor, setDisabled, setEffect, setEnabled, setFill, setFocusable, setFocusKeysEnabled, setFocusPainted, setFocusWhenPressed, setGrowHeight, setGrowWidth, setHeight, setLean, setLeanX, setLeanY, setManaged, setMargin, setMargin, setMaxHeight, setMaxSize, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinSize, setMinWidth, setName, setOpacity, setPadding, setPadding, setPaintable, setParent, setPickable, setPrefHeight, setPrefSize, setPrefSize, setPrefWidth, setProp, setRealClassName, setRotate, setScale, setScaleX, setScaleY, setSize, setSize, setSizeLocal, setSizeToBestSize, setSizeToPrefSize, setSpacing, setToolTip, setToolTipEnabled, setTransX, setTransY, setVertical, setVisible, setWidth, setX, setXY, setXYLocal, setY, stopAnimDeep, stopIntervals, toStringProps
Methods inherited from class snap.props.PropObject
addPropChangeListener, addPropChangeListener, firePropChange, firePropChange, firePropChange, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, isPropDefault, removePropChangeListener, removePropChangeListener, setPropsString, setPropValues
-
Field Details
-
_focusGainedText
-
ColCount_Prop
- See Also:
-
Edited_Prop
- See Also:
-
PromptText_Prop
- See Also:
-
Sel_Prop
- See Also:
-
TextFill_Prop
- See Also:
-
FireActionOnFocusLost_Prop
- See Also:
-
-
Constructor Details
-
TextField
public TextField()Constructor.
-
-
Method Details
-
getTextFill
Returns the text fill. -
setTextFill
Sets the text fill. -
getColCount
public int getColCount()Returns the column count. -
setColCount
public void setColCount(int aValue) Sets the column count. -
getPromptText
Returns the prompt text. -
setPromptText
Sets the prompt text. -
isFireActionOnFocusLost
public boolean isFireActionOnFocusLost()Returns whether text view fires action on focus lost (if text changed). -
setFireActionOnFocusLost
public void setFireActionOnFocusLost(boolean aValue) Sets whether text area sends action on focus lost (if text changed). -
getLabel
Returns the label in the background. -
getDefaultBorder
Returns the default border.- Overrides:
getDefaultBorder
in classView
-
getDefaultFill
Override to return white.- Overrides:
getDefaultFill
in classView
-
getTextWidth
public double getTextWidth()Returns the text width. -
getTextHeight
public double getTextHeight()Returns the text height. -
getTextBounds
Returns the text bounds. -
getCharIndexAt
public int getCharIndexAt(double anX) Returns the char index for given point in text coordinate space. -
getXForChar
public double getXForChar(int anIndex) Returns the char index for given point in text coordinate space. -
getPrefWidthImpl
protected double getPrefWidthImpl(double aH) Calculates the preferred width.- Overrides:
getPrefWidthImpl
in classView
-
getPrefHeightImpl
protected double getPrefHeightImpl(double aW) Calculates the preferred height.- Overrides:
getPrefHeightImpl
in classView
-
layoutImpl
protected void layoutImpl()Layout children.- Overrides:
layoutImpl
in classParentView
-
setFocused
protected void setFocused(boolean aValue) Override to track FocusGainedValue.- Overrides:
setFocused
in classView
-
textDidChange
protected void textDidChange()Override to update Prompt label. -
fireActionEvent
Override to reset FocusedGainedVal.- Overrides:
fireActionEvent
in classView
-
isEdited
public boolean isEdited()Returns whether text has been edited since last focus (while focused). -
setEdited
protected void setEdited(boolean aValue) Sets whether text has been edited since last focus (while focused). -
length
public int length()Returns the number of characters in the text string. -
charAt
public char charAt(int anIndex) Returns the individual character at given index. -
getText
Returns the plain string of the text being edited. -
setText
Set text string of text editor. -
getSelStart
public int getSelStart()Returns the character index of the start of the text selection. -
setSelStart
public void setSelStart(int aValue) Sets the selection start. -
getSelEnd
public int getSelEnd()Returns the character index of the end of the text selection. -
setSelEnd
public void setSelEnd(int aValue) Sets the selection end. -
isSelEmpty
public boolean isSelEmpty()Returns whether the selection is empty. -
setSel
public void setSel(int newStartEnd) Sets the character index of the text cursor. -
setSel
public void setSel(int aStart, int anEnd) Sets the character index of the start and end of the text selection. -
getSelString
Returns the selection string. -
getSelBounds
Returns the selection bounds. -
selectAll
public void selectAll()Selects all the characters in the text editor. -
replaceChars
Replaces the current selection with the given string. -
replaceChars
Replaces the current selection with the given string. -
delete
public void delete()Deletes the current selection. -
delete
public void delete(int aStart, int anEnd, boolean doUpdateSel) Deletes the given range of chars. -
selectForward
public void selectForward(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range). -
selectBackward
public void selectBackward(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range). -
selectLineStart
public void selectLineStart()Moves the insertion point to the beginning of line. -
selectLineEnd
public void selectLineEnd()Moves the insertion point to next newline or text end. -
deleteBackward
public void deleteBackward()Deletes the character before of the insertion point. -
deleteForward
public void deleteForward()Deletes the character after of the insertion point. -
deleteToLineEnd
public void deleteToLineEnd()Deletes the characters from the insertion point to the end of the line. -
clear
public void clear()Clears the text. -
setCompletionText
Sets text that represents a completion of current text. This preserves the capitalization of chars in the current text and sets the selection to the remainder. If next key press is delete, removes the added remainder. -
paintFront
Paints TextField.- Overrides:
paintFront
in classView
-
paintSel
Paints TextField Selection. -
processEvent
Process event.- Overrides:
processEvent
in classView
-
mousePressed
Handles mouse pressed. -
mouseDragged
Handles mouse dragged. -
mouseReleased
Handles mouse released. -
mouseMoved
Handle MouseMoved. -
keyPressed
Called when a key is pressed. -
keyTyped
Called when a key is typed. -
keyReleased
Called when a key is released. -
processActionEvent
Called when action event is received. -
showCursor
public void showCursor()Shows the cursor. -
hideCursor
public void hideCursor()Hides the cursor. -
cut
public void cut()Copies the current selection onto the clip board, then deletes the current selection. -
copy
public void copy()Copies the current selection onto the clipboard. -
paste
public void paste()Pasts the current clipboard data over the current selection. -
escape
Called when escape key is pressed to cancels editing in TextField. First cancel resets focus gained value. Second hands focus to previous view. -
setShowing
protected void setShowing(boolean aValue) Override to check caret animation and scrollSelToVisible when showing.- Overrides:
setShowing
in classParentView
-
getValuePropName
Returns a mapped property name.- Overrides:
getValuePropName
in classView
-
initProps
Override to customize for this class.- Overrides:
initProps
in classParentView
-
toString
Standard toString implementation.- Overrides:
toString
in classPropObject
-
toXMLView
XML archival.- Overrides:
toXMLView
in classParentView
-
fromXMLView
XML unarchival.- Overrides:
fromXMLView
in classParentView
-
setBackLabelAlignAnimatedOnFocused
Sets the given TextField to animate background label alignment from center to left when focused.
-