GNU Classpath (0.17) | ||
Frames | No Frames |
1: /* 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: 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; 49: 50: /** 51: * An abstract base class for delegates that provide the user 52: * interface for text editors. 53: * 54: * @see javax.swing.text.JTextComponent 55: * 56: * @author Ronald Veldema (rveldema@cs.vu.nl) 57: * @author Sascha Brawer (brawer@dandelis.ch) 58: */ 59: public abstract class TextUI 60: extends ComponentUI 61: { 62: /** 63: * Constructs a new <code>TextUI</code>. 64: */ 65: public TextUI() 66: { 67: } 68: 69: 70: /** 71: * Calculates the geometric extent of the character at the 72: * given offset. 73: * 74: * @param tc the <code>JTextComponent</code> for which this 75: * delegate object provides the user interface. 76: * 77: * @param pos the zero-based index of the character into the 78: * document model. 79: * 80: * @return the bounding box of the character at index 81: * <code>pos</code>, in view coordinates. 82: * 83: * @throws BadLocationException if <code>pos</code> does not 84: * designate a valid position in the document model. 85: * 86: * @see javax.swing.text.View#modelToView(int, 87: * javax.swing.text.Position.Bias, int, 88: * javax.swing.text.position.Bias, java.awt.Shape) 89: */ 90: public abstract Rectangle modelToView(JTextComponent tc, int pos) 91: throws BadLocationException; 92: 93: 94: /** 95: * Calculates the geometric extent of the character at the 96: * given offset. 97: * 98: * @param tc the <code>JTextComponent</code> for which this 99: * delegate object provides the user interface. 100: * 101: * @param pos the zero-based index of the character into the 102: * document model. 103: * 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}. 109: * 110: * @return the bounding box of the character at index 111: * <code>pos</code>, in view coordinates. 112: * 113: * @throws BadLocationException if <code>pos</code> does not 114: * designate a valid position in the document model. 115: * 116: * @see javax.swing.text.View#modelToView(int, 117: * javax.swing.text.Position.Bias, int, 118: * javax.swing.text.position.Bias, java.awt.Shape) 119: */ 120: public abstract Rectangle modelToView(JTextComponent tc, int pos, 121: Position.Bias bias) 122: throws BadLocationException; 123: 124: 125: /** 126: * Finds the caret position which is closest to the specified visual 127: * location. 128: * 129: * @param tc the <code>JTextComponent</code> for which this 130: * delegate object provides the user interface. 131: * 132: * @param loc the position in view coordinates. 133: * 134: * @return the caret position which is closest to <code>loc</code>. 135: * 136: * @see #viewToModel(JTextComponent, Point, Position.Bias[]) 137: */ 138: public abstract int viewToModel(JTextComponent t, Point pt); 139: 140: 141: /** 142: * Finds the caret position which is closest to the specified visual 143: * location. 144: * 145: * @param tc the <code>JTextComponent</code> for which this 146: * delegate object provides the user interface. 147: * 148: * @param loc the position in view coordinates. 149: * 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 155: * caret position. 156: * 157: * @return the caret position which is closest to <code>loc</code>. 158: */ 159: public abstract int viewToModel(JTextComponent tc, Point loc, 160: Position.Bias[] outBias); 161: 162: 163: 164: /** 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. 168: * 169: * @param tc the <code>JTextComponent</code> for which this 170: * delegate object provides the user interface. 171: * 172: * @param pos the current caret position, a zero-based index 173: * into the document model. 174: * 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}. 180: * 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. 188: * 189: * @throws BadLocationException if <code>pos</code> does not 190: * designate a valid position in the document model. 191: * 192: * @throws IllegalArgumentException if <code>direction</code> 193: * is not one of <code>Position.Bias.Forward</code> 194: * or <code>Position.Biad.Backward</code>. 195: */ 196: public abstract int getNextVisualPositionFrom(JTextComponent tc, 197: int pos, 198: Position.Bias bias, 199: int direction, 200: Position.Bias[] outBias) 201: throws BadLocationException; 202: 203: 204: /** 205: * Repaints a range of characters. 206: * 207: * @param tc the <code>JTextComponent</code> for which this 208: * delegate object provides the user interface. 209: * 210: * @param start the first character in the range that needs 211: * painting, indicated as an index into the document model. 212: * 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>. 217: */ 218: public abstract void damageRange(JTextComponent tc, int start, int end); 219: 220: 221: /** 222: * Repaints a range of characters, also specifying the bias for the 223: * start and end of the range. 224: * 225: * @param tc the <code>JTextComponent</code> for which this 226: * delegate object provides the user interface. 227: * 228: * @param start the first character in the range that needs 229: * painting, indicated as an index into the document model. 230: * 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>. 235: */ 236: public abstract void damageRange(JTextComponent tc, 237: int start, int end, 238: Position.Bias startBias, 239: Position.Bias endBias); 240: 241: 242: /** 243: * Retrieves the <code>EditorKit</code> managing policies and 244: * persistent state. 245: * 246: * @param tc the <code>JTextComponent</code> for which this 247: * delegate object provides the user interface. 248: * 249: * @return the <code>EditorKit</code> used by <code>tc</code>. 250: */ 251: public abstract EditorKit getEditorKit(JTextComponent tc); 252: 253: 254: /** 255: * Retrieves the root of the view tree that visually presents 256: * the text. 257: * 258: * @param tc the <code>JTextComponent</code> for which this 259: * delegate object provides the user interface. 260: * 261: * @return the root <code>View</code> used by <code>tc</code>. 262: */ 263: public abstract View getRootView(JTextComponent tc); 264: 265: 266: /** 267: * Returns a String for presenting a tool tip at the specified 268: * location. 269: * 270: * @param tc the <code>JTextComponent</code> for which this 271: * delegate object provides the user interface. 272: * 273: * @param loc the location for which the tool tip is requested. 274: * 275: * @return the text for the tool tip, or <code>null</code> to 276: * display no tool tip. 277: * 278: * @since 1.4 279: */ 280: public String getToolTipText(JTextComponent tc, Point loc) 281: { 282: return null; 283: } 284: }
GNU Classpath (0.17) |