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 AbstractWriter

    java.lang.Object
      |
      +--javax.swing.text.AbstractWriter

Direct Known Subclasses:
  HTMLWriter, MinimalHTMLWriter

public abstract class AbstractWriter
extends java.lang.Object

AbstractWriter is an abstract class that actually does the work of writing out the element tree including the attributes. In terms of how much is written out per line, the writer defaults to 80. But this value can be set by subclasses.

Field Summary
`protected static char` | `NEWLINE`

Constructor Summary
`protected` | `AbstractWriter(java.io.Writer w, Document doc)` Creates a new AbstractWriter.
`protected` | `AbstractWriter(java.io.Writer w, Document doc, int pos, int len)` Creates a new AbstractWriter.
`protected` | `AbstractWriter(java.io.Writer w, Element root)` Creates a new AbstractWriter.
`protected` | `AbstractWriter(java.io.Writer w, Element root, int pos, int len)` Creates a new AbstractWriter.

Method Summary
`protected void` | `decrIndent()` Decrements the indent level.
`protected Document` | `getDocument()` Fetches the document.
`protected ElementIterator` | `getElementIterator()` Fetches the ElementIterator.
`protected java.lang.String` | `getText(Element elem)` Returns the text associated with the element.
`protected void` | `incrIndent()` Increments the indent level.
`protected void` | `indent()` Does indentation.
`protected boolean` | `inRange(Element next)` This method determines whether the current element is in the range specified.
`protected void` | `setIndentSpace(int space)` Enables subclasses to specify how many spaces an indent maps to.
`protected void` | `setLineLength(int l)` Enables subclasses to set the number of characters they want written per line.
`protected void` | `text(Element elem)` Writes out text.
`protected abstract void` | `write()` This abstract method needs to be implemented by subclasses.
`protected void` | `write(char ch)` Writes out a character.
`protected void` | `write(java.lang.String str)` Writes out a string.
`protected void` | `writeAttributes(AttributeSet attr)` Writes out the set of attributes as " =" pairs.

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

Field Detail

### NEWLINE

    protected static final char NEWLINE

Constructor Detail

### AbstractWriter

    protected AbstractWriter(java.io.Writer w,
                             Document doc)

  Creates a new AbstractWriter. Initializes the ElementIterator with the default root of the document.
  Parameters:
    `a` - Writer.
    `a` - Document

### AbstractWriter

    protected AbstractWriter(java.io.Writer w,
                             Document doc,
                             int pos,
                             int len)

  Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
  Parameters:
    `a` - Writer
    `an` - Element
    `pos` - The location in the document to fetch the content.
    `len` - The amount to write out.

### AbstractWriter

    protected AbstractWriter(java.io.Writer w,
                             Element root)

  Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
  Parameters:
    `a` - Writer
    `an` - Element

### AbstractWriter

    protected AbstractWriter(java.io.Writer w,
                             Element root,
                             int pos,
                             int len)

  Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
  Parameters:
    `a` - Writer
    `an` - Element
    `pos` - The location in the document to fetch the content.
    `len` - The amount to write out.

Method Detail

### getElementIterator

    protected ElementIterator getElementIterator()

  Fetches the ElementIterator.
  Returns:
    the ElementIterator.

### getDocument

    protected Document getDocument()

  Fetches the document.
  Returns:
    the Document.

### inRange

    protected boolean inRange(Element next)

  This method determines whether the current element is in the range specified. When no range is specified, the range is initialized to be the entire document. inRange() returns true if the range specified intersects with the element's range.
  Parameters:
    `an` - Element.
  Returns:
    boolean that indicates whether the element is in the range.

### write

    protected abstract void write()
                           throws java.io.IOException,
                                  BadLocationException

  This abstract method needs to be implemented by subclasses. Its responsibility is to iterate over the elements and use the write() methods to generate output in the desired format.

### getText

    protected java.lang.String getText(Element elem)
                                throws BadLocationException

  Returns the text associated with the element. The assumption here is that the element is a leaf element. Throws a BadLocationException when encountered.
  Parameters:
    `an` - Element.
  Throws:
    BadLocationException - if pos represents an invalid location within the document.

### text

    protected void text(Element elem)
                 throws BadLocationException,
                        java.io.IOException

  Writes out text. If a range is specified when the constructor is invoked, then only the appropriate range of text is written out.
  Parameters:
    `an` - Element.
  Throws:
    java.io.IOException - on any I/O error
    BadLocationException - if pos represents an invalid location within the document.

### setLineLength

    protected void setLineLength(int l)

  Enables subclasses to set the number of characters they want written per line. The default is 100.
  Parameters:
    `the` - maximum line length.

### setIndentSpace

    protected void setIndentSpace(int space)

  Enables subclasses to specify how many spaces an indent maps to. When indentation takes place, the indent level is multiplied by this mapping. The default is 2.
  Parameters:
    `an` - int representing the space to indent mapping.

### incrIndent

    protected void incrIndent()

  Increments the indent level.

### decrIndent

    protected void decrIndent()

  Decrements the indent level.

### indent

    protected void indent()
                   throws java.io.IOException

  Does indentation. The number of spaces written out is indent level times the space to map mapping.
  Throws:
    java.io.IOException - on any I/O error

### write

    protected void write(char ch)
                  throws java.io.IOException

  Writes out a character. If the character is a newline then it resets the current length to 0. If the current length equals the maximum line length, then a newline is outputed and the current length is reset to 0.
  Parameters:
    `a` - char.
  Throws:
    java.io.IOException - on any I/O error

### write

    protected void write(java.lang.String str)
                  throws java.io.IOException

  Writes out a string. If writing out the string on the current line results in the maximum line length being exceeded, it then attempts to write this line out on the next line. However if the length of the string itself exceeds the maximum line length, it then recursively calls this method on the substring from 0 to max line length, and then again from max line length+1 to the end of the string -- inserting new lines where necessary.
  Parameters:
    `a` - String.
  Throws:
    java.io.IOException - on any I/O error

### writeAttributes

    protected void writeAttributes(AttributeSet attr)
                            throws java.io.IOException

  Writes out the set of attributes as " =" pairs. It throws an IOException when encountered.
  Parameters:
    `an` - AttributeSet.
  Throws:
    java.io.IOException - on any I/O error

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.