| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjava.awt.geom.RectangularShapejava.awt.geom.Rectangle2Djava.awt.Rectanglejavax.swing.text.DefaultCaretpublic class DefaultCaretextends Rectangleimplements Caret, FocusListener, MouseListener, MouseMotionListenerCaret interface.
Nested Class Summary |
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D | |
Rectangle2D.Double, Rectangle2D.Float | |
Field Summary | |
static int |
|
static int |
|
static int |
|
protected ChangeEvent |
|
protected EventListenerList |
|
Fields inherited from class java.awt.geom.Rectangle2D | |
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP | |
Constructor Summary | |
| |
Method Summary | |
void |
|
protected void |
|
protected void | |
void |
|
|
|
protected void |
|
void |
|
void |
|
int |
|
ChangeListener[] |
|
protected JTextComponent |
|
int |
|
Point |
|
int |
|
protected Highlighter.HighlightPainter |
|
int |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
protected void |
|
void |
|
void | |
protected void |
|
void |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.awt.Rectangle | |
add, add, add, contains, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, toString, translate, union | |
Methods inherited from class java.awt.geom.Rectangle2D | |
add, add, add, contains, contains, createIntersection, createUnion, equals, getBounds2D, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, outcode, setFrame, setRect, setRect, union | |
Methods inherited from class java.awt.geom.RectangularShape | |
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getHeight, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, getWidth, getX, getY, intersects, isEmpty, setFrame, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal | |
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public static final int ALWAYS_UPDATE
Indicates the Caret position should always be updated after Document changes even if the updates are not performed on the Event Dispatching thread.
- Field Value:
- 2
- Since:
- 1.5
public static final int NEVER_UPDATE
Indicates the Caret position should not be changed unless the Document length becomes less than the Caret position, in which case the Caret is moved to the end of the Document.
- Field Value:
- 1
- Since:
- 1.5
public static final int UPDATE_WHEN_ON_EDT
Indicates the Caret position should be updated only if Document changes are made on the Event Dispatcher thread.
- Field Value:
- 0
- Since:
- 1.5
public void addChangeListener(ChangeListener listener)
Registers aChangeListenerthat is notified whenever that state of thisCaretchanges.
- Specified by:
- addChangeListener in interface Caret
- Parameters:
listener- the listener to register to this caret
protected void adjustVisibility(Rectangle rect)
Adjusts the text component so that the caret is visible. This default implementation simply callsJComponent.scrollRectToVisible(Rectangle)on the text component. Subclasses may wish to change this.
protected void damage(Rectangle r)
Updates the carets rectangle properties to the specified rectangle and repaints the caret.
- Parameters:
r- the rectangle to set as the caret rectangle
public void deinstall(JTextComponent c)
Deinstalls thisCaretfrom the specifiedJTextComponent. This removes any listeners that have been registered by thisCaret.
- Parameters:
c- the text component from which to install this caret
publicextends EventListener> T[] getListeners(Class listenerType)
Returns all registered event listeners of the specified type.
- Parameters:
listenerType- the type of listener to return
- Returns:
- all registered event listeners of the specified type
protected void fireStateChanged()
Notifies all registeredChangeListeners that the state of thisCarethas changed.
public void focusGained(FocusEvent event)
Sets the caret tovisibleif the text component is editable.
- Specified by:
- focusGained in interface FocusListener
- Parameters:
event- theFocusEvent
public void focusLost(FocusEvent event)
Sets the caret toinvisible.
- Specified by:
- focusLost in interface FocusListener
- Parameters:
event- theFocusEvent
public int getBlinkRate()
Returns the blink rate of thisCaretin milliseconds. A value of0means that the caret does not blink.
- Specified by:
- getBlinkRate in interface Caret
- Returns:
- the blink rate of this
Caretor0if this caret does not blink
public ChangeListener[] getChangeListeners()
Returns all registeredChangeListeners of thisCaret.
- Returns:
- all registered
ChangeListeners of thisCaret
protected final JTextComponent getComponent()
Returns theJTextComponenton which thisCaretis installed.
- Returns:
- the
JTextComponenton which thisCaretis installed
public int getDot()
Returns the current position of thisCaretwithin theDocument.
- Returns:
- the current position of this
Caretwithin theDocument
public Point getMagicCaretPosition()
Returns the current visual position of thisCaret.
- Specified by:
- getMagicCaretPosition in interface Caret
- Returns:
- the current visual position of this
Caret
- See Also:
setMagicCaretPosition(Point)
public int getMark()
Returns the current position of themark. Themarkmarks the location in theDocumentthat is the end of a selection. If there is no selection, themarkis the same as thedot.
- Returns:
- the current position of the mark
protected Highlighter.HighlightPainter getSelectionPainter()
Returns theHighlighter.HighlightPainterthat should be used to paint the selection.
- Returns:
- the
Highlighter.HighlightPainterthat should be used to paint the selection
public int getUpdatePolicy()
Gets the caret update policy.
- Returns:
- the caret update policy.
- Since:
- 1.5
public void install(JTextComponent c)
Installs thisCareton the specifiedJTextComponent. This registers a couple of listeners on the text component.
- Parameters:
c- the text component on which to install this caret
public boolean isActive()
Returnstrueif thisCaretis blinking, andfalseif not. The returned value is independent of the visiblity of thisCaretas returned byisVisible().
- Returns:
trueif thisCaretis blinking, andfalseif not.
- Since:
- 1.5
- See Also:
isVisible()
public boolean isSelectionVisible()
Returnstrueif the selection is currently visible,falseotherwise.
- Specified by:
- isSelectionVisible in interface Caret
- Returns:
trueif the selection is currently visible,falseotherwise
public boolean isVisible()
Returnstrueif thisCaretis currently visible, andfalseif it is not.
- Returns:
trueif thisCaretis currently visible, andfalseif it is not
public void mouseClicked(MouseEvent event)
When the click is received from Button 1 then the following actions are performed here:
- If we receive a double click, the caret position (dot) is set to the position associated to the mouse click and the word at this location is selected. If there is no word at the pointer the gap is selected instead.
- If we receive a triple click, the caret position (dot) is set to the position associated to the mouse click and the line at this location is selected.
- Specified by:
- mouseClicked in interface MouseListener
- Parameters:
event- theMouseEventdescribing the click operation
public void mouseDragged(MouseEvent event)
Moves the caret position when the mouse is dragged over the text component, modifying the selectiony. When the text component where the caret is installed is disabled, the selection is not change but you can still scroll the text and update the caret's location.
- Specified by:
- mouseDragged in interface MouseMotionListener
- Parameters:
event- theMouseEventdescribing the drag operation
public void mouseEntered(MouseEvent event)
Indicates that the mouse has entered the text component. Nothing is done here.
- Specified by:
- mouseEntered in interface MouseListener
- Parameters:
event- theMouseEventdescribing the mouse operation
public void mouseExited(MouseEvent event)
Indicates that the mouse has exited the text component. Nothing is done here.
- Specified by:
- mouseExited in interface MouseListener
- Parameters:
event- theMouseEventdescribing the mouse operation
public void mouseMoved(MouseEvent event)
Indicates a mouse movement over the text component. Does nothing here.
- Specified by:
- mouseMoved in interface MouseMotionListener
- Parameters:
event- theMouseEventdescribing the mouse operation
public void mousePressed(MouseEvent event)
If the button 1 is pressed, the caret position is updated to the position of the mouse click and the text component requests the input focus if it is enabled. If the SHIFT key is held down, the caret will be moved, which might select the text between the old and new location.
- Specified by:
- mousePressed in interface MouseListener
- Parameters:
event- theMouseEventdescribing the press operation
public void mouseReleased(MouseEvent event)
Indicates that a mouse button has been released on the text component. Nothing is done here.
- Specified by:
- mouseReleased in interface MouseListener
- Parameters:
event- theMouseEventdescribing the mouse operation
protected void moveCaret(MouseEvent event)
Moves the caret to the position specified in theMouseEvent. This will cause a selection if the dot and mark are different.
- Parameters:
event- theMouseEventfrom which to fetch the position
public void moveDot(int dot)
Moves thedotlocation without touching themark. This is used when making a selection. If the underlying text component has aNavigationFilterinstalled the caret will call the corresponding method of that object.
- Parameters:
dot- the location where to move the dot
- See Also:
setDot(int)
public void paint(Graphics g)
Paints thisCaretusing the specifiedGraphicscontext.
- Parameters:
g- the graphics context to use
protected void positionCaret(MouseEvent event)
Repositions the caret to the position specified in theMouseEvent.
- Parameters:
event- theMouseEventfrom which to fetch the position
public void removeChangeListener(ChangeListener listener)
Removes aChangeListenerfrom the list of registered listeners.
- Specified by:
- removeChangeListener in interface Caret
- Parameters:
listener- the listener to remove
public void setBlinkRate(int rate)
Sets the blink rate of thisCaretin milliseconds. A value of0means that the caret does not blink.
- Specified by:
- setBlinkRate in interface Caret
- Parameters:
rate- the new blink rate to set
public void setDot(int dot)
Sets the current position of thisCaretwithin theDocument. This also sets themarkto the new location. If the underlying text component has aNavigationFilterinstalled the caret will call the corresponding method of that object.
- Parameters:
dot- the new position to be set
- See Also:
moveDot(int)
public void setMagicCaretPosition(Point p)
Sets the current visual position of thisCaret.
- Specified by:
- setMagicCaretPosition in interface Caret
- Parameters:
p- the Point to use for the saved location. May benullto indicate that there is no visual location
public void setSelectionVisible(boolean v)
Sets the visiblity state of the selection.
- Specified by:
- setSelectionVisible in interface Caret
- Parameters:
v-trueif the selection should be visible,falseotherwise
public void setUpdatePolicy(int policy)
Sets the Caret update policy.
- Parameters:
policy- the new policy. Valid values are: ALWAYS_UPDATE: always update the Caret position, even when Document updates don't occur on the Event Dispatcher thread. NEVER_UPDATE: don't update the Caret position unless the Document length becomes less than the Caret position (then update the Caret to the end of the Document). UPDATE_WHEN_ON_EDT: update the Caret position when the Document updates occur on the Event Dispatcher thread. This is the default.
- Throws:
IllegalArgumentException- if policy is not one of the above.
- Since:
- 1.5
public void setVisible(boolean v)
Sets the visibility state of the caret.trueshows theCaret,falsehides it.
- Specified by:
- setVisible in interface Caret
- Parameters:
v- the visibility to set