2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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., 59 Temple Place, Suite 330, Boston, MA
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
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. */
39 package javax
.swing
.plaf
;
41 import java
.awt
.Point
;
42 import java
.awt
.Rectangle
;
44 import javax
.swing
.text
.BadLocationException
;
45 import javax
.swing
.text
.EditorKit
;
46 import javax
.swing
.text
.JTextComponent
;
47 import javax
.swing
.text
.Position
;
48 import javax
.swing
.text
.View
;
51 * An abstract base class for delegates that provide the user
52 * interface for text editors.
54 * @see javax.swing.text.JTextComponent
56 * @author Ronald Veldema (rveldema@cs.vu.nl)
57 * @author Sascha Brawer (brawer@dandelis.ch)
59 public abstract class TextUI
63 * Constructs a new <code>TextUI</code>.
71 * Calculates the geometric extent of the character at the
74 * @param tc the <code>JTextComponent</code> for which this
75 * delegate object provides the user interface.
77 * @param pos the zero-based index of the character into the
80 * @return the bounding box of the character at index
81 * <code>pos</code>, in view coordinates.
83 * @throws BadLocationException if <code>pos</code> does not
84 * designate a valid position in the document model.
86 * @see javax.swing.text.View#modelToView(int,
87 * javax.swing.text.Position.Bias, int,
88 * javax.swing.text.position.Bias, java.awt.Shape)
90 public abstract Rectangle
modelToView(JTextComponent tc
, int pos
)
91 throws BadLocationException
;
95 * Calculates the geometric extent of the character at the
98 * @param tc the <code>JTextComponent</code> for which this
99 * delegate object provides the user interface.
101 * @param pos the zero-based index of the character into the
104 * @param bias whether to take the character before or after the
105 * caret position indicated by <code>pos</code>. The value
106 * must be either {@link
107 * javax.swing.text.Position.Bias#Backward} or {@link
108 * javax.swing.text.Position.Bias#Forward}.
110 * @return the bounding box of the character at index
111 * <code>pos</code>, in view coordinates.
113 * @throws BadLocationException if <code>pos</code> does not
114 * designate a valid position in the document model.
116 * @see javax.swing.text.View#modelToView(int,
117 * javax.swing.text.Position.Bias, int,
118 * javax.swing.text.position.Bias, java.awt.Shape)
120 public abstract Rectangle
modelToView(JTextComponent tc
, int pos
,
122 throws BadLocationException
;
126 * Finds the caret position which is closest to the specified visual
129 * @param tc the <code>JTextComponent</code> for which this
130 * delegate object provides the user interface.
132 * @param loc the position in view coordinates.
134 * @return the caret position which is closest to <code>loc</code>.
136 * @see #viewToModel(JTextComponent, Point, Position.Bias[])
138 public abstract int viewToModel(JTextComponent t
, Point pt
);
142 * Finds the caret position which is closest to the specified visual
145 * @param tc the <code>JTextComponent</code> for which this
146 * delegate object provides the user interface.
148 * @param loc the position in view coordinates.
150 * @param outBias an array whose size must be at least one.
151 * After the call, <code>outBias[0]</code> will indicate
152 * whether <code>loc</code> is in the glyph before
153 * (<code>Position.Bias.Backward</code>) or after
154 * (<code>Position.Bias.Forward</code>) the returned
157 * @return the caret position which is closest to <code>loc</code>.
159 public abstract int viewToModel(JTextComponent tc
, Point loc
,
160 Position
.Bias
[] outBias
);
165 * Calculates the caret position that is visually next to the given
166 * position. This is useful to determine where to move the caret
167 * after the user has pressed an arrow key.
169 * @param tc the <code>JTextComponent</code> for which this
170 * delegate object provides the user interface.
172 * @param pos the current caret position, a zero-based index
173 * into the document model.
175 * @param bias whether to take the character before or after the
176 * caret position indicated by <code>pos</code>. The value
177 * must be either {@link
178 * javax.swing.text.Position.Bias#Backward} or {@link
179 * javax.swing.text.Position.Bias#Forward}.
181 * @param direction the visual direction. Pass
182 * {@link javax.swing.SwingConstants#WEST} for the left
183 * arrow key, {@link javax.swing.SwingConstants#EAST}
184 * for the right arrow key, {@link
185 * javax.swing.SwingConstants#NORTH} for the up arrow
186 * key, or {@link javax.swing.SwingConstants#SOUTH}
187 * for the down arrow key.
189 * @throws BadLocationException if <code>pos</code> does not
190 * designate a valid position in the document model.
192 * @throws IllegalArgumentException if <code>direction</code>
193 * is not one of <code>Position.Bias.Forward</code>
194 * or <code>Position.Biad.Backward</code>.
196 public abstract int getNextVisualPositionFrom(JTextComponent tc
,
200 Position
.Bias
[] outBias
)
201 throws BadLocationException
;
205 * Repaints a range of characters.
207 * @param tc the <code>JTextComponent</code> for which this
208 * delegate object provides the user interface.
210 * @param start the first character in the range that needs
211 * painting, indicated as an index into the document model.
213 * @param end the last character in the range that needs
214 * painting, indicated as an index into the document model.
215 * <code>end</code> must be greater than or equal to
216 * <code>start</code>.
218 public abstract void damageRange(JTextComponent tc
, int start
, int end
);
222 * Repaints a range of characters, also specifying the bias for the
223 * start and end of the range.
225 * @param tc the <code>JTextComponent</code> for which this
226 * delegate object provides the user interface.
228 * @param start the first character in the range that needs
229 * painting, indicated as an index into the document model.
231 * @param end the last character in the range that needs
232 * painting, indicated as an index into the document model.
233 * <code>end</code> must be greater than or equal to
234 * <code>start</code>.
236 public abstract void damageRange(JTextComponent tc
,
238 Position
.Bias startBias
,
239 Position
.Bias endBias
);
243 * Retrieves the <code>EditorKit</code> managing policies and
246 * @param tc the <code>JTextComponent</code> for which this
247 * delegate object provides the user interface.
249 * @return the <code>EditorKit</code> used by <code>tc</code>.
251 public abstract EditorKit
getEditorKit(JTextComponent tc
);
255 * Retrieves the root of the view tree that visually presents
258 * @param tc the <code>JTextComponent</code> for which this
259 * delegate object provides the user interface.
261 * @return the root <code>View</code> used by <code>tc</code>.
263 public abstract View
getRootView(JTextComponent tc
);
267 * Returns a String for presenting a tool tip at the specified
270 * @param tc the <code>JTextComponent</code> for which this
271 * delegate object provides the user interface.
273 * @param loc the location for which the tool tip is requested.
275 * @return the text for the tool tip, or <code>null</code> to
276 * display no tool tip.
280 public String
getToolTipText(JTextComponent tc
, Point loc
)