edu.rice.cs.util.swing
Class HighlightManager

java.lang.Object
  extended by edu.rice.cs.util.swing.HighlightManager

public class HighlightManager
extends Object

This class has synchronized public methods because it is accessed outside of the event thread.


Nested Class Summary
 class HighlightManager.HighlightInfo
          The public inner class defining a "smart" highlight, which can return the value of its start and end offsets for comparison with other highlights.
 
Field Summary
private  JTextComponent _component
          The component necessary for creating positions in in the document, which is also contained within this component.
private  Vector<Stack<HighlightManager.HighlightInfo>> _highlights
          An unsorted Vector of Stack, each of which corresponds to a unique region in the document.
 
Constructor Summary
HighlightManager(JTextComponent jtc)
          Constructor
 
Method Summary
private  Stack<HighlightManager.HighlightInfo> _getStackAt(HighlightManager.HighlightInfo h)
          Returns the Stack corresponding to the given region in the document, or null in none exists.
 HighlightManager.HighlightInfo addHighlight(int startOffset, int endOffset, Highlighter.HighlightPainter p)
          Adds a highlight using the supplied painter to the vector element(Stack) that exactly corresponds to the specified bounds.
 void removeHighlight(HighlightManager.HighlightInfo newLite)
          Removes a given highlight (HighlightInfo) from the highlighter
 void removeHighlight(int startOffset, int endOffset, Highlighter.HighlightPainter p)
          Removes a highlight with the specified start/end offsets and the given painter.
 int size()
          Size of highlight stack; used only for unit testing
 String toString()
          Overrides to toString() to support unit testing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_highlights

private Vector<Stack<HighlightManager.HighlightInfo>> _highlights
An unsorted Vector of Stack, each of which corresponds to a unique region in the document. All HighlightInfo objects within a given stack must correspond to the same region but must have unique Highlighter.HighlightPainters. Each stack is ordered so the most recent highlight is at the top.


_component

private JTextComponent _component
The component necessary for creating positions in in the document, which is also contained within this component.

Constructor Detail

HighlightManager

public HighlightManager(JTextComponent jtc)
Constructor

Parameters:
jtc - the component whose document will have positions created therein.
Method Detail

toString

public String toString()
Overrides to toString() to support unit testing

Overrides:
toString in class Object

size

public int size()
Size of highlight stack; used only for unit testing


addHighlight

public HighlightManager.HighlightInfo addHighlight(int startOffset,
                                                   int endOffset,
                                                   Highlighter.HighlightPainter p)
Adds a highlight using the supplied painter to the vector element(Stack) that exactly corresponds to the specified bounds. The most recently added highlights over a given range appear on top of the older highlights. All highlights in a given range(Stack) must be unique, that is, each must use a different painter--redundant highlights are shifted to the top of the stack, but not added twice.

Parameters:
startOffset - the offset at which the highlight is to begin.
endOffset - the offset at which the highlight is to end.
p - the Highlighter.HighlightPainter for painting
Returns:
HighlightInfo the HighlightInfo object, for keeping a tag of a given highlight

_getStackAt

private Stack<HighlightManager.HighlightInfo> _getStackAt(HighlightManager.HighlightInfo h)
Returns the Stack corresponding to the given region in the document, or null in none exists. ASSUMES that every Stack in the vector has a unique region.

Parameters:
h - the descriptor for the desired region.
Returns:
the corresponding Stack, or null

removeHighlight

public void removeHighlight(int startOffset,
                            int endOffset,
                            Highlighter.HighlightPainter p)
Removes a highlight with the specified start/end offsets and the given painter.

Parameters:
startOffset - the offset at which the desired highlight should start.
endOffset - the offset at which the desired highlight shoud end.
p - the Highlighter.HighlightPainter for painting

removeHighlight

public void removeHighlight(HighlightManager.HighlightInfo newLite)
Removes a given highlight (HighlightInfo) from the highlighter

Parameters:
newLite - the HighlightInfo object corresponding to the highlight needed to be removed