Class SyntaxView
java.lang.Object
javax.swing.text.View
org.fife.ui.rsyntaxtextarea.SyntaxView
- All Implemented Interfaces:
SwingConstants, TabExpander, TokenOrientedView
The
javax.swing.text.View object used by RSyntaxTextArea
when word wrap is disabled. It implements syntax highlighting for
programming languages using the colors and font styles specified by the
RSyntaxTextArea.
You don't really have to do anything to use this class, as
RSyntaxTextAreaUI automatically sets the text area's view to be
an instance of this class if word wrap is disabled.
The tokens that specify how to paint the syntax-highlighted text are gleaned
from the text area's RSyntaxDocument.
- Version:
- 0.3
- Author:
- Robert Futrell
-
Field Summary
Fields inherited from class View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXISFields inherited from interface SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
ConstructorsConstructorDescriptionSyntaxView(Element elem) Constructs a newSyntaxViewwrapped around an element. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangedUpdate(DocumentEvent changes, Shape a, ViewFactory f) Gives notification from the document that attributes were changed in a location that this view is responsible for.protected voiddamageLineRange(int line0, int line1, Shape a, Component host) Repaint the given line range.intgetNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) Provides a way to determine the next visually represented model location that one might place a caret.floatgetPreferredSpan(int axis) Determines the preferred span for this view along an axis.getTokenListForPhysicalLineAbove(int offset) Returns a token list for the physical line above the physical line containing the specified offset into the document.getTokenListForPhysicalLineBelow(int offset) Returns a token list for the physical line below the physical line containing the specified offset into the document.voidinsertUpdate(DocumentEvent changes, Shape a, ViewFactory f) Gives notification that something was inserted into the document in a location that this view is responsible for.protected RectanglelineToRect(Shape a, int line) Determine the rectangle that represents the given line.modelToView(int pos, Shape a, Position.Bias b) Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) Provides a mapping, for a given region, from the document model coordinate space to the view coordinate space.floatnextTabStop(float x, int tabOffset) Returns the next tab stop position after a given reference position.voidActually paints the text area.voidremoveUpdate(DocumentEvent changes, Shape a, ViewFactory f) Gives notification that something was removed from the document in a location that this view is responsible for.voidsetSize(float width, float height) protected voidupdateDamage(DocumentEvent changes, Shape a, ViewFactory f) Repaint the region of change covered by the given document event.intviewToModel(float fx, float fy, Shape a, Position.Bias[] bias) Provides a mapping from the view coordinate space to the logical coordinate space of the model.intintyForLineContaining(Rectangle alloc, int offs) Methods inherited from class View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, isVisible, modelToView, preferenceChanged, remove, removeAll, replace, setParent, updateChildren, updateLayout, viewToModel
-
Constructor Details
-
SyntaxView
Constructs a newSyntaxViewwrapped around an element.- Parameters:
elem- The element representing the text to display.
-
-
Method Details
-
changedUpdate
Gives notification from the document that attributes were changed in a location that this view is responsible for.- Overrides:
changedUpdatein classView- Parameters:
changes- the change information from the associated documenta- the current allocation of the viewf- the factory to use to rebuild if the view has children- See Also:
-
damageLineRange
Repaint the given line range.- Parameters:
line0- The starting line number to repaint. This must be a valid line number in the model.line1- The ending line number to repaint. This must be a valid line number in the model.a- The region allocated for the view to render into.host- The component hosting the view (used to call repaint).
-
getNextVisualPositionFrom
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException Provides a way to determine the next visually represented model location that one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some locations in the model.- Overrides:
getNextVisualPositionFromin classView- Parameters:
pos- the position to convert >= 0a- the allocated region to render intodirection- the direction from the current position that can be thought of as the arrow keys typically found on a keyboard. This may beSwingConstants.WEST,SwingConstants.EAST,SwingConstants.NORTH, orSwingConstants.SOUTH.- Returns:
- the location within the model that best represents the next location visual position.
- Throws:
BadLocationException- If the offset specified is invalid.IllegalArgumentException- for an invalid direction
-
getPreferredSpan
public float getPreferredSpan(int axis) Determines the preferred span for this view along an axis.- Specified by:
getPreferredSpanin classView- Parameters:
axis- may be either View.X_AXIS or View.Y_AXIS- Returns:
- the span the view would like to be rendered into >= 0. Typically, the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
- Throws:
IllegalArgumentException- for an invalid axis
-
getTokenListForPhysicalLineAbove
Returns a token list for the physical line above the physical line containing the specified offset into the document. Note that for this plain (non-wrapped) view, this is simply the token list for the logical line above the line containingoffset, since lines are not wrapped.- Specified by:
getTokenListForPhysicalLineAbovein interfaceTokenOrientedView- Parameters:
offset- The offset in question.- Returns:
- A token list for the physical (and in this view, logical) line
before this one. If
offsetis in the first line in the document,nullis returned.
-
getTokenListForPhysicalLineBelow
Returns a token list for the physical line below the physical line containing the specified offset into the document. Note that for this plain (non-wrapped) view, this is simply the token list for the logical line below the line containingoffset, since lines are not wrapped.- Specified by:
getTokenListForPhysicalLineBelowin interfaceTokenOrientedView- Parameters:
offset- The offset in question.- Returns:
- A token list for the physical (and in this view, logical) line
after this one. If
offsetis in the last physical line in the document,nullis returned.
-
insertUpdate
Gives notification that something was inserted into the document in a location that this view is responsible for.- Overrides:
insertUpdatein classView- Parameters:
changes- The change information from the associated document.a- The current allocation of the view.f- The factory to use to rebuild if the view has children.
-
lineToRect
-
modelToView
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.- Specified by:
modelToViewin classView- Parameters:
pos- the position to convert >= 0a- the allocated region to render into- Returns:
- the bounding box of the given position
- Throws:
BadLocationException- if the given position does not represent a valid location in the associated document- See Also:
-
modelToView
public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException Provides a mapping, for a given region, from the document model coordinate space to the view coordinate space. The specified region is created as a union of the first and last character positions.This is implemented to subtract the width of the second character, as this view's
modelToViewactually returns the width of the character instead of "1" or "0" like the View implementations injavax.swing.text. Thus, if we don't override this method, theViewimplementation will return one character's width too much for its consumers (implementations ofjavax.swing.text.Highlighter).- Overrides:
modelToViewin classView- Parameters:
p0- the position of the first character (>=0)b0- The bias of the first character position, toward the previous character or the next character represented by the offset, in case the position is a boundary of two views;b0will have one of these values:-
Position.Bias.Forward -
Position.Bias.Backward
-
p1- the position of the last character (>=0)b1- the bias for the second character position, defined one of the legal values shown abovea- the area of the view, which encompasses the requested region- Returns:
- the bounding box which is a union of the region specified by the first and last character positions
- Throws:
BadLocationException- if the given position does not represent a valid location in the associated documentIllegalArgumentException- ifb0orb1are not one of the legalPosition.Biasvalues listed above- See Also:
-
nextTabStop
public float nextTabStop(float x, int tabOffset) Returns the next tab stop position after a given reference position. This implementation does not support things like centering so it ignores the tabOffset argument.- Specified by:
nextTabStopin interfaceTabExpander- Parameters:
x- the current position >= 0tabOffset- the position within the text stream that the tab occurred at >= 0.- Returns:
- the tab stop, measured in points >= 0
-
paint
-
removeUpdate
Gives notification that something was removed from the document in a location that this view is responsible for.- Overrides:
removeUpdatein classView- Parameters:
changes- the change information from the associated documenta- the current allocation of the viewf- the factory to use to rebuild if the view has children
-
setSize
-
updateDamage
Repaint the region of change covered by the given document event. Damages the line that begins the range to cover the case when the insert/remove is only on one line. If lines are added or removed, damages the whole view. The longest line is checked to see if it has changed. -
viewToModel
Provides a mapping from the view coordinate space to the logical coordinate space of the model.- Specified by:
viewToModelin classView- Parameters:
fx- the X coordinate >= 0fy- the Y coordinate >= 0a- the allocated region to render into- Returns:
- the location within the model that best represents the given point in the view >= 0
-
yForLine
-
yForLineContaining
- Throws:
BadLocationException
-