edu.stanford.nlp.swing
Class SmartCaret

java.lang.Object
  extended byjava.awt.geom.RectangularShape
      extended byjava.awt.geom.Rectangle2D
          extended byjava.awt.Rectangle
              extended byjavax.swing.text.DefaultCaret
                  extended byedu.stanford.nlp.swing.SmartCaret
All Implemented Interfaces:
Caret, Cloneable, EventListener, FocusListener, MouseListener, MouseMotionListener, Serializable, Shape

public class SmartCaret
extends DefaultCaret

Caret that implements smart-drag-selection ala MS Word. To use this with a JTextComponent, call setCaret.

TODO:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 
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
SmartCaret()
           
 
Method Summary
protected  void moveCaret(MouseEvent e)
          Moves the caret to an appropriate position based on the drag event.
 int nextWordStartAfter(int pos, String text)
           
protected  void positionCaret(MouseEvent e)
          Records original caret position and next word boundary.
 
Methods inherited from class javax.swing.text.DefaultCaret
addChangeListener, adjustVisibility, damage, deinstall, equals, fireStateChanged, focusGained, focusLost, getBlinkRate, getChangeListeners, getComponent, getDot, getListeners, getMagicCaretPosition, getMark, getSelectionPainter, install, isSelectionVisible, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, moveDot, paint, removeChangeListener, repaint, setBlinkRate, setDot, 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
 

Constructor Detail

SmartCaret

public SmartCaret()
Method Detail

moveCaret

protected void moveCaret(MouseEvent e)
Moves the caret to an appropriate position based on the drag event. If the selection started in the middle of a word and the caret gets dragged past the beginning of the next word, the selection is extended back to include all of the original word. At this point forward selection happens a word at a time, i.e. once a word is partially selected, it becomes completely selected. This can be undone by moving the caret backwards.


positionCaret

protected void positionCaret(MouseEvent e)
Records original caret position and next word boundary.


nextWordStartAfter

public int nextWordStartAfter(int pos,
                              String text)


Stanford NLP Group