org.fife.ui.rtextarea

## Class RTextAreaUI

- java.lang.Object
- - javax.swing.plaf.ComponentUI
  - - javax.swing.plaf.TextUI
    - - javax.swing.plaf.basic.BasicTextUI
      - - javax.swing.plaf.basic.BasicTextAreaUI
        - - org.fife.ui.rtextarea.RTextAreaUI

All Implemented Interfaces:
  ViewFactory

Direct Known Subclasses:
  RSyntaxTextAreaUI

    public class RTextAreaUI
    extends BasicTextAreaUI

The UI used by instances of `RTextArea`. This UI takes into account all of the "extras" involved in an `RTextArea`, including having a special caret (for insert and overwrite), background images, highlighting the current line, etc.

Version:
  0.5
Author:
  Robert Futrell

### Nested Class Summary

### Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicTextUI

`BasicTextUI.BasicCaret, BasicTextUI.BasicHighlighter`

### Field Summary

Fields
`protected RTextArea` `textArea`

### Constructor Summary

Constructors
Constructor and Description
`RTextAreaUI(JComponent textArea)` Constructor.

### Method Summary

Methods
`View` `create(Element elem)` Creates the view for an element.
`protected Caret` `createCaret()` Returns the default caret for an `RTextArea`.
`protected Keymap` `createKeymap()` Creates the keymap for this text area.
`protected ActionMap` `createRTextAreaActionMap()` Creates a default action map.
`static ComponentUI` `createUI(JComponent textArea)` Creates a UI for an RTextArea.
`protected String` `getActionMapName()` Returns the name to use to cache/fetch the shared action map.
`EditorKit` `getEditorKit(JTextComponent tc)` Fetches the EditorKit for the UI.
`RTextArea` `getRTextArea()` Returns the text area for which we are the UI.
`protected InputMap` `getRTextAreaInputMap()` Get the InputMap to use for the UI.
`protected Rectangle` `getVisibleEditorRect()` Gets the allocation to give the root View.
`protected void` `installDefaults()`
`protected void` `installKeyboardActions()`
`void` `installUI(JComponent c)` Installs this UI to the given text component.
`protected void` `paintBackground(Graphics g)`
`protected void` `paintCurrentLineHighlight(Graphics g, Rectangle visibleRect)` Paints the highlighted current line, if it is enabled.
`protected void` `paintLineHighlights(Graphics g)` Paints any line highlights.
`protected void` `paintMarginLine(Graphics g, Rectangle visibleRect)` Draws the "margin line" if enabled.
`int` `yForLine(int line)` Returns the y-coordinate of the specified line.
`int` `yForLineContaining(int offs)` Returns the y-coordinate of the line containing an offset.

### Methods inherited from class javax.swing.plaf.basic.BasicTextAreaUI

`getBaseline, getBaselineResizeBehavior, getMinimumSize, getPreferredSize, getPropertyPrefix, propertyChange`

### Methods inherited from class javax.swing.plaf.basic.BasicTextUI

`create, createHighlighter, damageRange, damageRange, getComponent, getKeymapName, getMaximumSize, getNextVisualPositionFrom, getRootView, getToolTipText, installListeners, modelChanged, modelToView, modelToView, paint, paintSafely, setView, uninstallDefaults, uninstallKeyboardActions, uninstallListeners, uninstallUI, update, viewToModel, viewToModel`

### Methods inherited from class javax.swing.plaf.ComponentUI

`contains, getAccessibleChild, getAccessibleChildrenCount`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### textArea

    protected RTextArea textArea

### Constructor Detail

#### RTextAreaUI

    public RTextAreaUI(JComponent textArea)

Constructor.

Parameters:
  `textArea` - An instance of `RTextArea`.
Throws:
  `IllegalArgumentException` - If `textArea` is not an instance of `RTextArea`.

### Method Detail

#### createUI

    public static ComponentUI createUI(JComponent textArea)

Creates a UI for an RTextArea.

Parameters:
  `textArea` - A text area.
Returns:
  The UI.

#### create

    public View create(Element elem)

Creates the view for an element. Returns a WrappedPlainView or PlainView.

Specified by:
  `create` in interface `ViewFactory`
Overrides:
  `create` in class `BasicTextAreaUI`
Parameters:
  `elem` - The element.
Returns:
  The view.

#### createCaret

    protected Caret createCaret()

Returns the default caret for an `RTextArea`. This caret is capable of displaying itself differently for insert/overwrite modes.

Overrides:
  `createCaret` in class `BasicTextUI`
Returns:
  The caret.

#### createKeymap

    protected Keymap createKeymap()

Creates the keymap for this text area. This takes the super class's keymap, but sets the default keystroke to be RTextAreaEditorKit's DefaultKeyTypedAction. This must be done to override the default keymap's default key-typed action.

Overrides:
  `createKeymap` in class `BasicTextUI`
Returns:
  The keymap.

#### createRTextAreaActionMap

    protected ActionMap createRTextAreaActionMap()

Creates a default action map. This action map contains actions for all basic text area work - cut, copy, paste, select, caret motion, etc.

This isn't named `createActionMap()` because there is a package-private member by that name in `BasicTextAreaUI`, and some compilers will give warnings that we are not overriding that method since it is package-private.

Returns:
  The action map.

#### getActionMapName

    protected String getActionMapName()

Returns the name to use to cache/fetch the shared action map. This should be overridden by subclasses if the subclass has its own custom editor kit to install, so its actions get picked up.

Returns:
  The name of the cached action map.

#### getEditorKit

    public EditorKit getEditorKit(JTextComponent tc)

Fetches the EditorKit for the UI.

Overrides:
  `getEditorKit` in class `BasicTextUI`
Parameters:
  `tc` - the text component for which this UI is installed
Returns:
  the editor capabilities
See Also:
  `TextUI.getEditorKit(javax.swing.text.JTextComponent)`

#### getRTextArea

    public RTextArea getRTextArea()

Returns the text area for which we are the UI.

Returns:
  The text area.

#### getRTextAreaInputMap

    protected InputMap getRTextAreaInputMap()

Get the InputMap to use for the UI.

This method is not named `getInputMap()` because there is a package-private method in `BasicTextAreaUI` with that name. Thus, creating a new method with that name causes certain compilers to issue warnings that you are not actually overriding the original method (since it is package-private).

#### getVisibleEditorRect

    protected Rectangle getVisibleEditorRect()

Gets the allocation to give the root View. Due to an unfortunate set of historical events this method is inappropriately named. The Rectangle returned has nothing to do with visibility. The component must have a non-zero positive size for this translation to be computed.

Overrides:
  `getVisibleEditorRect` in class `BasicTextUI`
Returns:
  the bounding box for the root view

#### installDefaults

    protected void installDefaults()

Overrides:
  `installDefaults` in class `BasicTextAreaUI`

#### installKeyboardActions

    protected void installKeyboardActions()

Overrides:
  `installKeyboardActions` in class `BasicTextUI`

#### installUI

    public void installUI(JComponent c)

Installs this UI to the given text component.

Overrides:
  `installUI` in class `BasicTextUI`

#### paintBackground

    protected void paintBackground(Graphics g)

Overrides:
  `paintBackground` in class `BasicTextUI`

#### paintCurrentLineHighlight

    protected void paintCurrentLineHighlight(Graphics g,
                                 Rectangle visibleRect)

Paints the highlighted current line, if it is enabled.

Parameters:
  `g` - The graphics context with which to paint.
  `visibleRect` - The visible rectangle of the text area.

#### paintLineHighlights

    protected void paintLineHighlights(Graphics g)

Paints any line highlights.

Parameters:
  `g` - The graphics context.

#### paintMarginLine

    protected void paintMarginLine(Graphics g,
                       Rectangle visibleRect)

Draws the "margin line" if enabled.

Parameters:
  `g` - The graphics context to paint with.
  `visibleRect` - The visible rectangle of this text area.

#### yForLine

    public int yForLine(int line)
                 throws BadLocationException

Returns the y-coordinate of the specified line.

The default implementation is equivalent to:

     int startOffs = textArea.getLineStartOffset(line);
     return yForLineContaining(startOffs);

Subclasses that can calculate this value more quickly than traditional `BasicTextUI.modelToView(JTextComponent, int)` calls should override this method to do so. This method may be used when the entire bounding box isn't needed, to speed up rendering.

Parameters:
  `line` - The line number.
Returns:
  The y-coordinate of the top of the line, or `-1` if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding).
Throws:
  `BadLocationException` - If `line` isn't a valid line number for this document.

#### yForLineContaining

    public int yForLineContaining(int offs)
                           throws BadLocationException

Returns the y-coordinate of the line containing an offset.

The default implementation is equivalent to:

     int line = textArea.getLineOfOffset(offs);
     int startOffs = textArea.getLineStartOffset(line);
     return modelToView(startOffs).y;

Subclasses that can calculate this value more quickly than traditional `BasicTextUI.modelToView(JTextComponent, int)` calls should override this method to do so. This method may be used when the entire bounding box isn't needed, to speed up rendering.

Parameters:
  `offs` - The offset info the document.
Returns:
  The y-coordinate of the top of the offset, or `-1` if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding).
Throws:
  `BadLocationException` - If `offs` isn't a valid offset into the document.