javax.swing.text
Class WrappedPlainView

java.lang.Object
  extended by javax.swing.text.View
      extended by javax.swing.text.CompositeView
          extended by javax.swing.text.BoxView
              extended by javax.swing.text.WrappedPlainView
All Implemented Interfaces:
SwingConstants, TabExpander

public class WrappedPlainView
extends BoxView
implements TabExpander


Field Summary
 
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
WrappedPlainView(Element elem)
           
WrappedPlainView(Element elem, boolean wordWrap)
           
 
Method Summary
protected  int calculateBreakPosition(int p0, int p1)
          Calculates the break position for the text between model positions p0 and p1.
 void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Called when the portion of the Document that this View is responsible for changes.
protected  void drawLine(int p0, int p1, Graphics g, int x, int y)
          Draws a line of text, suppressing white space at the end and expanding tabs.
protected  int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
          Renders the range of text as selected text.
protected  int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
          Renders the range of text as normal unhighlighted text.
protected  Segment getLineBuffer()
          Provides access to the Segment used for retrievals from the Document.
 float getMaximumSpan(int axis)
          Determines the maximum span along the given axis.
 float getMinimumSpan(int axis)
          Determines the minimum span along the given axis.
 float getPreferredSpan(int axis)
          Determines the preferred span along the given axis.
protected  int getTabSize()
          Returns the tab size for the Document based on PlainDocument.tabSizeAttribute, defaulting to 8 if this property is not defined
 void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Called when something was inserted.
protected  void loadChildren(ViewFactory f)
          Loads the children to initiate the view.
 float nextTabStop(float x, int tabStop)
          Returns the next tab stop position after a given reference position.
 void paint(Graphics g, Shape a)
          Renders the Element that is associated with this View.
 void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Called when something is removed.
 void setSize(float width, float height)
          Sets the size of the View.
 
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, dump, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, remove, removeAll, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappedPlainView

public WrappedPlainView(Element elem)

WrappedPlainView

public WrappedPlainView(Element elem,
                        boolean wordWrap)
Method Detail

getLineBuffer

protected final Segment getLineBuffer()
Provides access to the Segment used for retrievals from the Document.

Returns:
the Segment.

nextTabStop

public float nextTabStop(float x,
                         int tabStop)
Returns the next tab stop position after a given reference position. This implementation ignores the tabStop argument.

Specified by:
nextTabStop in interface TabExpander
Parameters:
x - the current x position in pixels
tabStop - the position within the text stream that the tab occured at

getTabSize

protected int getTabSize()
Returns the tab size for the Document based on PlainDocument.tabSizeAttribute, defaulting to 8 if this property is not defined

Returns:
the tab size.

drawLine

protected void drawLine(int p0,
                        int p1,
                        Graphics g,
                        int x,
                        int y)
Draws a line of text, suppressing white space at the end and expanding tabs. Calls drawSelectedText and drawUnselectedText.

Parameters:
p0 - starting document position to use
p1 - ending document position to use
g - graphics context
x - starting x position
y - starting y position

drawSelectedText

protected int drawSelectedText(Graphics g,
                               int x,
                               int y,
                               int p0,
                               int p1)
                        throws BadLocationException
Renders the range of text as selected text. Just paints the text in the color specified by the host component. Assumes the highlighter will render the selected background.

Parameters:
g - the graphics context
x - the starting X coordinate
y - the starting Y coordinate
p0 - the starting model location
p1 - the ending model location
Returns:
the X coordinate of the end of the text
Throws:
BadLocationException - if the given range is invalid

drawUnselectedText

protected int drawUnselectedText(Graphics g,
                                 int x,
                                 int y,
                                 int p0,
                                 int p1)
                          throws BadLocationException
Renders the range of text as normal unhighlighted text.

Parameters:
g - the graphics context
x - the starting X coordinate
y - the starting Y coordinate
p0 - the starting model location
p1 - the end model location
Returns:
the X location of the end off the range
Throws:
BadLocationException - if the range given is invalid

loadChildren

protected void loadChildren(ViewFactory f)
Loads the children to initiate the view. Called by setParent. Creates a WrappedLine for each child Element.

Overrides:
loadChildren in class CompositeView
Parameters:
f - the view factory to use for creating new child views
See Also:
CompositeView.setParent(javax.swing.text.View)

calculateBreakPosition

protected int calculateBreakPosition(int p0,
                                     int p1)
Calculates the break position for the text between model positions p0 and p1. Will break on word boundaries or character boundaries depending on the break argument given in construction of this WrappedPlainView. Used by the nested WrappedLine class to determine when to start the next logical line.

Parameters:
p0 - the start model position
p1 - the end model position
Returns:
the model position at which to break the text

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span along the given axis. Implemented to cache the font metrics and then call the super classes method.

Overrides:
getPreferredSpan in class BoxView
Parameters:
axis - the axis
Returns:
the preferred span of this View.

getMinimumSpan

public float getMinimumSpan(int axis)
Determines the minimum span along the given axis. Implemented to cache the font metrics and then call the super classes method.

Overrides:
getMinimumSpan in class BoxView
Parameters:
axis - the axis
Returns:
the minimum span of this view along the specified axis

getMaximumSpan

public float getMaximumSpan(int axis)
Determines the maximum span along the given axis. Implemented to cache the font metrics and then call the super classes method.

Overrides:
getMaximumSpan in class BoxView
Parameters:
axis - the axis
Returns:
the maximum span of this view along the specified axis

insertUpdate

public void insertUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Called when something was inserted. Overridden so that the view factory creates WrappedLine views.

Overrides:
insertUpdate in class View
Parameters:
e - the DocumentEvent that describes the change
a - the shape of the view
f - the ViewFactory for creating child views

removeUpdate

public void removeUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Called when something is removed. Overridden so that the view factory creates WrappedLine views.

Overrides:
removeUpdate in class View
Parameters:
e - the DocumentEvent that describes the change
a - the shape of the view
f - the ViewFactory for creating child views

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
Called when the portion of the Document that this View is responsible for changes. Overridden so that the view factory creates WrappedLine views.

Overrides:
changedUpdate in class View
Parameters:
e - the DocumentEvent that describes the change
a - the shape of the view
f - the ViewFactory for creating child views

paint

public void paint(Graphics g,
                  Shape a)
Renders the Element that is associated with this View. Caches the metrics and then calls super.paint to paint all the child views.

Overrides:
paint in class BoxView
Parameters:
g - the Graphics context to render to
a - the allocated region for the Element

setSize

public void setSize(float width,
                    float height)
Sets the size of the View. Implemented to update the metrics and then call super method.

Overrides:
setSize in class BoxView
Parameters:
width - the new width
height - the new height