Class SimpleTextField

  • All Implemented Interfaces:
    Field

    public class SimpleTextField
    extends java.lang.Object
    implements Field
    The simplest possible Text field. It does not clip and should only be used when the text values always fit in field.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleTextField​(java.lang.String text, java.awt.FontMetrics fontMetrics, int startX, int width, boolean allowCursorAtEnd, HighlightFactory hlFactory)
      Constructs a new SimpleTextField.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(int x, int y)
      Returns true if the given point is in this field
      protected int findColumn​(java.lang.String textString, int x)
      Finds the column position for the given pixel x coordinate in the indicated text string.
      int getCol​(int row, int x)
      Returns the cursor column position for the given x coordinate on the given row
      java.awt.Rectangle getCursorBounds​(int row, int col)
      Returns a bounding rectangle for the cursor at the given position
      java.awt.FontMetrics getFontMetrics()
      Get the font metrics for this field.
      java.awt.Color getForeground()
      Get the foreground color.
      int getHeight()
      Returns the height of this field when populated with the given data
      int getHeightAbove()
      Returns the height above the baseLine
      int getHeightBelow()
      Returns the height below the baseLine
      int getNumCols​(int row)
      Returns the number of columns in the given row
      int getNumDataRows()
      Returns the number of data model rows represented by this field.
      int getNumRows()
      Returns the number of rows in this field
      int getPreferredWidth()
      The minimum required width to paint the contents of this field
      int getRow​(int y)
      Returns the row containing the given y coordinate
      int getScrollableUnitIncrement​(int topOfScreen, int direction, int max)
      Returns the amount to scroll to the next or previous line
      int getStartX()
      Returns the horizontal position of this field
      java.lang.String getText()
      Returns a string containing all the text in the field
      java.lang.String getTextWithLineSeparators()
      Returns a string containing all the text in the field with extra newlines
      int getWidth()
      Returns the current width of this field
      int getX​(int row, int col)
      Returns the x coordinate for the given cursor position
      int getY​(int row)
      Returns the y coordinate for the given row
      boolean isAllowCursorAtEnd()
      Returns true if the cursor is allow to be position past the last character.
      boolean isPrimary()
      Returns true if this field is "primary" (the most important) field; used to determine the "primary" line in the layout
      boolean isValid​(int row, int col)
      Returns true if the given row and column represent a valid location for this field with the given data
      void paint​(javax.swing.JComponent c, java.awt.Graphics g, PaintContext context, java.awt.Rectangle clip, FieldBackgroundColorManager colorManager, RowColLocation cursorLoc, int rowHeight)
      Paints this field
      protected void paintHighlights​(java.awt.Graphics g, Highlight[] highlights)  
      protected void paintSelection​(java.awt.Graphics g, FieldBackgroundColorManager colorManager, int row)  
      void rowHeightChanged​(int newHeightAbove, int newHeightBelow)
      notifies field that the rowHeight changed
      int screenLocationToTextOffset​(int row, int col)
      Returns the text offset in the overall field text string for the given row and column
      void setFontMetrics​(java.awt.FontMetrics metrics)
      Sets the font metrics
      void setForeground​(java.awt.Color color)
      Set the foreground color for this field.
      void setPrimary​(boolean state)
      Sets this primary state of this field.
      RowColLocation textOffsetToScreenLocation​(int textOffset)
      Returns the row, column position for an offset into the string returned by getText()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • text

        protected java.lang.String text
      • metrics

        protected java.awt.FontMetrics metrics
      • startX

        protected int startX
      • foregroundColor

        protected java.awt.Color foregroundColor
      • width

        protected int width
      • preferredWidth

        protected int preferredWidth
      • heightAbove

        protected int heightAbove
      • heightBelow

        protected int heightBelow
      • numCols

        protected int numCols
      • allowCursorAtEnd

        protected boolean allowCursorAtEnd
      • isPrimary

        protected boolean isPrimary
    • Constructor Detail

      • SimpleTextField

        public SimpleTextField​(java.lang.String text,
                               java.awt.FontMetrics fontMetrics,
                               int startX,
                               int width,
                               boolean allowCursorAtEnd,
                               HighlightFactory hlFactory)
        Constructs a new SimpleTextField.
        Parameters:
        text - The text for the field.
        fontMetrics - the fontMetrics used to render the text.
        startX - the starting x coordinate.
        width - the width of the field.
        allowCursorAtEnd - if true, allows the cursor to go one position past the end of the text.
    • Method Detail

      • isAllowCursorAtEnd

        public boolean isAllowCursorAtEnd()
        Returns true if the cursor is allow to be position past the last character.
      • getWidth

        public int getWidth()
        Description copied from interface: Field
        Returns the current width of this field
        Specified by:
        getWidth in interface Field
        Returns:
        the current width of this field
        See Also:
        Field.getWidth()
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from interface: Field
        The minimum required width to paint the contents of this field
        Specified by:
        getPreferredWidth in interface Field
        Returns:
        the minimum required width to paint the contents of this field
      • getHeight

        public int getHeight()
        Description copied from interface: Field
        Returns the height of this field when populated with the given data
        Specified by:
        getHeight in interface Field
        Returns:
        the height
        See Also:
        Field.getHeight()
      • getStartX

        public int getStartX()
        Description copied from interface: Field
        Returns the horizontal position of this field
        Specified by:
        getStartX in interface Field
        Returns:
        the position
        See Also:
        Field.getStartX()
      • getNumDataRows

        public int getNumDataRows()
        Description copied from interface: Field
        Returns the number of data model rows represented by this field. Some fields may change the row count by wrapping or truncating. The value returned here will be the original data row count before any transformations were applied.
        Specified by:
        getNumDataRows in interface Field
        Returns:
        the number of data rows
      • getNumRows

        public int getNumRows()
        Description copied from interface: Field
        Returns the number of rows in this field
        Specified by:
        getNumRows in interface Field
        Returns:
        the number of rows in this field
        See Also:
        Field.getNumRows()
      • getNumCols

        public int getNumCols​(int row)
        Description copied from interface: Field
        Returns the number of columns in the given row
        Specified by:
        getNumCols in interface Field
        Parameters:
        row - the row from which to get the number of columns; this is the screen row
        Returns:
        the number of columns
        See Also:
        Field.getNumCols(int)
      • getRow

        public int getRow​(int y)
        Description copied from interface: Field
        Returns the row containing the given y coordinate
        Specified by:
        getRow in interface Field
        Parameters:
        y - vertical pixel coordinate relative to the top of the screen
        Returns:
        the row
        See Also:
        Field.getRow(int)
      • getCol

        public int getCol​(int row,
                          int x)
        Description copied from interface: Field
        Returns the cursor column position for the given x coordinate on the given row
        Specified by:
        getCol in interface Field
        Parameters:
        row - the text row to find the column on
        x - the horizontal pixel coordinate for which to find the character position
        Returns:
        the column
        See Also:
        Field.getCol(int, int)
      • getY

        public int getY​(int row)
        Description copied from interface: Field
        Returns the y coordinate for the given row
        Specified by:
        getY in interface Field
        Parameters:
        row - the text row of interest
        Returns:
        the y value
        See Also:
        Field.getY(int)
      • getX

        public int getX​(int row,
                        int col)
        Description copied from interface: Field
        Returns the x coordinate for the given cursor position
        Specified by:
        getX in interface Field
        Parameters:
        row - the text row of interest
        col - the character column
        Returns:
        the x value
        See Also:
        Field.getX(int, int)
      • isValid

        public boolean isValid​(int row,
                               int col)
        Description copied from interface: Field
        Returns true if the given row and column represent a valid location for this field with the given data
        Specified by:
        isValid in interface Field
        Parameters:
        row - the text row
        col - the character position
        Returns:
        tru if valid
        See Also:
        Field.isValid(int, int)
      • paint

        public void paint​(javax.swing.JComponent c,
                          java.awt.Graphics g,
                          PaintContext context,
                          java.awt.Rectangle clip,
                          FieldBackgroundColorManager colorManager,
                          RowColLocation cursorLoc,
                          int rowHeight)
        Description copied from interface: Field
        Paints this field
        Specified by:
        paint in interface Field
        Parameters:
        c - the component to paint onto
        g - the graphics context
        context - common paint parameters
        clip - the clipping region to paint into
        colorManager - contains background color information for the field
        cursorLoc - the row,column cursor location within the field or null if the field does not contain the cursor
        rowHeight - the number of pixels in each row of text in the field
      • paintHighlights

        protected void paintHighlights​(java.awt.Graphics g,
                                       Highlight[] highlights)
      • getCursorBounds

        public java.awt.Rectangle getCursorBounds​(int row,
                                                  int col)
        Description copied from interface: Field
        Returns a bounding rectangle for the cursor at the given position
        Specified by:
        getCursorBounds in interface Field
        Parameters:
        row - the text row
        col - the character position
        Returns:
        the rectangle
      • findColumn

        protected int findColumn​(java.lang.String textString,
                                 int x)
        Finds the column position for the given pixel x coordinate in the indicated text string.
      • contains

        public boolean contains​(int x,
                                int y)
        Description copied from interface: Field
        Returns true if the given point is in this field
        Specified by:
        contains in interface Field
        Parameters:
        x - the horizontal coordinate of the point
        y - the relative y position in this layout
        Returns:
        true if the given point is in this field
        See Also:
        Field.contains(int, int)
      • setForeground

        public void setForeground​(java.awt.Color color)
        Set the foreground color for this field.
        Parameters:
        color - the new foreground color.
      • getForeground

        public java.awt.Color getForeground()
        Get the foreground color.
        Returns:
        Color could return null if the setForeground() method was not called, and if this method is called before the paint() method was called.
      • getScrollableUnitIncrement

        public int getScrollableUnitIncrement​(int topOfScreen,
                                              int direction,
                                              int max)
        Description copied from interface: Field
        Returns the amount to scroll to the next or previous line
        Specified by:
        getScrollableUnitIncrement in interface Field
        Parameters:
        topOfScreen - the current y position of the top of the screen
        direction - the direction of the scroll (1 down, -1 up)
        max - the maximum amount to scroll for the entire row - will be positive for down, and negative for up)
        Returns:
        the scroll amount
        See Also:
        Field.getScrollableUnitIncrement(int, int, int)
      • setFontMetrics

        public void setFontMetrics​(java.awt.FontMetrics metrics)
        Sets the font metrics
        Parameters:
        metrics - the fontmetrics to use.
      • getFontMetrics

        public java.awt.FontMetrics getFontMetrics()
        Get the font metrics for this field.
      • isPrimary

        public boolean isPrimary()
        Description copied from interface: Field
        Returns true if this field is "primary" (the most important) field; used to determine the "primary" line in the layout
        Specified by:
        isPrimary in interface Field
        Returns:
        true if this field is "primary"
      • setPrimary

        public void setPrimary​(boolean state)
        Sets this primary state of this field.
        Parameters:
        state - if true, then makes this field primary.
      • getHeightAbove

        public int getHeightAbove()
        Description copied from interface: Field
        Returns the height above the baseLine
        Specified by:
        getHeightAbove in interface Field
        Returns:
        the height above
      • getHeightBelow

        public int getHeightBelow()
        Description copied from interface: Field
        Returns the height below the baseLine
        Specified by:
        getHeightBelow in interface Field
        Returns:
        the height below
      • rowHeightChanged

        public void rowHeightChanged​(int newHeightAbove,
                                     int newHeightBelow)
        Description copied from interface: Field
        notifies field that the rowHeight changed
        Specified by:
        rowHeightChanged in interface Field
        Parameters:
        newHeightAbove - the height above the baseline
        newHeightBelow - the height below the baseline
      • getText

        public java.lang.String getText()
        Description copied from interface: Field
        Returns a string containing all the text in the field
        Specified by:
        getText in interface Field
        Returns:
        the string
      • getTextWithLineSeparators

        public java.lang.String getTextWithLineSeparators()
        Description copied from interface: Field
        Returns a string containing all the text in the field with extra newlines
        Specified by:
        getTextWithLineSeparators in interface Field
        Returns:
        a string containing all the text in the field with extra newlines
      • textOffsetToScreenLocation

        public RowColLocation textOffsetToScreenLocation​(int textOffset)
        Description copied from interface: Field
        Returns the row, column position for an offset into the string returned by getText()
        Specified by:
        textOffsetToScreenLocation in interface Field
        Parameters:
        textOffset - the offset into the entire text string for this field
        Returns:
        a RowColLocation that contains the row,column location in the field for a position in the overall field text
      • screenLocationToTextOffset

        public int screenLocationToTextOffset​(int row,
                                              int col)
        Description copied from interface: Field
        Returns the text offset in the overall field text string for the given row and column
        Specified by:
        screenLocationToTextOffset in interface Field
        Parameters:
        row - the row
        col - the column
        Returns:
        the offset