Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.text.DefaultCaret

java.lang.Object
  |
  +--com.sun.java.swing.text.DefaultCaret

public class DefaultCaret
extends java.lang.Object
implements Caret, java.io.Serializable, java.awt.event.FocusListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener
An implementation of Caret for a view that maps over the entire portion of the model represented (i.e. there are no holes in the area represented) and renders the insert position as a vertical line. The foreground color of the component is the color of the caret and the background color of the component is the color of the selections made by moving the caret. The Highlighter implementation of the associated UI is used to actually render the selection.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Caret, Serialized Form

Field Summary
ChangeEvent changeEvent
          The change event for the model.
EventListenerList listenerList
          The event listener list.
 
Constructor Summary
DefaultCaret()
          Constructs a default caret.
 
Method Summary
void addChangeListener(ChangeListener l)
          Adds a listener to track whenever the caret position has been changed.
void adjustVisibility(java.awt.Rectangle nloc)
          Scrolls the associated view (if necessary) to make the caret visible.
void damage(java.awt.Rectangle r)
          Damages the area surrounding the caret to cause it to be repainted.
void deinstall(JTextComponent c)
          Called when the UI is being removed from the interface of a JTextComponent.
void fireStateChanged()
          Notifies all listeners that have registered interest for notification on this event type.
void focusGained(java.awt.event.FocusEvent e)
          Called when the component containing the caret gains focus.
void focusLost(java.awt.event.FocusEvent e)
          Called when the component containing the caret loses focus.
int getBlinkRate()
          Gets the caret blink rate.
JTextComponent getComponent()
          Gets the editor component that this caret is for.
int getDot()
          Fetches the current position of the caret.
java.awt.Point getMagicCaretPosition()
          Gets the saved caret position.
int getMark()
          Fetches the current position of the mark.
Highlighter.HighlightPainter getSelectionPainter()
          Gets the painter for the Highlighter.
void install(JTextComponent c)
          Called when the UI is being installed into the interface of a JTextComponent.
boolean isSelectionVisible()
          Checks whether the current selection is visible.
boolean isVisible()
          Determines if the caret is currently visible.
void mouseClicked(java.awt.event.MouseEvent e)
          Called when the mouse is clicked.
void mouseDragged(java.awt.event.MouseEvent e)
          Moves the caret position according to the mouse pointer's current location.
void mouseEntered(java.awt.event.MouseEvent e)
          Called when the mouse enters a region.
void mouseExited(java.awt.event.MouseEvent e)
          Called when the mouse exits a region.
void mouseMoved(java.awt.event.MouseEvent e)
          Called when the mouse is moved.
void mousePressed(java.awt.event.MouseEvent e)
          Requests focus on the associated text component, and tries to set the cursor position.
void mouseReleased(java.awt.event.MouseEvent e)
          Called when the mouse is released.
void moveCaret(java.awt.event.MouseEvent e)
          Tries to move the position of the caret from the coordinates of a mouse event, using viewToModel().
void moveDot(int dot)
          Moves the caret position to some other position.
void paint(java.awt.Graphics g)
          Renders the caret as a vertical line.
void positionCaret(java.awt.event.MouseEvent e)
          Tries to set the position of the caret from the coordinates of a mouse event, using viewToModel().
void removeChangeListener(ChangeListener l)
          Removes a listener that was tracking caret position changes.
void setBlinkRate(int rate)
          Sets the caret blink rate.
void setDot(int dot)
          Sets the caret position and mark to some position.
void setMagicCaretPosition(java.awt.Point p)
          Saves the current caret position.
void setSelectionVisible(boolean vis)
          Changes the selection visibility.
void setVisible(boolean e)
          Sets the caret visibility, and repaints the caret.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
The event listener list.

changeEvent

protected ChangeEvent changeEvent
The change event for the model. Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".
Constructor Detail

DefaultCaret

public DefaultCaret()
Constructs a default caret.
Method Detail

getComponent

protected final JTextComponent getComponent()
Gets the editor component that this caret is for.
Returns:
the component

damage

protected void damage(java.awt.Rectangle r)
Damages the area surrounding the caret to cause it to be repainted. If paint() is reimplemented, this method should also be reimplemented.
Parameters:
r - the current location of the caret
See Also:
paint

adjustVisibility

protected void adjustVisibility(java.awt.Rectangle nloc)
Scrolls the associated view (if necessary) to make the caret visible. Since how this should be done is somewhat of a policy, this method can be reimplemented to change the behavior. By default the scrollRectToVisible method is called on the associated component.
Parameters:
nloc - the new position to scroll to

getSelectionPainter

protected Highlighter.HighlightPainter getSelectionPainter()
Gets the painter for the Highlighter.
Returns:
the painter

positionCaret

protected void positionCaret(java.awt.event.MouseEvent e)
Tries to set the position of the caret from the coordinates of a mouse event, using viewToModel().
Parameters:
e - the mouse event

moveCaret

protected void moveCaret(java.awt.event.MouseEvent e)
Tries to move the position of the caret from the coordinates of a mouse event, using viewToModel(). This will cause a selection if the dot and mark are different.
Parameters:
e - the mouse event

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Called when the component containing the caret gains focus. This is implemented to set the caret to visible if the component is editable, and sets the selection to visible.
Specified by:
focusGained(java.awt.event.FocusEvent) in interface java.awt.event.FocusListener
Parameters:
e - the focus event
See Also:
focusGained

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Called when the component containing the caret loses focus. This is implemented to set the caret to visibility to false, and to set the selection visibility to false.
Specified by:
focusLost(java.awt.event.FocusEvent) in interface java.awt.event.FocusListener
Parameters:
e - the focus event
See Also:
focusLost

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Called when the mouse is clicked. A double click selects a word, and a triple click the current line.
Specified by:
mouseClicked(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event
See Also:
mouseClicked

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Requests focus on the associated text component, and tries to set the cursor position.
Specified by:
mousePressed(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event
See Also:
mousePressed

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Called when the mouse is released.
Specified by:
mouseReleased(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event
See Also:
mouseReleased

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Called when the mouse enters a region.
Specified by:
mouseEntered(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event
See Also:
mouseEntered

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Called when the mouse exits a region.
Specified by:
mouseExited(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event
See Also:
mouseExited

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Moves the caret position according to the mouse pointer's current location. This effectively extends the selection.
Specified by:
mouseDragged(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse event
See Also:
mouseDragged

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Called when the mouse is moved.
Specified by:
mouseMoved(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse event
See Also:
mouseMoved

paint

public void paint(java.awt.Graphics g)
Renders the caret as a vertical line. If this is reimplemented the damage method should also be reimplemented as it assumes the shape of the caret is a vertical line. Sets the caret color to the value returned by getCaretColor().
Specified by:
paint in interface Caret
Parameters:
g - the graphics context
See Also:
damage

install

public void install(JTextComponent c)
Called when the UI is being installed into the interface of a JTextComponent. This can be used to gain access to the model that is being navigated by the implementation of this interface. Sets the dot and mark to 0, and establishes document, property change, focus, mouse, and mouse motion listeners.
Specified by:
install in interface Caret
Parameters:
c - the component
See Also:
install

deinstall

public void deinstall(JTextComponent c)
Called when the UI is being removed from the interface of a JTextComponent. This is used to unregister any listeners that were attached.
Specified by:
deinstall in interface Caret
Parameters:
c - the component
See Also:
deinstall

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a listener to track whenever the caret position has been changed.
Specified by:
addChangeListener in interface Caret
Parameters:
l - the listener
See Also:
addChangeListener

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a listener that was tracking caret position changes.
Specified by:
removeChangeListener in interface Caret
Parameters:
l - the listener
See Also:
removeChangeListener

fireStateChanged

protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method. The listener list is processed last to first.
See Also:
EventListenerList

setSelectionVisible

public void setSelectionVisible(boolean vis)
Changes the selection visibility.
Specified by:
setSelectionVisible in interface Caret
Parameters:
vis - the new visibility

isSelectionVisible

public boolean isSelectionVisible()
Checks whether the current selection is visible.
Specified by:
isSelectionVisible in interface Caret
Returns:
true if the selection is visible

isVisible

public boolean isVisible()
Determines if the caret is currently visible.
Specified by:
isVisible in interface Caret
Returns:
true if visible else false
See Also:
isVisible

setVisible

public void setVisible(boolean e)
Sets the caret visibility, and repaints the caret.
Specified by:
setVisible in interface Caret
Parameters:
e - the visibility specifier
See Also:
setVisible

setBlinkRate

public void setBlinkRate(int rate)
Sets the caret blink rate.
Specified by:
setBlinkRate in interface Caret
Parameters:
rate - the rate in milliseconds, 0 to stop blinking
See Also:
setBlinkRate

getBlinkRate

public int getBlinkRate()
Gets the caret blink rate.
Specified by:
getBlinkRate in interface Caret
See Also:
getBlinkRate

getDot

public int getDot()
Fetches the current position of the caret.
Specified by:
getDot in interface Caret
Returns:
the position >= 0
See Also:
getDot

getMark

public int getMark()
Fetches the current position of the mark. If there is a selection, the dot and mark will not be the same.
Specified by:
getMark in interface Caret
Returns:
the position >= 0
See Also:
getMark

setDot

public void setDot(int dot)
Sets the caret position and mark to some position. This implicitly sets the selection range to zero.
Specified by:
setDot in interface Caret
Parameters:
dot - the position >= 0
See Also:
setDot

moveDot

public void moveDot(int dot)
Moves the caret position to some other position.
Specified by:
moveDot in interface Caret
Parameters:
dot - the position >= 0
See Also:
moveDot

setMagicCaretPosition

public void setMagicCaretPosition(java.awt.Point p)
Saves the current caret position. This is used when caret up/down actions occur, moving between lines that have uneven end positions.
Specified by:
setMagicCaretPosition in interface Caret
Parameters:
p - the position
See Also:
getMagicCaretPosition, UpAction, DownAction

getMagicCaretPosition

public java.awt.Point getMagicCaretPosition()
Gets the saved caret position.
Specified by:
getMagicCaretPosition in interface Caret
Returns:
the position see #setMagicCaretPosition

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.