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 by `RTextArea`. This caret has all of the properties that `javax.swing.text.DefaultCaret` does, as well as adding the following niceties:

- This caret can paint itself several different ways:
  1. As a vertical line (like `DefaultCaret`)
  2. As a slightly thicker vertical line (like Eclipse)
  3. As an underline
  4. As a "block caret"
  5. As a rectangle around the current character
- 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.

Version:
  0.6
Author:
  Robert Futrell
See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D

`Rectangle2D.Double, Rectangle2D.Float`

### Field Summary

Fields
`static int` `BLOCK_BORDER_STYLE` The block border style.
`static int` `BLOCK_STYLE` The block style.
`static int` `MAX_STYLE` The maximum value of a caret style.
`static int` `MIN_STYLE` The minimum value of a caret style.
`static int` `THICK_VERTICAL_LINE_STYLE` A thicker vertical line (2 pixels instead of 1).
`static int` `UNDERLINE_STYLE` The horizontal line style.
`static int` `VERTICAL_LINE_STYLE` The vertical line style.

### Fields inherited from class javax.swing.text.DefaultCaret

`ALWAYS_UPDATE, changeEvent, listenerList, NEVER_UPDATE, UPDATE_WHEN_ON_EDT`

### Fields inherited from class java.awt.Rectangle

`height, width, x, y`

### Fields inherited from class java.awt.geom.Rectangle2D

`OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP`

### Constructor Summary

Constructors
Constructor and Description
`ConfigurableCaret()` Creates the caret using `VERTICAL_LINE_STYLE`.
`ConfigurableCaret(int style)` Constructs a new `ConfigurableCaret`.

### Method Summary

Methods
`protected void` `damage(Rectangle r)` Overridden to damage the correct width of the caret, since this caret can be different sizes.
`void` `deinstall(JTextComponent c)` Called when the UI is being removed from the interface of a JTextComponent.
`boolean` `getRoundedSelectionEdges()` Returns whether this caret's selection uses rounded edges.
`protected Highlighter.HighlightPainter` `getSelectionPainter()` Gets the painter for the Highlighter.
`int` `getStyle()` Gets the current style of this caret.
`protected RTextArea` `getTextArea()` Gets the text editor component that this caret is bound to.
`void` `install(JTextComponent c)` Installs this caret on a text component.
`void` `mouseClicked(MouseEvent e)` Called when the mouse is clicked.
`void` `mousePressed(MouseEvent e)` Overridden to also focus the text component on right mouse clicks.
`void` `paint(Graphics g)` Paints the cursor.
`void` `setRoundedSelectionEdges(boolean rounded)` Sets whether this caret's selection should have rounded edges.
`void` `setSelectionVisible(boolean visible)` Overridden to always render the selection, even when the text component loses focus.
`void` `setStyle(int 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`

### Field Detail

#### MIN_STYLE

    public static final int MIN_STYLE

The minimum value of a caret style.

See Also:
  Constant Field Values

#### VERTICAL_LINE_STYLE

    public static final int VERTICAL_LINE_STYLE

The vertical line style.

See Also:
  Constant Field Values

#### UNDERLINE_STYLE

    public static final int UNDERLINE_STYLE

The horizontal line style.

See Also:
  Constant Field Values

#### BLOCK_STYLE

    public static final int BLOCK_STYLE

The block style.

See Also:
  Constant Field Values

#### BLOCK_BORDER_STYLE

    public static final int BLOCK_BORDER_STYLE

The block border style.

See Also:
  Constant Field Values

#### THICK_VERTICAL_LINE_STYLE

    public static final int THICK_VERTICAL_LINE_STYLE

A thicker vertical line (2 pixels instead of 1).

See Also:
  Constant Field Values

#### MAX_STYLE

    public static final int MAX_STYLE

The maximum value of a caret style.

See Also:
  Constant Field Values

### Constructor Detail

#### ConfigurableCaret

    public ConfigurableCaret()

Creates the caret using `VERTICAL_LINE_STYLE`.

#### ConfigurableCaret

    public ConfigurableCaret(int style)

Constructs a new `ConfigurableCaret`.

Parameters:
  `style` - The style to use when painting the caret. If this is invalid, then `VERTICAL_LINE_STYLE` is 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:
  `damage` in class `DefaultCaret`
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:
  `deinstall` in interface `Caret`
Overrides:
  `deinstall` in class `DefaultCaret`
Parameters:
  `c` - The text component. If this is not an `RTextArea`, an `Exception` will 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:
  `getSelectionPainter` in class `DefaultCaret`
Returns:
  The painter.

#### getStyle

    public int getStyle()

Gets the current style of this caret.

Returns:
  The caret's style.
See Also:
  `setStyle(int)`

#### install

    public void install(JTextComponent c)

Installs this caret on a text component.

Specified by:
  `install` in interface `Caret`
Overrides:
  `install` in class `DefaultCaret`
Parameters:
  `c` - The text component. If this is not an `RTextArea`, an `Exception` will be thrown.
See Also:
  `Caret.install(javax.swing.text.JTextComponent)`

#### 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:
  `mouseClicked` in interface `MouseListener`
Overrides:
  `mouseClicked` in class `DefaultCaret`
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:
  `mousePressed` in interface `MouseListener`
Overrides:
  `mousePressed` in class `DefaultCaret`
Parameters:
  `e` - The mouse event.

#### paint

    public void paint(Graphics g)

Paints the cursor.

Specified by:
  `paint` in interface `Caret`
Overrides:
  `paint` in class `DefaultCaret`
Parameters:
  `g` - The graphics context in which to paint.

#### 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:
  `setSelectionVisible` in interface `Caret`
Overrides:
  `setSelectionVisible` in class `DefaultCaret`
Parameters:
  `visible` - Whether the selection should be visible. This parameter is ignored.

#### setStyle

    public void setStyle(int style)

Sets the style used when painting the caret.

Parameters:
  `style` - The style to use. If this isn't one of `VERTICAL_LINE_STYLE`, `UNDERLINE_STYLE`, or `BLOCK_STYLE`, then `VERTICAL_LINE_STYLE` is used.
See Also:
  `getStyle()`