1 |
/* Caret.java -- |
/* Caret.java -- |
2 |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
43 |
|
|
44 |
import javax.swing.event.ChangeListener; |
import javax.swing.event.ChangeListener; |
45 |
|
|
46 |
|
/** |
47 |
|
* Defines the method to be implemented by a caret that can be used in Swing |
48 |
|
* text components. |
49 |
|
* |
50 |
|
* @author original author unknown |
51 |
|
* @author Roman Kennke (roman@kennke.org) |
52 |
|
*/ |
53 |
public interface Caret |
public interface Caret |
54 |
{ |
{ |
55 |
|
/** |
56 |
|
* Registers a {@link ChangeListener} that is notified whenever that state |
57 |
|
* of this <code>Caret</code> changes. |
58 |
|
* |
59 |
|
* @param l the listener to register to this caret |
60 |
|
*/ |
61 |
void addChangeListener(ChangeListener l); |
void addChangeListener(ChangeListener l); |
62 |
|
|
63 |
|
/** |
64 |
|
* Removes a {@link ChangeListener} from the list of registered listeners. |
65 |
|
* |
66 |
|
* @param l the listener to remove |
67 |
|
*/ |
68 |
|
void removeChangeListener(ChangeListener l); |
69 |
|
|
70 |
|
/** |
71 |
|
* Installs this <code>Caret</code> on the specified text component. This |
72 |
|
* usually involves setting up listeners. |
73 |
|
* |
74 |
|
* This method is called by {@link JTextComponent#setCaret(Caret)} after |
75 |
|
* this caret has been set on the text component. |
76 |
|
* |
77 |
|
* @param c the text component to install this caret to |
78 |
|
*/ |
79 |
|
void install(JTextComponent c); |
80 |
|
|
81 |
|
/** |
82 |
|
* Deinstalls this <code>Caret</code> from the specified text component. |
83 |
|
* This usually involves removing listeners from the text component. |
84 |
|
* |
85 |
|
* This method is called by {@link JTextComponent#setCaret(Caret)} before |
86 |
|
* this caret is removed from the text component. |
87 |
|
* |
88 |
|
* @param c the text component to deinstall this caret from |
89 |
|
*/ |
90 |
void deinstall(JTextComponent c); |
void deinstall(JTextComponent c); |
91 |
|
|
92 |
|
/** |
93 |
|
* Returns the blink rate of this <code>Caret</code> in milliseconds. |
94 |
|
* A value of <code>0</code> means that the caret does not blink. |
95 |
|
* |
96 |
|
* @return the blink rate of this <code>Caret</code> or <code>0</code> if |
97 |
|
* this caret does not blink |
98 |
|
*/ |
99 |
int getBlinkRate(); |
int getBlinkRate(); |
100 |
|
|
101 |
|
/** |
102 |
|
* Sets the blink rate of this <code>Caret</code> in milliseconds. |
103 |
|
* A value of <code>0</code> means that the caret does not blink. |
104 |
|
* |
105 |
|
* @param rate the new blink rate to set |
106 |
|
*/ |
107 |
|
void setBlinkRate(int rate); |
108 |
|
|
109 |
|
/** |
110 |
|
* Returns the current position of this <code>Caret</code> within the |
111 |
|
* <code>Document</code>. |
112 |
|
* |
113 |
|
* @return the current position of this <code>Caret</code> within the |
114 |
|
* <code>Document</code> |
115 |
|
*/ |
116 |
int getDot(); |
int getDot(); |
117 |
|
|
118 |
|
/** |
119 |
|
* Sets the current position of this <code>Caret</code> within the |
120 |
|
* <code>Document</code>. This also sets the <code>mark</code> to the |
121 |
|
* new location. |
122 |
|
* |
123 |
|
* @param dot the new position to be set |
124 |
|
* |
125 |
|
* @see {@link #moveDot(int)} |
126 |
|
*/ |
127 |
|
void setDot(int dot); |
128 |
|
|
129 |
Point getMagicCaretPosition(); |
/** |
130 |
|
* Moves the <code>dot</code> location without touching the |
131 |
int getMark(); |
* <code>mark</code>. This is used when making a selection. |
132 |
|
* |
133 |
void install(JTextComponent c); |
* @param dot the location where to move the dot |
134 |
|
* |
135 |
boolean isSelectionVisible(); |
* @see {@link #setDot(int)} |
136 |
|
*/ |
|
boolean isVisible(); |
|
|
|
|
137 |
void moveDot(int dot); |
void moveDot(int dot); |
138 |
|
|
139 |
void paint(Graphics g); |
/** |
140 |
|
* Returns the current position of the <code>mark</code>. The |
141 |
void removeChangeListener(ChangeListener l); |
* <code>mark</code> marks the location in the <code>Document</code> that |
142 |
|
* is the end of a selection. If there is no selection, the <code>mark</code> |
143 |
void setBlinkRate(int rate); |
* is the same as the <code>dot</code>. |
144 |
|
* |
145 |
void setDot(int dot); |
* @return the current position of the mark |
146 |
|
*/ |
147 |
|
int getMark(); |
148 |
|
|
149 |
|
/** |
150 |
|
* Returns the current visual position of this <code>Caret</code>. |
151 |
|
* |
152 |
|
* @return the current visual position of this <code>Caret</code> |
153 |
|
* |
154 |
|
* @see {@link #setMagicCaretPosition} |
155 |
|
*/ |
156 |
|
Point getMagicCaretPosition(); |
157 |
|
|
158 |
|
/** |
159 |
|
* Sets the current visual position of this <code>Caret</code>. |
160 |
|
* |
161 |
|
* @param p the Point to use for the saved location. May be <code>null</code> |
162 |
|
* to indicate that there is no visual location |
163 |
|
*/ |
164 |
void setMagicCaretPosition(Point p); |
void setMagicCaretPosition(Point p); |
165 |
|
|
166 |
|
/** |
167 |
|
* Returns <code>true</code> if the selection is currently visible, |
168 |
|
* <code>false</code> otherwise. |
169 |
|
* |
170 |
|
* @return <code>true</code> if the selection is currently visible, |
171 |
|
* <code>false</code> otherwise |
172 |
|
*/ |
173 |
|
boolean isSelectionVisible(); |
174 |
|
|
175 |
|
/** |
176 |
|
* Sets the visiblity state of the selection. |
177 |
|
* |
178 |
|
* @param v <code>true</code> if the selection should be visible, |
179 |
|
* <code>false</code> otherwise |
180 |
|
*/ |
181 |
void setSelectionVisible(boolean v); |
void setSelectionVisible(boolean v); |
182 |
|
|
183 |
|
/** |
184 |
|
* Returns <code>true</code> if this <code>Caret</code> is currently visible, |
185 |
|
* and <code>false</code> if it is not. |
186 |
|
* |
187 |
|
* @return <code>true</code> if this <code>Caret</code> is currently visible, |
188 |
|
* and <code>false</code> if it is not |
189 |
|
*/ |
190 |
|
boolean isVisible(); |
191 |
|
|
192 |
|
/** |
193 |
|
* Sets the visibility state of the caret. <code>true</code> shows the |
194 |
|
* <code>Caret</code>, <code>false</code> hides it. |
195 |
|
* |
196 |
|
* @param v the visibility to set |
197 |
|
*/ |
198 |
void setVisible(boolean v); |
void setVisible(boolean v); |
199 |
|
|
200 |
|
/** |
201 |
|
* Paints this <code>Caret</code> to the specified <code>Graphics</code> |
202 |
|
* context. |
203 |
|
* |
204 |
|
* @param g the graphics context to render to |
205 |
|
*/ |
206 |
|
void paint(Graphics g); |
207 |
} |
} |