1 |
772 |
jeremybenn |
/* TextUI.java --
|
2 |
|
|
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package javax.swing.plaf;
|
40 |
|
|
|
41 |
|
|
import java.awt.Point;
|
42 |
|
|
import java.awt.Rectangle;
|
43 |
|
|
import java.awt.Shape;
|
44 |
|
|
|
45 |
|
|
import javax.swing.text.BadLocationException;
|
46 |
|
|
import javax.swing.text.EditorKit;
|
47 |
|
|
import javax.swing.text.JTextComponent;
|
48 |
|
|
import javax.swing.text.Position;
|
49 |
|
|
import javax.swing.text.View;
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* An abstract base class for delegates that provide the user
|
53 |
|
|
* interface for text editors.
|
54 |
|
|
*
|
55 |
|
|
* @see javax.swing.text.JTextComponent
|
56 |
|
|
*
|
57 |
|
|
* @author Ronald Veldema (rveldema@cs.vu.nl)
|
58 |
|
|
* @author Sascha Brawer (brawer@dandelis.ch)
|
59 |
|
|
*/
|
60 |
|
|
public abstract class TextUI extends ComponentUI
|
61 |
|
|
{
|
62 |
|
|
/**
|
63 |
|
|
* Constructs a new <code>TextUI</code>.
|
64 |
|
|
*/
|
65 |
|
|
public TextUI()
|
66 |
|
|
{
|
67 |
|
|
// Nothing to do here.
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Calculates the geometric extent of the character at the
|
73 |
|
|
* given offset.
|
74 |
|
|
*
|
75 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
76 |
|
|
* delegate object provides the user interface.
|
77 |
|
|
*
|
78 |
|
|
* @param pos the zero-based index of the character into the
|
79 |
|
|
* document model.
|
80 |
|
|
*
|
81 |
|
|
* @return the bounding box of the character at index
|
82 |
|
|
* <code>pos</code>, in view coordinates.
|
83 |
|
|
*
|
84 |
|
|
* @throws BadLocationException if <code>pos</code> does not
|
85 |
|
|
* designate a valid position in the document model.
|
86 |
|
|
*
|
87 |
|
|
* @see javax.swing.text.ComponentView#modelToView(int, Shape, Position.Bias)
|
88 |
|
|
*/
|
89 |
|
|
public abstract Rectangle modelToView(JTextComponent tc, int pos)
|
90 |
|
|
throws BadLocationException;
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Calculates the geometric extent of the character at the
|
95 |
|
|
* given offset.
|
96 |
|
|
*
|
97 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
98 |
|
|
* delegate object provides the user interface.
|
99 |
|
|
*
|
100 |
|
|
* @param pos the zero-based index of the character into the
|
101 |
|
|
* document model.
|
102 |
|
|
*
|
103 |
|
|
* @param bias whether to take the character before or after the
|
104 |
|
|
* caret position indicated by <code>pos</code>. The value
|
105 |
|
|
* must be either {@link
|
106 |
|
|
* javax.swing.text.Position.Bias#Backward} or {@link
|
107 |
|
|
* javax.swing.text.Position.Bias#Forward}.
|
108 |
|
|
*
|
109 |
|
|
* @return the bounding box of the character at index
|
110 |
|
|
* <code>pos</code>, in view coordinates.
|
111 |
|
|
*
|
112 |
|
|
* @throws BadLocationException if <code>pos</code> does not
|
113 |
|
|
* designate a valid position in the document model.
|
114 |
|
|
*
|
115 |
|
|
* @see javax.swing.text.ComponentView#modelToView(int, Shape, Position.Bias)
|
116 |
|
|
*/
|
117 |
|
|
public abstract Rectangle modelToView(JTextComponent tc, int pos,
|
118 |
|
|
Position.Bias bias)
|
119 |
|
|
throws BadLocationException;
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
/**
|
123 |
|
|
* Finds the caret position which is closest to the specified visual
|
124 |
|
|
* location.
|
125 |
|
|
*
|
126 |
|
|
* @param t the <code>JTextComponent</code> for which this
|
127 |
|
|
* delegate object provides the user interface.
|
128 |
|
|
*
|
129 |
|
|
* @param pt the position in view coordinates.
|
130 |
|
|
*
|
131 |
|
|
* @return the caret position which is closest to <code>loc</code>.
|
132 |
|
|
*
|
133 |
|
|
* @see #viewToModel(JTextComponent, Point, Position.Bias[])
|
134 |
|
|
*/
|
135 |
|
|
public abstract int viewToModel(JTextComponent t, Point pt);
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
/**
|
139 |
|
|
* Finds the caret position which is closest to the specified visual
|
140 |
|
|
* location.
|
141 |
|
|
*
|
142 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
143 |
|
|
* delegate object provides the user interface.
|
144 |
|
|
*
|
145 |
|
|
* @param loc the position in view coordinates.
|
146 |
|
|
*
|
147 |
|
|
* @param outBias an array whose size must be at least one.
|
148 |
|
|
* After the call, <code>outBias[0]</code> will indicate
|
149 |
|
|
* whether <code>loc</code> is in the glyph before
|
150 |
|
|
* (<code>Position.Bias.Backward</code>) or after
|
151 |
|
|
* (<code>Position.Bias.Forward</code>) the returned
|
152 |
|
|
* caret position.
|
153 |
|
|
*
|
154 |
|
|
* @return the caret position which is closest to <code>loc</code>.
|
155 |
|
|
*/
|
156 |
|
|
public abstract int viewToModel(JTextComponent tc, Point loc,
|
157 |
|
|
Position.Bias[] outBias);
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
/**
|
162 |
|
|
* Calculates the caret position that is visually next to the given
|
163 |
|
|
* position. This is useful to determine where to move the caret
|
164 |
|
|
* after the user has pressed an arrow key.
|
165 |
|
|
*
|
166 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
167 |
|
|
* delegate object provides the user interface.
|
168 |
|
|
*
|
169 |
|
|
* @param pos the current caret position, a zero-based index
|
170 |
|
|
* into the document model.
|
171 |
|
|
*
|
172 |
|
|
* @param bias whether to take the character before or after the
|
173 |
|
|
* caret position indicated by <code>pos</code>. The value
|
174 |
|
|
* must be either {@link
|
175 |
|
|
* javax.swing.text.Position.Bias#Backward} or {@link
|
176 |
|
|
* javax.swing.text.Position.Bias#Forward}.
|
177 |
|
|
*
|
178 |
|
|
* @param direction the visual direction. Pass
|
179 |
|
|
* {@link javax.swing.SwingConstants#WEST} for the left
|
180 |
|
|
* arrow key, {@link javax.swing.SwingConstants#EAST}
|
181 |
|
|
* for the right arrow key, {@link
|
182 |
|
|
* javax.swing.SwingConstants#NORTH} for the up arrow
|
183 |
|
|
* key, or {@link javax.swing.SwingConstants#SOUTH}
|
184 |
|
|
* for the down arrow key.
|
185 |
|
|
*
|
186 |
|
|
* @throws BadLocationException if <code>pos</code> does not
|
187 |
|
|
* designate a valid position in the document model.
|
188 |
|
|
*
|
189 |
|
|
* @throws IllegalArgumentException if <code>direction</code>
|
190 |
|
|
* is not one of <code>Position.Bias.Forward</code>
|
191 |
|
|
* or <code>Position.Bias.Backward</code>.
|
192 |
|
|
*/
|
193 |
|
|
public abstract int getNextVisualPositionFrom(JTextComponent tc,
|
194 |
|
|
int pos,
|
195 |
|
|
Position.Bias bias,
|
196 |
|
|
int direction,
|
197 |
|
|
Position.Bias[] outBias)
|
198 |
|
|
throws BadLocationException;
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
/**
|
202 |
|
|
* Repaints a range of characters.
|
203 |
|
|
*
|
204 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
205 |
|
|
* delegate object provides the user interface.
|
206 |
|
|
*
|
207 |
|
|
* @param start the first character in the range that needs
|
208 |
|
|
* painting, indicated as an index into the document model.
|
209 |
|
|
*
|
210 |
|
|
* @param end the last character in the range that needs
|
211 |
|
|
* painting, indicated as an index into the document model.
|
212 |
|
|
* <code>end</code> must be greater than or equal to
|
213 |
|
|
* <code>start</code>.
|
214 |
|
|
*/
|
215 |
|
|
public abstract void damageRange(JTextComponent tc, int start, int end);
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
/**
|
219 |
|
|
* Repaints a range of characters, also specifying the bias for the
|
220 |
|
|
* start and end of the range.
|
221 |
|
|
*
|
222 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
223 |
|
|
* delegate object provides the user interface.
|
224 |
|
|
*
|
225 |
|
|
* @param start the first character in the range that needs
|
226 |
|
|
* painting, indicated as an index into the document model.
|
227 |
|
|
*
|
228 |
|
|
* @param end the last character in the range that needs
|
229 |
|
|
* painting, indicated as an index into the document model.
|
230 |
|
|
* <code>end</code> must be greater than or equal to
|
231 |
|
|
* <code>start</code>.
|
232 |
|
|
*/
|
233 |
|
|
public abstract void damageRange(JTextComponent tc,
|
234 |
|
|
int start, int end,
|
235 |
|
|
Position.Bias startBias,
|
236 |
|
|
Position.Bias endBias);
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
/**
|
240 |
|
|
* Retrieves the <code>EditorKit</code> managing policies and
|
241 |
|
|
* persistent state.
|
242 |
|
|
*
|
243 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
244 |
|
|
* delegate object provides the user interface.
|
245 |
|
|
*
|
246 |
|
|
* @return the <code>EditorKit</code> used by <code>tc</code>.
|
247 |
|
|
*/
|
248 |
|
|
public abstract EditorKit getEditorKit(JTextComponent tc);
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
/**
|
252 |
|
|
* Retrieves the root of the view tree that visually presents
|
253 |
|
|
* the text.
|
254 |
|
|
*
|
255 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
256 |
|
|
* delegate object provides the user interface.
|
257 |
|
|
*
|
258 |
|
|
* @return the root <code>View</code> used by <code>tc</code>.
|
259 |
|
|
*/
|
260 |
|
|
public abstract View getRootView(JTextComponent tc);
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
/**
|
264 |
|
|
* Returns a String for presenting a tool tip at the specified
|
265 |
|
|
* location.
|
266 |
|
|
*
|
267 |
|
|
* @param tc the <code>JTextComponent</code> for which this
|
268 |
|
|
* delegate object provides the user interface.
|
269 |
|
|
*
|
270 |
|
|
* @param loc the location for which the tool tip is requested.
|
271 |
|
|
*
|
272 |
|
|
* @return the text for the tool tip, or <code>null</code> to
|
273 |
|
|
* display no tool tip.
|
274 |
|
|
*
|
275 |
|
|
* @since 1.4
|
276 |
|
|
*/
|
277 |
|
|
public String getToolTipText(JTextComponent tc, Point loc)
|
278 |
|
|
{
|
279 |
|
|
return null;
|
280 |
|
|
}
|
281 |
|
|
}
|