001/* Caret.java -- 002 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.swing.text; 040 041import java.awt.Graphics; 042import java.awt.Point; 043 044import javax.swing.event.ChangeListener; 045 046/** 047 * Defines the method to be implemented by a caret that can be used in Swing 048 * text components. 049 * 050 * @author original author unknown 051 * @author Roman Kennke (roman@kennke.org) 052 */ 053public interface Caret 054{ 055 /** 056 * Registers a {@link ChangeListener} that is notified whenever that state 057 * of this <code>Caret</code> changes. 058 * 059 * @param l the listener to register to this caret 060 */ 061 void addChangeListener(ChangeListener l); 062 063 /** 064 * Removes a {@link ChangeListener} from the list of registered listeners. 065 * 066 * @param l the listener to remove 067 */ 068 void removeChangeListener(ChangeListener l); 069 070 /** 071 * Installs this <code>Caret</code> on the specified text component. This 072 * usually involves setting up listeners. 073 * 074 * This method is called by {@link JTextComponent#setCaret(Caret)} after 075 * this caret has been set on the text component. 076 * 077 * @param c the text component to install this caret to 078 */ 079 void install(JTextComponent c); 080 081 /** 082 * Deinstalls this <code>Caret</code> from the specified text component. 083 * This usually involves removing listeners from the text component. 084 * 085 * This method is called by {@link JTextComponent#setCaret(Caret)} before 086 * this caret is removed from the text component. 087 * 088 * @param c the text component to deinstall this caret from 089 */ 090 void deinstall(JTextComponent c); 091 092 /** 093 * Returns the blink rate of this <code>Caret</code> in milliseconds. 094 * A value of <code>0</code> means that the caret does not blink. 095 * 096 * @return the blink rate of this <code>Caret</code> or <code>0</code> if 097 * this caret does not blink 098 */ 099 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}