Class WrappedSyntaxView
java.lang.Object
javax.swing.text.View
javax.swing.text.CompositeView
javax.swing.text.BoxView
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView
- All Implemented Interfaces:
SwingConstants, TabExpander
The view used by
RSyntaxTextArea when word wrap is enabled.- Version:
- 0.2
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intcalculateBreakPosition(int p0, Token tokenList, float x0) This is called by the nested wrapped line views to determine the break location.voidchangedUpdate(DocumentEvent e, Shape a, ViewFactory f) Gives notification from the document that attributes were changed in a location that this view is responsible for.protected voiddrawView(org.fife.ui.rsyntaxtextarea.TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int line) Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple lines if necessary.protected voiddrawViewWithSelection(org.fife.ui.rsyntaxtextarea.TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int selStart, int selEnd) Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple lines if necessary.getChildAllocation(int index, Shape a) Fetches the allocation for the given child view.getChildAllocationImpl(int line, Shape a) Fetches the allocation for the given child view to render into.floatgetMaximumSpan(int axis) Determines the maximum span for this view along an axis.floatgetMinimumSpan(int axis) Determines the minimum span for this view along an axis.floatgetPreferredSpan(int axis) Determines the preferred span for this view along an axis.protected intReturns the tab size set for the document, defaulting to 5.protected ViewgetViewAtPoint(int x, int y, Rectangle alloc) Overridden to allow for folded regions.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 voidLoads all of the children to initialize the view.modelToView(int pos, Shape a, Position.Bias b) 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.voidPaints the word-wrapped text.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) Sets the size of the view.intviewToModel(float x, float y, Shape a, Position.Bias[] bias) intintyForLineContaining(Rectangle alloc, int offs) Methods inherited from class BoxView
baselineLayout, baselineRequirements, calculateMajorAxisRequirements, calculateMinorAxisRequirements, childAllocation, flipEastAndWestAtEnds, forwardUpdate, getAlignment, getAxis, getHeight, getOffset, getResizeWeight, getSpan, getWidth, isAfter, isAllocationValid, isBefore, isLayoutValid, layout, layoutChanged, layoutMajorAxis, layoutMinorAxis, paintChild, preferenceChanged, replace, setAxisMethods inherited from class CompositeView
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, getViewIndexAtPosition, setInsets, setParagraphInsets, setParentMethods inherited from class 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
-
Constructor Details
-
WrappedSyntaxView
Creates a new WrappedSyntaxView. Lines will be wrapped on character boundaries.- Parameters:
elem- the element underlying the view
-
-
Method Details
-
calculateBreakPosition
This is called by the nested wrapped line views to determine the break location. This can be reimplemented to alter the breaking behavior. It will either break at word or character boundaries depending upon the break argument given at construction. -
changedUpdate
Gives notification from the document that attributes were changed in a location that this view is responsible for.- Overrides:
changedUpdatein classView- Parameters:
e- 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:
-
drawView
protected void drawView(org.fife.ui.rsyntaxtextarea.TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int line) Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple lines if necessary.- Parameters:
painter- The painter to use to render tokens.g- The graphics context in which to paint.r- The rectangle in which to paint.view- TheViewto paint.fontHeight- The height of the font being used.y- The y-coordinate at which to begin painting.
-
drawViewWithSelection
protected void drawViewWithSelection(org.fife.ui.rsyntaxtextarea.TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int selStart, int selEnd) Draws a single view (i.e., a line of text for a wrapped view), wrapping the text onto multiple lines if necessary. Any selected text is rendered with the editor's "selected text" color.- Parameters:
painter- The painter to use to render tokens.g- The graphics context in which to paint.r- The rectangle in which to paint.view- TheViewto paint.fontHeight- The height of the font being used.y- The y-coordinate at which to begin painting.selStart- The start of the selection.selEnd- The end of the selection.
-
getChildAllocation
Fetches the allocation for the given child view.Overridden to account for code folding.
- Overrides:
getChildAllocationin classBoxView- Parameters:
index- The index of the child, >= 0 &&< getViewCount().a- The allocation to this view- Returns:
- The allocation to the child; or
nullifaisnull; ornullif the layout is invalid
-
getChildAllocationImpl
Fetches the allocation for the given child view to render into.Overridden to account for lines hidden by collapsed folded regions.
- Parameters:
line- The index of the child, >= 0 &&< getViewCount()a- The allocation to this view- Returns:
- The allocation to the child
-
getMaximumSpan
public float getMaximumSpan(int axis) Determines the maximum span for this view along an axis. This is implemented to provide the superclass behavior after first making sure that the current font metrics are cached (for the nested lines which use the metrics to determine the height of the potentially wrapped lines).- Overrides:
getMaximumSpanin classBoxView- Parameters:
axis- may be either View.X_AXIS or View.Y_AXIS- Returns:
- the span the view would like to be rendered into. 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.
- See Also:
-
getMinimumSpan
public float getMinimumSpan(int axis) Determines the minimum span for this view along an axis. This is implemented to provide the superclass behavior after first making sure that the current font metrics are cached (for the nested lines which use the metrics to determine the height of the potentially wrapped lines).- Overrides:
getMinimumSpanin classBoxView- Parameters:
axis- may be either View.X_AXIS or View.Y_AXIS- Returns:
- the span the view would like to be rendered into. 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.
- See Also:
-
getPreferredSpan
public float getPreferredSpan(int axis) Determines the preferred span for this view along an axis. This is implemented to provide the superclass behavior after first making sure that the current font metrics are cached (for the nested lines which use the metrics to determine the height of the potentially wrapped lines).- Overrides:
getPreferredSpanin classBoxView- Parameters:
axis- may be either View.X_AXIS or View.Y_AXIS- Returns:
- the span the view would like to be rendered into. 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.
- See Also:
-
getTabSize
protected int getTabSize()Returns the tab size set for the document, defaulting to 5.- Returns:
- the tab size
-
getViewAtPoint
Overridden to allow for folded regions.- Overrides:
getViewAtPointin classBoxView
-
insertUpdate
Gives notification that something was inserted into the document in a location that this view is responsible for. This is implemented to simply update the children.- Overrides:
insertUpdatein classView- Parameters:
changes- The change information from the associated document.a- the current allocation of the viewf- the factory to use to rebuild if the view has children- See Also:
-
loadChildren
Loads all of the children to initialize the view. This is called by thesetParentmethod. Subclasses can re-implement this to initialize their child views in a different manner. The default implementation creates a child view for each child element.- Overrides:
loadChildrenin classCompositeView- Parameters:
f- the view factory
-
modelToView
- Overrides:
modelToViewin classBoxView- Throws:
BadLocationException
-
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 classCompositeView- 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. This is implemented to simply update the children.- Overrides:
removeUpdatein classView- Parameters:
changes- The change information from the associated document.a- the current allocation of the viewf- the factory to use to rebuild if the view has children- See Also:
-
setSize
-
viewToModel
- Overrides:
viewToModelin classBoxView
-
yForLine
- Throws:
BadLocationException
-
yForLineContaining
- Throws:
BadLocationException
-