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に適しています。 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)
offset
からoffset
+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インスタンスの位置をリセットします。
-
コンストラクタの詳細
-
StringContent
public StringContent()新しいStringContentオブジェクトを作成します。 初期サイズのデフォルトは10です。 -
StringContent
public StringContent(int initialLength)指定された初期サイズで新しいStringContentオブジェクトを作成します。 長さが1より小さい場合、サイズ1が使われます。- パラメータ:
initialLength
- 初期サイズ
-
-
メソッドの詳細
-
length
public int length()コンテンツの長さを返します。- 定義:
length
、インタフェース:AbstractDocument.Content
- 戻り値:
- 長さ>= 1
- 関連項目:
AbstractDocument.Content.length()
-
insertString
public UndoableEdit insertString(int where, String str) throws BadLocationExceptionコンテンツに文字列を挿入します。- 定義:
insertString
、インタフェース:AbstractDocument.Content
- パラメータ:
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()より小さくなっている必要があります。- 定義:
remove
、インタフェース:AbstractDocument.Content
- パラメータ:
where
- 開始位置>= 0nitems
- 削除対象の文字数>= 0- 戻り値:
- 元に戻すためのUndoableEditオブジェクト
- 例外:
BadLocationException
- 指定された位置が無効な場合- 関連項目:
AbstractDocument.Content.remove(int, int)
-
getString
public String getString(int where, int len) throws BadLocationExceptionコンテンツの一部を取り出します。where+lenは、length()以下になっている必要があります。- 定義:
getString
、インタフェース:AbstractDocument.Content
- パラメータ:
where
- 開始位置>= 0len
- 取り出す長さ>= 0- 戻り値:
- コンテンツを表す文字列。空の場合もある
- 例外:
BadLocationException
- 指定された位置が無効な場合- 関連項目:
AbstractDocument.Content.getString(int, int)
-
getChars
public void getChars(int where, int len, Segment chars) throws BadLocationExceptionコンテンツの一部を取り出します。where+lenは、length()以下になっている必要があります- 定義:
getChars
、インタフェース:AbstractDocument.Content
- パラメータ:
where
- 開始位置>= 0len
- 取得対象の文字数>= 0chars
- 文字を返す先のSegmentオブジェクト- 例外:
BadLocationException
- 指定された位置が無効な場合- 関連項目:
AbstractDocument.Content.getChars(int, int, javax.swing.text.Segment)
-
createPosition
public Position createPosition(int offset) throws BadLocationExceptionコンテンツが変更されたときに変更を追跡するコンテンツ内の位置を作成します。- 定義:
createPosition
、インタフェース:AbstractDocument.Content
- パラメータ:
offset
- 位置を作成するオフセット>= 0- 戻り値:
- 位置
- 例外:
BadLocationException
- 指定された位置が無効な場合
-
getPositionsInRange
offset
からoffset
+length
の範囲にある位置に対応するUndoPosRefのインスタンスを含むベクターを返します。v
がnullではない場合、一致する位置がそこに配置されます。 結果として得られる位置を持つベクターが返されます。これは内部での使用を目的としていて、一般にはサブクラスを対象にしていません。
- パラメータ:
v
- 使用するベクター。nullの場合は新しいベクターが作成されるoffset
- 開始オフセット>= 0length
- 長さ>= 0- 戻り値:
- インスタンスのセット
-
updateUndoPositions
protected void updateUndoPositions(Vector positions)positions
のすべてのUndoPosRefインスタンスの位置をリセットします。これは内部での使用を目的としていて、一般にはサブクラスを対象にしていません。
- パラメータ:
positions
- インスタンスの位置
-