Source for javax.swing.text.Caret

   1: /* Caret.java --
   2:    Copyright (C) 2002, 2004, 2005 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.text;
  40: 
  41: import java.awt.Graphics;
  42: import java.awt.Point;
  43: 
  44: import javax.swing.event.ChangeListener;
  45: 
  46: /**
  47:  * Defines the method to be implemented by a caret that can be used in Swing
  48:  * text components.
  49:  *
  50:  * @author original author unknown
  51:  * @author Roman Kennke (roman@kennke.org)
  52:  */
  53: public interface Caret
  54: {
  55:   /**
  56:    * Registers a {@link ChangeListener} that is notified whenever that state
  57:    * of this <code>Caret</code> changes.
  58:    *
  59:    * @param l the listener to register to this caret
  60:    */
  61:   void addChangeListener(ChangeListener l);
  62: 
  63:   /**
  64:    * Removes a {@link ChangeListener} from the list of registered listeners.
  65:    *
  66:    * @param l the listener to remove
  67:    */
  68:   void removeChangeListener(ChangeListener l);
  69: 
  70:   /**
  71:    * Installs this <code>Caret</code> on the specified text component. This
  72:    * usually involves setting up listeners.
  73:    *
  74:    * This method is called by {@link JTextComponent#setCaret(Caret)} after
  75:    * this caret has been set on the text component.
  76:    *
  77:    * @param c the text component to install this caret to
  78:    */
  79:   void install(JTextComponent c);
  80: 
  81:   /**
  82:    * Deinstalls this <code>Caret</code> from the specified text component.
  83:    * This usually involves removing listeners from the text component.
  84:    *
  85:    * This method is called by {@link JTextComponent#setCaret(Caret)} before
  86:    * this caret is removed from the text component.
  87:    *
  88:    * @param c the text component to deinstall this caret from
  89:    */
  90:   void deinstall(JTextComponent c);
  91: 
  92:   /**
  93:    * Returns the blink rate of this <code>Caret</code> in milliseconds.
  94:    * A value of <code>0</code> means that the caret does not blink.
  95:    *
  96:    * @return the blink rate of this <code>Caret</code> or <code>0</code> if
  97:    *         this caret does not blink
  98:    */
  99:   int getBlinkRate();
 100: 
 101:   /**
 102:    * Sets the blink rate of this <code>Caret</code> in milliseconds.
 103:    * A value of <code>0</code> means that the caret does not blink.
 104:    *
 105:    * @param rate the new blink rate to set
 106:    */
 107:   void setBlinkRate(int rate);
 108: 
 109:   /**
 110:    * Returns the current position of this <code>Caret</code> within the
 111:    * <code>Document</code>.
 112:    *
 113:    * @return the current position of this <code>Caret</code> within the
 114:    *         <code>Document</code>
 115:    */
 116:   int getDot();
 117: 
 118:   /**
 119:    * Sets the current position of this <code>Caret</code> within the
 120:    * <code>Document</code>. This also sets the <code>mark</code> to the
 121:    * new location.
 122:    *
 123:    * @param dot the new position to be set
 124:    *
 125:    * @see #moveDot(int)
 126:    */
 127:   void setDot(int dot);
 128: 
 129:   /**
 130:    * Moves the <code>dot</code> location without touching the
 131:    * <code>mark</code>. This is used when making a selection.
 132:    *
 133:    * @param dot the location where to move the dot
 134:    *
 135:    * @see #setDot(int)
 136:    */
 137:   void moveDot(int dot);
 138: 
 139:   /**
 140:    * Returns the current position of the <code>mark</code>. The
 141:    * <code>mark</code> marks the location in the <code>Document</code> that
 142:    * is the end of a selection. If there is no selection, the <code>mark</code>
 143:    * is the same as the <code>dot</code>.
 144:    *
 145:    * @return the current position of the mark
 146:    */
 147:   int getMark();
 148: 
 149:   /**
 150:    * Returns the current visual position of this <code>Caret</code>.
 151:    *
 152:    * @return the current visual position of this <code>Caret</code>
 153:    *
 154:    * @see #setMagicCaretPosition
 155:    */
 156:   Point getMagicCaretPosition();
 157: 
 158:   /**
 159:    * Sets the current visual position of this <code>Caret</code>.
 160:    *
 161:    * @param p the Point to use for the saved location. May be <code>null</code>
 162:    *        to indicate that there is no visual location
 163:    */
 164:   void setMagicCaretPosition(Point p);
 165: 
 166:   /**
 167:    * Returns <code>true</code> if the selection is currently visible,
 168:    * <code>false</code> otherwise.
 169:    *
 170:    * @return <code>true</code> if the selection is currently visible,
 171:    *         <code>false</code> otherwise
 172:    */
 173:   boolean isSelectionVisible();
 174: 
 175:   /**
 176:    * Sets the visiblity state of the selection.
 177:    *
 178:    * @param v <code>true</code> if the selection should be visible,
 179:    *        <code>false</code> otherwise
 180:    */
 181:   void setSelectionVisible(boolean v);
 182: 
 183:   /**
 184:    * Returns <code>true</code> if this <code>Caret</code> is currently visible,
 185:    * and <code>false</code> if it is not.
 186:    *
 187:    * @return <code>true</code> if this <code>Caret</code> is currently visible,
 188:    *         and <code>false</code> if it is not
 189:    */
 190:   boolean isVisible();
 191: 
 192:   /**
 193:    * Sets the visibility state of the caret. <code>true</code> shows the
 194:    * <code>Caret</code>, <code>false</code> hides it.
 195:    *
 196:    * @param v the visibility to set
 197:    */
 198:   void setVisible(boolean v);
 199: 
 200:   /**
 201:    * Paints this <code>Caret</code> to the specified <code>Graphics</code>
 202:    * context.
 203:    *
 204:    * @param g the graphics context to render to
 205:    */
 206:   void paint(Graphics g);
 207: }