com.borland.primetime.editor
Class EditorCaret

java.lang.Object
  |
  +--java.awt.geom.RectangularShape
        |
        +--java.awt.geom.Rectangle2D
              |
              +--java.awt.Rectangle
                    |
                    +--javax.swing.text.DefaultCaret
                          |
                          +--com.borland.primetime.editor.EditorCaret
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.io.Serializable, java.awt.Shape

public class EditorCaret
extends javax.swing.text.DefaultCaret
implements java.awt.event.FocusListener, java.awt.event.MouseListener

This is our custom Caret, derived from DefaultCaret. A number of things were added or altered from the default implementation:

See Also:
javax.swing.DefaultCaret, Serialized Form

Inner classes inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
protected static javax.swing.text.Highlighter.HighlightPainter noHighlightPainter
          We don't use the built-in highlighter support, so we use this static instance of a HighlightPainter that doesn't actually paint.
protected  int pressClickCount
           
 
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
 
Constructor Summary
EditorCaret()
          Constructs a new EditorCaret.
 
Method Summary
protected  void damage(java.awt.Rectangle r)
          Damages the area surrounding the caret to cause it to be repainted in a new location.
protected  void fireStateChanged()
          This method is called whenever the caret position changes.
 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.
protected  javax.swing.text.Highlighter.HighlightPainter getSelectionPainter()
          Gets the painter for the Highlighter.
 void mouseClicked(java.awt.event.MouseEvent e)
          Called when the mouse is clicked.
 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 mousePressed(java.awt.event.MouseEvent e)
          We've overridden this method to do a number of things, depending on the situation: If the associated component is enabled, request focus for it. If the left button was pressed with no modifiers, set the caret position. If the left button was pressed with the SHIFT key held down, move the caret, effectively extending the selection. If left button was double-clicked, select a word. If left button was triple-clicked, select the line. If the right mouse button was clicked outside of the selection, set the caret position. If the right mouse button was clicked within the selection, do nothing.
 void mouseReleased(java.awt.event.MouseEvent e)
          Called when the mouse is released.
 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 setDot(int dot)
          Sets the caret position and mark to some position.
 
Methods inherited from class javax.swing.text.DefaultCaret
addChangeListener, adjustVisibility, deinstall, equals, getBlinkRate, getComponent, getDot, getListeners, getMagicCaretPosition, getMark, install, isSelectionVisible, isVisible, mouseDragged, mouseMoved, moveCaret, positionCaret, 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

noHighlightPainter

protected static javax.swing.text.Highlighter.HighlightPainter noHighlightPainter
We don't use the built-in highlighter support, so we use this static instance of a HighlightPainter that doesn't actually paint.

pressClickCount

protected int pressClickCount
Constructor Detail

EditorCaret

public EditorCaret()
Constructs a new EditorCaret.
Method Detail

damage

protected void damage(java.awt.Rectangle r)
Damages the area surrounding the caret to cause it to be repainted in a new location. If paint() is reimplemented, this method should also be reimplemented. This method should update the caret bounds (x, y, width, and height).
Overrides:
damage in class javax.swing.text.DefaultCaret
Parameters:
r - the current location of the caret
See Also:
paint(java.awt.Graphics)

getSelectionPainter

protected javax.swing.text.Highlighter.HighlightPainter getSelectionPainter()
Gets the painter for the Highlighter.
Overrides:
getSelectionPainter in class javax.swing.text.DefaultCaret
Returns:
the painter

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Called when the component containing the caret gains focus. We override the default implementation of this method, because we want the caret to be visible even if the component is not editable.
Specified by:
focusGained in interface java.awt.event.FocusListener
Overrides:
focusGained in class javax.swing.text.DefaultCaret
Parameters:
e - the focus event
See Also:
FocusListener.focusGained(java.awt.event.FocusEvent)

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 visibility to false.
Specified by:
focusLost in interface java.awt.event.FocusListener
Overrides:
focusLost in class javax.swing.text.DefaultCaret
Parameters:
e - the focus event
See Also:
FocusListener.focusLost(java.awt.event.FocusEvent)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Called when the mouse is clicked.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Overrides:
mouseClicked in class javax.swing.text.DefaultCaret
Parameters:
e - the mouse event
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
We've overridden this method to do a number of things, depending on the situation:
Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class javax.swing.text.DefaultCaret
Parameters:
e - the mouse event
See Also:
MouseListener.mousePressed(java.awt.event.MouseEvent)

mouseReleased

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

mouseEntered

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

mouseExited

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

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().

If there are multiple text directions present in the associated document, a flag indicating the caret bias will be rendered. This will occur only if the associated document is a subclass of AbstractDocument and there are multiple bidi levels present in the bidi element structure (i.e. the text has multiple directions associated with it).

Overrides:
paint in class javax.swing.text.DefaultCaret
Parameters:
g - the graphics context
See Also:
damage(java.awt.Rectangle)

setDot

public void setDot(int dot)
Sets the caret position and mark to some position. This implicitly sets the selection range to zero.
Overrides:
setDot in class javax.swing.text.DefaultCaret
Parameters:
dot - the position >= 0
See Also:
Caret.setDot(int)

moveDot

public void moveDot(int dot)
Moves the caret position to some other position.
Overrides:
moveDot in class javax.swing.text.DefaultCaret
Parameters:
dot - the position >= 0
See Also:
Caret.moveDot(int)

fireStateChanged

protected void fireStateChanged()
This method is called whenever the caret position changes. We take this opportunity to clear the magic caret position.
Overrides:
fireStateChanged in class javax.swing.text.DefaultCaret
See Also:
DefaultCaret.fireStateChanged()