JavaTM Platform
Standard Ed. 6

javax.swing.text
クラス StringContent

java.lang.Object
  上位を拡張 javax.swing.text.StringContent
すべての実装されたインタフェース:
Serializable, AbstractDocument.Content

public final class StringContent
extends Object
implements AbstractDocument.Content, Serializable

比較的小さなドキュメントおよびデバッグには便利な、強引な実装である AbstractDocument.Content インタフェースの実装です。これは、文字コンテンツを単純な文字配列として管理します。これも効率的ではありません。

代わりに、ギャップバッファーまたはピーステーブルの実装を使うことをお勧めします。このバッファーはサイズが大きくなりません。

警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の運用や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。JDK Version 1.4 以降、すべての JavaBeans の長期間の運用サポートは、java.beans パッケージに追加されています。詳細は、XMLEncoder を参照してください。


コンストラクタの概要
StringContent()
          新しい StringContent オブジェクトを作成します。
StringContent(int initialLength)
          指定された初期サイズで新しい StringContent オブジェクトを作成します。
 
メソッドの概要
 Position createPosition(int offset)
          コンテンツが変更されたときに変更を追跡するコンテンツ内の位置を作成します。
 void getChars(int where, int len, Segment chars)
          コンテンツの一部を取り出します。
protected  Vector getPositionsInRange(Vector v, int offset, int length)
          offsetoffset + length の範囲にある位置に対応する UndoPosRef のインスタンスを含むベクターを返します。
 String getString(int where, int len)
          コンテンツの一部を取り出します。
 UndoableEdit insertString(int where, String str)
          コンテンツに文字列を挿入します。
 int length()
          コンテンツの長さを返します。
 UndoableEdit remove(int where, int nitems)
          コンテンツの一部を削除します。
protected  void updateUndoPositions(Vector positions)
          positions のすべての UndoPosRef インスタンスの位置をリセットします。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

コンストラクタの詳細

StringContent

public StringContent()
新しい StringContent オブジェクトを作成します。初期サイズのデフォルトは 10 です。


StringContent

public StringContent(int initialLength)
指定された初期サイズで新しい StringContent オブジェクトを作成します。長さが 1 より小さい場合、サイズ 1 が使われます。

パラメータ:
initialLength - 初期サイズ
メソッドの詳細

length

public int length()
コンテンツの長さを返します。

定義:
インタフェース AbstractDocument.Content 内の length
戻り値:
長さ >= 1
関連項目:
AbstractDocument.Content.length()

insertString

public UndoableEdit insertString(int where,
                                 String str)
                          throws BadLocationException
コンテンツに文字列を挿入します。

定義:
インタフェース AbstractDocument.Content 内の insertString
パラメータ:
where - 開始位置 >= 0 && < length()
str - 挿入する null 以外の文字列
戻り値:
元に戻すための UndoableEdit オブジェクト
例外:
BadLocationException - 指定された位置が無効な場合
関連項目:
AbstractDocument.Content.insertString(int, java.lang.String)

remove

public UndoableEdit remove(int where,
                           int nitems)
                    throws BadLocationException
コンテンツの一部を削除します。where + nitems は、length() より小さくなっている必要があります。

定義:
インタフェース AbstractDocument.Content 内の remove
パラメータ:
where - 開始位置 >= 0
nitems - 削除対象の文字数 >= 0
戻り値:
元に戻すための UndoableEdit オブジェクト
例外:
BadLocationException - 指定された位置が無効な場合
関連項目:
AbstractDocument.Content.remove(int, int)

getString

public String getString(int where,
                        int len)
                 throws BadLocationException
コンテンツの一部を取り出します。where + len は、length() 以下になっている必要があります。

定義:
インタフェース AbstractDocument.Content 内の getString
パラメータ:
where - 開始位置 >= 0
len - 取り出す長さ >= 0
戻り値:
コンテンツを表す文字列。空の場合もある
例外:
BadLocationException - 指定された位置が無効な場合
関連項目:
AbstractDocument.Content.getString(int, int)

getChars

public void getChars(int where,
                     int len,
                     Segment chars)
              throws BadLocationException
コンテンツの一部を取り出します。where + len は、length() 以下になっている必要があります。

定義:
インタフェース AbstractDocument.Content 内の getChars
パラメータ:
where - 開始位置 >= 0
len - 検索対象の文字数 >= 0
chars - 文字を返す先の Segment オブジェクト
例外:
BadLocationException - 指定された位置が無効な場合
関連項目:
AbstractDocument.Content.getChars(int, int, javax.swing.text.Segment)

createPosition

public Position createPosition(int offset)
                        throws BadLocationException
コンテンツが変更されたときに変更を追跡するコンテンツ内の位置を作成します。

定義:
インタフェース AbstractDocument.Content 内の createPosition
パラメータ:
offset - 位置を作成するオフセット >= 0
戻り値:
位置
例外:
BadLocationException - 指定された位置が無効な場合

getPositionsInRange

protected Vector getPositionsInRange(Vector v,
                                     int offset,
                                     int length)
offsetoffset + length の範囲にある位置に対応する UndoPosRef のインスタンスを含むベクターを返します。v が null ではない場合、一致する位置がそこに配置されます。結果として得られる位置を持つベクタが返されます。

これは内部での使用を目的としていて、一般にはサブクラスを対象にしていません。

パラメータ:
v - 使用するベクタ。null の場合は新しいベクタが作成される
offset - 開始オフセット <= 0
length - 長さ >= 0
戻り値:
インスタンスのセット

updateUndoPositions

protected void updateUndoPositions(Vector positions)
positions のすべての UndoPosRef インスタンスの位置をリセットします。

これは内部での使用を目的としていて、一般にはサブクラスを対象にしていません。

パラメータ:
positions - インスタンスの位置

JavaTM Platform
Standard Ed. 6

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

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