JavaTM Platform
Standard Ed. 6

javax.swing.text
クラス AbstractWriter

java.lang.Object
  上位を拡張 javax.swing.text.AbstractWriter
直系の既知のサブクラス:
HTMLWriter, MinimalHTMLWriter

public abstract class AbstractWriter
extends Object

AbstractWriter は、属性を含む要素ツリーを実際に書き出す abstract クラスです。1 行あたりに書き出す文字数のデフォルトは 100 です。 ただし、この値はサブクラスで設定することができます。


フィールドの概要
protected static char NEWLINE
          テキストパッケージモデルの改行法です。
 
コンストラクタの概要
protected AbstractWriter(Writer w, Document doc)
          新しい AbstractWriter を作成します。
protected AbstractWriter(Writer w, Document doc, int pos, int len)
          新しい AbstractWriter を作成します。
protected AbstractWriter(Writer w, Element root)
          新しい AbstractWriter を作成します。
protected AbstractWriter(Writer w, Element root, int pos, int len)
          新しい AbstractWriter を作成します。
 
メソッドの概要
protected  void decrIndent()
          インデントレベルを減分します。
protected  boolean getCanWrapLines()
          行がラップ可能かどうかを返します。
protected  int getCurrentLineLength()
          現在の行の長さを返します。
protected  Document getDocument()
          ドキュメントを取得します。
protected  ElementIterator getElementIterator()
          ElementIterator を取得します。
 int getEndOffset()
          出力対象の最後のオフセットを返します。
protected  int getIndentLevel()
          現在のインデントレベルを返します。
protected  int getIndentSpace()
          インデントするスペースの量を返します。
protected  int getLineLength()
          行の長さの最大値を返します。
 String getLineSeparator()
          改行を表すときに使用する文字列を返します。
 int getStartOffset()
          出力対象の最初のオフセットを返します。
protected  String getText(Element elem)
          要素に関連したテキストを返します。
protected  Writer getWriter()
          コンテンツを出力するときに使用するライターを返します。
protected  void incrIndent()
          インデントレベルを増分します。
protected  void indent()
          インデントを行います。
protected  boolean inRange(Element next)
          このメソッドは、現在の要素が指定された範囲内にあるかどうかを判定します。
protected  boolean isLineEmpty()
          現在の行の長さが空の場合は、true を返します。
protected  void output(char[] content, int start, int length)
          コンテンツ書き込み時の最後の停止です。
protected  void setCanWrapLines(boolean newValue)
          行をラップできるかどうかを設定します。
protected  void setCurrentLineLength(int length)
          現在の行の長さを設定します。
protected  void setIndentSpace(int space)
          インデントにマッピングするスペースの数をサブクラスから指定できるようにします。
protected  void setLineLength(int l)
          1 行あたりに書き込むことのできる文字数をサブクラスから設定できるようにします。
 void setLineSeparator(String value)
          改行を表すときに使用する String を設定します。
protected  void text(Element elem)
          テキストを書き出します。
protected abstract  void write()
          この抽象メソッドは、サブクラスによって実装される必要があります。
protected  void write(char ch)
          文字を書き出します。
protected  void write(char[] chars, int startIndex, int length)
          すべての書き出しメソッドはこれを呼び出します。
protected  void write(String content)
          文字列を書き出します。
protected  void writeAttributes(AttributeSet attr)
          属性セットを "=" のペアとして書き出します。
protected  void writeLineSeparator()
          行区切り文字を書き出します。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

NEWLINE

protected static final char NEWLINE
テキストパッケージモデルの改行法です。

関連項目:
getLineSeparator(), 定数フィールド値
コンストラクタの詳細

AbstractWriter

protected AbstractWriter(Writer w,
                         Document doc)
新しい AbstractWriter を作成します。デフォルトのドキュメントルートを使って ElementIterator を初期化します。

パラメータ:
w - Writer
doc - Document

AbstractWriter

protected AbstractWriter(Writer w,
                         Document doc,
                         int pos,
                         int len)
新しい AbstractWriter を作成します。渡された要素を使って ElementIterator を初期化します。

パラメータ:
w - Writer
doc - Element
pos - コンテンツを取得する ドキュメント内の位置
len - 書き出す量

AbstractWriter

protected AbstractWriter(Writer w,
                         Element root)
新しい AbstractWriter を作成します。渡された要素を使って ElementIterator を初期化します。

パラメータ:
w - Writer
root - Element

AbstractWriter

protected AbstractWriter(Writer w,
                         Element root,
                         int pos,
                         int len)
新しい AbstractWriter を作成します。渡された要素を使って ElementIterator を初期化します。

パラメータ:
w - Writer
root - Element
pos - コンテンツを取得する ドキュメント内の位置
len - 書き出す量
メソッドの詳細

getStartOffset

public int getStartOffset()
出力対象の最初のオフセットを返します。

導入されたバージョン:
1.3

getEndOffset

public int getEndOffset()
出力対象の最後のオフセットを返します。

導入されたバージョン:
1.3

getElementIterator

protected ElementIterator getElementIterator()
ElementIterator を取得します。

戻り値:
ElementIterator

getWriter

protected Writer getWriter()
コンテンツを出力するときに使用するライターを返します。

導入されたバージョン:
1.3

getDocument

protected Document getDocument()
ドキュメントを取得します。

戻り値:
Document

inRange

protected boolean inRange(Element next)
このメソッドは、現在の要素が指定された範囲内にあるかどうかを判定します。範囲が指定されなかった場合は、ドキュメント全体が範囲として初期化されます。 inRange() は、指定された範囲が要素の範囲と交差している場合に true を返します。

パラメータ:
next - Element
戻り値:
要素が範囲内かどうかを示す boolean 型の値

write

protected abstract void write()
                       throws IOException,
                              BadLocationException
この抽象メソッドは、サブクラスによって実装される必要があります。この抽象メソッドの役割は、要素を反復し、write() メソッドを使って必要な形式の出力を生成することです。

例外:
IOException
BadLocationException

getText

protected String getText(Element elem)
                  throws BadLocationException
要素に関連したテキストを返します。このメソッドは、渡された要素が葉の要素であると仮定します。例外が発生すると BadLocationException をスローします。

パラメータ:
elem - Element
戻り値:
String としてのテキスト
例外:
BadLocationException - pos がドキュメント内の 無効な位置を表す場合

text

protected void text(Element elem)
             throws BadLocationException,
                    IOException
テキストを書き出します。コンストラクタの呼び出し時に範囲が指定されている場合は、対応する範囲のテキストだけが書き出されます。

パラメータ:
elem - Element
例外:
IOException - 入出力エラーが発生した場合
BadLocationException - pos がドキュメント内の 無効な位置を表す場合

setLineLength

protected void setLineLength(int l)
1 行あたりに書き込むことのできる文字数をサブクラスから設定できるようにします。デフォルトは 100 です。

パラメータ:
l - 行の長さの最大値

getLineLength

protected int getLineLength()
行の長さの最大値を返します。

導入されたバージョン:
1.3

setCurrentLineLength

protected void setCurrentLineLength(int length)
現在の行の長さを設定します。

導入されたバージョン:
1.3

getCurrentLineLength

protected int getCurrentLineLength()
現在の行の長さを返します。

導入されたバージョン:
1.3

isLineEmpty

protected boolean isLineEmpty()
現在の行の長さが空の場合は、true を返します。getCurrentLineLength == 0 || indent が空の行上で呼び出された場合には true です。

導入されたバージョン:
1.3

setCanWrapLines

protected void setCanWrapLines(boolean newValue)
行をラップできるかどうかを設定します。行に書き込み中は切り替え可能です。たとえば、HTML の出力は引用文字列を出力するときには、この設定は false となります。

導入されたバージョン:
1.3

getCanWrapLines

protected boolean getCanWrapLines()
行がラップ可能かどうかを返します。false の場合は、lineSeparator は出力されません。

導入されたバージョン:
1.3

setIndentSpace

protected void setIndentSpace(int space)
インデントにマッピングするスペースの数をサブクラスから指定できるようにします。インデントを行うと、インデントレベルとマッピングの積が計算されます。デフォルトは 2 です。

パラメータ:
space - インデントにマッピングするスペースを表す int 値

getIndentSpace

protected int getIndentSpace()
インデントするスペースの量を返します。

導入されたバージョン:
1.3

setLineSeparator

public void setLineSeparator(String value)
改行を表すときに使用する String を設定します。これは、コンストラクタ内の Document または System プロパティー line.separator で初期化されます。

導入されたバージョン:
1.3

getLineSeparator

public String getLineSeparator()
改行を表すときに使用する文字列を返します。

導入されたバージョン:
1.3

incrIndent

protected void incrIndent()
インデントレベルを増分します。インデントが getLineLength() よりも大きくなるような getIndentSpace() * getIndentLevel() となるとインデントしません。


decrIndent

protected void decrIndent()
インデントレベルを減分します。


getIndentLevel

protected int getIndentLevel()
現在のインデントレベルを返します。つまり、incrIndent が呼び出された回数から decrIndent が呼び出された回数を引いた数です。

導入されたバージョン:
1.3

indent

protected void indent()
               throws IOException
インデントを行います。書き出されるスペースの数は、インデントレベルとマッピングされたスペースの数の積になります。現在の行が空の場合は、何も行われず行は空のままです。

例外:
IOException - 入出力エラーが発生した場合

write

protected void write(char ch)
              throws IOException
文字を書き出します。これは char[] を取り出す write メソッドを呼び出すときに実装されます。

パラメータ:
ch - char
例外:
IOException - 入出力エラーが発生した場合

write

protected void write(String content)
              throws IOException
文字列を書き出します。これは char[] を取り出す write メソッドを呼び出すときに実装されます。

パラメータ:
content - String
例外:
IOException - 入出力エラーが発生した場合

writeLineSeparator

protected void writeLineSeparator()
                           throws IOException
行区切り文字を書き出します。これは output を直接呼び出して、lineLength を 0 に設定します。

例外:
IOException
導入されたバージョン:
1.3

write

protected void write(char[] chars,
                     int startIndex,
                     int length)
              throws IOException
すべての書き出しメソッドはこれを呼び出します。getCanWrapLines() が false を返すと NEWLINE を含まない chars の各シーケンス付き output を呼び出し、続いて writeLineSeparator を呼び出します。一方、getCanWrapLines() が true を返すと、必要に応じて文字列を分割して getLineLength を受け取ります。唯一の例外は現在の文字列に空白が含まれない場合で、行の長さが getLineLength を超えるため収まりません。

例外:
IOException
導入されたバージョン:
1.3

writeAttributes

protected void writeAttributes(AttributeSet attr)
                        throws IOException
属性セットを "=" のペアとして書き出します。入出力エラーが発生すると IOException をスローします。

パラメータ:
attr - AttributeSet
例外:
IOException - 入出力エラーが発生した場合

output

protected void output(char[] content,
                      int start,
                      int length)
               throws IOException
コンテンツ書き込み時の最後の停止です。すべての書き込みメソッドは最終的にはこのメソッドとなり、ライターで write を呼び出します。

このメソッドも length に基づき行の長さを更新します。改行を出力するために呼び出されると、現在の行の長さをリセットして無効にする必要があります。この実行が呼び出し側に依存する場合は、writeLineSeparator を使用して改行を書き出し、現在の行の長さのプロパティーを更新します。

例外:
IOException
導入されたバージョン:
1.3

JavaTM Platform
Standard Ed. 6

バグの報告と機能のリクエスト
さらに詳しい API リファレンスおよび開発者ドキュメントについては、Java SE 開発者用ドキュメントを参照してください。開発者向けの詳細な解説、概念の概要、用語の定義、バグの回避策、およびコード実例が含まれています。

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。