javax.swing.text

Class PlainView

public class PlainView extends View implements TabExpander

Field Summary
protected FontMetricsmetrics
Constructor Summary
PlainView(Element elem)
Method Summary
voidchangedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when attributes were changed in the Document in a location that this view is responsible for.
protected voiddamageLineRange(int line0, int line1, Shape a, Component host)
Repaint the given line range.
protected voiddrawLine(int lineIndex, Graphics g, int x, int y)
Draws a line of text.
protected intdrawSelectedText(Graphics g, int x, int y, int p0, int p1)
protected intdrawUnselectedText(Graphics g, int x, int y, int p0, int p1)
Draws a chunk of unselected text.
protected SegmentgetLineBuffer()
Provides a {@link Segment} object, that can be used to fetch text from the document.
floatgetPreferredSpan(int axis)
protected intgetTabSize()
Returns the tab size of a tab.
voidinsertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when something is inserted into the Document that this View is displaying.
protected RectanglelineToRect(Shape a, int line)
ShapemodelToView(int position, Shape a, Position.Bias b)
floatnextTabStop(float x, int tabStop)
Returns the next tab stop position after a given reference position.
voidpaint(Graphics g, Shape s)
voidremoveUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when something is removed from the Document that this View is displaying.
protected voidupdateDamage(DocumentEvent changes, Shape a, ViewFactory f)
Since insertUpdate and removeUpdate each deal with children Elements being both added and removed, they both have to perform the same checks.
protected voidupdateMetrics()
intviewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.

Field Detail

metrics

protected FontMetrics metrics

Constructor Detail

PlainView

public PlainView(Element elem)

Method Detail

changedUpdate

public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when attributes were changed in the Document in a location that this view is responsible for.

damageLineRange

protected void damageLineRange(int line0, int line1, Shape a, Component host)
Repaint the given line range. This is called from insertUpdate, changedUpdate, and removeUpdate when no new lines were added and no lines were removed, to repaint the line that was modified.

Parameters: line0 the start of the range line1 the end of the range a the rendering region of the host host the Component that uses this View (used to call repaint on that Component)

Since: 1.4

drawLine

protected void drawLine(int lineIndex, Graphics g, int x, int y)
Draws a line of text. The X and Y coordinates specify the start of the baseline of the line.

Parameters: lineIndex the index of the line g the graphics to use for drawing the text x the X coordinate of the baseline y the Y coordinate of the baseline

drawSelectedText

protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1)

drawUnselectedText

protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
Draws a chunk of unselected text.

Parameters: g the graphics to use for drawing the text x the X coordinate of the baseline y the Y coordinate of the baseline p0 the start position in the text model p1 the end position in the text model

Returns: the X location of the end of the range

Throws: BadLocationException if p0 or p1 are invalid

getLineBuffer

protected final Segment getLineBuffer()
Provides a {@link Segment} object, that can be used to fetch text from the document.

UNKNOWN: {@link Segment} object, that can be used to fetch text from the document

getPreferredSpan

public float getPreferredSpan(int axis)

getTabSize

protected int getTabSize()
Returns the tab size of a tab. Checks the Document's properties for PlainDocument.tabSizeAttribute and returns it if it is defined, otherwise returns 8.

Returns: the tab size.

insertUpdate

public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when something is inserted into the Document that this View is displaying.

Parameters: changes the DocumentEvent for the changes. a the allocation of the View f the ViewFactory used to rebuild

lineToRect

protected Rectangle lineToRect(Shape a, int line)

Since: 1.4

modelToView

public Shape modelToView(int position, Shape a, Position.Bias b)

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.

Parameters: x the current x position in pixels tabStop the position within the text stream that the tab occured at

paint

public void paint(Graphics g, Shape s)

removeUpdate

public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f)
This method is called when something is removed from the Document that this View is displaying.

Parameters: changes the DocumentEvent for the changes. a the allocation of the View f the ViewFactory used to rebuild

updateDamage

protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f)
Since insertUpdate and removeUpdate each deal with children Elements being both added and removed, they both have to perform the same checks. So they both simply call this method.

Parameters: changes the DocumentEvent for the changes to the Document. a the allocation of the View. f the ViewFactory to use for rebuilding.

updateMetrics

protected void updateMetrics()

Since: 1.4

viewToModel

public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.

Parameters: x the x coordinate in the view space y the y coordinate in the view space a the allocation of this View b the bias to use

Returns: the position in the document that corresponds to the screen coordinates x, y