ewe.ui
Class DisplayLine

java.lang.Object
  extended byewe.util.LinkedListElement
      extended byewe.ui.DisplayLine

public class DisplayLine
extends LinkedListElement


Nested Class Summary
static interface DisplayLine.WidthProvider
           
 
Field Summary
 int displayWidth
          This is the width that was used when the DisplayLine was created split.
static int ENDS_WITH_NEWLINE
          This indicates that this line actually has a '\n' character at the end.
static int ENDS_WITH_SPACE
          This is not used.
static int FIRST_WIDTH_ONLY
           
 int flags
           
 boolean invalid
          This is used by mTextPad and TextFormatters
 int lengthOfLine
          This is valid immediately after a split.
 String line
           
 int lineIndex
          This is the index of the line within the editor/display.
 int numberInSection
          Only valid for the first line in a section.
static int PROVIDES_SPACE_ABOVE_LINE
          This indicates that this line is used to provide blank lines above a non-blank line.
static int PROVIDES_SPACE_BELOW_LINE
          This indicates that this line is used to provide blank lines below a non-blank line.
static int SPLIT_GET_LENGTHS
           
static int SPLIT_NO_WRAP
           
static int widest
          This is only valid immediately after doing a splitLines() call.
 int width
          This is the width of the line.
 
Fields inherited from class ewe.util.LinkedListElement
next, prev
 
Constructor Summary
DisplayLine()
           
 
Method Summary
 int compareLineLengths(DisplayLine lines)
          This compares the lengths of the lines as given in the array.
static String concatenate(DisplayLine from, DisplayLine to)
           
static String concatenate(DisplayLine lines, int start, int length)
           
 int countBlankLines(boolean above)
          Count how many blank lines are above or below this line.
 int countToSectionEnd()
          This returns how many lines are from this line (inclusive) to the end of this section.
 int findSectionIndex(DisplayLine line)
          This finds the index of the section the line is on.
static DisplayLine getBlankLines(int count, boolean forAbove)
          Get a sequence of blank (empty) lines to be placed either above or below a data line.
 DisplayLine getIndexedSection(int index)
           
 int getPositionInSection(int cursorLine, int cursorPos)
          This returns the position in the section of the specified cursor line and position in the editor/display.
 DisplayLine getSection(int indexOfThisLine)
          Gets the first DisplayLine in the section that this line happens to be in.
 String getSectionText()
          This can only be called on a section start.
 int getWidth(FontMetrics fm, int options)
           
 int hasSectionChanged(DisplayLine changedLine, FontMetrics fm, int width)
          This changes the text of a line within a section and then sees if any lines apart from that line would be changed.
 int hasSectionChanged(DisplayLine changedLine, FontMetrics fm, int width, FormattedTextSpecs fts)
          This changes the text of a line within a section and then sees if any lines apart from that line would be changed.
 int length()
           
 Dimension locate(int characterIndex, Dimension dest)
          This locates the row and column index of a character from the original text in the list of DisplayLines.
 Dimension positionInSection(int position, Dimension dest, boolean onPrev)
          This calculates the cursor line and position for the given offset position from the start of the section.
static DisplayLine[] replaceLines(DisplayLine[] original, int start, DisplayLine[] newLines)
           
 int replaceSection(DisplayLine newSection)
          This replaces the section with the provided section (which can actually have more than one section in it).
static DisplayLine split(String text, FontMetrics fm, int width, int options)
           
static DisplayLine split(String text, FontMetrics fm, int width, int options, FormattedTextSpecs ft)
           
static DisplayLine split(String text, FontMetrics fm, int width, int options, FormattedTextSpecs fts, DisplayLine.WidthProvider wp)
           
static DisplayLine[] splitLines(String text, FontMetrics fm, int width, int options)
          Split the lines.
 String substring(int start, int end)
           
static String[] toLines(DisplayLine all)
           
 String toString()
          Return a String representation of this object.
 int trueLength()
           
 
Methods inherited from class ewe.util.LinkedListElement
addSectionAfter, addSectionBefore, countInRange, countNext, countPrev, getNext, getPrev, removeSection, replaceSection, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

line

public String line

flags

public int flags

width

public int width
This is the width of the line. If it is split with wrapping then it is the width of the first word.


lineIndex

public int lineIndex
This is the index of the line within the editor/display.


numberInSection

public int numberInSection
Only valid for the first line in a section.


lengthOfLine

public int lengthOfLine
This is valid immediately after a split.


displayWidth

public int displayWidth
This is the width that was used when the DisplayLine was created split.


invalid

public boolean invalid
This is used by mTextPad and TextFormatters


ENDS_WITH_NEWLINE

public static final int ENDS_WITH_NEWLINE
This indicates that this line actually has a '\n' character at the end. However it will not be present in the String given by the line member. Its trueLength() will be equal to its length() plus one.

See Also:
Constant Field Values

ENDS_WITH_SPACE

public static final int ENDS_WITH_SPACE
This is not used.

See Also:
Constant Field Values

PROVIDES_SPACE_ABOVE_LINE

public static final int PROVIDES_SPACE_ABOVE_LINE
This indicates that this line is used to provide blank lines above a non-blank line. It is used with empty lines (line == "" and no ENDS_WITH_NEWLINE) to indicate that it was placed there to provide space above a data line. There may be a number of these in sequence.

See Also:
Constant Field Values

PROVIDES_SPACE_BELOW_LINE

public static final int PROVIDES_SPACE_BELOW_LINE
This indicates that this line is used to provide blank lines below a non-blank line. It is used with empty lines (line == "" and no ENDS_WITH_NEWLINE) to indicate that it was placed there to provide space below a data line. There may be a number of these in sequence.

See Also:
Constant Field Values

widest

public static int widest
This is only valid immediately after doing a splitLines() call. It gives the width of the widest word.


SPLIT_NO_WRAP

public static final int SPLIT_NO_WRAP
See Also:
Constant Field Values

FIRST_WIDTH_ONLY

public static final int FIRST_WIDTH_ONLY
See Also:
Constant Field Values

SPLIT_GET_LENGTHS

public static final int SPLIT_GET_LENGTHS
See Also:
Constant Field Values
Constructor Detail

DisplayLine

public DisplayLine()
Method Detail

getSection

public DisplayLine getSection(int indexOfThisLine)
Gets the first DisplayLine in the section that this line happens to be in. It will also calculate the lineIndex and numberInSection values for that first line.


findSectionIndex

public int findSectionIndex(DisplayLine line)
This finds the index of the section the line is on.


getIndexedSection

public DisplayLine getIndexedSection(int index)

countToSectionEnd

public int countToSectionEnd()
This returns how many lines are from this line (inclusive) to the end of this section.

Returns:
The number of lines from this line to the end of its section. This value will always be a minimum of 1, if the line is the last line in the section.

compareLineLengths

public int compareLineLengths(DisplayLine lines)
This compares the lengths of the lines as given in the array. It returns the index of the first line which differs, or -1 if no lines differ.


hasSectionChanged

public int hasSectionChanged(DisplayLine changedLine,
                             FontMetrics fm,
                             int width,
                             FormattedTextSpecs fts)
This changes the text of a line within a section and then sees if any lines apart from that line would be changed. If so, it will return the index of the first line which has changed, or -1 if none has been changed. This must be invoked on the first line of the section.


hasSectionChanged

public int hasSectionChanged(DisplayLine changedLine,
                             FontMetrics fm,
                             int width)
This changes the text of a line within a section and then sees if any lines apart from that line would be changed. If so, it will return the index of the first line which has changed, or -1 if none has been changed. This must be invoked on the first line of the section.


getPositionInSection

public int getPositionInSection(int cursorLine,
                                int cursorPos)
This returns the position in the section of the specified cursor line and position in the editor/display. This must be invoked on the first line in the section as calculated by getSection().


positionInSection

public Dimension positionInSection(int position,
                                   Dimension dest,
                                   boolean onPrev)
This calculates the cursor line and position for the given offset position from the start of the section. The width of the returned Dimension gives the "cursorPos" element and the height gives the "cursorLine" element.


replaceSection

public int replaceSection(DisplayLine newSection)
This replaces the section with the provided section (which can actually have more than one section in it). It must be called on the first line of a section only. Returns the difference in the number of lines after the section is replaced. The provided section may be null.


getSectionText

public String getSectionText()
This can only be called on a section start.


toLines

public static String[] toLines(DisplayLine all)

splitLines

public static DisplayLine[] splitLines(String text,
                                       FontMetrics fm,
                                       int width,
                                       int options)
Split the lines.

Parameters:
text - The text to be split.
fm - The FontMetrics for the Font and surface to be used for display.
width - The width in pixels of the display area.
options - This is a combination of SPLIT_GET_LENGTHS, SPLIT_NO_WRAP and FIRST_WIDTH_ONLY
Returns:
An array of DisplayLine objects.

getWidth

public int getWidth(FontMetrics fm,
                    int options)

split

public static DisplayLine split(String text,
                                FontMetrics fm,
                                int width,
                                int options)

split

public static DisplayLine split(String text,
                                FontMetrics fm,
                                int width,
                                int options,
                                FormattedTextSpecs ft)

split

public static DisplayLine split(String text,
                                FontMetrics fm,
                                int width,
                                int options,
                                FormattedTextSpecs fts,
                                DisplayLine.WidthProvider wp)

toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

length

public int length()

trueLength

public int trueLength()

substring

public String substring(int start,
                        int end)

concatenate

public static String concatenate(DisplayLine lines,
                                 int start,
                                 int length)

concatenate

public static String concatenate(DisplayLine from,
                                 DisplayLine to)

replaceLines

public static DisplayLine[] replaceLines(DisplayLine[] original,
                                         int start,
                                         DisplayLine[] newLines)

locate

public Dimension locate(int characterIndex,
                        Dimension dest)
This locates the row and column index of a character from the original text in the list of DisplayLines.

Parameters:
characterIndex - The original index of the character.
dest - a destination Dimension to hold the results. It can be null, in which case a new one will be allocated and returned.
Returns:
A Dimension object where the width variable denotes the index within the line and the height variable donates the index of the line. It will return null if the index is not in the orignal text.

getBlankLines

public static DisplayLine getBlankLines(int count,
                                        boolean forAbove)
Get a sequence of blank (empty) lines to be placed either above or below a data line.

Parameters:
count - The number of lines to get.
forAbove - if this is true then the lines are meant to be above a data line, otherwise it is for below a data line.
Returns:
a sequence of blank lines to be placed either above or below a data line.

countBlankLines

public int countBlankLines(boolean above)
Count how many blank lines are above or below this line.

Parameters:
above - if this is true then you are counting the blank lines above, otherwise you are counting those below.
Returns:
the number of blank lines above or below this one.