java.util.TimeZone型のプロパティエディタを作らないといけなかったので簡単に作ってみた。
思ったより簡単なのね。
package sample;
import java.beans.PropertyEditorSupport;
import java.util.TimeZone;
// PropertyEditorSupportを継承する
public class TimeZonePropertyEditor extends PropertyEditorSupport {
private String[] supportedTimeZoneNames;
public TimeZonePropertyEditor() {
supportedTimeZoneNames = TimeZone.getAvailableIDs();
}
// 文字列を値に
public void setAsText(String text) throws java.lang.IllegalArgumentException {
setValue(TimeZone.getTimeZone(text));
}
// 値を文字列に
public String getAsText() {
TimeZone timeZone = (TimeZone) getValue();
return timeZone == null ? "null" : timeZone.getID();
}
// プロパティエディタにドロップダウンで出したい文字列を配列で返す
public String[] getTags() {
return supportedTimeZoneNames;
}
// プロパティの初期化の時に使うJavaのコードを返す
public String getJavaInitializationString() {
return "java.util.TimeZone.getTimeZone(\"" + getAsText() + "\")";
}
}
ばっちり!
あ~でもこれだと、nullの時におかしな動きするかぁ…
直さなきゃ。