Interface FieldElement

All Known Implementing Classes:
AbstractTextFieldElement, AnnotatedTextFieldElement, ClangFieldElement, CompositeFieldElement, StrutFieldElement, TextFieldElement

public interface FieldElement
Used by Fields to combine text, attributes and location information (for example to and from screen and data locations). FieldFactory classes can use the various implementations of this interface, or create new ones, to include additional information specific to the fields that they create.
  • Method Summary

    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
    getColor(int charIndex)
    Returns the color for a given character within this element, since different colors may be applied to different characters.
    Translates the given character index to a data location related to the data model, as determined by the FieldFactory.
    getFieldElement(int column)
    Returns the inner-most FieldElement inside this field element at the given location
    int
    Returns the amount of height above the baseline of this element.
    int
    Returns the amount of height below the baseline of this element.
    int
    As the name implies, this method returns the maximum number of characters from this field element that will fit within the given width.
    int
    Returns the string width of this element.
    Returns the text contained by this field element.
    int
    Returns the length of the text within this element.
    void
    paint(JComponent c, 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.
    replaceAll(char[] targets, char replacement)
    Returns a new FieldElement with all occurrences of the target characters replaced with the given replacement character.
    substring(int start)
    Returns a new FieldElement containing just the characters beginning at the given index.
    substring(int start, int end)
    Returns a new FieldElement containing just the characters beginning at the given start index (inclusive) and ending at the given end index (exclusive).
  • Method Details

    • getText

      String getText()
      Returns the text contained by this field element.
      Returns:
      the text contained by this field element.
    • length

      int length()
      Returns the length of the text within this element. This is a convenience method for calling getText().length().
      Returns:
      the length of the text within this element.
    • getStringWidth

      int getStringWidth()
      Returns the string width of this element. The width is based upon the associated FontMetrics object within this element.
      Returns:
      the string width of this element.
    • getHeightAbove

      int getHeightAbove()
      Returns the amount of height above the baseline of this element.
      Returns:
      the amount of height above the baseline of this element.
    • getHeightBelow

      int getHeightBelow()
      Returns the amount of height below the baseline of this element.
      Returns:
      the amount of height below the baseline of this element.
    • charAt

      char charAt(int index)
      Returns the character at the given index.
      Parameters:
      index - the index of the character in this field element.
      Returns:
      the character at the given index.
    • getColor

      Color getColor(int charIndex)
      Returns the color for a given character within this element, since different colors may be applied to different characters.
      Parameters:
      charIndex - The character index
      Returns:
      the color for a given character within this element.
    • substring

      FieldElement substring(int start)
      Returns a new FieldElement containing just the characters beginning at the given index.
      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.
    • substring

      FieldElement substring(int start, int end)
      Returns a new FieldElement containing just the characters beginning at the given start index (inclusive) and ending at the given end index (exclusive).
      Parameters:
      start - The starting index (inclusive) from which to substring this element.
      end - The end index (exclusive) to which the substring will be performed.
      Returns:
      a new FieldElement containing just the characters beginning at the given index.
    • replaceAll

      FieldElement replaceAll(char[] targets, char replacement)
      Returns a new FieldElement with all occurrences of the target characters replaced with the given replacement character.
      Parameters:
      targets - The array of characters to replace.
      replacement - The replacement character.
      Returns:
      a new FieldElement with all occurrences of the target characters replaced with the given replacement character.
    • getMaxCharactersForWidth

      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.
      Parameters:
      width - The width constraint
      Returns:
      the maximum number of characters from this field element that will fit within the given width.
    • getDataLocationForCharacterIndex

      RowColLocation getDataLocationForCharacterIndex(int characterIndex)
      Translates the given character index to a data location related to the data model, as determined by the FieldFactory.
      Parameters:
      characterIndex - The character index to translate.
      Returns:
      The data location in the model coordinates.
    • getCharacterIndexForDataLocation

      int getCharacterIndexForDataLocation(int dataRow, int dataColumn)
      Returns the character index appropriate for the given data location
      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; -1 if this field does not contain the given location
    • paint

      void paint(JComponent c, 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.
      Parameters:
      c - the component being painted.
      g - the Graphics object used to paint the field text.
      x - the horizontal screen position to paint
      y - the vertical screen position to paint.
    • getFieldElement

      FieldElement getFieldElement(int column)
      Returns the inner-most FieldElement inside this field element at the given location
      Parameters:
      column - the character offset.
      Returns:
      the inner-most FieldElement inside this field element at the given location