Package snap.view

Class TextField

All Implemented Interfaces:
PropChange.DoChange, XMLArchiver.Archivable

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

  • Constructor Details

    • TextField

      public TextField()
      Constructor.
  • Method Details

    • initStyleProps

      protected void initStyleProps()
      Override to support TextColor.
      Overrides:
      initStyleProps in class View
    • getTextColor

      public Color getTextColor()
      Returns the text color.
      Overrides:
      getTextColor in class View
    • setTextColor

      public void setTextColor(Color aPaint)
      Sets the text color.
      Overrides:
      setTextColor in class View
    • 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).
    • isMultiline

      public boolean isMultiline()
      Returns whether text field accepts multiple lines of text.
    • setMultiline

      public void setMultiline(boolean aValue)
      Sets whether text field accepts multiple lines of text.
    • getLabel

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

      protected void setFocused(boolean aValue)
      Override to track FocusGainedValue.
      Overrides:
      setFocused in class View
    • 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.
    • 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.
    • getSelEnd

      public int getSelEnd()
      Returns the character index of the end of the text selection.
    • 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.
    • 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.
    • 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
    • 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
    • processEvent

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

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

      protected void processActionEvent(ViewEvent anEvent)
      Called when action event is received.
    • 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.
    • setFont

      public void setFont(Font aFont)
      Override to update font.
      Overrides:
      setFont in class ParentView
    • parentFontChanged

      protected void parentFontChanged()
      Override to update font.
      Overrides:
      parentFontChanged 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
    • getPropValue

      public Object getPropValue(String aPropName)
      Returns the value for given prop name.
      Overrides:
      getPropValue in class ParentView
    • setPropValue

      public void setPropValue(String aPropName, Object aValue)
      Sets the value for given prop name.
      Overrides:
      setPropValue 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.