001 /* TextUI.java --
002 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package javax.swing.plaf;
040
041 import java.awt.Point;
042 import java.awt.Rectangle;
043 import java.awt.Shape;
044
045 import javax.swing.text.BadLocationException;
046 import javax.swing.text.EditorKit;
047 import javax.swing.text.JTextComponent;
048 import javax.swing.text.Position;
049 import javax.swing.text.View;
050
051 /**
052 * An abstract base class for delegates that provide the user
053 * interface for text editors.
054 *
055 * @see javax.swing.text.JTextComponent
056 *
057 * @author Ronald Veldema (rveldema@cs.vu.nl)
058 * @author Sascha Brawer (brawer@dandelis.ch)
059 */
060 public abstract class TextUI extends ComponentUI
061 {
062 /**
063 * Constructs a new <code>TextUI</code>.
064 */
065 public TextUI()
066 {
067 // Nothing to do here.
068 }
069
070
071 /**
072 * Calculates the geometric extent of the character at the
073 * given offset.
074 *
075 * @param tc the <code>JTextComponent</code> for which this
076 * delegate object provides the user interface.
077 *
078 * @param pos the zero-based index of the character into the
079 * document model.
080 *
081 * @return the bounding box of the character at index
082 * <code>pos</code>, in view coordinates.
083 *
084 * @throws BadLocationException if <code>pos</code> does not
085 * designate a valid position in the document model.
086 *
087 * @see javax.swing.text.ComponentView#modelToView(int, Shape, Position.Bias)
088 */
089 public abstract Rectangle modelToView(JTextComponent tc, int pos)
090 throws BadLocationException;
091
092
093 /**
094 * Calculates the geometric extent of the character at the
095 * given offset.
096 *
097 * @param tc the <code>JTextComponent</code> for which this
098 * delegate object provides the user interface.
099 *
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 }