edu.rice.cs.drjava.ui
Class ReverseHighlighter

java.lang.Object
  extended by javax.swing.text.LayeredHighlighter
      extended by javax.swing.text.DefaultHighlighter
          extended by edu.rice.cs.drjava.ui.ReverseHighlighter
All Implemented Interfaces:
Highlighter

public class ReverseHighlighter
extends DefaultHighlighter

Implements the Highlighter interfaces. Implements a simple highlight painter, but stores the highlights in reverse order. That means that the selection (for copying) is always the foremost hightlight, and after that, the highlights are drawn from most recent to oldest. Based on DefaultHighlighter by Timothy Prinzing, version 1.39 12/19/03 Unfortunately, as the vector of highlights in DefaultHighlighter was private, there was no efficient way to make use of inheritance.


Nested Class Summary
static class ReverseHighlighter.DefaultFrameHighlightPainter
          Simple highlight painter that draws a rectangular box around text.
static class ReverseHighlighter.DefaultUnderlineHighlightPainter
          Simple highlight painter that underlines text.
static class ReverseHighlighter.DrJavaHighlightPainter
          This class is a wrapper for the DefaultHighlightPainter that allows us to tell whether a highlight was requested by DrJava or by Swing (as in selected text).
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultHighlighter
DefaultHighlighter.DefaultHighlightPainter
 
Nested classes/interfaces inherited from class javax.swing.text.LayeredHighlighter
LayeredHighlighter.LayerPainter
 
Nested classes/interfaces inherited from interface javax.swing.text.Highlighter
Highlighter.Highlight, Highlighter.HighlightPainter
 
Field Summary
 
Fields inherited from class javax.swing.text.DefaultHighlighter
DefaultPainter
 
Constructor Summary
ReverseHighlighter()
          Creates a new ReverseHighlighter object.
 
Method Summary
 Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p)
          Adds a highlight to the view.
 void changeHighlight(Object tag, int p0, int p1)
          Changes a highlight.
 void deinstall(JTextComponent c)
          Called when the UI is being removed from the interface of a JTextComponent.
 boolean getDrawsLayeredHighlights()
           
 Highlighter.Highlight[] getHighlights()
          Makes a copy of the highlights.
 void install(JTextComponent c)
          Called when the UI is being installed into the interface of a JTextComponent.
 void paint(Graphics g)
          Renders the highlights.
 void paintLayeredHighlights(Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view)
          When leaf Views (such as LabelView) are rendering they should call into this method.
 void removeAllHighlights()
          Removes all highlights.
 void removeHighlight(Object tag)
          Removes a highlight from the view.
 void setDrawsLayeredHighlights(boolean newValue)
          If true, highlights are drawn as the Views draw the text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReverseHighlighter

public ReverseHighlighter()
Creates a new ReverseHighlighter object.

Method Detail

paint

public void paint(Graphics g)
Renders the highlights.

Specified by:
paint in interface Highlighter
Overrides:
paint in class DefaultHighlighter
Parameters:
g - the graphics context

install

public void install(JTextComponent c)
Called when the UI is being installed into the interface of a JTextComponent. Installs the editor, and removes any existing highlights.

Specified by:
install in interface Highlighter
Overrides:
install in class DefaultHighlighter
Parameters:
c - the editor component
See Also:
Highlighter.install(javax.swing.text.JTextComponent)

deinstall

public void deinstall(JTextComponent c)
Called when the UI is being removed from the interface of a JTextComponent.

Specified by:
deinstall in interface Highlighter
Overrides:
deinstall in class DefaultHighlighter
Parameters:
c - the component
See Also:
Highlighter.deinstall(javax.swing.text.JTextComponent)

addHighlight

public Object addHighlight(int p0,
                           int p1,
                           Highlighter.HighlightPainter p)
                    throws BadLocationException
Adds a highlight to the view. Returns a tag that can be used to refer to the highlight.

Specified by:
addHighlight in interface Highlighter
Overrides:
addHighlight in class DefaultHighlighter
Parameters:
p0 - the start offset of the range to highlight >= 0
p1 - the end offset of the range to highlight >= p0
p - the painter to use to actually render the highlight
Returns:
an object that can be used as a tag to refer to the highlight
Throws:
BadLocationException - if the specified location is invalid

removeHighlight

public void removeHighlight(Object tag)
Removes a highlight from the view.

Specified by:
removeHighlight in interface Highlighter
Overrides:
removeHighlight in class DefaultHighlighter
Parameters:
tag - the reference to the highlight

removeAllHighlights

public void removeAllHighlights()
Removes all highlights.

Specified by:
removeAllHighlights in interface Highlighter
Overrides:
removeAllHighlights in class DefaultHighlighter

changeHighlight

public void changeHighlight(Object tag,
                            int p0,
                            int p1)
                     throws BadLocationException
Changes a highlight.

Specified by:
changeHighlight in interface Highlighter
Overrides:
changeHighlight in class DefaultHighlighter
Parameters:
tag - the highlight tag
p0 - the beginning of the range >= 0
p1 - the end of the range >= p0
Throws:
BadLocationException - if the specified location is invalid

getHighlights

public Highlighter.Highlight[] getHighlights()
Makes a copy of the highlights. Does not actually clone each highlight, but only makes references to them.

Specified by:
getHighlights in interface Highlighter
Overrides:
getHighlights in class DefaultHighlighter
Returns:
the copy
See Also:
Highlighter.getHighlights()

paintLayeredHighlights

public void paintLayeredHighlights(Graphics g,
                                   int p0,
                                   int p1,
                                   Shape viewBounds,
                                   JTextComponent editor,
                                   View view)
When leaf Views (such as LabelView) are rendering they should call into this method. If a highlight is in the given region it will be drawn immediately.

Overrides:
paintLayeredHighlights in class DefaultHighlighter
Parameters:
g - Graphics used to draw
p0 - starting offset of view
p1 - ending offset of view
viewBounds - Bounds of View
editor - JTextComponent
view - View instance being rendered

setDrawsLayeredHighlights

public void setDrawsLayeredHighlights(boolean newValue)
If true, highlights are drawn as the Views draw the text. That is the Views will call into paintLayeredHighlight which will result in a rectangle being drawn before the text is drawn (if the offsets are in a highlighted region that is). For this to work the painter supplied must be an instance of LayeredHighlightPainter.

Overrides:
setDrawsLayeredHighlights in class DefaultHighlighter

getDrawsLayeredHighlights

public boolean getDrawsLayeredHighlights()
Overrides:
getDrawsLayeredHighlights in class DefaultHighlighter