Package editor
Class GosuStyleContext.GosuSourceView
java.lang.Object
javax.swing.text.View
javax.swing.text.CompositeView
javax.swing.text.BoxView
javax.swing.text.WrappedPlainView
editor.GosuStyleContext.GosuSourceView
- All Implemented Interfaces:
SwingConstants
,TabExpander
- Enclosing class:
- GosuStyleContext
View that uses the lexical information to determine the style
characteristics of the text that it renders. This simply colorizes the
various tokens and assumes a constant font family and size.
-
Field Summary
FieldsFields 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
ConstructorsConstructorDescriptionGosuSourceView
(Element elem) Construct a simple syntax highlight view of gosu source. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
drawSelectedText
(Graphics g, int x, int y, int p0, int p1) Renders the given range in the model as normal unselected text.final int
drawTabbedText
(Segment s, Style style, Font font, int x, int y, Graphics2D g, TabExpander e, int startOffset) final void
drawText
(Graphics2D g2, Style style, Font font, String text, int x, int y) Draws text using a TextLayout.protected int
drawUnselectedText
(Graphics g, int x, int y, int p0, int p1) void
Renders using the given rendering surface and area on that surface.(package private) void
updateScanner
(int p) Update the scanner (if necessary) to point to the appropriate token for the given start position needed for rendering.Methods inherited from class javax.swing.text.WrappedPlainView
calculateBreakPosition, changedUpdate, drawLine, drawLine, drawSelectedText, drawUnselectedText, getLineBuffer, getMaximumSpan, getMinimumSpan, getPreferredSpan, getTabSize, insertUpdate, loadChildren, nextTabStop, removeUpdate, setSize
Methods inherited from class javax.swing.text.BoxView
baselineLayout, baselineRequirements, calculateMajorAxisRequirements, calculateMinorAxisRequirements, childAllocation, flipEastAndWestAtEnds, forwardUpdate, getAlignment, getAxis, getChildAllocation, getHeight, getOffset, getResizeWeight, getSpan, getViewAtPoint, getWidth, isAfter, isAllocationValid, isBefore, isLayoutValid, layout, layoutChanged, layoutMajorAxis, layoutMinorAxis, modelToView, paintChild, preferenceChanged, replace, setAxis, viewToModel
Methods inherited from class javax.swing.text.CompositeView
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, getViewIndexAtPosition, modelToView, setInsets, setParagraphInsets, setParent
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, remove, removeAll, updateChildren, updateLayout, viewToModel
-
Field Details
-
_lexer
GosuDocument.Scanner _lexer
-
-
Constructor Details
-
GosuSourceView
GosuSourceView(Element elem) Construct a simple syntax highlight view of gosu source.
-
-
Method Details
-
paint
Renders using the given rendering surface and area on that surface. This is implemented to invalidate the lexical scanner after rendering so that the next request to drawUnselectedText will set a new range for the scanner.- Overrides:
paint
in classWrappedPlainView
- Parameters:
g
- The rendering surface to usea
- The allocated region to render into
-
drawSelectedText
protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException Renders the given range in the model as normal unselected text. This is implemented to paint colors based upon the token-to-color translations. To reduce the number of calls to the Graphics object, text is batched up until a color change is detected or the entire requested range has been reached.- Overrides:
drawSelectedText
in classWrappedPlainView
- Parameters:
g
- The graphics contextx
- The starting X coordinatey
- The starting Y coordinatep0
- The beginning position in the modelp1
- The ending position in the model- Returns:
- The location of the end of the range
- Throws:
BadLocationException
- if the range is invalid
-
drawUnselectedText
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException - Overrides:
drawUnselectedText
in classWrappedPlainView
- Throws:
BadLocationException
-
updateScanner
void updateScanner(int p) Update the scanner (if necessary) to point to the appropriate token for the given start position needed for rendering. -
drawTabbedText
public final int drawTabbedText(Segment s, Style style, Font font, int x, int y, Graphics2D g, TabExpander e, int startOffset) -
drawText
Draws text using a TextLayout. This method of drawing text is necessary to support certain attribute esp. TextAttribute.UNDERLINE and TextAttribute.STRIKETHROUGH .
-