|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.text.View
org.fife.ui.rsyntaxtextarea.SyntaxView
public class SyntaxView
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
.
Field Summary | |
---|---|
protected FontMetrics |
metrics
Font metrics for the current font. |
protected int |
tabBase
|
Fields inherited from class javax.swing.text.View |
---|
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS |
Fields inherited from interface javax.swing.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 | |
---|---|
SyntaxView(Element elem)
Constructs a new SyntaxView wrapped around an element. |
Method Summary | |
---|---|
void |
changedUpdate(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 void |
damageLineRange(int line0,
int line1,
Shape a,
Component host)
Repaint the given line range. |
float |
drawLine(Token token,
Graphics2D g,
float x,
float y)
Draws the passed-in text using syntax highlighting for the current language. |
int |
getNextVisualPositionFrom(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. |
float |
getPreferredSpan(int axis)
Determines the preferred span for this view along an axis. |
protected int |
getTabSize()
Returns the tab size set for the document, defaulting to 5. |
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(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 Rectangle |
lineToRect(Shape a,
int line)
Determine the rectangle that represents the given line. |
Shape |
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. |
Shape |
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. |
float |
nextTabStop(float x,
int tabOffset)
Returns the next tab stop position after a given reference position. |
void |
paint(Graphics g,
Shape a)
Actually paints the text area. |
protected boolean |
possiblyUpdateLongLine(Element line,
int lineNumber)
If the passed-in line is longer than the current longest line, then the longest line is updated. |
void |
removeUpdate(DocumentEvent changes,
Shape a,
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(DocumentEvent changes,
Shape a,
ViewFactory f)
Repaint the region of change covered by the given document event. |
protected void |
updateMetrics()
Checks to see if the font metrics and longest line are up-to-date. |
int |
viewToModel(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. |
int |
yForLineContaining(Rectangle alloc,
int offs)
Returns the y-coordinate of the line containing a specified offset. |
Methods inherited from class javax.swing.text.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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected FontMetrics metrics
protected int tabBase
Constructor Detail |
---|
public SyntaxView(Element elem)
SyntaxView
wrapped around an element.
elem
- The element representing the text to display.Method Detail |
---|
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
changedUpdate
in class 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, Shape a, 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 float drawLine(Token token, Graphics2D g, float x, float y)
token
- The list of tokens to draw.g
- The graphics context in which to draw.x
- The x-coordinate at which to draw.y
- The y-coordinate at which to draw.
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom
in class 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.
BadLocationException
IllegalArgumentException
- for an invalid directionpublic float getPreferredSpan(int axis)
getPreferredSpan
in class View
axis
- may be either View.X_AXIS or View.Y_AXIS
IllegalArgumentException
- for an invalid axisprotected int getTabSize()
public Token getTokenListForPhysicalLineAbove(int offset)
offset
, since lines
are not wrapped.
getTokenListForPhysicalLineAbove
in interface 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
in interface TokenOrientedView
offset
- The offset in question.
offset
is in the last physical
line in the document, null
is returned.public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
insertUpdate
in class 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 Rectangle lineToRect(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 Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
modelToView
in class View
pos
- the position to convert >= 0a
- the allocated region to render into
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 Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws 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
in class 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 region
BadLocationException
- if the given position does
not represent a valid location in the associated document
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
in interface TabExpander
x
- the current position >= 0tabOffset
- the position within the text stream
that the tab occurred at >= 0.
public void paint(Graphics g, Shape a)
paint
in class View
g
- The graphics context with which to paint.a
- The allocated region in which to render.drawLine(org.fife.ui.rsyntaxtextarea.Token, java.awt.Graphics2D, float, float)
protected boolean possiblyUpdateLongLine(Element line, int lineNumber)
line
- The line to test against the current longest.lineNumber
- The line number of the passed-in line.
true
iff the current longest line was updated.public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f)
removeUpdate
in class 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
in class View
protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f)
protected void updateMetrics()
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias)
viewToModel
in class View
fx
- the X coordinate >= 0fy
- the Y coordinate >= 0a
- the allocated region to render into
public int yForLineContaining(Rectangle alloc, int offs) throws 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.
BadLocationException
- If offs
isn't a valid offset
into the document.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |