Extension SDK 10.1.2

oracle.javatools.editor.highlight
Class HighlightLayer

java.lang.Object
  extended byoracle.javatools.editor.highlight.HighlightLayer

public final class HighlightLayer
extends java.lang.Object

A HighlightedLayer is a container for highlights added to an editor pane. Highlights are segments of text are created in a specific highlight layer rather than directly in the editor pane. This allows different modules to maintain and manipulate their highlights in separate layers without affect each other.

Let's visit an example of how to highlight text - take the example of the selected text maintained by the caret. In order for the caret to have the selected text highlighted, it needs to create a highlight layer and add it to the editor pane. Once the layer is added, it can add, change, or remove highlights using the highlight layer directly. The highlight layer will take care of making sure the editor view is kept up-to-date as far as painting is concerned.

There are certain highlights that track a line, such as a caret line, or breakpoint line. Use addLineHighlight() for creating such a line highlight. Line highlights cannot be changed to non-line highlights once created.

Note that highlighted text are created using buffer OffsetMarks and will track those offsets when the buffer changes.


Constructor Summary
HighlightLayer(BasicEditorPane editor)
          Constructs a new highlight layer associated with the given editor.
 
Method Summary
 HighlightedText addHighlight(HighlightStyle style, int startOffset, int endOffset)
          Adds a highlight to the editor pane using the specified style and offsets.
 HighlightedText addLineHighlight(HighlightStyle style, int line)
          Adds a highlight to the editor pane using the specified style and offsets.
 void changeHighlight(HighlightedText highlightedText, HighlightStyle newHighlightStyle)
          Changes the highlight style of the previously created highlighted region of text.
 void changeHighlight(HighlightedText highlightedText, HighlightStyle newHighlightStyle, int newStartOffset, int newEndOffset)
          Moves the highlight region to a new set of offsets in the editor, and changes the highlight style used.
 void changeHighlight(HighlightedText highlightedText, int newStartOffset, int newEndOffset)
          Moves the highlight region to a new set of offsets in the editor.
 void removeAllHighlights()
          Removes all highlights in this layer from the associated editor pane.
 void removeHighlight(HighlightedText highlightedText)
          Removes the given highlight from the editor pane.
 void renderHighlights(HighlightedFragmentsList fragmentsList, int startOffset, int endOffset)
          This routine is used by the editor view to obtain all of the highlights in this highlight layer in the given offset range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HighlightLayer

public HighlightLayer(BasicEditorPane editor)
Constructs a new highlight layer associated with the given editor.

Method Detail

addHighlight

public HighlightedText addHighlight(HighlightStyle style,
                                    int startOffset,
                                    int endOffset)
Adds a highlight to the editor pane using the specified style and offsets.

Parameters:
style - the highlight style to use
startOffset - the start of the highlighted segment of text
endOffset - the end of the highlighted segment of text

addLineHighlight

public HighlightedText addLineHighlight(HighlightStyle style,
                                        int line)
Adds a highlight to the editor pane using the specified style and offsets.

Parameters:
style - the highlight style to use
line - the 0-based line to highlight
Returns:
the line highlight instance, or null if the specified line is invalid

removeHighlight

public void removeHighlight(HighlightedText highlightedText)
Removes the given highlight from the editor pane.

Parameters:
highlightedText - the highlight to remove

removeAllHighlights

public void removeAllHighlights()
Removes all highlights in this layer from the associated editor pane.


changeHighlight

public void changeHighlight(HighlightedText highlightedText,
                            HighlightStyle newHighlightStyle)
Changes the highlight style of the previously created highlighted region of text.

Parameters:
highlightedText - the highlight that was previously created
newHighlightStyle - the new highlight style to use

changeHighlight

public void changeHighlight(HighlightedText highlightedText,
                            int newStartOffset,
                            int newEndOffset)
Moves the highlight region to a new set of offsets in the editor.

Parameters:
highlightedText - the highlight that was previously created
newStartOffset - the new starting location for the highlight
newEndOffset - the new ending location for the highlight

changeHighlight

public void changeHighlight(HighlightedText highlightedText,
                            HighlightStyle newHighlightStyle,
                            int newStartOffset,
                            int newEndOffset)
Moves the highlight region to a new set of offsets in the editor, and changes the highlight style used.

Parameters:
highlightedText - the highlight that was previously created
newHighlightStyle - the new highlight style to use
newStartOffset - the new starting location for the highlight
newEndOffset - the new ending location for the highlight

renderHighlights

public void renderHighlights(HighlightedFragmentsList fragmentsList,
                             int startOffset,
                             int endOffset)
This routine is used by the editor view to obtain all of the highlights in this highlight layer in the given offset range.

Parameters:
fragmentsList - the list to add the highlight fragments to
startOffset - the start of the painting area
endOffset - the end of the painting area

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.