Package snap.view

Class TextField

All Implemented Interfaces:
PropChange.DoChange, XMLArchiver.Archivable

public class TextField extends ParentView
An view subclass for editing a single line of text.
  • Field Details

  • Constructor Details

    • TextField

      public TextField()
      Constructor.
  • Method Details

    • getTextFill

      public Paint getTextFill()
      Returns the text fill.
    • setTextFill

      public void setTextFill(Paint aPaint)
      Sets the text fill.
    • getColCount

      public int getColCount()
      Returns the column count.
    • setColCount

      public void setColCount(int aValue)
      Sets the column count.
    • getPromptText

      public String getPromptText()
      Returns the prompt text.
    • setPromptText

      public void setPromptText(String aStr)
      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

      public Label getLabel()
      Returns the label in the background.
    • getDefaultBorder

      public Border getDefaultBorder()
      Returns the default border.
      Overrides:
      getDefaultBorder in class View
    • getDefaultFill

      public Paint getDefaultFill()
      Override to return white.
      Overrides:
      getDefaultFill in class View
    • getTextWidth

      public double getTextWidth()
      Returns the text width.
    • getTextHeight

      public double getTextHeight()
      Returns the text height.
    • getTextBounds

      public Rect getTextBounds(boolean inBounds)
      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 class View
    • getPrefHeightImpl

      protected double getPrefHeightImpl(double aW)
      Calculates the preferred height.
      Overrides:
      getPrefHeightImpl in class View
    • layoutImpl

      protected void layoutImpl()
      Layout children.
      Overrides:
      layoutImpl in class ParentView
    • setFocused

      protected void setFocused(boolean aValue)
      Override to track FocusGainedValue.
      Overrides:
      setFocused in class View
    • textDidChange

      protected void textDidChange()
      Override to update Prompt label.
    • fireActionEvent

      protected void fireActionEvent(ViewEvent anEvent)
      Override to reset FocusedGainedVal.
      Overrides:
      fireActionEvent in class View
    • 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

      public String getText()
      Returns the plain string of the text being edited.
      Overrides:
      getText in class View
    • setText

      public void setText(String aString)
      Set text string of text editor.
      Overrides:
      setText in class View
    • 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

      public String getSelString()
      Returns the selection string.
    • getSelBounds

      public Rect getSelBounds()
      Returns the selection bounds.
    • selectAll

      public void selectAll()
      Selects all the characters in the text editor.
    • replaceChars

      public void replaceChars(String aString)
      Replaces the current selection with the given string.
    • replaceChars

      public void replaceChars(String aString, int aStart, int anEnd, boolean doUpdateSel)
      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

      public void setCompletionText(String aString)
      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

      protected void paintFront(Painter aPntr)
      Paints TextField.
      Overrides:
      paintFront in class View
    • paintSel

      protected void paintSel(Painter aPntr)
      Paints TextField Selection.
    • processEvent

      protected void processEvent(ViewEvent anEvent)
      Process event.
      Overrides:
      processEvent in class View
    • mousePressed

      protected void mousePressed(ViewEvent anEvent)
      Handles mouse pressed.
    • mouseDragged

      protected void mouseDragged(ViewEvent anEvent)
      Handles mouse dragged.
    • mouseReleased

      protected void mouseReleased(ViewEvent anEvent)
      Handles mouse released.
    • mouseMoved

      protected void mouseMoved(ViewEvent anEvent)
      Handle MouseMoved.
    • keyPressed

      protected void keyPressed(ViewEvent anEvent)
      Called when a key is pressed.
    • keyTyped

      protected void keyTyped(ViewEvent anEvent)
      Called when a key is typed.
    • keyReleased

      protected void keyReleased(ViewEvent anEvent)
      Called when a key is released.
    • processActionEvent

      protected void processActionEvent(ViewEvent anEvent)
      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

      public void escape(ViewEvent anEvent)
      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 class ParentView
    • getValuePropName

      public String getValuePropName()
      Returns a mapped property name.
      Overrides:
      getValuePropName in class View
    • initProps

      protected void initProps(PropSet aPropSet)
      Override to customize for this class.
      Overrides:
      initProps in class ParentView
    • toString

      public String toString()
      Standard toString implementation.
      Overrides:
      toString in class PropObject
    • toXMLView

      public XMLElement toXMLView(XMLArchiver anArchiver)
      XML archival.
      Overrides:
      toXMLView in class ParentView
    • fromXMLView

      public void fromXMLView(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Overrides:
      fromXMLView in class ParentView
    • setBackLabelAlignAnimatedOnFocused

      public static void setBackLabelAlignAnimatedOnFocused(TextField aTextField, boolean aValue)
      Sets the given TextField to animate background label alignment from center to left when focused.