Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.3.0)

E17493-04


oracle.javatools.editor
Class BasicCaret

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.Rectangle
              extended by javax.swing.text.DefaultCaret
                  extended by oracle.javatools.editor.BasicCaret

All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.Shape, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.text.Caret
Direct Known Subclasses:
DragDropPlugin.DragCaret

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

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
static class BasicCaret.MiddleButtonBehavior
           

 

Nested classes/interfaces 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 int CARET_EDITOR_SELECTION_COLUMNS
          The type of editor selection which includes character obeying the following rules: 1 - The character between the line containing the first selection mark and the line containing the last selection mark (inclusive).
static java.lang.String CARET_EDITOR_SELECTION_TYPE
          The property name for the type of selection the editor (e.g.
static int CARET_EDITOR_SELECTION_WRAP
          The type of editor selection which runs from the very first character in the selection start to the very end containing all characters in between (inclusive).
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_RIGHT_CLICK_SELECTION
          The property name for whether right-click will position the caret when clicking outside of a selection.
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
ALWAYS_UPDATE, changeEvent, listenerList, NEVER_UPDATE, UPDATE_WHEN_ON_EDT

 

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

 

Constructor Summary
BasicCaret()
          Creates a new instance of the BasicCaret.

 

Method Summary
protected  void adjustCaretPosition(java.awt.event.MouseEvent event)
          Utility routine to adjust the caret position based on the given mouse event.
protected  void adjustVisibility(java.awt.Rectangle newRect)
          Scrolls the associated view (if necessary) to make the caret visible.
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.
protected  java.awt.Rectangle getCaretInsets(java.awt.Rectangle caretRect)
          Using the specified caretRectangle, fetch a new rectangle that includes the caret visible insets around it.
 EditorSelection getEditorSelection()
          The caret can work with different types of selection models.
 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 install(javax.swing.text.JTextComponent component)
          Called when the UI is being installed into the interface of a JTextComponent.
protected  boolean isPressInSelection(java.awt.event.MouseEvent event)
          Utility routine to check if the given mouse event is within the current selection.
 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 setDot(int dot)
          Sets the caret position and mark to some position.
 void setEditorSelection(EditorSelection newEditorSelection)
          Change the selection model used by this caret.
 void setInsertMode(boolean insertMode)
          Changes the caret mode between insert and overwrite mode.
 void toggleInsertMode()
          Toggles the current insert mode.
 void updateHighlight()
          Get the selection highlight to reapply it's highlighs

 

Methods inherited from class javax.swing.text.DefaultCaret
addChangeListener, equals, focusLost, getBlinkRate, getChangeListeners, getComponent, getDot, getDotBias, getListeners, getMagicCaretPosition, getMark, getMarkBias, getSelectionPainter, getUpdatePolicy, isActive, isSelectionVisible, isVisible, mouseEntered, mouseExited, mouseMoved, moveDot, removeChangeListener, repaint, setBlinkRate, setDot, setMagicCaretPosition, setSelectionVisible, setUpdatePolicy, 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

CARET_RIGHT_CLICK_SELECTION

public static final java.lang.String CARET_RIGHT_CLICK_SELECTION
The property name for whether right-click will position the caret when clicking outside of a selection. If true, right-click will position the caret when clicking outside the selection. If false, right-click will never position the caret if there is a selection.
See Also:
Constant Field Values

CARET_EDITOR_SELECTION_TYPE

public static final java.lang.String CARET_EDITOR_SELECTION_TYPE
The property name for the type of selection the editor (e.g. wrap, columns)
See Also:
Constant Field Values

CARET_EDITOR_SELECTION_WRAP

public static final int CARET_EDITOR_SELECTION_WRAP
The type of editor selection which runs from the very first character in the selection start to the very end containing all characters in between (inclusive). This constant indicates the use of EditorSelectionWrap
See Also:
Constant Field Values

CARET_EDITOR_SELECTION_COLUMNS

public static final int CARET_EDITOR_SELECTION_COLUMNS
The type of editor selection which includes character obeying the following rules: 1 - The character between the line containing the first selection mark and the line containing the last selection mark (inclusive). 2 - The character lies horizontally between the first and last selection marks. This constant indicates the use of EditorSelectionColumns
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
Overrides:
install in class javax.swing.text.DefaultCaret
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
Overrides:
deinstall in class javax.swing.text.DefaultCaret
Parameters:
component - the component

adjustVisibility

protected void adjustVisibility(java.awt.Rectangle newRect)
Scrolls the associated view (if necessary) to make the caret visible.
Overrides:
adjustVisibility in class javax.swing.text.DefaultCaret
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
Overrides:
setDot in class javax.swing.text.DefaultCaret
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
Overrides:
moveDot in class javax.swing.text.DefaultCaret
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.
Overrides:
fireStateChanged in class javax.swing.text.DefaultCaret

updateHighlight

public void updateHighlight()
Get the selection highlight to reapply it's highlighs

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.

Overrides:
moveCaret in class javax.swing.text.DefaultCaret
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.

Overrides:
positionCaret in class javax.swing.text.DefaultCaret
Parameters:
event - the mouse event

adjustCaretPosition

protected void adjustCaretPosition(java.awt.event.MouseEvent event)
Utility routine to adjust the caret position based on the given mouse event.
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

isPressInSelection

protected boolean isPressInSelection(java.awt.event.MouseEvent event)
Utility routine to check if the given mouse event is within the current selection.
Parameters:
event - the mouse event
Returns:
true if the mouse press occurred inside the selection

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
Overrides:
focusGained in class javax.swing.text.DefaultCaret
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.
Overrides:
damage in class javax.swing.text.DefaultCaret
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
Overrides:
paint in class javax.swing.text.DefaultCaret
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.

getEditorSelection

public EditorSelection getEditorSelection()
The caret can work with different types of selection models. e.g., Selections that wrap from line to line from beginning to end; or selections by column.
Returns:
The selection model

setEditorSelection

public void setEditorSelection(EditorSelection newEditorSelection)
Change the selection model used by this caret. The visible selection will be cleared as part of this opertaion. The EditorSelection will be queried via canSupportEditor() to determine if the selection type is suitable for the editor, if not then this method will make no change to the selection or selection type.
Parameters:
newEditorSelection -

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
Overrides:
mouseClicked in class javax.swing.text.DefaultCaret
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
Overrides:
mouseDragged in class javax.swing.text.DefaultCaret
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
Overrides:
mousePressed in class javax.swing.text.DefaultCaret
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
Overrides:
mouseReleased in class javax.swing.text.DefaultCaret
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.

getCaretInsets

protected java.awt.Rectangle getCaretInsets(java.awt.Rectangle caretRect)
Using the specified caretRectangle, fetch a new rectangle that includes the caret visible insets around it. If jump scrolling is enabled, then there are no caret visible insets.
Parameters:
caretRect - the caret rectangle
Returns:
a new rectangle that includes visible insets around the caretRect

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.3.0)

E17493-04


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