Package org.fife.ui.rtextarea
Class ConfigurableCaret
- java.lang.Object
-
- java.awt.geom.RectangularShape
-
- java.awt.geom.Rectangle2D
-
- java.awt.Rectangle
-
- javax.swing.text.DefaultCaret
-
- org.fife.ui.rtextarea.ConfigurableCaret
-
- All Implemented Interfaces:
FocusListener,MouseListener,MouseMotionListener,Shape,Serializable,Cloneable,EventListener,Caret
public class ConfigurableCaret extends DefaultCaret
The caret used byRTextArea. This caret has all of the properties thatjavax.swing.text.DefaultCaretdoes, as well as adding the following niceties:- This caret can render itself many different ways; see the
setStyle(CaretStyle)method andCaretStylefor more information. - On Microsoft Windows and other operating systems that do not support system selection (i.e., selecting text, then pasting via the middle mouse button), clicking the middle mouse button will cause a regular paste operation to occur. On systems that support system selection (i.e., all UNIX variants), the middle mouse button will behave normally.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
-
-
Field Summary
-
Fields inherited from class javax.swing.text.DefaultCaret
ALWAYS_UPDATE, changeEvent, listenerList, NEVER_UPDATE, UPDATE_WHEN_ON_EDT
-
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
-
-
Constructor Summary
Constructors Constructor Description ConfigurableCaret()Creates the caret usingCaretStyle.THICK_VERTICAL_LINE_STYLE.ConfigurableCaret(CaretStyle style)Constructs a newConfigurableCaret.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddamage(Rectangle r)Overridden to damage the correct width of the caret, since this caret can be different sizes.voiddeinstall(JTextComponent c)Called when the UI is being removed from the interface of a JTextComponent.booleangetRoundedSelectionEdges()Returns whether this caret's selection uses rounded edges.protected Highlighter.HighlightPaintergetSelectionPainter()Gets the painter for the Highlighter.CaretStylegetStyle()Gets the current style of this caret.protected RTextAreagetTextArea()Gets the text editor component that this caret is bound to.voidinstall(JTextComponent c)Installs this caret on a text component.booleanisAlwaysVisible()Returns whether this caret is always visible (as opposed to blinking, or not visible when the editor's window is not focused).voidmouseClicked(MouseEvent e)Called when the mouse is clicked.voidmousePressed(MouseEvent e)Overridden to also focus the text component on right mouse clicks.voidpaint(Graphics g)Paints the cursor.voidsetAlwaysVisible(boolean alwaysVisible)Toggles whether this caret should always be visible (as opposed to blinking, or not visible when the editor's window is not focused).voidsetRoundedSelectionEdges(boolean rounded)Sets whether this caret's selection should have rounded edges.voidsetSelectionVisible(boolean visible)Overridden to always render the selection, even when the text component loses focus.voidsetStyle(CaretStyle style)Sets the style used when painting the caret.-
Methods inherited from class javax.swing.text.DefaultCaret
addChangeListener, adjustVisibility, equals, fireStateChanged, focusGained, focusLost, getBlinkRate, getChangeListeners, getComponent, getDot, getDotBias, getListeners, getMagicCaretPosition, getMark, getMarkBias, getUpdatePolicy, isActive, isSelectionVisible, isVisible, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseReleased, moveCaret, moveDot, moveDot, positionCaret, removeChangeListener, repaint, setBlinkRate, setDot, setDot, setMagicCaretPosition, setUpdatePolicy, 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
-
ConfigurableCaret
public ConfigurableCaret()
Creates the caret usingCaretStyle.THICK_VERTICAL_LINE_STYLE.
-
ConfigurableCaret
public ConfigurableCaret(CaretStyle style)
Constructs a newConfigurableCaret.- Parameters:
style- The style to use when painting the caret. If this is invalid, thenCaretStyle.THICK_VERTICAL_LINE_STYLEis used.
-
-
Method Detail
-
damage
protected void damage(Rectangle r)
Overridden to damage the correct width of the caret, since this caret can be different sizes.- Overrides:
damagein classDefaultCaret- Parameters:
r- The current location of the caret.
-
deinstall
public void deinstall(JTextComponent c)
Called when the UI is being removed from the interface of a JTextComponent. This is used to unregister any listeners that were attached.- Specified by:
deinstallin interfaceCaret- Overrides:
deinstallin classDefaultCaret- Parameters:
c- The text component. If this is not anRTextArea, anExceptionwill be thrown.- See Also:
Caret.deinstall(javax.swing.text.JTextComponent)
-
getTextArea
protected RTextArea getTextArea()
Gets the text editor component that this caret is bound to.- Returns:
- The
RTextArea.
-
getRoundedSelectionEdges
public boolean getRoundedSelectionEdges()
Returns whether this caret's selection uses rounded edges.- Returns:
- Whether this caret's edges are rounded.
- See Also:
setRoundedSelectionEdges(boolean)
-
getSelectionPainter
protected Highlighter.HighlightPainter getSelectionPainter()
Gets the painter for the Highlighter. This is overridden to return our custom selection painter.- Overrides:
getSelectionPainterin classDefaultCaret- Returns:
- The painter.
-
getStyle
public CaretStyle getStyle()
Gets the current style of this caret.- Returns:
- The caret's style.
- See Also:
setStyle(CaretStyle)
-
install
public void install(JTextComponent c)
Installs this caret on a text component.- Specified by:
installin interfaceCaret- Overrides:
installin classDefaultCaret- Parameters:
c- The text component. If this is not anRTextArea, anExceptionwill be thrown.- See Also:
Caret.install(javax.swing.text.JTextComponent)
-
isAlwaysVisible
public boolean isAlwaysVisible()
Returns whether this caret is always visible (as opposed to blinking, or not visible when the editor's window is not focused). This can be used by popup windows that want the caret's location to still be visible for contextual purposes while they are displayed.- Returns:
- Whether this caret is always visible.
- See Also:
setAlwaysVisible(boolean)
-
mouseClicked
public void mouseClicked(MouseEvent e)
Called when the mouse is clicked. If the click was generated from button1, a double click selects a word, and a triple click the current line.- Specified by:
mouseClickedin interfaceMouseListener- Overrides:
mouseClickedin classDefaultCaret- Parameters:
e- the mouse event- See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)
-
mousePressed
public void mousePressed(MouseEvent e)
Overridden to also focus the text component on right mouse clicks.- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classDefaultCaret- Parameters:
e- The mouse event.
-
paint
public void paint(Graphics g)
Paints the cursor.- Specified by:
paintin interfaceCaret- Overrides:
paintin classDefaultCaret- Parameters:
g- The graphics context in which to paint.
-
setAlwaysVisible
public void setAlwaysVisible(boolean alwaysVisible)
Toggles whether this caret should always be visible (as opposed to blinking, or not visible when the editor's window is not focused). This can be used by popup windows that want the caret's location to still be visible for contextual purposes while they are displayed.- Parameters:
alwaysVisible- Whether this caret should always be visible.- See Also:
isAlwaysVisible()
-
setRoundedSelectionEdges
public void setRoundedSelectionEdges(boolean rounded)
Sets whether this caret's selection should have rounded edges.- Parameters:
rounded- Whether it should have rounded edges.- See Also:
getRoundedSelectionEdges()
-
setSelectionVisible
public void setSelectionVisible(boolean visible)
Overridden to always render the selection, even when the text component loses focus.- Specified by:
setSelectionVisiblein interfaceCaret- Overrides:
setSelectionVisiblein classDefaultCaret- Parameters:
visible- Whether the selection should be visible. This parameter is ignored.
-
setStyle
public void setStyle(CaretStyle style)
Sets the style used when painting the caret.- Parameters:
style- The style to use. This should not benull.- See Also:
getStyle()
-
-