4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.config;
12 import jp.sfjp.jindolf.data.DialogPref;
13 import jp.sfjp.jindolf.glyph.FontInfo;
14 import jp.sfjp.jindolf.net.ProxyInfo;
15 import jp.sourceforge.jovsonz.JsBoolean;
16 import jp.sourceforge.jovsonz.JsObject;
17 import jp.sourceforge.jovsonz.JsPair;
18 import jp.sourceforge.jovsonz.JsValue;
23 public class AppSetting{
25 private static final String HASH_PROXY = "proxy";
27 private static final String HASH_FONT = "font";
28 private static final String HASH_USEBODYICON = "useBodyIcon";
29 private static final String HASH_USEMONOTOMB = "useMonoTomb";
30 private static final String HASH_SIMPLEMODE = "isSimpleMode";
31 private static final String HASH_ALIGNBALOON = "alignBaloonWidth";
33 private OptionInfo optInfo;
34 private ConfigStore configStore;
35 private FontInfo fontInfo = FontInfo.DEFAULT_FONTINFO;
37 private int frameWidth = 800;
38 private int frameHeight = 600;
39 private int frameXpos = Integer.MIN_VALUE;
40 private int frameYpos = Integer.MIN_VALUE;
42 private ProxyInfo proxyInfo = ProxyInfo.DEFAULT;
44 private DialogPref dialogPref = new DialogPref();
46 private JsValue loadedNetConfig;
47 private JsValue loadedTalkConfig;
59 * @param optionInfo コマンドライン情報
62 private static ConfigStore parseConfigStore(OptionInfo optionInfo){
64 optionInfo.getExclusiveOption(CmdOption.OPT_CONFDIR,
65 CmdOption.OPT_NOCONF );
70 if(opt == CmdOption.OPT_NOCONF){
73 }else if(opt == CmdOption.OPT_CONFDIR){
74 String path = optionInfo.getStringArg(CmdOption.OPT_CONFDIR);
76 configPath = FileUtils.supplyFullPath(new File(path));
79 File path = ConfigFile.getImplicitConfigDirectory();
83 ConfigStore result = new ConfigStore(useConfig, configPath);
89 * コマンドラインオプションからアプリ設定を展開する。
90 * @param optionInfo オプション情報
92 public void applyOptionInfo(OptionInfo optionInfo){
93 this.optInfo = optionInfo;
94 this.configStore = parseConfigStore(optionInfo);
96 applyGeometrySetting();
103 private void applyFontSetting(){
104 String fontName = this.optInfo.getStringArg(CmdOption.OPT_INITFONT);
106 Boolean useAntiAlias =
107 this.optInfo.getBooleanArg(CmdOption.OPT_ANTIALIAS);
108 if(useAntiAlias == null){
109 useAntiAlias = this.fontInfo.isAntiAliased();
112 Boolean useFractional =
113 this.optInfo.getBooleanArg(CmdOption.OPT_FRACTIONAL);
114 if(useFractional == null){
115 useFractional = this.fontInfo.usesFractionalMetrics();
118 if(fontName != null){
119 Font font = Font.decode(fontName);
120 this.fontInfo = this.fontInfo.deriveFont(font);
124 this.fontInfo.deriveRenderContext(useAntiAlias,
133 private void applyGeometrySetting(){
136 ival = this.optInfo.initialFrameWidth();
137 if(ival != null) this.frameWidth = ival;
139 ival = this.optInfo.initialFrameHeight();
140 if(ival != null) this.frameHeight = ival;
142 ival = this.optInfo.initialFrameXpos();
143 if(ival != null) this.frameXpos = ival;
145 ival = this.optInfo.initialFrameYpos();
146 if(ival != null) this.frameYpos = ival;
153 * @return コマンドラインオプション情報
155 public OptionInfo getOptionInfo(){
163 public ConfigStore getConfigStore(){
164 return this.configStore;
171 public int initialFrameWidth(){
172 return this.frameWidth;
179 public int initialFrameHeight(){
180 return this.frameHeight;
185 * 特に指示されていなければInteger.MIN_VALUEを返す。
186 * @return 初期のフレーム位置のX座標
188 public int initialFrameXpos(){
189 return this.frameXpos;
194 * 特に指示されていなければInteger.MIN_VALUEを返す。
195 * @return 初期のフレーム位置のY座標
197 public int initialFrameYpos(){
198 return this.frameYpos;
205 public FontInfo getFontInfo(){
206 return this.fontInfo;
211 * @param fontInfo フォント設定
213 public void setFontInfo(FontInfo fontInfo){
214 this.fontInfo = fontInfo;
222 public ProxyInfo getProxyInfo(){
223 return this.proxyInfo;
228 * @param proxyInfo プロクシ設定。nullならプロクシなしと解釈される。
230 public void setProxyInfo(ProxyInfo proxyInfo){
231 if(proxyInfo == null) this.proxyInfo = ProxyInfo.DEFAULT;
232 else this.proxyInfo = proxyInfo;
240 public DialogPref getDialogPref(){
241 return this.dialogPref;
248 public void setDialogPref(DialogPref pref){
249 if(pref == null) this.dialogPref = new DialogPref();
250 else this.dialogPref = pref;
257 private void loadNetConfig(){
258 JsObject root = this.configStore.loadNetConfig();
259 if(root == null) return;
260 this.loadedNetConfig = root;
262 JsValue value = root.getValue(HASH_PROXY);
263 if( ! (value instanceof JsObject) ) return;
264 JsObject proxy = (JsObject) value;
266 ProxyInfo info = ProxyInfo.decodeJson(proxy);
276 private void loadTalkConfig(){
277 JsObject root = this.configStore.loadTalkConfig();
278 if(root == null) return;
279 this.loadedTalkConfig = root;
281 JsValue value = root.getValue(HASH_FONT);
282 if(value instanceof JsObject){
283 JsObject font = (JsObject) value;
284 FontInfo info = FontInfo.decodeJson(font);
289 DialogPref pref = new DialogPref();
291 value = root.getValue(HASH_USEBODYICON);
292 if(value instanceof JsBoolean){
293 boolValue = (JsBoolean) value;
294 pref.setBodyImageSetting(boolValue.booleanValue());
296 value = root.getValue(HASH_USEMONOTOMB);
297 if(value instanceof JsBoolean){
298 boolValue = (JsBoolean) value;
299 pref.setMonoImageSetting(boolValue.booleanValue());
301 value = root.getValue(HASH_SIMPLEMODE);
302 if(value instanceof JsBoolean){
303 boolValue = (JsBoolean) value;
304 pref.setSimpleMode(boolValue.booleanValue());
306 value = root.getValue(HASH_ALIGNBALOON);
307 if(value instanceof JsBoolean){
308 boolValue = (JsBoolean) value;
309 pref.setAlignBalooonWidthSetting(boolValue.booleanValue());
319 private void saveNetConfig(){
320 if( ! getConfigStore().useStoreFile() ) return;
322 JsObject root = new JsObject();
323 JsObject proxy = ProxyInfo.buildJson(getProxyInfo());
324 root.putValue(HASH_PROXY, proxy);
326 if(this.loadedNetConfig != null){
327 if(this.loadedNetConfig.equals(root)) return;
330 this.configStore.saveNetConfig(root);
338 private void saveTalkConfig(){
339 if( ! getConfigStore().useStoreFile() ) return;
341 JsObject root = new JsObject();
343 JsObject font = FontInfo.buildJson(getFontInfo());
344 root.putValue(HASH_FONT, font);
346 DialogPref pref = getDialogPref();
348 new JsPair(HASH_USEBODYICON, pref.useBodyImage());
350 new JsPair(HASH_USEMONOTOMB, pref.useMonoImage());
352 new JsPair(HASH_SIMPLEMODE, pref.isSimpleMode());
354 new JsPair(HASH_ALIGNBALOON, pref.alignBaloonWidth());
355 root.putPair(useBodyIcon);
356 root.putPair(useMonoTomb);
357 root.putPair(isSimple);
358 root.putPair(alignBaloon);
360 if(this.loadedTalkConfig != null){
361 if(this.loadedTalkConfig.equals(root)) return;
364 this.configStore.saveTalkConfig(root);
370 * 各種設定を設定格納ディレクトリからロードする。
372 public void loadConfig(){
379 * 各種設定を設定格納ディレクトリへセーブする。
381 public void saveConfig(){