org.eclipse.swt.custom
Class DefaultLineStyler

java.lang.Object
  |
  +--org.eclipse.swt.custom.DefaultLineStyler
All Implemented Interfaces:
EventListener, LineBackgroundListener, LineStyleListener, org.eclipse.swt.internal.SWTEventListener

class DefaultLineStyler
extends Object
implements LineStyleListener, LineBackgroundListener


Field Summary
(package private)  StyledTextContent content
           
(package private)  Color[] lineBackgrounds
           
(package private)  int lineCount
           
(package private)  int lineExpandExp
           
(package private)  int styleCount
           
(package private)  int styleExpandExp
           
(package private)  StyleRange[] styles
           
 
Constructor Summary
DefaultLineStyler(StyledTextContent content)
          Creates a new default line styler.
 
Method Summary
(package private)  void clearStyle(StyleRange clearStyle)
          Removes style information that is defined for the range of text in clearStyle.
(package private)  void deleteStyle(int index)
          Deletes the style at index.
(package private)  void deleteStyles(int index, int count)
          Delete count styles starting at index.
(package private)  void expandLinesBy(int numLines)
          Increases the linebackgrounds array to accomodate new line background information.
(package private)  Color getLineBackground(int index)
          Returns the background color of a line.
(package private)  Point getOverlappingStyles(int start, int length)
          Returns the indexes of the styles that overlap the given range.
(package private)  StyleRange getStyleRangeAtOffset(int offset)
          Returns the style for the character at offset.
(package private)  StyleRange[] getStyleRanges()
          Returns the styles that are defined.
(package private)  StyleRange[] getStyleRangesFor(int offset, int length)
          Returns the styles for the given range.
(package private)  boolean insertMergeStyle(StyleRange style, int index)
          Inserts a style, merging it with adjacent styles if possible.
(package private)  void insertStyle(StyleRange style, int index)
          Inserts a style at the given location.
(package private)  void insertStyles(StyleRange[] insertStyles, int index)
          Insert the styles at the given location.
 void lineGetBackground(LineBackgroundEvent event)
          Handles the get line background color callback.
 void lineGetStyle(LineStyleEvent event)
          Handles the get line style information callback.
(package private)  void linesChanging(int start, int delta)
           
(package private)  boolean mergeStyleAfter(StyleRange style, int index)
          Merges the style with the style after it if possible.
(package private)  boolean mergeStyleBefore(StyleRange style, int index)
          Merges the style with the style before it if possible.
(package private)  void replaceStyleRanges(int start, int length, StyleRange[] ranges)
          Replace the styles for the given range.
(package private)  int searchForStyle(int start, int end)
          Searches for the first style in the start - end range.
(package private)  void setLineBackground(int startLine, int count, Color background)
          Updates the line background colors to reflect a new color.
(package private)  void setStyleRange(StyleRange newStyle)
          Update the styles to reflect the new style.
(package private)  void setStyleRanges(StyleRange[] styles)
          Sets the array of styles and discards old styles.
(package private)  void textChanging(int start, int delta)
           
 void textChanging(TextChangingEvent event)
          Updates the style ranges and line backgrounds to reflect a pending text change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

content

StyledTextContent content

styles

StyleRange[] styles

styleCount

int styleCount

styleExpandExp

int styleExpandExp

lineExpandExp

int lineExpandExp

lineCount

int lineCount

lineBackgrounds

Color[] lineBackgrounds
Constructor Detail

DefaultLineStyler

public DefaultLineStyler(StyledTextContent content)
Creates a new default line styler.

Parameters:
content - the text to which the styles apply
Method Detail

insertStyle

void insertStyle(StyleRange style,
                 int index)
Inserts a style at the given location.

Parameters:
style - the new style
index - the index at which to insert the style (the new style will reside at this index)

insertStyles

void insertStyles(StyleRange[] insertStyles,
                  int index)
Insert the styles at the given location.

Parameters:
insertStyles - the new styles
index - the index at which to insert the styles (the first new style will reside at this index)

insertMergeStyle

boolean insertMergeStyle(StyleRange style,
                         int index)
Inserts a style, merging it with adjacent styles if possible.

Parameters:
style - the new style
index - the index at which to insert the style (the new style will reside at this index)
Returns:
true if the style was inserted, false if the style was merged with an adjacent style

mergeStyleBefore

boolean mergeStyleBefore(StyleRange style,
                         int index)
Merges the style with the style before it if possible.

Parameters:
style - the new style
index - the index at which to attempt the merge.
Returns:
true if the style was merged, false otherwise

mergeStyleAfter

boolean mergeStyleAfter(StyleRange style,
                        int index)
Merges the style with the style after it if possible.

Parameters:
style - the new style
index - the index at which to attempt the merge.
Returns:
true if the style was merged, false otherwise

clearStyle

void clearStyle(StyleRange clearStyle)
Removes style information that is defined for the range of text in clearStyle.

Parameters:
clearStyle - the style information to use for clearing

expandLinesBy

void expandLinesBy(int numLines)
Increases the linebackgrounds array to accomodate new line background information.

Parameters:
numLines - the number to increase the array by

deleteStyle

void deleteStyle(int index)
Deletes the style at index.

Parameters:
index - the index of the style to be deleted

deleteStyles

void deleteStyles(int index,
                  int count)
Delete count styles starting at index.

Parameters:
index - the index of the style to be deleted
count - the number of styles to be deleted

getStyleRanges

StyleRange[] getStyleRanges()
Returns the styles that are defined.

Returns:
the copied array of styles

lineGetBackground

public void lineGetBackground(LineBackgroundEvent event)
Handles the get line background color callback.

Specified by:
lineGetBackground in interface LineBackgroundListener

lineGetStyle

public void lineGetStyle(LineStyleEvent event)
Handles the get line style information callback.

Specified by:
lineGetStyle in interface LineStyleListener

searchForStyle

int searchForStyle(int start,
                   int end)
Searches for the first style in the start - end range.

Returns:
the index of the first style that overlaps the input range

setLineBackground

void setLineBackground(int startLine,
                       int count,
                       Color background)
Updates the line background colors to reflect a new color. Called by StyledText.

Parameters:
startLine - index of the first line to color
background - the background color for the lines

setStyleRange

void setStyleRange(StyleRange newStyle)
Update the styles to reflect the new style. newStyle will replace any old style for the range. When this method is called, the DefaultLineStyler may merge the new style with an existing style (if possible). Called by StyledText when a style is added. Called by StyledText.

Parameters:
newStyle - the new style information.

replaceStyleRanges

void replaceStyleRanges(int start,
                        int length,
                        StyleRange[] ranges)
Replace the styles for the given range.


setStyleRanges

void setStyleRanges(StyleRange[] styles)
Sets the array of styles and discards old styles. Called by StyledText.

Parameters:
styles - the new styles, must be in order and non-overlapping

textChanging

public void textChanging(TextChangingEvent event)
Updates the style ranges and line backgrounds to reflect a pending text change. Called by StyledText when a TextChangingEvent is received.

Parameters:
event - the event with the text change information

linesChanging

void linesChanging(int start,
                   int delta)

textChanging

void textChanging(int start,
                  int delta)

getOverlappingStyles

Point getOverlappingStyles(int start,
                           int length)
Returns the indexes of the styles that overlap the given range. Styles that partially or fully overlap the range will be returned.

Returns:
Point where x is the index of the starting overlap style, y is the number of styles that overlap the range

getLineBackground

Color getLineBackground(int index)
Returns the background color of a line. Called by StyledText. It is safe to return the existing Color object since the colors are set and managed by the client.

Parameters:
index - the line index
Returns:
the background color of the line at the given index

getStyleRangeAtOffset

StyleRange getStyleRangeAtOffset(int offset)
Returns the style for the character at offset. Called by StyledText. Returns a new style. Does not return the existing style.

Parameters:
offset - the character position in the text
Returns:
a cloned StyleRange with start == offset and length == 1 if a style is specified or null if no style is specified

getStyleRangesFor

StyleRange[] getStyleRangesFor(int offset,
                               int length)
Returns the styles for the given range. Returns the existing styles, so be careful not to modify the return value. Styles are not cloned in order to make this method as efficient as possible.

Parameters:
offset - the start position of the text range
length - the length of the text range
Returns:
a StyleRange array or null if no styles are specified for the text range


comments?