GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.Rectangle
javax.swing.text.DefaultCaret
public class DefaultCaret
extends Rectangle
implements Caret, FocusListener, MouseListener, MouseMotionListener
Caret
interface.
Nested Class Summary |
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D | |
Rectangle2D.Double , Rectangle2D.Float |
Field Summary | |
static int |
|
static int |
|
static int |
|
protected ChangeEvent |
|
protected EventListenerList |
|
Fields inherited from class java.awt.geom.Rectangle2D | |
OUT_BOTTOM , OUT_LEFT , OUT_RIGHT , OUT_TOP |
Constructor Summary | |
|
Method Summary | |
void |
|
protected void |
|
protected void | |
void |
|
|
|
protected void |
|
void |
|
void |
|
int |
|
ChangeListener[] |
|
protected JTextComponent |
|
int |
|
Point |
|
int |
|
protected Highlighter.HighlightPainter |
|
int |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
protected void |
|
void |
|
void | |
protected void |
|
void |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.awt.Rectangle | |
add , add , add , contains , contains , contains , contains , createIntersection , createUnion , equals , getBounds , getBounds2D , getHeight , getLocation , getSize , getWidth , getX , getY , grow , inside , intersection , intersects , isEmpty , move , outcode , reshape , resize , setBounds , setBounds , setLocation , setLocation , setRect , setSize , setSize , toString , translate , union |
Methods inherited from class java.awt.geom.Rectangle2D | |
add , add , add , contains , contains , createIntersection , createUnion , equals , getBounds2D , getPathIterator , getPathIterator , hashCode , intersect , intersects , intersectsLine , intersectsLine , outcode , outcode , setFrame , setRect , setRect , union |
Methods inherited from class java.awt.geom.RectangularShape | |
clone , contains , contains , getBounds , getCenterX , getCenterY , getFrame , getHeight , getMaxX , getMaxY , getMinX , getMinY , getPathIterator , getWidth , getX , getY , intersects , isEmpty , setFrame , setFrame , setFrame , setFrameFromCenter , setFrameFromCenter , setFrameFromDiagonal , setFrameFromDiagonal |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final int ALWAYS_UPDATE
Indicates the Caret position should always be updated after Document changes even if the updates are not performed on the Event Dispatching thread.
- Field Value:
- 2
- Since:
- 1.5
public static final int NEVER_UPDATE
Indicates the Caret position should not be changed unless the Document length becomes less than the Caret position, in which case the Caret is moved to the end of the Document.
- Field Value:
- 1
- Since:
- 1.5
public static final int UPDATE_WHEN_ON_EDT
Indicates the Caret position should be updated only if Document changes are made on the Event Dispatcher thread.
- Field Value:
- 0
- Since:
- 1.5
public void addChangeListener(ChangeListener listener)
Registers aChangeListener
that is notified whenever that state of thisCaret
changes.
- Specified by:
- addChangeListener in interface Caret
- Parameters:
listener
- the listener to register to this caret
protected void adjustVisibility(Rectangle rect)
Adjusts the text component so that the caret is visible. This default implementation simply callsJComponent.scrollRectToVisible(Rectangle)
on the text component. Subclasses may wish to change this.
protected void damage(Rectangle r)
Updates the carets rectangle properties to the specified rectangle and repaints the caret.
- Parameters:
r
- the rectangle to set as the caret rectangle
public void deinstall(JTextComponent c)
Deinstalls thisCaret
from the specifiedJTextComponent
. This removes any listeners that have been registered by thisCaret
.
- Parameters:
c
- the text component from which to install this caret
publicextends EventListener> T[] getListeners(Class listenerType)
Returns all registered event listeners of the specified type.
- Parameters:
listenerType
- the type of listener to return
- Returns:
- all registered event listeners of the specified type
protected void fireStateChanged()
Notifies all registeredChangeListener
s that the state of thisCaret
has changed.
public void focusGained(FocusEvent event)
Sets the caret tovisible
if the text component is editable.
- Specified by:
- focusGained in interface FocusListener
- Parameters:
event
- theFocusEvent
public void focusLost(FocusEvent event)
Sets the caret toinvisible
.
- Specified by:
- focusLost in interface FocusListener
- Parameters:
event
- theFocusEvent
public int getBlinkRate()
Returns the blink rate of thisCaret
in milliseconds. A value of0
means that the caret does not blink.
- Specified by:
- getBlinkRate in interface Caret
- Returns:
- the blink rate of this
Caret
or0
if this caret does not blink
public ChangeListener[] getChangeListeners()
Returns all registeredChangeListener
s of thisCaret
.
- Returns:
- all registered
ChangeListener
s of thisCaret
protected final JTextComponent getComponent()
Returns theJTextComponent
on which thisCaret
is installed.
- Returns:
- the
JTextComponent
on which thisCaret
is installed
public int getDot()
Returns the current position of thisCaret
within theDocument
.
- Returns:
- the current position of this
Caret
within theDocument
public Point getMagicCaretPosition()
Returns the current visual position of thisCaret
.
- Specified by:
- getMagicCaretPosition in interface Caret
- Returns:
- the current visual position of this
Caret
- See Also:
setMagicCaretPosition(Point)
public int getMark()
Returns the current position of themark
. Themark
marks the location in theDocument
that is the end of a selection. If there is no selection, themark
is the same as thedot
.
- Returns:
- the current position of the mark
protected Highlighter.HighlightPainter getSelectionPainter()
Returns theHighlighter.HighlightPainter
that should be used to paint the selection.
- Returns:
- the
Highlighter.HighlightPainter
that should be used to paint the selection
public int getUpdatePolicy()
Gets the caret update policy.
- Returns:
- the caret update policy.
- Since:
- 1.5
public void install(JTextComponent c)
Installs thisCaret
on the specifiedJTextComponent
. This registers a couple of listeners on the text component.
- Parameters:
c
- the text component on which to install this caret
public boolean isActive()
Returnstrue
if thisCaret
is blinking, andfalse
if not. The returned value is independent of the visiblity of thisCaret
as returned byisVisible()
.
- Returns:
true
if thisCaret
is blinking, andfalse
if not.
- Since:
- 1.5
- See Also:
isVisible()
public boolean isSelectionVisible()
Returnstrue
if the selection is currently visible,false
otherwise.
- Specified by:
- isSelectionVisible in interface Caret
- Returns:
true
if the selection is currently visible,false
otherwise
public boolean isVisible()
Returnstrue
if thisCaret
is currently visible, andfalse
if it is not.
- Returns:
true
if thisCaret
is currently visible, andfalse
if it is not
public void mouseClicked(MouseEvent event)
When the click is received from Button 1 then the following actions are performed here:
- If we receive a double click, the caret position (dot) is set to the position associated to the mouse click and the word at this location is selected. If there is no word at the pointer the gap is selected instead.
- If we receive a triple click, the caret position (dot) is set to the position associated to the mouse click and the line at this location is selected.
- Specified by:
- mouseClicked in interface MouseListener
- Parameters:
event
- theMouseEvent
describing the click operation
public void mouseDragged(MouseEvent event)
Moves the caret position when the mouse is dragged over the text component, modifying the selectiony. When the text component where the caret is installed is disabled, the selection is not change but you can still scroll the text and update the caret's location.
- Specified by:
- mouseDragged in interface MouseMotionListener
- Parameters:
event
- theMouseEvent
describing the drag operation
public void mouseEntered(MouseEvent event)
Indicates that the mouse has entered the text component. Nothing is done here.
- Specified by:
- mouseEntered in interface MouseListener
- Parameters:
event
- theMouseEvent
describing the mouse operation
public void mouseExited(MouseEvent event)
Indicates that the mouse has exited the text component. Nothing is done here.
- Specified by:
- mouseExited in interface MouseListener
- Parameters:
event
- theMouseEvent
describing the mouse operation
public void mouseMoved(MouseEvent event)
Indicates a mouse movement over the text component. Does nothing here.
- Specified by:
- mouseMoved in interface MouseMotionListener
- Parameters:
event
- theMouseEvent
describing the mouse operation
public void mousePressed(MouseEvent event)
If the button 1 is pressed, the caret position is updated to the position of the mouse click and the text component requests the input focus if it is enabled. If the SHIFT key is held down, the caret will be moved, which might select the text between the old and new location.
- Specified by:
- mousePressed in interface MouseListener
- Parameters:
event
- theMouseEvent
describing the press operation
public void mouseReleased(MouseEvent event)
Indicates that a mouse button has been released on the text component. Nothing is done here.
- Specified by:
- mouseReleased in interface MouseListener
- Parameters:
event
- theMouseEvent
describing the mouse operation
protected void moveCaret(MouseEvent event)
Moves the caret to the position specified in theMouseEvent
. This will cause a selection if the dot and mark are different.
- Parameters:
event
- theMouseEvent
from which to fetch the position
public void moveDot(int dot)
Moves thedot
location without touching themark
. This is used when making a selection. If the underlying text component has aNavigationFilter
installed the caret will call the corresponding method of that object.
- Parameters:
dot
- the location where to move the dot
- See Also:
setDot(int)
public void paint(Graphics g)
Paints thisCaret
using the specifiedGraphics
context.
- Parameters:
g
- the graphics context to use
protected void positionCaret(MouseEvent event)
Repositions the caret to the position specified in theMouseEvent
.
- Parameters:
event
- theMouseEvent
from which to fetch the position
public void removeChangeListener(ChangeListener listener)
Removes aChangeListener
from the list of registered listeners.
- Specified by:
- removeChangeListener in interface Caret
- Parameters:
listener
- the listener to remove
public void setBlinkRate(int rate)
Sets the blink rate of thisCaret
in milliseconds. A value of0
means that the caret does not blink.
- Specified by:
- setBlinkRate in interface Caret
- Parameters:
rate
- the new blink rate to set
public void setDot(int dot)
Sets the current position of thisCaret
within theDocument
. This also sets themark
to the new location. If the underlying text component has aNavigationFilter
installed the caret will call the corresponding method of that object.
- Parameters:
dot
- the new position to be set
- See Also:
moveDot(int)
public void setMagicCaretPosition(Point p)
Sets the current visual position of thisCaret
.
- Specified by:
- setMagicCaretPosition in interface Caret
- Parameters:
p
- the Point to use for the saved location. May benull
to indicate that there is no visual location
public void setSelectionVisible(boolean v)
Sets the visiblity state of the selection.
- Specified by:
- setSelectionVisible in interface Caret
- Parameters:
v
-true
if the selection should be visible,false
otherwise
public void setUpdatePolicy(int policy)
Sets the Caret update policy.
- Parameters:
policy
- the new policy. Valid values are: ALWAYS_UPDATE: always update the Caret position, even when Document updates don't occur on the Event Dispatcher thread. NEVER_UPDATE: don't update the Caret position unless the Document length becomes less than the Caret position (then update the Caret to the end of the Document). UPDATE_WHEN_ON_EDT: update the Caret position when the Document updates occur on the Event Dispatcher thread. This is the default.
- Throws:
IllegalArgumentException
- if policy is not one of the above.
- Since:
- 1.5
public void setVisible(boolean v)
Sets the visibility state of the caret.true
shows theCaret
,false
hides it.
- Specified by:
- setVisible in interface Caret
- Parameters:
v
- the visibility to set
GNU Classpath (0.95) |