edu.stanford.nlp.swing
Class SmartCaret
java.lang.Object
java.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.Rectangle
javax.swing.text.DefaultCaret
edu.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:
- shift-click select shouldn't select whole word, only drag-select
- retreating selection should revert to char-by-char mode
- ...but after moving past next word, go back to full word mode
- backwards selection should work like forwards selection
- starting in the middle of whitespace should select back to prev word
- See Also:
- Serialized Form
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 |
SmartCaret
public SmartCaret()
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