to.tetramorph.util
クラス Preference

java.lang.Object
  上位を拡張 java.util.Dictionary<K,V>
      上位を拡張 java.util.Hashtable<Object,Object>
          上位を拡張 java.util.Properties
              上位を拡張 to.tetramorph.util.Preference
すべての実装されたインタフェース:
Serializable, Cloneable, Map<Object,Object>

public class Preference
extends Properties

Propertiesを拡張したクラスで、ColorやAspectTypeなどを文字列表現でset/get、 ファイルにもload/storeできる。 DBへの登録はPropertiesクラスで行っているので、それをcopyすることで Preferenceオブジェクトを作成する。

 Properties p = db.getProperties("Default");
 Preference pref = new Preference();
 pref.copy(p);
 

関連項目:
直列化された形式

フィールドの概要
 
クラス java.util.Properties から継承されたフィールド
defaults
 
コンストラクタの概要
Preference()
          空のプレファランスを作成
Preference(Properties prop)
          デフォルトのプレファランスをもつオブジェクトを作成
 
メソッドの概要
 void copy(Properties prop)
          propをこのオブジェクトにコピーする。
 AspectType[] getAspectTypes(String key)
          keyに対応するAspectType配列を取得する。
 Boolean getBoolean(String key)
          keyに対応するBooleanを取得する。
 Boolean getBoolean(String key, boolean def)
          keyに対応するBooleanを取得するが、keyが存在しないならdefの値を返す。
 Color getColor(String key)
          プロパティからカラーを取得
 Color getColor(String key, Color defaultColor)
          プロパティからカラーを取得。
 Color[] getColors(String key)
          プロパティキーに対応する複数のカラーを返す。
 Color[] getColors(String key, Color[] defaultColors)
          プロパティキーに対応する複数のColorを返す。
 Double getDouble(String key)
          keyに対応するDoubleを取得する。
 Font getFont(String key)
           
 Font getFont(String key, Font defFont)
          フォントを返す。
 int[] getIntArray(String key)
          カンマで区切られた文字配列を分解してint配列にして返す。
 int[] getIntArray(String key, int[] defArray)
          カンマで区切られた文字配列を分解してint配列にして返す。
 Integer getInteger(String key)
          keyに対応するIntegerを取得する。
 Integer getInteger(String key, Integer defValue)
          keyに対応するIntegerを取得する。
 Long getLong(String key)
          keyに対応するLongを取得する。
 Long getLong(String key, Long defValue)
          keyに対応するLongを取得する。
static Preference getNewPreference(Preference prop)
          Preferenceのディープコピーによる複製を返す。
 Place getPlace(String key)
          キーに対応するPlaceオブジェクトを返す。
 Place getPlace(String key, Place defPlace)
          キーに対応するPlaceオブジェクトを返す。
 Rectangle getRectangle(String key)
          keyに対応するRectangleを取得する。
 String[] getStringArray(String key)
          keyに対応するString配列を取得する。
 void setAspectTypes(String key, AspectType[] values)
          AspectType配列をセットする。
 void setBoolean(String key, boolean value)
          Booleanをセットする。
 void setColor(String key, Color c)
          Colorをプロパティにセット
 void setColors(String key, Color[] c)
          Color配列をプロパティとして保存する。
 void setDouble(String key, Double value)
          Doubleをセットする。
 void setFont(String key, Font font)
          フォントを記憶する。
 void setIntArray(String key, int[] array)
          int配列を文字列に変換してカンマで区切ってプロパティにセット
 void setInteger(String key, Integer value)
          Integerをセットする。
 void setLong(String key, Long value)
          Longをセットする。
 void setPlace(String key, Place place)
          名前をつけてPlaceオブジェクトを保管する
 void setRectangle(String key, Rectangle value)
          Rectangleをセットする。
 void setStringArray(String key, String[] values)
          String配列をセットする。
 
クラス java.util.Properties から継承されたメソッド
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
クラス java.util.Hashtable から継承されたメソッド
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
クラス java.lang.Object から継承されたメソッド
finalize, getClass, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

Preference

public Preference()
空のプレファランスを作成


Preference

public Preference(Properties prop)
デフォルトのプレファランスをもつオブジェクトを作成

メソッドの詳細

setInteger

public void setInteger(String key,
                       Integer value)
Integerをセットする。

パラメータ:
key - Integerの名前
value - Integerの値

getInteger

public Integer getInteger(String key)
keyに対応するIntegerを取得する。


getInteger

public Integer getInteger(String key,
                          Integer defValue)
keyに対応するIntegerを取得する。keyが存在しなければdefValueを返す。


setIntArray

public void setIntArray(String key,
                        int[] array)
int配列を文字列に変換してカンマで区切ってプロパティにセット

パラメータ:
key - プロパティキー
array - 登録するint配列

getIntArray

public int[] getIntArray(String key)
カンマで区切られた文字配列を分解してint配列にして返す。

パラメータ:
key - プロパティキー

getIntArray

public int[] getIntArray(String key,
                         int[] defArray)
カンマで区切られた文字配列を分解してint配列にして返す。

パラメータ:
key - プロパティキー
defArray - キーが存在しない場合に返すデフォルトのint配列。

setBoolean

public void setBoolean(String key,
                       boolean value)
Booleanをセットする。


getBoolean

public Boolean getBoolean(String key)
keyに対応するBooleanを取得する。 キーが存在しないならnullを返す。


getBoolean

public Boolean getBoolean(String key,
                          boolean def)
keyに対応するBooleanを取得するが、keyが存在しないならdefの値を返す。


setDouble

public void setDouble(String key,
                      Double value)
Doubleをセットする。


getDouble

public Double getDouble(String key)
keyに対応するDoubleを取得する。


setLong

public void setLong(String key,
                    Long value)
Longをセットする。

パラメータ:
key - Integerの名前
value - Integerの値

getLong

public Long getLong(String key)
keyに対応するLongを取得する。


getLong

public Long getLong(String key,
                    Long defValue)
keyに対応するLongを取得する。keyが存在しなければdefValueを返す。


setRectangle

public void setRectangle(String key,
                         Rectangle value)
Rectangleをセットする。


getRectangle

public Rectangle getRectangle(String key)
keyに対応するRectangleを取得する。


setStringArray

public void setStringArray(String key,
                           String[] values)
String配列をセットする。セパレータに罫線のコード"┃"を使用しているので、 文字列中にこの文字は混入してはいけない。


getStringArray

public String[] getStringArray(String key)
keyに対応するString配列を取得する。


setColor

public void setColor(String key,
                     Color c)
Colorをプロパティにセット


getColor

public Color getColor(String key)
プロパティからカラーを取得


getColor

public Color getColor(String key,
                      Color defaultColor)
プロパティからカラーを取得。取得できないときはdefaultColorを返す。


setColors

public void setColors(String key,
                      Color[] c)
Color配列をプロパティとして保存する。色情報はR,G,B,Aに分解され十進数として カンマで区切られた形式で保管される。かならず4チャンネル分保管される。 なお配列の中にnullの要素がある場合、それは"-1,-1,-1,-1,"として表現され、 getColors()では、nullに復元される。


getColors

public Color[] getColors(String key)
プロパティキーに対応する複数のカラーを返す。

パラメータ:
key - "255,128,64,255, ....."というように、1色につき4つの数値(r,g,b,a) によって構成される文字列を指定する。カンマで分割したとき要素数は4で割り切れ なければならない。割り切れないときはIllegalArgumentExceptionが出る。 また数値に変換できない文字列が入った場合、一つの数値が256以上の場合も同様。 keyにnullまたは""が与えられたときはnullを返す。

getColors

public Color[] getColors(String key,
                         Color[] defaultColors)
プロパティキーに対応する複数のColorを返す。 取得できなかったときは、defaultColorsを返す。


setAspectTypes

public void setAspectTypes(String key,
                           AspectType[] values)
AspectType配列をセットする。


getAspectTypes

public AspectType[] getAspectTypes(String key)
keyに対応するAspectType配列を取得する。


setPlace

public void setPlace(String key,
                     Place place)
名前をつけてPlaceオブジェクトを保管する


getPlace

public Place getPlace(String key)
キーに対応するPlaceオブジェクトを返す。


getPlace

public Place getPlace(String key,
                      Place defPlace)
キーに対応するPlaceオブジェクトを返す。キーが無いときはdefPlaceを返す。


setFont

public void setFont(String key,
                    Font font)
フォントを記憶する。floatのサイズは保管できない。Font#getSize()で取得した 値を保管する。

パラメータ:
key -
font -

getFont

public Font getFont(String key,
                    Font defFont)
フォントを返す。

パラメータ:
key -
defFont - keyがみつからないときのデフォルトフォント。
戻り値:
フォント

getFont

public Font getFont(String key)

copy

public void copy(Properties prop)
propをこのオブジェクトにコピーする。


getNewPreference

public static Preference getNewPreference(Preference prop)
Preferenceのディープコピーによる複製を返す。

パラメータ:
prop - コピー元のPreference
戻り値:
複製されたPreference