KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > Highlighter


1 /*
2  * @(#)Highlighter.java 1.22 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.text;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Graphics JavaDoc;
11 import java.awt.Shape JavaDoc;
12
13 /**
14  * An interface for an object that allows one to mark up the background
15  * with colored areas.
16  *
17  * @author Timothy Prinzing
18  * @version 1.22 12/19/03
19  */

20 public interface Highlighter {
21
22     /**
23      * Called when the UI is being installed into the
24      * interface of a JTextComponent. This can be used
25      * to gain access to the model that is being navigated
26      * by the implementation of this interface.
27      *
28      * @param c the JTextComponent editor
29      */

30     public void install(JTextComponent JavaDoc c);
31
32     /**
33      * Called when the UI is being removed from the
34      * interface of a JTextComponent. This is used to
35      * unregister any listeners that were attached.
36      *
37      * @param c the JTextComponent editor
38      */

39     public void deinstall(JTextComponent JavaDoc c);
40
41     /**
42      * Renders the highlights.
43      *
44      * @param g the graphics context.
45      */

46     public void paint(Graphics JavaDoc g);
47
48     /**
49      * Adds a highlight to the view. Returns a tag that can be used
50      * to refer to the highlight.
51      *
52      * @param p0 the beginning of the range >= 0
53      * @param p1 the end of the range >= p0
54      * @param p the painter to use for the actual highlighting
55      * @return an object that refers to the highlight
56      * @exception BadLocationException for an invalid range specification
57      */

58     public Object JavaDoc addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException JavaDoc;
59
60     /**
61      * Removes a highlight from the view.
62      *
63      * @param tag which highlight to remove
64      */

65     public void removeHighlight(Object JavaDoc tag);
66
67     /**
68      * Removes all highlights this highlighter is responsible for.
69      */

70     public void removeAllHighlights();
71
72     /**
73      * Changes the given highlight to span a different portion of
74      * the document. This may be more efficient than a remove/add
75      * when a selection is expanding/shrinking (such as a sweep
76      * with a mouse) by damaging only what changed.
77      *
78      * @param tag which highlight to change
79      * @param p0 the beginning of the range >= 0
80      * @param p1 the end of the range >= p0
81      * @exception BadLocationException for an invalid range specification
82      */

83     public void changeHighlight(Object JavaDoc tag, int p0, int p1) throws BadLocationException JavaDoc;
84
85     /**
86      * Fetches the current list of highlights.
87      *
88      * @return the highlight list
89      */

90     public Highlight[] getHighlights();
91
92     /**
93      * Highlight renderer.
94      */

95     public interface HighlightPainter {
96
97     /**
98      * Renders the highlight.
99          *
100          * @param g the graphics context
101          * @param p0 the starting offset in the model >= 0
102          * @param p1 the ending offset in the model >= p0
103          * @param bounds the bounding box for the highlight
104          * @param c the editor
105      */

106         public void paint(Graphics JavaDoc g, int p0, int p1, Shape JavaDoc bounds, JTextComponent JavaDoc c);
107
108     }
109
110     public interface Highlight {
111
112         /**
113          * Gets the starting model offset for the highlight.
114          *
115          * @return the starting offset >= 0
116          */

117     public int getStartOffset();
118
119         /**
120          * Gets the ending model offset for the highlight.
121          *
122          * @return the ending offset >= 0
123          */

124     public int getEndOffset();
125
126         /**
127          * Gets the painter for the highlighter.
128          *
129          * @return the painter
130          */

131     public HighlightPainter getPainter();
132
133     }
134
135 };
136
137
Popular Tags