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:
javax.swing.text.ViewFactory
- Direct Known Subclasses:
RSyntaxTextAreaUI
public class RTextAreaUI extends javax.swing.plaf.basic.BasicTextAreaUIThe UI used by instances ofRTextArea. This UI takes into account all the "extras" involved in anRTextArea, including having a special caret (for insert and overwrite), background images, highlighting the current line, etc.- Version:
- 0.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classRTextAreaUI.FocusActionRegistered in the ActionMap.
-
Field Summary
Fields Modifier and Type Field Description private static javax.swing.text.EditorKitDEFAULT_KITprivate static javax.swing.TransferHandlerDEFAULT_TRANSFER_HANDLERprivate static java.lang.StringRTEXTAREA_KEYMAP_NAMEprivate static java.lang.StringSHARED_ACTION_MAP_NAMEprivate static java.lang.StringSHARED_INPUT_MAP_NAMEprotected RTextAreatextArea
-
Constructor Summary
Constructors Constructor Description RTextAreaUI(javax.swing.JComponent textArea)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcorrectNimbusDefaultProblems(javax.swing.text.JTextComponent editor)The Nimbus LAF (and any Synth laf might have similar issues) doesn't set many UIManager properties that BasicLAF UI's look for.javax.swing.text.Viewcreate(javax.swing.text.Element elem)Creates the view for an element.protected javax.swing.text.CaretcreateCaret()Returns the default caret for anRTextArea.protected javax.swing.text.HighlightercreateHighlighter()protected javax.swing.text.KeymapcreateKeymap()Creates the keymap for this text area.protected javax.swing.ActionMapcreateRTextAreaActionMap()Creates a default action map.static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent textArea)Creates a UI for an RTextArea.protected java.lang.StringgetActionMapName()Returns the name to use to cache/fetch the shared action map.javax.swing.text.EditorKitgetEditorKit(javax.swing.text.JTextComponent tc)Fetches the EditorKit for the UI.RTextAreagetRTextArea()Returns the text area for which we are the UI.private javax.swing.ActionMapgetRTextAreaActionMap()Returns an action map to use by a text area.protected javax.swing.InputMapgetRTextAreaInputMap()Get the InputMap to use for the UI.protected java.awt.RectanglegetVisibleEditorRect()Gets the allocation to give the root View.protected voidinstallDefaults()protected voidinstallKeyboardActions()voidinstallUI(javax.swing.JComponent c)Installs this UI to the given text component.protected voidpaintBackground(java.awt.Graphics g)protected voidpaintCurrentLineHighlight(java.awt.Graphics g, java.awt.Rectangle visibleRect)Paints the highlighted current line, if it is enabled.protected voidpaintEditorAugmentations(java.awt.Graphics g)Paints editor augmentations added by RTextArea: highlighted lines, current line highlight, and margin line.protected voidpaintLineHighlights(java.awt.Graphics g)Paints any line highlights.protected voidpaintMarginLine(java.awt.Graphics g, java.awt.Rectangle visibleRect)Draws the "margin line" if enabled.protected voidpaintSafely(java.awt.Graphics g)intyForLine(int line)Returns the y-coordinate of the specified line.intyForLineContaining(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, damageRange, damageRange, getComponent, getKeymapName, getMaximumSize, getNextVisualPositionFrom, getRootView, getToolTipText, installListeners, modelChanged, modelToView, modelToView, modelToView2D, paint, setView, uninstallDefaults, uninstallKeyboardActions, uninstallListeners, uninstallUI, update, viewToModel, viewToModel, viewToModel2D
-
-
-
-
Field Detail
-
SHARED_ACTION_MAP_NAME
private static final java.lang.String SHARED_ACTION_MAP_NAME
- See Also:
- Constant Field Values
-
SHARED_INPUT_MAP_NAME
private static final java.lang.String SHARED_INPUT_MAP_NAME
- See Also:
- Constant Field Values
-
textArea
protected RTextArea textArea
-
DEFAULT_KIT
private static final javax.swing.text.EditorKit DEFAULT_KIT
-
DEFAULT_TRANSFER_HANDLER
private static final javax.swing.TransferHandler DEFAULT_TRANSFER_HANDLER
-
RTEXTAREA_KEYMAP_NAME
private static final java.lang.String RTEXTAREA_KEYMAP_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
createUI
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent textArea)
Creates a UI for an RTextArea.- Parameters:
textArea- A text area.- Returns:
- The UI.
-
correctNimbusDefaultProblems
private void correctNimbusDefaultProblems(javax.swing.text.JTextComponent editor)
The Nimbus LAF (and any Synth laf might have similar issues) doesn't set many UIManager properties that BasicLAF UI's look for. This causes problems for custom Basic-based UI's such as RTextAreaUI. This method attempts to detect if Nimbus has been installed, and if so, sets proper values for some editor properties.- Parameters:
editor- The text area.
-
create
public javax.swing.text.View create(javax.swing.text.Element elem)
Creates the view for an element. Returns a WrappedPlainView or PlainView.- Specified by:
createin interfacejavax.swing.text.ViewFactory- Overrides:
createin classjavax.swing.plaf.basic.BasicTextAreaUI- Parameters:
elem- The element.- Returns:
- The view.
-
createCaret
protected javax.swing.text.Caret createCaret()
Returns the default caret for anRTextArea. This caret is capable of displaying itself differently for insert/overwrite modes.- Overrides:
createCaretin classjavax.swing.plaf.basic.BasicTextUI- Returns:
- The caret.
-
createHighlighter
protected javax.swing.text.Highlighter createHighlighter()
- Overrides:
createHighlighterin classjavax.swing.plaf.basic.BasicTextUI
-
createKeymap
protected javax.swing.text.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:
createKeymapin classjavax.swing.plaf.basic.BasicTextUI- Returns:
- The keymap.
-
createRTextAreaActionMap
protected javax.swing.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 inBasicTextAreaUI, and some compilers will give warnings that we are not overriding that method since it is package-private.- Returns:
- The action map.
-
getActionMapName
protected java.lang.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 javax.swing.text.EditorKit getEditorKit(javax.swing.text.JTextComponent tc)
Fetches the EditorKit for the UI.- Overrides:
getEditorKitin classjavax.swing.plaf.basic.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.
-
getRTextAreaActionMap
private javax.swing.ActionMap getRTextAreaActionMap()
Returns an action map to use by a text area.This method is not named
getActionMap()because there is a package-private method inBasicTextAreaUIwith 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).- Returns:
- The action map.
- See Also:
createRTextAreaActionMap()
-
getRTextAreaInputMap
protected javax.swing.InputMap getRTextAreaInputMap()
Get the InputMap to use for the UI.This method is not named
getInputMap()because there is a package-private method inBasicTextAreaUIwith 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 java.awt.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:
getVisibleEditorRectin classjavax.swing.plaf.basic.BasicTextUI- Returns:
- the bounding box for the root view
-
installDefaults
protected void installDefaults()
- Overrides:
installDefaultsin classjavax.swing.plaf.basic.BasicTextAreaUI
-
installKeyboardActions
protected void installKeyboardActions()
- Overrides:
installKeyboardActionsin classjavax.swing.plaf.basic.BasicTextUI
-
installUI
public void installUI(javax.swing.JComponent c)
Installs this UI to the given text component.- Overrides:
installUIin classjavax.swing.plaf.basic.BasicTextUI
-
paintBackground
protected void paintBackground(java.awt.Graphics g)
- Overrides:
paintBackgroundin classjavax.swing.plaf.basic.BasicTextUI
-
paintCurrentLineHighlight
protected void paintCurrentLineHighlight(java.awt.Graphics g, java.awt.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.
-
paintEditorAugmentations
protected void paintEditorAugmentations(java.awt.Graphics g)
Paints editor augmentations added by RTextArea: highlighted lines, current line highlight, and margin line.- Parameters:
g- The graphics context with which to paint.
-
paintLineHighlights
protected void paintLineHighlights(java.awt.Graphics g)
Paints any line highlights.- Parameters:
g- The graphics context.
-
paintMarginLine
protected void paintMarginLine(java.awt.Graphics g, java.awt.Rectangle visibleRect)Draws the "margin line" if enabled.- Parameters:
g- The graphics context to paint with.visibleRect- The visible rectangle of this text area.
-
paintSafely
protected void paintSafely(java.awt.Graphics g)
- Overrides:
paintSafelyin classjavax.swing.plaf.basic.BasicTextUI
-
yForLine
public int yForLine(int line) throws javax.swing.text.BadLocationExceptionReturns 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 traditionalBasicTextUI.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
-1if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding). - Throws:
javax.swing.text.BadLocationException- Iflineisn't a valid line number for this document.
-
yForLineContaining
public int yForLineContaining(int offs) throws javax.swing.text.BadLocationExceptionReturns 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 traditionalBasicTextUI.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
-1if this text area doesn't yet have a positive size or the line is hidden (i.e. from folding). - Throws:
javax.swing.text.BadLocationException- Ifoffsisn't a valid offset into the document.
-
-