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