public class SyntaxView extends javax.swing.text.View implements javax.swing.text.TabExpander, TokenOrientedView
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
.
构造器和说明 |
---|
SyntaxView(javax.swing.text.Element elem)
Constructs a new
SyntaxView wrapped around an element. |
限定符和类型 | 方法和说明 |
---|---|
void |
changedUpdate(javax.swing.event.DocumentEvent changes,
java.awt.Shape a,
javax.swing.text.ViewFactory f)
Gives notification from the document that attributes were changed
in a location that this view is responsible for.
|
protected void |
damageLineRange(int line0,
int line1,
java.awt.Shape a,
java.awt.Component host)
Repaint the given line range.
|
int |
getNextVisualPositionFrom(int pos,
javax.swing.text.Position.Bias b,
java.awt.Shape a,
int direction,
javax.swing.text.Position.Bias[] biasRet)
Provides a way to determine the next visually represented model
location that one might place a caret.
|
float |
getPreferredSpan(int axis)
Determines the preferred span for this view along an
axis.
|
Token |
getTokenListForPhysicalLineAbove(int offset)
Returns a token list for the physical line above the physical
line containing the specified offset into the document.
|
Token |
getTokenListForPhysicalLineBelow(int offset)
Returns a token list for the physical line below the physical
line containing the specified offset into the document.
|
void |
insertUpdate(javax.swing.event.DocumentEvent changes,
java.awt.Shape a,
javax.swing.text.ViewFactory f)
Gives notification that something was inserted into the document
in a location that this view is responsible for.
|
protected java.awt.Rectangle |
lineToRect(java.awt.Shape a,
int line)
Determine the rectangle that represents the given line.
|
java.awt.Shape |
modelToView(int p0,
javax.swing.text.Position.Bias b0,
int p1,
javax.swing.text.Position.Bias b1,
java.awt.Shape a)
Provides a mapping, for a given region, from the document model
coordinate space to the view coordinate space.
|
java.awt.Shape |
modelToView(int pos,
java.awt.Shape a,
javax.swing.text.Position.Bias b)
Provides a mapping from the document model coordinate space
to the coordinate space of the view mapped to it.
|
float |
nextTabStop(float x,
int tabOffset)
Returns the next tab stop position after a given reference position.
|
void |
paint(java.awt.Graphics g,
java.awt.Shape a)
Actually paints the text area.
|
void |
removeUpdate(javax.swing.event.DocumentEvent changes,
java.awt.Shape a,
javax.swing.text.ViewFactory f)
Gives notification that something was removed from the document
in a location that this view is responsible for.
|
void |
setSize(float width,
float height) |
protected void |
updateDamage(javax.swing.event.DocumentEvent changes,
java.awt.Shape a,
javax.swing.text.ViewFactory f)
Repaint the region of change covered by the given document
event.
|
int |
viewToModel(float fx,
float fy,
java.awt.Shape a,
javax.swing.text.Position.Bias[] bias)
Provides a mapping from the view coordinate space to the logical
coordinate space of the model.
|
int |
yForLine(java.awt.Rectangle alloc,
int line)
Returns the y-coordinate of the specified line.
|
int |
yForLineContaining(java.awt.Rectangle alloc,
int offs)
Returns the y-coordinate of the line containing a specified offset.
|
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
public SyntaxView(javax.swing.text.Element elem)
SyntaxView
wrapped around an element.elem
- The element representing the text to display.public void changedUpdate(javax.swing.event.DocumentEvent changes, java.awt.Shape a, javax.swing.text.ViewFactory f)
changedUpdate
在类中 javax.swing.text.View
changes
- the change information from the associated documenta
- the current allocation of the viewf
- the factory to use to rebuild if the view has childrenView.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
protected void damageLineRange(int line0, int line1, java.awt.Shape a, java.awt.Component host)
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).public int getNextVisualPositionFrom(int pos, javax.swing.text.Position.Bias b, java.awt.Shape a, int direction, javax.swing.text.Position.Bias[] biasRet) throws javax.swing.text.BadLocationException
getNextVisualPositionFrom
在类中 javax.swing.text.View
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 be SwingConstants.WEST, SwingConstants.EAST,
SwingConstants.NORTH, or SwingConstants.SOUTH.javax.swing.text.BadLocationException
java.lang.IllegalArgumentException
- for an invalid directionpublic float getPreferredSpan(int axis)
getPreferredSpan
在类中 javax.swing.text.View
axis
- may be either View.X_AXIS or View.Y_AXISjava.lang.IllegalArgumentException
- for an invalid axispublic Token getTokenListForPhysicalLineAbove(int offset)
offset
, since lines
are not wrapped.getTokenListForPhysicalLineAbove
在接口中 TokenOrientedView
offset
- The offset in question.offset
is in the first line in
the document, null
is returned.public Token getTokenListForPhysicalLineBelow(int offset)
offset
, since lines
are not wrapped.getTokenListForPhysicalLineBelow
在接口中 TokenOrientedView
offset
- The offset in question.offset
is in the last physical
line in the document, null
is returned.public void insertUpdate(javax.swing.event.DocumentEvent changes, java.awt.Shape a, javax.swing.text.ViewFactory f)
insertUpdate
在类中 javax.swing.text.View
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.protected java.awt.Rectangle lineToRect(java.awt.Shape a, int line)
a
- The region allocated for the view to render intoline
- The line number to find the region of. This must
be a valid line number in the model.public java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b) throws javax.swing.text.BadLocationException
modelToView
在类中 javax.swing.text.View
pos
- the position to convert >= 0a
- the allocated region to render intojavax.swing.text.BadLocationException
- if the given position does not
represent a valid location in the associated documentView.modelToView(int, java.awt.Shape, javax.swing.text.Position.Bias)
public java.awt.Shape modelToView(int p0, javax.swing.text.Position.Bias b0, int p1, javax.swing.text.Position.Bias b1, java.awt.Shape a) throws javax.swing.text.BadLocationException
This is implemented to subtract the width of the second character, as
this view's modelToView
actually returns the width of the
character instead of "1" or "0" like the View implementations in
javax.swing.text
. Thus, if we don't override this method,
the View
implementation will return one character's width
too much for its consumers (implementations of
javax.swing.text.Highlighter
).
modelToView
在类中 javax.swing.text.View
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; b0
will 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 regionjavax.swing.text.BadLocationException
- if the given position does
not represent a valid location in the associated documentjava.lang.IllegalArgumentException
- if b0
or
b1
are not one of the
legal Position.Bias
values listed aboveView.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])
public float nextTabStop(float x, int tabOffset)
nextTabStop
在接口中 javax.swing.text.TabExpander
x
- the current position >= 0tabOffset
- the position within the text stream
that the tab occurred at >= 0.public void paint(java.awt.Graphics g, java.awt.Shape a)
paint
在类中 javax.swing.text.View
g
- The graphics context with which to paint.a
- The allocated region in which to render.public void removeUpdate(javax.swing.event.DocumentEvent changes, java.awt.Shape a, javax.swing.text.ViewFactory f)
removeUpdate
在类中 javax.swing.text.View
changes
- the change information from the associated documenta
- the current allocation of the viewf
- the factory to use to rebuild if the view has childrenpublic void setSize(float width, float height)
setSize
在类中 javax.swing.text.View
protected void updateDamage(javax.swing.event.DocumentEvent changes, java.awt.Shape a, javax.swing.text.ViewFactory f)
public int viewToModel(float fx, float fy, java.awt.Shape a, javax.swing.text.Position.Bias[] bias)
viewToModel
在类中 javax.swing.text.View
fx
- the X coordinate >= 0fy
- the Y coordinate >= 0a
- the allocated region to render intopublic int yForLine(java.awt.Rectangle alloc, int line) throws javax.swing.text.BadLocationException
This method is quicker than using traditional
modelToView(int)
calls, as the entire bounding box isn't
computed.
alloc
- The area the text area can render into.line
- The line number.-1
if
this text area doesn't yet have a positive size or the line is
hidden (i.e. from folding).javax.swing.text.BadLocationException
- If line
isn't a valid line
number for this document.public int yForLineContaining(java.awt.Rectangle alloc, int offs) throws javax.swing.text.BadLocationException
This method is quicker than using traditional
modelToView(int)
calls, as the entire bounding box isn't
computed.
alloc
- The area the text area can render into.offs
- The offset info the document.-1
if
this text area doesn't yet have a positive size or the line is
hidden (i.e. from folding).javax.swing.text.BadLocationException
- If offs
isn't a valid offset
into the document.