public class BaseCaret extends Object implements Caret, MouseListener, MouseMotionListener, PropertyChangeListener, DocumentListener, ActionListener, AtomicLockListener, FoldHierarchyListener
Modifier and Type | Field and Description |
---|---|
protected Font |
afterCaretFont
Font of the text underlying the caret.
|
protected Font |
beforeCaretFont
Font of the text right before the caret
|
static String |
BLOCK_CARET
Caret type representing block covering current character
|
protected ChangeEvent |
changeEvent
Change event.
|
protected JTextComponent |
component
Component this caret is bound to
|
protected char[] |
dotChar
Dot array of one character under caret
|
protected Timer |
flasher
Timer used for blinking the caret
|
static String |
LINE_CARET
Default caret type
|
protected EventListenerList |
listenerList
Listeners
|
protected Color |
textBackColor
Background color of the text underlying the caret.
|
protected Color |
textForeColor
Foreground color of the text underlying the caret.
|
static String |
THICK_LINE_CARET |
static String |
THIN_LINE_CARET
One dot thin line compatible with Swing default caret
|
Constructor and Description |
---|
BaseCaret() |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent evt)
Fired when blink timer fires
|
void |
addChangeListener(ChangeListener l)
Adds listener to track when caret position was changed
|
void |
atomicLock(AtomicLockEvent evt) |
void |
atomicUnlock(AtomicLockEvent evt) |
void |
changedUpdate(DocumentEvent evt) |
void |
deinstall(JTextComponent c)
Called when UI is being removed from JTextComponent
|
boolean |
equals(Object o)
Redefine to Object.equals() to prevent defaulting to Rectangle.equals()
which would cause incorrect firing
|
void |
extendRectangularSelection(boolean toRight,
boolean ctrl)
Extend rectangular selection either by char in a specified selection
or by word (if ctrl is pressed).
|
protected void |
fireStateChanged()
Notifies listeners that caret position has changed
|
void |
foldHierarchyChanged(FoldHierarchyEvent evt)
Deprecated.
|
int |
getBlinkRate()
Returns blink rate of the caret or 0 if caret doesn't blink
|
int |
getDot()
Gets the current position of the caret
|
protected JComponent |
getEventComponent(MouseEvent e) |
Point |
getMagicCaretPosition()
Get position used to mark begining of the selected block
|
int |
getMark()
Gets the current position of the selection mark.
|
int |
hashCode() |
void |
insertUpdate(DocumentEvent evt) |
void |
install(JTextComponent c)
Called when UI is being installed into JTextComponent
|
protected boolean |
isDragPossible(MouseEvent e)
Determines if the following are true:
the press event is located over a selection
the dragEnabled property is true
A TranferHandler is installed
|
boolean |
isSelectionVisible()
Is the selection visible?
|
boolean |
isVisible()
Whether the caret currently visible.
|
protected int |
mapDragOperationFromModifiers(MouseEvent e) |
protected void |
modelChanged(BaseDocument oldDoc,
BaseDocument newDoc) |
void |
mouseClicked(MouseEvent evt) |
void |
mouseDragged(MouseEvent evt) |
void |
mouseEntered(MouseEvent evt) |
void |
mouseExited(MouseEvent evt) |
void |
mouseMoved(MouseEvent evt) |
void |
mousePressed(MouseEvent evt) |
void |
mouseReleased(MouseEvent evt) |
void |
moveDot(int offset) |
void |
moveDot(int offset,
Rectangle scrollRect,
int scrollPolicy)
Deprecated.
use #setDot(int) preceded by
JComponent.scrollRectToVisible() . |
void |
paint(Graphics g)
Renders the caret
|
protected void |
paintCustomCaret(Graphics g) |
void |
propertyChange(PropertyChangeEvent evt) |
void |
refresh() |
void |
refresh(boolean retainInView)
Refreshes caret display on the screen.
|
void |
removeChangeListener(ChangeListener l)
Removes listeners to caret position changes
|
void |
removeUpdate(DocumentEvent evt) |
void |
setBlinkRate(int rate)
Sets the caret blink rate.
|
void |
setDot(int offset)
Assign the caret a new offset in the underlying document.
|
void |
setDot(int offset,
boolean expandFold) |
void |
setDot(int offset,
Rectangle scrollRect,
int scrollPolicy)
Deprecated.
use #setDot(int) preceded by
JComponent.scrollRectToVisible() . |
void |
setDot(int offset,
Rectangle scrollRect,
int scrollPolicy,
boolean expandFold)
Deprecated.
use #setDot(int, boolean) preceded by
JComponent.scrollRectToVisible() . |
void |
setMagicCaretPosition(Point p)
Saves the current caret position.
|
void |
setSelectionVisible(boolean v)
Sets the selection visibility
|
void |
setVisible(boolean v)
Sets the caret visibility
|
protected void |
setVisibleImpl(boolean v) |
protected void |
update(boolean scrollViewToCaret)
Update the caret's visual position.
|
void |
updateRectangularUpDownSelection() |
public static final String BLOCK_CARET
public static final String THIN_LINE_CARET
public static final String THICK_LINE_CARET
public static final String LINE_CARET
protected JTextComponent component
protected EventListenerList listenerList
protected Timer flasher
protected ChangeEvent changeEvent
protected char[] dotChar
protected Font afterCaretFont
protected Font beforeCaretFont
protected Color textForeColor
protected Color textBackColor
public void install(JTextComponent c)
public void deinstall(JTextComponent c)
protected void modelChanged(BaseDocument oldDoc, BaseDocument newDoc)
protected void paintCustomCaret(Graphics g)
protected void update(boolean scrollViewToCaret)
scrollViewToCaret
- whether the view of the text component should be
scrolled to the position of the caret.public boolean equals(Object o)
public void addChangeListener(ChangeListener l)
addChangeListener
in interface Caret
public void removeChangeListener(ChangeListener l)
removeChangeListener
in interface Caret
protected void fireStateChanged()
public final boolean isVisible()
protected void setVisibleImpl(boolean v)
public void setVisible(boolean v)
setVisible
in interface Caret
public final boolean isSelectionVisible()
isSelectionVisible
in interface Caret
public void setSelectionVisible(boolean v)
setSelectionVisible
in interface Caret
public void setMagicCaretPosition(Point p)
setMagicCaretPosition
in interface Caret
p
- the Point to use for the saved positionpublic final Point getMagicCaretPosition()
getMagicCaretPosition
in interface Caret
public void setBlinkRate(int rate)
setBlinkRate
in interface Caret
rate
- blink rate in milliseconds, 0 means no blinkpublic int getBlinkRate()
getBlinkRate
in interface Caret
public int getDot()
public int getMark()
public void setDot(int offset)
public void setDot(int offset, boolean expandFold)
@Deprecated public void setDot(int offset, Rectangle scrollRect, int scrollPolicy, boolean expandFold)
JComponent.scrollRectToVisible()
.Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.
offset
- offset in the document to which the caret should be positioned.scrollRect
- rectangle to which the editor window should be scrolled.scrollPolicy
- the way how scrolling should be done.
One of EditorUI.SCROLL_*
constants.expandFold
- whether possible fold at the caret position should be expanded.@Deprecated public void setDot(int offset, Rectangle scrollRect, int scrollPolicy)
JComponent.scrollRectToVisible()
.Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.
offset
- offset in the document to which the caret should be positioned.scrollRect
- rectangle to which the editor window should be scrolled.scrollPolicy
- the way how scrolling should be done.
One of EditorUI.SCROLL_*
constants.@Deprecated public void moveDot(int offset, Rectangle scrollRect, int scrollPolicy)
JComponent.scrollRectToVisible()
.Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.
offset
- offset in the document to which the caret should be positioned.scrollRect
- rectangle to which the editor window should be scrolled.scrollPolicy
- the way how scrolling should be done.
One of EditorUI.SCROLL_*
constants.public void insertUpdate(DocumentEvent evt)
insertUpdate
in interface DocumentListener
public void removeUpdate(DocumentEvent evt)
removeUpdate
in interface DocumentListener
public void atomicLock(AtomicLockEvent evt)
atomicLock
in interface AtomicLockListener
public void atomicUnlock(AtomicLockEvent evt)
atomicUnlock
in interface AtomicLockListener
public void changedUpdate(DocumentEvent evt)
changedUpdate
in interface DocumentListener
public void mousePressed(MouseEvent evt)
mousePressed
in interface MouseListener
public void mouseReleased(MouseEvent evt)
mouseReleased
in interface MouseListener
public void mouseClicked(MouseEvent evt)
mouseClicked
in interface MouseListener
public void mouseEntered(MouseEvent evt)
mouseEntered
in interface MouseListener
public void mouseExited(MouseEvent evt)
mouseExited
in interface MouseListener
public void mouseMoved(MouseEvent evt)
mouseMoved
in interface MouseMotionListener
public void mouseDragged(MouseEvent evt)
mouseDragged
in interface MouseMotionListener
public void updateRectangularUpDownSelection()
public void extendRectangularSelection(boolean toRight, boolean ctrl)
toRight
- true for right or false for left.ctrl
- protected int mapDragOperationFromModifiers(MouseEvent e)
protected boolean isDragPossible(MouseEvent e)
This is implemented to check for a TransferHandler. Subclasses should perform the remaining conditions.
protected JComponent getEventComponent(MouseEvent e)
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
public void actionPerformed(ActionEvent evt)
actionPerformed
in interface ActionListener
@Deprecated public void foldHierarchyChanged(FoldHierarchyEvent evt)
foldHierarchyChanged
in interface FoldHierarchyListener
evt
- public final void refresh()
public void refresh(boolean retainInView)
The method has two modes: it can reposition the view just if it originally displayed the caret and the caret became invisible, and it can scroll the caret into view unconditionally.
retainInView
- true to scroll only if the caret was visible. False to refresh regardless of visibility.