Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.swing.text
Class PlainView

    java.lang.Object
      |
      +--javax.swing.text.View
            |
            +--javax.swing.text.PlainView

Direct Known Subclasses:
  FieldView

public class PlainView
extends View
implements TabExpander

Implements View interface for a simple multi-line text view that has text in one font and color. The view represents each child element as a line of text.

See Also:
  `View`

Field Summary
`protected java.awt.FontMetrics` | `metrics` Font metrics for the currrent font.

Fields inherited from class javax.swing.text.View
`BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS`

Constructor Summary
`PlainView(Element elem)` Constructs a new PlainView wrapped on an element.

Method Summary
`void` | `changedUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)` Gives notification from the document that attributes were changed in a location that this view is responsible for.
`protected void` | `drawLine(int lineIndex, java.awt.Graphics g, int x, int y)` Renders a line of text, suppressing whitespace at the end and exanding any tabs.
`protected int` | `drawSelectedText(java.awt.Graphics g, int x, int y, int p0, int p1)` Renders the given range in the model as selected text.
`protected int` | `drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)` Renders the given range in the model as normal unselected text.
`protected Segment` | `getLineBuffer()` Gives access to a buffer that can be used to fetch text from the associated document.
`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 8.
`void` | `insertUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)` Gives notification that something was inserted into the document in a location that this view is responsible for.
`java.awt.Shape` | `modelToView(int pos, java.awt.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(java.awt.Graphics g, java.awt.Shape a)` Renders using the given rendering surface and area on that surface.
`void` | `preferenceChanged(View child, boolean width, boolean height)` Signals that the desired span has changed.
`void` | `removeUpdate(DocumentEvent changes, java.awt.Shape a, ViewFactory f)` Gives notification that something was removed from the document in a location that this view is responsible for.
`int` | `viewToModel(float fx, float fy, java.awt.Shape a, Position.Bias[] bias)` Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Methods inherited from class javax.swing.text.View
`breakView, createFragment, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getView, getViewCount, getViewFactory, isVisible, modelToView, modelToView, setParent, setSize, viewToModel`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### metrics

    protected java.awt.FontMetrics metrics

  Font metrics for the currrent font.

Constructor Detail

### PlainView

    public PlainView(Element elem)

  Constructs a new PlainView wrapped on an element.
  Parameters:
    `elem` - the element

Method Detail

### getTabSize

    protected int getTabSize()

  Returns the tab size set for the document, defaulting to 8.
  Returns:
    the tab size

### drawLine

    protected void drawLine(int lineIndex,
                            java.awt.Graphics g,
                            int x,
                            int y)

  Renders a line of text, suppressing whitespace at the end and exanding any tabs. This is implemented to make calls to the methods `drawUnselectedText` and `drawSelectedText` so that the way selected and unselected text are rendered can be customized.
  Parameters:
    `lineIndex` - the line to draw >= 0
    `g` - the graphics context
    `x` - the starting X position >= 0
    `y` - the starting Y position >= 0
  See Also:
    `drawUnselectedText(java.awt.Graphics, int, int, int, int)`, `drawSelectedText(java.awt.Graphics, int, int, int, int)`

### drawUnselectedText

    protected int drawUnselectedText(java.awt.Graphics g,
                                     int x,
                                     int y,
                                     int p0,
                                     int p1)
                              throws BadLocationException

  Renders the given range in the model as normal unselected text. Uses the foreground or disabled color to render the text.
  Parameters:
    `g` - the graphics context
    `x` - the starting X coordinate >= 0
    `y` - the starting Y coordinate >= 0
    `p0` - the beginning position in the model >= 0
    `p1` - the ending position in the model >= 0
  Throws:
    BadLocationException - if the range is invalid

### drawSelectedText

    protected int drawSelectedText(java.awt.Graphics g,
                                   int x,
                                   int y,
                                   int p0,
                                   int p1)
                            throws BadLocationException

  Renders the given range in the model as selected text. This is implemented to render the text in the color specified in the hosting component. It assumes the highlighter will render the selected background.
  Parameters:
    `g` - the graphics context
    `x` - the starting X coordinate >= 0
    `y` - the starting Y coordinate >= 0
    `p0` - the beginning position in the model >= 0
    `p1` - the ending position in the model >= 0
  Throws:
    BadLocationException - if the range is invalid

### getLineBuffer

    protected final Segment getLineBuffer()

  Gives access to a buffer that can be used to fetch text from the associated document.

### getPreferredSpan

    public float getPreferredSpan(int axis)

  Determines the preferred span for this view along an axis.
  Parameters:
    `axis` - may be either View.X_AXIS or View.Y_AXIS
  Throws:
    java.lang.IllegalArgumentException - for an invalid axis
  Overrides:
    getPreferredSpan in class View

### paint

    public void paint(java.awt.Graphics g,
                      java.awt.Shape a)

  Renders using the given rendering surface and area on that surface. The view may need to do layout and create child views to enable itself to render into the given allocation.
  Parameters:
    `g` - the rendering surface to use
    `a` - the allocated region to render into
  Overrides:
    paint in class View
  See Also:
    `View.paint(java.awt.Graphics, java.awt.Shape)`

### preferenceChanged

    public void preferenceChanged(View child,
                                  boolean width,
                                  boolean height)

  Signals that the desired span has changed.
  Parameters:
    `child` - the child view
    `width` - true if the width preference has changed
    `height` - true if the height preference has changed
  Overrides:
    preferenceChanged in class View
  See Also:
    `JComponent.revalidate()`

### modelToView

    public java.awt.Shape modelToView(int pos,
                                      java.awt.Shape a,
                                      Position.Bias b)
                               throws BadLocationException

  Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
  Parameters:
    `pos` - the position to convert >= 0
    `a` - the allocated region to render into
  Returns:
    the bounding box of the given position
  Throws:
    BadLocationException - if the given position does not represent a valid location in the associated document
  Overrides:
    modelToView in class View
  See Also:
    `View.modelToView(int, java.awt.Shape, javax.swing.text.Position.Bias)`

### viewToModel

    public int viewToModel(float fx,
                           float fy,
                           java.awt.Shape a,
                           Position.Bias[] bias)

  Provides a mapping from the view coordinate space to the logical coordinate space of the model.
  Parameters:
    `fx` - the X coordinate >= 0
    `fy` - the Y coordinate >= 0
    `a` - the allocated region to render into
  Returns:
    the location within the model that best represents the given point in the view >= 0
  Overrides:
    viewToModel in class View
  See Also:
    `View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])`

### insertUpdate

    public void insertUpdate(DocumentEvent changes,
                             java.awt.Shape a,
                             ViewFactory f)

  Gives notification that something was inserted into the document in a location that this view is responsible for.
  Parameters:
    `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
  Overrides:
    insertUpdate in class View
  See Also:
    `View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)`

### removeUpdate

    public void removeUpdate(DocumentEvent changes,
                             java.awt.Shape a,
                             ViewFactory f)

  Gives notification that something was removed from the document in a location that this view is responsible for.
  Parameters:
    `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
  Overrides:
    removeUpdate in class View
  See Also:
    `View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)`

### changedUpdate

    public void changedUpdate(DocumentEvent changes,
                              java.awt.Shape a,
                              ViewFactory f)

  Gives notification from the document that attributes were changed in a location that this view is responsible for.
  Parameters:
    `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
  Overrides:
    changedUpdate in class View
  See Also:
    `View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)`

### 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:
    nextTabStop in interface TabExpander
  Parameters:
    `x` - the current position >= 0
    `tabOffset` - the position within the text stream that the tab occurred at >= 0.
  Returns:
    the tab stop, measured in points >= 0

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.