Package docking.widgets.fieldpanel.field
Class CompositeFieldElement
- java.lang.Object
-
- docking.widgets.fieldpanel.field.CompositeFieldElement
-
- All Implemented Interfaces:
FieldElement
public class CompositeFieldElement extends java.lang.Object implements FieldElement
A FieldElement that is composed of other FieldElements. The elements are laid out horizontally.
-
-
Constructor Summary
Constructors Constructor Description CompositeFieldElement(FieldElement[] fieldElements)
CompositeFieldElement(java.util.List<? extends FieldElement> elements)
-
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 locationjava.awt.Color
getColor(int index)
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 column)
Returns the inner-most FieldElement inside this field element at the given locationint
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
getNumElements()
Returns the number of sub-elements contained in this fieldint
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
replaceAll(char[] targets, char repacement)
Returns a new FieldElement with all occurrences of the target characters replaced with the given replacement character.FieldElement
substring(int start)
Returns a new FieldElement containing just the characters beginning at the given index.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).java.lang.String
toString()
-
-
-
Constructor Detail
-
CompositeFieldElement
public CompositeFieldElement(java.util.List<? extends FieldElement> elements)
-
CompositeFieldElement
public CompositeFieldElement(FieldElement[] fieldElements)
-
-
Method Detail
-
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 interfaceFieldElement
- Parameters:
width
- The width constraint- Returns:
- the maximum number of characters from this field element that will fit within the given width.
-
getColor
public java.awt.Color getColor(int index)
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 interfaceFieldElement
- Parameters:
index
- The character index- Returns:
- the color for a given character within this element.
-
charAt
public char charAt(int index)
Description copied from interface:FieldElement
Returns the character at the given index.- Specified by:
charAt
in interfaceFieldElement
- Parameters:
index
- the index of the character in this field element.- Returns:
- the character at the given index.
-
getHeightAbove
public int getHeightAbove()
Description copied from interface:FieldElement
Returns the amount of height above the baseline of this element.- Specified by:
getHeightAbove
in interfaceFieldElement
- Returns:
- the amount of height above the baseline of this element.
-
getHeightBelow
public int getHeightBelow()
Description copied from interface:FieldElement
Returns the amount of height below the baseline of this element.- Specified by:
getHeightBelow
in interfaceFieldElement
- Returns:
- the amount of height below the baseline of this element.
-
replaceAll
public FieldElement replaceAll(char[] targets, char repacement)
Description copied from interface:FieldElement
Returns a new FieldElement with all occurrences of the target characters replaced with the given replacement character.- Specified by:
replaceAll
in interfaceFieldElement
- Parameters:
targets
- The array of characters to replace.repacement
- The replacement character.- Returns:
- a new FieldElement with all occurrences of the target characters replaced with the given replacement character.
-
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 interfaceFieldElement
- 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
public FieldElement substring(int start, int end)
Description copied from interface:FieldElement
Returns a new FieldElement containing just the characters beginning at the given start index (inclusive) and ending at the given end index (exclusive).- Specified by:
substring
in interfaceFieldElement
- 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.
-
getFieldElement
public FieldElement getFieldElement(int column)
Description copied from interface:FieldElement
Returns the inner-most FieldElement inside this field element at the given location- Specified by:
getFieldElement
in interfaceFieldElement
- Parameters:
column
- the character offset.- Returns:
- the inner-most FieldElement inside this field element at the given location
-
length
public int length()
Description copied from interface:FieldElement
Returns the length of the text within this element. This is a convenience method for callinggetText().length()
.- Specified by:
length
in interfaceFieldElement
- Returns:
- the length of the text within this element.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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 interfaceFieldElement
- Returns:
- the string width of this element.
-
getText
public java.lang.String getText()
Description copied from interface:FieldElement
Returns the text contained by this field element.- Specified by:
getText
in interfaceFieldElement
- Returns:
- the text contained by this field element.
-
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 interfaceFieldElement
- Parameters:
c
- the component being painted.g
- the Graphics object used to paint the field text.x
- the horizontal screen position to painty
- the vertical screen position to paint.
-
getNumElements
public int getNumElements()
Returns the number of sub-elements contained in this field- Returns:
- the number of sub-elements contained in this field
-
getDataLocationForCharacterIndex
public RowColLocation getDataLocationForCharacterIndex(int characterIndex)
Description copied from interface:FieldElement
Translates the given character index to a data location related to the data model, as determined by the FieldFactory.- Specified by:
getDataLocationForCharacterIndex
in interfaceFieldElement
- Parameters:
characterIndex
- The character index to translate.- Returns:
- The data location in the model coordinates.
-
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 interfaceFieldElement
- 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
-
-