モジュール java.base
パッケージ java.text

クラスAttributedString


  • public class AttributedString
    extends Object
    テキストとそのテキストに関連する属性情報を保持します。 テキストを読み取るユーザーが、AttributedCharacterIteratorインタフェース経由で属性付きテキストにアクセスする必要がある場合、このクラスを実際のデータ・ストレージとして使用できます。

    属性はキーと値のペアであり、キーで識別されます。 1つの文字に対して複数の属性キーを定義することはできません。

    属性の値は不変です。つまり、クライアントやストレージによって変更できません。 属性の値は常に参照渡しです。複製されることはありません。

    導入されたバージョン:
    1.2
    関連項目:
    AttributedCharacterIterator, Annotation
    • コンストラクタの詳細

      • AttributedString

        public AttributedString​(String text)
        指定されたテキストを持つAttributedStringインスタンスを構築します。
        パラメータ:
        text - この属性付き文字列のテキスト。
        例外:
        NullPointerException - textがnullである場合。
      • AttributedString

        public AttributedString​(String text,
                                Map<? extends AttributedCharacterIterator.Attribute,​?> attributes)
        指定されたテキストと属性を持つAttributedStringインスタンスを構築します。
        パラメータ:
        text - この属性付き文字列のテキスト。
        attributes - 文字列全体に適用する属性。
        例外:
        NullPointerException - textまたはattributesがnullの場合。
        IllegalArgumentException - テキスト長が0で、かつ属性パラメータが空のMapでない場合(長さ0の範囲には属性を適用できない)。
      • AttributedString

        public AttributedString​(AttributedCharacterIterator text)
        指定されたAttributedCharacterIteratorが表現する属性付きテキストを持つ、AttributedStringインスタンスを構築します。
        パラメータ:
        text - この属性付き文字列のテキスト。
        例外:
        NullPointerException - textがnullである場合。
      • AttributedString

        public AttributedString​(AttributedCharacterIterator text,
                                int beginIndex,
                                int endIndex)
        指定されたAttributedCharacterIteratorが表現する属性付きテキストの部分範囲を持つAttributedStringインスタンスを構築します。 指定された範囲が空のテキストを生成する場合、すべての属性が破棄されます。 元の属性範囲の部分範囲に対しては、Annotationオブジェクトによってラップされた属性はすべて破棄されます。
        パラメータ:
        text - この属性付き文字列のテキスト。
        beginIndex - 範囲の先頭文字のインデックス。
        endIndex - 範囲の末尾文字の次の文字のインデックス。
        例外:
        NullPointerException - textがnullである場合。
        IllegalArgumentException - beginIndexとendIndexで指定された部分範囲がテキストの範囲外にある場合。
        関連項目:
        Annotation
      • AttributedString

        public AttributedString​(AttributedCharacterIterator text,
                                int beginIndex,
                                int endIndex,
                                AttributedCharacterIterator.Attribute[] attributes)
        指定されたAttributedCharacterIteratorが表現する属性付きテキストの部分範囲を持つAttributedStringインスタンスを構築します。 指定された属性に一致する属性だけがインスタンスに組み込まれます。 指定された範囲が空のテキストを生成する場合、すべての属性が破棄されます。 元の属性範囲の部分範囲に対しては、Annotationオブジェクトによってラップされた属性はすべて破棄されます。
        パラメータ:
        text - この属性付き文字列のテキスト。
        beginIndex - 範囲の先頭文字のインデックス。
        endIndex - 範囲の末尾文字の次の文字のインデックス。
        attributes - テキストから抽出する属性を指定する。 nullが指定された場合、利用可能なすべての属性が使用される。
        例外:
        NullPointerException - textがnullである場合。
        IllegalArgumentException - beginIndexとendIndexで指定された部分範囲がテキストの範囲外にある場合。
        関連項目:
        Annotation
    • メソッドの詳細

      • addAttribute

        public void addAttribute​(AttributedCharacterIterator.Attribute attribute,
                                 Object value,
                                 int beginIndex,
                                 int endIndex)
        属性を文字列の部分範囲に追加します。
        パラメータ:
        attribute - 属性キー
        value - 属性の値。 nullの場合もあります。
        beginIndex - 範囲の先頭文字のインデックス。
        endIndex - 範囲の末尾文字の次の文字のインデックス。
        例外:
        NullPointerException - attributeがnullである場合。
        IllegalArgumentException - beginIndexが0より小さい場合、endIndexが文字列の長さより大きい場合、またはbeginIndexとendIndexが一緒になって文字列の空でない部分範囲を定義しない場合。
      • addAttributes

        public void addAttributes​(Map<? extends AttributedCharacterIterator.Attribute,​?> attributes,
                                  int beginIndex,
                                  int endIndex)
        一連の属性を文字列の部分範囲に追加します。
        パラメータ:
        attributes - 文字列に追加する属性。
        beginIndex - 範囲の先頭文字のインデックス。
        endIndex - 範囲の末尾文字の次の文字のインデックス。
        例外:
        NullPointerException - attributesがnullの場合。
        IllegalArgumentException - beginIndexが0より小さい場合、endIndexが文字列の長さよりも大きいか、beginIndexとendIndexが一緒に文字列の空でない部分範囲を定義せず、属性パラメータが空のMapではありません。
      • getIterator

        public AttributedCharacterIterator getIterator()
        この文字列の内容全体にアクセスできるAttributedCharacterIteratorインスタンスを作成します。
        戻り値:
        テキストとその属性にアクセスできるイテレータ。
      • getIterator

        public AttributedCharacterIterator getIterator​(AttributedCharacterIterator.Attribute[] attributes)
        この文字列の選択された内容にアクセスできるAttributedCharacterIteratorインスタンスを作成します。 attributesに含まれていない属性の情報を実装者が保持する場合、それらの情報をこのイテレータ経由でアクセス可能にする必要はありません。 リストがnullの場合、利用可能なすべての属性の情報にアクセスできる必要があります。
        パラメータ:
        attributes - クライアントが興味を持っている属性のリスト
        戻り値:
        テキスト全体とその選択された属性にアクセスできるイテレータ
      • getIterator

        public AttributedCharacterIterator getIterator​(AttributedCharacterIterator.Attribute[] attributes,
                                                       int beginIndex,
                                                       int endIndex)
        この文字列の選択された内容にアクセスできるAttributedCharacterIteratorインスタンスを作成します。 attributesに含まれていない属性の情報を実装者が保持する場合、それらの情報をこのイテレータ経由でアクセス可能にする必要はありません。 リストがnullの場合、利用可能なすべての属性の情報にアクセスできる必要があります。
        パラメータ:
        attributes - クライアントが興味を持っている属性のリスト
        beginIndex - 最初の文字のインデックス
        endIndex - 最後の文字のあとに続く文字のインデックス
        戻り値:
        テキストおよびテキストの属性にアクセスできるイテレータ
        例外:
        IllegalArgumentException - beginIndexが0より小さい場合、endIndexは文字列の長さより大きくなるか、beginIndexはendIndexより大きい。