Extension SDK 10.1.2

oracle.javatools.editor
Class BasicCaret

java.lang.Object
  extended byjava.awt.geom.RectangularShape
      extended byjava.awt.geom.Rectangle2D
          extended byjava.awt.Rectangle
              extended byjavax.swing.text.DefaultCaret
                  extended byoracle.javatools.editor.BasicCaret
All Implemented Interfaces:
javax.swing.text.Caret, java.lang.Cloneable, java.util.EventListener, java.awt.event.FocusListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener, java.io.Serializable, java.awt.Shape, TextBufferListener
Direct Known Subclasses:
DragDropPlugin.DragCaret

public class BasicCaret
extends javax.swing.text.DefaultCaret
implements java.beans.PropertyChangeListener, TextBufferListener

A BasicCaret extends the DefaultCaret to modify the default behavior about the visibility of the selection, and other extra features.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
static java.lang.String CARET_BLINK_RATE
          The property name for the blink rate of the caret.
static java.lang.String CARET_COLOR
          The property name for the color of the caret.
static int CARET_DOUBLE_UNDER_BAR
          The constant for the double-thickness under bar caret shape.
static int CARET_DOUBLE_VERTICAL_BAR
          The constant for the double-thickness vertical bar caret shape.
static java.lang.String CARET_ENABLE_BLINK
          The property name for whether the caret should blink.
static int CARET_OUTLINE_BOX
          The constant for the outline box caret shape.
static int CARET_QUAD_UNDER_BAR
          The constant for the quad-thickness under bar caret shape.
static int CARET_QUAD_VERTICAL_BAR
          The constant for the quad-thickness vertical bar caret shape.
static java.lang.String CARET_SHAPE_INSERT
          The property name for the caret shape in insert mode.
static java.lang.String CARET_SHAPE_OVERWRITE
          The property name for the caret shape in ovewrite mode.
static int CARET_SOLID_BOX
          The constant for the solid box caret shape.
static int CARET_TRIPLE_UNDER_BAR
          The constant for the triple-thickness under bar caret shape.
static int CARET_TRIPLE_VERTICAL_BAR
          The constant for the triple-thickness vertical bar caret shape.
static int CARET_UNDER_BAR
          The constant for the single-thickness under bar caret shape.
static int CARET_VERTICAL_BAR
          The constant for the single-thickness vertical bar caret shape.
static java.lang.String CARET_XOR_PAINTING
          The property name for whether the caret should use xor painting or regular painting.
static java.lang.String HIGHLIGHT_SELECTION_NAME
          The name of the selection highlight style.
protected  int lastClickCount
          Stores the click count from the last mousePressed event.
protected  int lastClickOffset
          Stores the offset from the first mousePressed event.
 
Fields inherited from class javax.swing.text.DefaultCaret
changeEvent, listenerList
 
Fields inherited from class java.awt.Rectangle
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Fields inherited from interface oracle.javatools.buffer.TextBufferListener
EOL_TYPE_ATTRIBUTE, MODIFIED_ATTRIBUTE, READ_ONLY_ATTRIBUTE, RELOAD_END_ATTRIBUTE, RELOAD_START_ATTRIBUTE
 
Constructor Summary
BasicCaret()
          Creates a new instance of the BasicCaret.
 
Method Summary
protected  void adjustVisibility(java.awt.Rectangle newRect)
          Scrolls the associated view (if necessary) to make the caret visible.
 void attributeUpdate(int attribute)
          Provides notification regarding a change to one of the buffer attributes.
protected  void damage(java.awt.Rectangle r)
          This damages the area surrounding the caret to cause it to be repainted in the a new location.
 void deinstall(javax.swing.text.JTextComponent component)
          Called when the UI is being removed from the interface of a JTextComponent.
protected  void fireStateChanged()
          Notifies all listeners that have registered interest for notification on this event type.
 void focusGained(java.awt.event.FocusEvent event)
          Called when the component containing the caret gains focus.
 ActionInvoker getActionInvoker()
          Fetches the action invoker to use to execute some particular action.
 boolean getInsertMode()
          Fetches whether the caret is currently in insert mode or overwrite mode.
protected  int getOffsetForMouseEvent(java.awt.event.MouseEvent event)
          Utility routine to fetch the editor offset most closely associated with an X-Y point in the given mouse event.
 void insertUpdate(int offset, int count, char[] insertedData)
          Provides notification about an insertion into the text buffer.
 void install(javax.swing.text.JTextComponent component)
          Called when the UI is being installed into the interface of a JTextComponent.
 void mouseClicked(java.awt.event.MouseEvent event)
          Called when the mouse is clicked.
 void mouseDragged(java.awt.event.MouseEvent event)
          Invoked when the mouse button has been pressed and dragged.
 void mousePressed(java.awt.event.MouseEvent event)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(java.awt.event.MouseEvent event)
          Invoked when a mouse button has been released on a component.
protected  void moveCaret(java.awt.event.MouseEvent event)
          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)
          Paints the caret.
protected  void positionCaret(java.awt.event.MouseEvent event)
          Tries to set the position of the caret from the coordinates of a mouse event, using viewToModel().
 void propertyChange(java.beans.PropertyChangeEvent event)
          This method gets called when a bound property is changed.
 void removeUpdate(int offset, int count, char[] removedData)
          Provides notification about a removal from the text buffer.
 void setDot(int dot)
          Sets the caret position and mark to some position.
 void setInsertMode(boolean insertMode)
          Changes the caret mode between insert and overwrite mode.
 void toggleInsertMode()
          Toggles the current insert mode.
 
Methods inherited from class javax.swing.text.DefaultCaret
addChangeListener, equals, focusLost, getBlinkRate, getChangeListeners, getComponent, getDot, getListeners, getMagicCaretPosition, getMark, getSelectionPainter, isSelectionVisible, isVisible, mouseEntered, mouseExited, mouseMoved, removeChangeListener, repaint, setBlinkRate, setMagicCaretPosition, setSelectionVisible, setVisible, toString
 
Methods inherited from class java.awt.Rectangle
add, add, add, contains, contains, contains, contains, createIntersection, createUnion, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, translate, union
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
 

Field Detail

CARET_VERTICAL_BAR

public static final int CARET_VERTICAL_BAR
The constant for the single-thickness vertical bar caret shape.

See Also:
Constant Field Values

CARET_DOUBLE_VERTICAL_BAR

public static final int CARET_DOUBLE_VERTICAL_BAR
The constant for the double-thickness vertical bar caret shape.

See Also:
Constant Field Values

CARET_TRIPLE_VERTICAL_BAR

public static final int CARET_TRIPLE_VERTICAL_BAR
The constant for the triple-thickness vertical bar caret shape.

See Also:
Constant Field Values

CARET_QUAD_VERTICAL_BAR

public static final int CARET_QUAD_VERTICAL_BAR
The constant for the quad-thickness vertical bar caret shape.

See Also:
Constant Field Values

CARET_UNDER_BAR

public static final int CARET_UNDER_BAR
The constant for the single-thickness under bar caret shape.

See Also:
Constant Field Values

CARET_DOUBLE_UNDER_BAR

public static final int CARET_DOUBLE_UNDER_BAR
The constant for the double-thickness under bar caret shape.

See Also:
Constant Field Values

CARET_TRIPLE_UNDER_BAR

public static final int CARET_TRIPLE_UNDER_BAR
The constant for the triple-thickness under bar caret shape.

See Also:
Constant Field Values

CARET_QUAD_UNDER_BAR

public static final int CARET_QUAD_UNDER_BAR
The constant for the quad-thickness under bar caret shape.

See Also:
Constant Field Values

CARET_OUTLINE_BOX

public static final int CARET_OUTLINE_BOX
The constant for the outline box caret shape.

See Also:
Constant Field Values

CARET_SOLID_BOX

public static final int CARET_SOLID_BOX
The constant for the solid box caret shape.

See Also:
Constant Field Values

CARET_SHAPE_INSERT

public static final java.lang.String CARET_SHAPE_INSERT
The property name for the caret shape in insert mode.

See Also:
Constant Field Values

CARET_SHAPE_OVERWRITE

public static final java.lang.String CARET_SHAPE_OVERWRITE
The property name for the caret shape in ovewrite mode.

See Also:
Constant Field Values

CARET_ENABLE_BLINK

public static final java.lang.String CARET_ENABLE_BLINK
The property name for whether the caret should blink.

See Also:
Constant Field Values

CARET_BLINK_RATE

public static final java.lang.String CARET_BLINK_RATE
The property name for the blink rate of the caret.

See Also:
Constant Field Values

CARET_COLOR

public static final java.lang.String CARET_COLOR
The property name for the color of the caret.

See Also:
Constant Field Values

CARET_XOR_PAINTING

public static final java.lang.String CARET_XOR_PAINTING
The property name for whether the caret should use xor painting or regular painting. XOR painting does not work on some platforms it seems (Macintosh.)

See Also:
Constant Field Values

lastClickCount

protected int lastClickCount
Stores the click count from the last mousePressed event. This is so that we can support word boundaries in the mouseDragged.


lastClickOffset

protected int lastClickOffset
Stores the offset from the first mousePressed event. This is so that if we do a double-click, then drag, we can reverse directions properly.


HIGHLIGHT_SELECTION_NAME

public static final java.lang.String HIGHLIGHT_SELECTION_NAME
The name of the selection highlight style.

See Also:
Constant Field Values
Constructor Detail

BasicCaret

public BasicCaret()
Creates a new instance of the BasicCaret.

Method Detail

install

public void install(javax.swing.text.JTextComponent component)
Called when the UI is being installed into the interface of a JTextComponent.

Specified by:
install in interface javax.swing.text.Caret
Parameters:
component - the component

deinstall

public void deinstall(javax.swing.text.JTextComponent component)
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 javax.swing.text.Caret
Parameters:
component - the component

adjustVisibility

protected void adjustVisibility(java.awt.Rectangle newRect)
Scrolls the associated view (if necessary) to make the caret visible.

Parameters:
newRect - the new position to make visible

setDot

public void setDot(int dot)
Sets the caret position and mark to some position. This implicitly sets the selection range to zero. We override this in order to clear the magic column (as the JavaDoc comments in DefaultCaret indicates, but doesn't implement.)

Specified by:
setDot in interface javax.swing.text.Caret
Parameters:
dot - the position >= 0

moveDot

public void moveDot(int dot)
Moves the caret position to some other position.

Specified by:
moveDot in interface javax.swing.text.Caret
Parameters:
dot - the position >= 0

fireStateChanged

protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. We override this here in order to trap changes to the dot or mark for doing selection highlighting using the HighlightLayer facilities.


getActionInvoker

public ActionInvoker getActionInvoker()
Fetches the action invoker to use to execute some particular action.

Returns:
the action invoker

moveCaret

protected void moveCaret(java.awt.event.MouseEvent event)
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.

We override the default behavior here to take into account whether we are in insert or overwrite mode. If in insert mode, if the user clicks in the right side of a letter, the cursor will go to the right of the letter.

Parameters:
event - the mouse event

positionCaret

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

We override the default behavior here to take into account whether we are in insert or overwrite mode. If in insert mode, if the user clicks in the right side of a letter, the cursor will go to the right of the letter.

Parameters:
event - the mouse event

getOffsetForMouseEvent

protected int getOffsetForMouseEvent(java.awt.event.MouseEvent event)
Utility routine to fetch the editor offset most closely associated with an X-Y point in the given mouse event.

Parameters:
event - the mouse event that occurred
Returns:
the closest editor offset

focusGained

public void focusGained(java.awt.event.FocusEvent event)
Called when the component containing the caret gains focus. This is implemented to set the caret to visible if the component is editable.

Overriding default behavior so that the caret is visible even if the buffer is read only.

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
event - the focus event
See Also:
FocusListener.focusGained(java.awt.event.FocusEvent)

damage

protected void damage(java.awt.Rectangle r)
This damages the area surrounding the caret to cause it to be repainted in the a new location.

Parameters:
r - the current location of the caret

paint

public void paint(java.awt.Graphics g)
Paints the caret. This overrides the paint method in DefaultCaret to handle the overwrite mode case, where we paint the cursor as a block.

Specified by:
paint in interface javax.swing.text.Caret
Parameters:
g - the graphics context

getInsertMode

public boolean getInsertMode()
Fetches whether the caret is currently in insert mode or overwrite mode.

Returns:
true if in insert mode

setInsertMode

public void setInsertMode(boolean insertMode)
Changes the caret mode between insert and overwrite mode.

Parameters:
insertMode - true if setting in insert mode

toggleInsertMode

public void toggleInsertMode()
Toggles the current insert mode.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Called when the mouse is clicked. If the click was generated from button1, a double click selects a word, and a triple click the current line. Override this so that it uses our actions.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - the mouse event
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Invoked when the mouse button has been pressed and dragged. We override this so that we can support dragging over word or line increments.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
event - the mouse drag event

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Invoked when a mouse button has been pressed on a component. We override the mousePressed() method of the super class to check for whether a popup menu was requested.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
event - the mouse event that occurred

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Invoked when a mouse button has been released on a component. We override the mousePressed() method of the super class to check for whether a popup menu was requested.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
event - the mouse event that occurred

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - A PropertyChangeEvent object describing the event source and the property that has changed.

insertUpdate

public void insertUpdate(int offset,
                         int count,
                         char[] insertedData)
Provides notification about an insertion into the text buffer.

Specified by:
insertUpdate in interface TextBufferListener
Parameters:
offset - the offset where the insert took place
count - the number of characters inserted (insertedData.length)
insertedData - the contents of the insertion

removeUpdate

public void removeUpdate(int offset,
                         int count,
                         char[] removedData)
Provides notification about a removal from the text buffer.

Specified by:
removeUpdate in interface TextBufferListener
Parameters:
offset - the offset where the removal took place
count - the number of characters removed (removedData.length)
removedData - the contents of the removal

attributeUpdate

public void attributeUpdate(int attribute)
Provides notification regarding a change to one of the buffer attributes. The possible attributes are defined in this interface.

Specified by:
attributeUpdate in interface TextBufferListener
Parameters:
attribute - the attribute that changed

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.