Package org.fife.ui.rsyntaxtextarea
Class RSyntaxTextAreaUI
- 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
-
- org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaUI
-
- All Implemented Interfaces:
javax.swing.text.ViewFactory
public class RSyntaxTextAreaUI extends RTextAreaUI
UI used byRSyntaxTextArea
. This allows us to implement syntax highlighting.- Version:
- 0.1
-
-
Field Summary
Fields Modifier and Type Field Description private static javax.swing.text.EditorKit
DEFAULT_KIT
private static java.lang.String
SHARED_ACTION_MAP_NAME
private static java.lang.String
SHARED_INPUT_MAP_NAME
-
Fields inherited from class org.fife.ui.rtextarea.RTextAreaUI
textArea
-
-
Constructor Summary
Constructors Constructor Description RSyntaxTextAreaUI(javax.swing.JComponent rSyntaxTextArea)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.swing.text.View
create(javax.swing.text.Element elem)
Creates the view for an element.protected javax.swing.text.Highlighter
createHighlighter()
Creates the highlighter to use for syntax text areas.static javax.swing.plaf.ComponentUI
createUI(javax.swing.JComponent ta)
Creates and returns an instance of this UI.protected java.lang.String
getActionMapName()
Returns the name to use to cache/fetch the shared action map.javax.swing.text.EditorKit
getEditorKit(javax.swing.text.JTextComponent tc)
Fetches the EditorKit for the UI.protected javax.swing.InputMap
getRTextAreaInputMap()
Get the InputMap to use for the UI.protected void
paintEditorAugmentations(java.awt.Graphics g)
Paints editor augmentations added by RTextArea: highlighted lines, current line highlight, and margin line.protected void
paintMatchedBracket(java.awt.Graphics g)
Paints the "matched bracket", if any.protected void
paintMatchedBracketImpl(java.awt.Graphics g, RSyntaxTextArea rsta, java.awt.Rectangle r)
protected void
propertyChange(java.beans.PropertyChangeEvent e)
Gets called whenever a bound property is changed on this UI'sRSyntaxTextArea
.void
refreshSyntaxHighlighting()
Updates the view.int
yForLine(int line)
Returns the y-coordinate of the specified line.int
yForLineContaining(int offs)
Returns the y-coordinate of the line containing a specified offset.-
Methods inherited from class org.fife.ui.rtextarea.RTextAreaUI
createCaret, createKeymap, createRTextAreaActionMap, getRTextArea, getVisibleEditorRect, installDefaults, installKeyboardActions, installUI, paintBackground, paintCurrentLineHighlight, paintLineHighlights, paintMarginLine, paintSafely
-
Methods inherited from class javax.swing.plaf.basic.BasicTextAreaUI
getBaseline, getBaselineResizeBehavior, getMinimumSize, getPreferredSize, getPropertyPrefix
-
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
-
DEFAULT_KIT
private static final javax.swing.text.EditorKit DEFAULT_KIT
-
-
Method Detail
-
createUI
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent ta)
Creates and returns an instance of this UI.- Parameters:
ta
- The text area that will use the UI.- Returns:
- The UI.
-
create
public javax.swing.text.View create(javax.swing.text.Element elem)
Creates the view for an element.- Specified by:
create
in interfacejavax.swing.text.ViewFactory
- Overrides:
create
in classRTextAreaUI
- Parameters:
elem
- The element.- Returns:
- The view.
-
createHighlighter
protected javax.swing.text.Highlighter createHighlighter()
Creates the highlighter to use for syntax text areas.- Overrides:
createHighlighter
in classRTextAreaUI
- Returns:
- The highlighter.
-
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.- Overrides:
getActionMapName
in classRTextAreaUI
- 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:
getEditorKit
in classRTextAreaUI
- Parameters:
tc
- The text component for which this UI is installed.- Returns:
- The editor capabilities.
- See Also:
TextUI.getEditorKit(javax.swing.text.JTextComponent)
-
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 inBasicTextAreaUI
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).- Overrides:
getRTextAreaInputMap
in classRTextAreaUI
-
paintEditorAugmentations
protected void paintEditorAugmentations(java.awt.Graphics g)
Description copied from class:RTextAreaUI
Paints editor augmentations added by RTextArea: highlighted lines, current line highlight, and margin line.- Overrides:
paintEditorAugmentations
in classRTextAreaUI
- Parameters:
g
- The graphics context with which to paint.
-
paintMatchedBracket
protected void paintMatchedBracket(java.awt.Graphics g)
Paints the "matched bracket", if any.- Parameters:
g
- The graphics context.
-
paintMatchedBracketImpl
protected void paintMatchedBracketImpl(java.awt.Graphics g, RSyntaxTextArea rsta, java.awt.Rectangle r)
-
propertyChange
protected void propertyChange(java.beans.PropertyChangeEvent e)
Gets called whenever a bound property is changed on this UI'sRSyntaxTextArea
.- Overrides:
propertyChange
in classjavax.swing.plaf.basic.BasicTextAreaUI
- Parameters:
e
- The property change event.
-
refreshSyntaxHighlighting
public void refreshSyntaxHighlighting()
Updates the view. This should be called when the underlyingRSyntaxTextArea
changes its syntax editing style.
-
yForLine
public int yForLine(int line) throws javax.swing.text.BadLocationException
Returns the y-coordinate of the specified line.This method is quicker than using traditional
modelToView(int)
calls, as the entire bounding box isn't computed.- Overrides:
yForLine
in classRTextAreaUI
- 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:
javax.swing.text.BadLocationException
- Ifline
isn't a valid line number for this document.
-
yForLineContaining
public int yForLineContaining(int offs) throws javax.swing.text.BadLocationException
Returns the y-coordinate of the line containing a specified offset.This is faster than calling
modelToView(offs).y
, so it is preferred if you do not need the actual bounding box.- Overrides:
yForLineContaining
in classRTextAreaUI
- 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:
javax.swing.text.BadLocationException
- Ifoffs
isn't a valid offset into the document.
-
-