站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

BaseCaret (Editor Library) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib/1 1.14.0 3

org.netbeans.editor
Class BaseCaret

java.lang.Object
  extended by org.netbeans.editor.BaseCaret
All Implemented Interfaces:
ActionListener, MouseListener, MouseMotionListener, PropertyChangeListener, EventListener, DocumentListener, Caret, FoldHierarchyListener, AtomicLockListener, SettingsChangeListener
Direct Known Subclasses:
ExtCaret

public class BaseCaret
extends Object
implements Caret, MouseListener, MouseMotionListener, PropertyChangeListener, DocumentListener, ActionListener, SettingsChangeListener, AtomicLockListener, FoldHierarchyListener

Caret implementation


Field Summary
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 THIN_LINE_CARET
          One dot thin line compatible with Swing default caret
 
Constructor Summary
BaseCaret()
           
 
Method Summary
 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
protected  void fireStateChanged()
          Notifies listeners that caret position has changed
 void foldHierarchyChanged(FoldHierarchyEvent evt)
           
 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.
 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 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 settingsChange(SettingsChangeEvent evt)
          Called when settings were changed.
 void setVisible(boolean v)
          Sets the caret visibility
protected  void setVisibleImpl(boolean v)
           
protected  void update(boolean scrollViewToCaret)
          Update the caret's visual position.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK_CARET

public static final String BLOCK_CARET
Caret type representing block covering current character

See Also:
Constant Field Values

LINE_CARET

public static final String LINE_CARET
Default caret type

See Also:
Constant Field Values

THIN_LINE_CARET

public static final String THIN_LINE_CARET
One dot thin line compatible with Swing default caret

See Also:
Constant Field Values

component

protected JTextComponent component
Component this caret is bound to


listenerList

protected EventListenerList listenerList
Listeners


flasher

protected Timer flasher
Timer used for blinking the caret


changeEvent

protected ChangeEvent changeEvent
Change event. Only one instance needed because it has only source property


dotChar

protected char[] dotChar
Dot array of one character under caret


afterCaretFont

protected Font afterCaretFont
Font of the text underlying the caret. It can be used in caret painting.


beforeCaretFont

protected Font beforeCaretFont
Font of the text right before the caret


textForeColor

protected Color textForeColor
Foreground color of the text underlying the caret. It can be used in caret painting.


textBackColor

protected Color textBackColor
Background color of the text underlying the caret. It can be used in caret painting.

Constructor Detail

BaseCaret

public BaseCaret()
Method Detail

settingsChange

public void settingsChange(SettingsChangeEvent evt)
Called when settings were changed. The method is called also in constructor, so the code must count with the evt being null.

Specified by:
settingsChange in interface SettingsChangeListener

install

public void install(JTextComponent c)
Called when UI is being installed into JTextComponent

Specified by:
install in interface Caret

deinstall

public void deinstall(JTextComponent c)
Called when UI is being removed from JTextComponent

Specified by:
deinstall in interface Caret

modelChanged

protected void modelChanged(BaseDocument oldDoc,
                            BaseDocument newDoc)

paint

public void paint(Graphics g)
Renders the caret

Specified by:
paint in interface Caret

paintCustomCaret

protected void paintCustomCaret(Graphics g)

update

protected void update(boolean scrollViewToCaret)
Update the caret's visual position.
The document is read-locked while calling this method.

Parameters:
scrollViewToCaret - whether the view of the text component should be scrolled to the position of the caret.

equals

public boolean equals(Object o)
Redefine to Object.equals() to prevent defaulting to Rectangle.equals() which would cause incorrect firing

Overrides:
equals in class Object

addChangeListener

public void addChangeListener(ChangeListener l)
Adds listener to track when caret position was changed

Specified by:
addChangeListener in interface Caret

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes listeners to caret position changes

Specified by:
removeChangeListener in interface Caret

fireStateChanged

protected void fireStateChanged()
Notifies listeners that caret position has changed


isVisible

public final boolean isVisible()
Whether the caret currently visible.
Although the caret is visible it may be in a state when it's not physically showing on screen in case when it's blinking.

Specified by:
isVisible in interface Caret

setVisibleImpl

protected void setVisibleImpl(boolean v)

setVisible

public void setVisible(boolean v)
Sets the caret visibility

Specified by:
setVisible in interface Caret

isSelectionVisible

public final boolean isSelectionVisible()
Is the selection visible?

Specified by:
isSelectionVisible in interface Caret

setSelectionVisible

public void setSelectionVisible(boolean v)
Sets the selection visibility

Specified by:
setSelectionVisible in interface Caret

setMagicCaretPosition

public void setMagicCaretPosition(Point p)
Saves the current caret position. This is used when caret up or down actions occur, moving between lines that have uneven end positions.

Specified by:
setMagicCaretPosition in interface Caret
Parameters:
p - the Point to use for the saved position

getMagicCaretPosition

public final Point getMagicCaretPosition()
Get position used to mark begining of the selected block

Specified by:
getMagicCaretPosition in interface Caret

setBlinkRate

public void setBlinkRate(int rate)
Sets the caret blink rate.

Specified by:
setBlinkRate in interface Caret
Parameters:
rate - blink rate in milliseconds, 0 means no blink

getBlinkRate

public int getBlinkRate()
Returns blink rate of the caret or 0 if caret doesn't blink

Specified by:
getBlinkRate in interface Caret

getDot

public int getDot()
Gets the current position of the caret

Specified by:
getDot in interface Caret

getMark

public int getMark()
Gets the current position of the selection mark. If there's a selection this position will be different from the caret position.

Specified by:
getMark in interface Caret

setDot

public void setDot(int offset)
Assign the caret a new offset in the underlying document.
This method implicitly sets the selection range to zero.

Specified by:
setDot in interface Caret

setDot

public void setDot(int offset,
                   boolean expandFold)

setDot

public void setDot(int offset,
                   Rectangle scrollRect,
                   int scrollPolicy,
                   boolean expandFold)
Deprecated. use #setDot(int, boolean) preceded by JComponent.scrollRectToVisible().

Sets the caret position to some position. This causes removal of the active selection. If expandFold set to true fold containing offset position will be expanded.

Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.

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.

setDot

public void setDot(int offset,
                   Rectangle scrollRect,
                   int scrollPolicy)
Deprecated. use #setDot(int) preceded by JComponent.scrollRectToVisible().

Sets the caret position to some position. This causes removal of the active selection.

Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.

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.

moveDot

public void moveDot(int offset)
Specified by:
moveDot in interface Caret

moveDot

public void moveDot(int offset,
                    Rectangle scrollRect,
                    int scrollPolicy)
Deprecated. use #setDot(int) preceded by JComponent.scrollRectToVisible().

Makes selection by moving dot but leaving mark.

Note: This method is deprecated and the present implementation ignores values of scrollRect and scrollPolicy parameters.

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.

insertUpdate

public void insertUpdate(DocumentEvent evt)
Specified by:
insertUpdate in interface DocumentListener

removeUpdate

public void removeUpdate(DocumentEvent evt)
Specified by:
removeUpdate in interface DocumentListener

atomicLock

public void atomicLock(AtomicLockEvent evt)
Specified by:
atomicLock in interface AtomicLockListener

atomicUnlock

public void atomicUnlock(AtomicLockEvent evt)
Specified by:
atomicUnlock in interface AtomicLockListener

changedUpdate

public void changedUpdate(DocumentEvent evt)
Specified by:
changedUpdate in interface DocumentListener

mouseClicked

public void mouseClicked(MouseEvent evt)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent evt)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent evt)
Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent evt)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent evt)
Specified by:
mouseExited in interface MouseListener

mapDragOperationFromModifiers

protected int mapDragOperationFromModifiers(MouseEvent e)

isDragPossible

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

This is implemented to check for a TransferHandler. Subclasses should perform the remaining conditions.


getEventComponent

protected JComponent getEventComponent(MouseEvent e)

mouseDragged

public void mouseDragged(MouseEvent evt)
Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent evt)
Specified by:
mouseMoved in interface MouseMotionListener

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

actionPerformed

public void actionPerformed(ActionEvent evt)
Fired when blink timer fires

Specified by:
actionPerformed in interface ActionListener

foldHierarchyChanged

public void foldHierarchyChanged(FoldHierarchyEvent evt)
Specified by:
foldHierarchyChanged in interface FoldHierarchyListener

org.netbeans.modules.editor.lib/1 1.14.0 3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.