Class AbstractTextFieldElement

  • All Implemented Interfaces:
    FieldElement
    Direct Known Subclasses:
    AnnotatedTextFieldElement, ClangFieldElement, TextFieldElement

    public abstract class AbstractTextFieldElement
    extends java.lang.Object
    implements FieldElement
    An object that wraps a string and provides data that describes how to render that string.

    This class was created as a place to house attributes of rendering that are not described by Java's Font object, like underlining.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected AttributedString attributedString
      the attributed string displayed by this field element
      protected int column
      the offset within the field's row where this element begins
      protected int row
      the row within the field where this element begins
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)
      Returns the character at the given index.
      int getCharacterIndexForDataLocation​(int dataRow, int dataColumn)
      Returns the character index appropriate for the given data location
      java.awt.Color getColor​(int charIndex)
      Returns the color for a given character within this element, since different colors may be applied to different characters.
      RowColLocation getDataLocationForCharacterIndex​(int characterIndex)
      Translates the given character index to a data location related to the data model, as determined by the FieldFactory.
      FieldElement getFieldElement​(int characterOffset)
      Returns the inner-most FieldElement inside this field element at the given location
      int getHeightAbove()
      Returns the amount of height above the baseline of this element.
      int getHeightBelow()
      Returns the amount of height below the baseline of this element.
      int getMaxCharactersForWidth​(int width)
      As the name implies, this method returns the maximum number of characters from this field element that will fit within the given width.
      int getStringWidth()
      Returns the string width of this element.
      java.lang.String getText()
      Returns the text contained by this field element.
      int length()
      Returns the length of the text within this element.
      void paint​(javax.swing.JComponent c, java.awt.Graphics g, int x, int y)
      Paints the text contained in this field element at the given x,y screen coordinate using the given Graphics object.
      FieldElement substring​(int start)
      Returns a new FieldElement containing just the characters beginning at the given index.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • attributedString

        protected AttributedString attributedString
        the attributed string displayed by this field element
      • row

        protected int row
        the row within the field where this element begins
      • column

        protected int column
        the offset within the field's row where this element begins
    • Constructor Detail

      • AbstractTextFieldElement

        protected AbstractTextFieldElement​(AttributedString attributedString,
                                           int row,
                                           int column)
    • Method Detail

      • getText

        public java.lang.String getText()
        Description copied from interface: FieldElement
        Returns the text contained by this field element.
        Specified by:
        getText in interface FieldElement
        Returns:
        the text contained by this field element.
        See Also:
        FieldElement.getText()
      • charAt

        public char charAt​(int index)
        Description copied from interface: FieldElement
        Returns the character at the given index.
        Specified by:
        charAt in interface FieldElement
        Parameters:
        index - the index of the character in this field element.
        Returns:
        the character at the given index.
        See Also:
        FieldElement.charAt(int)
      • length

        public int length()
        Description copied from interface: FieldElement
        Returns the length of the text within this element. This is a convenience method for calling getText().length().
        Specified by:
        length in interface FieldElement
        Returns:
        the length of the text within this element.
        See Also:
        FieldElement.length()
      • getStringWidth

        public int getStringWidth()
        Description copied from interface: FieldElement
        Returns the string width of this element. The width is based upon the associated FontMetrics object within this element.
        Specified by:
        getStringWidth in interface FieldElement
        Returns:
        the string width of this element.
        See Also:
        FieldElement.getStringWidth()
      • getMaxCharactersForWidth

        public int getMaxCharactersForWidth​(int width)
        Description copied from interface: FieldElement
        As the name implies, this method returns the maximum number of characters from this field element that will fit within the given width.
        Specified by:
        getMaxCharactersForWidth in interface FieldElement
        Parameters:
        width - The width constraint
        Returns:
        the maximum number of characters from this field element that will fit within the given width.
        See Also:
        FieldElement.getMaxCharactersForWidth(int)
      • getColor

        public java.awt.Color getColor​(int charIndex)
        Description copied from interface: FieldElement
        Returns the color for a given character within this element, since different colors may be applied to different characters.
        Specified by:
        getColor in interface FieldElement
        Parameters:
        charIndex - The character index
        Returns:
        the color for a given character within this element.
        See Also:
        FieldElement.getColor(int)
      • getFieldElement

        public FieldElement getFieldElement​(int characterOffset)
        Description copied from interface: FieldElement
        Returns the inner-most FieldElement inside this field element at the given location
        Specified by:
        getFieldElement in interface FieldElement
        Parameters:
        characterOffset - the charactor offset.
        Returns:
        the inner-most FieldElement inside this field element at the given location
        See Also:
        FieldElement.getFieldElement(int)
      • substring

        public FieldElement substring​(int start)
        Description copied from interface: FieldElement
        Returns a new FieldElement containing just the characters beginning at the given index.
        Specified by:
        substring in interface FieldElement
        Parameters:
        start - The starting index (inclusive) from which to substring this element.
        Returns:
        a new FieldElement containing just the characters beginning at the given index.
        See Also:
        FieldElement.substring(int)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getCharacterIndexForDataLocation

        public int getCharacterIndexForDataLocation​(int dataRow,
                                                    int dataColumn)
        Description copied from interface: FieldElement
        Returns the character index appropriate for the given data location
        Specified by:
        getCharacterIndexForDataLocation in interface FieldElement
        Parameters:
        dataRow - the row in the data model as determined by the creating field factory.
        dataColumn - the column in the data model as determined by the creating field factory.
        Returns:
        the character index appropriate for the given data location
        See Also:
        FieldElement.getCharacterIndexForDataLocation(int, int)
      • paint

        public void paint​(javax.swing.JComponent c,
                          java.awt.Graphics g,
                          int x,
                          int y)
        Description copied from interface: FieldElement
        Paints the text contained in this field element at the given x,y screen coordinate using the given Graphics object.
        Specified by:
        paint in interface FieldElement
        g - the Graphics object used to paint the field text.
        x - the horizontal screen position to paint
        y - the vertical screen position to paint.
        See Also:
        docking.widgets.fieldpanel.field.FieldElement#paint(java.awt.Graphics, int, int)