Jindolfプロジェクトは、CGIゲーム「人狼BBS」を快適にプレイするための専用クライアントを製作するために発足したオープンソースプロジェクトです。
リビジョン | a7ab8f9253aa74a853ec13b95d1853b691948234 (tree) |
---|---|
日時 | 2020-10-11 23:48:20 |
作者 | Olyutorskii <olyutorskii@user...> |
コミッター | Olyutorskii |
Merge branch 'release/v4.101.4'
@@ -4,6 +4,10 @@ | ||
4 | 4 | Jindolf 変更履歴 |
5 | 5 | |
6 | 6 | |
7 | +4.101.4 (2020-10-11) | |
8 | + ・G国URL変更に伴い JinParser 2.102.4 に対応。 | |
9 | + ・ログ出力ウィンドウをQuetexJに変更。 | |
10 | + | |
7 | 11 | 4.101.2 (2020-04-20) |
8 | 12 | ・G国亡国に伴い JinParser 2.102.2 に対応。 |
9 | 13 | ・ログイン管理画面の廃止。 |
@@ -6,7 +6,7 @@ | ||
6 | 6 | |
7 | 7 | <!-- |
8 | 8 | Checkstyle modules |
9 | - for Checkstyle 8.31 or later | |
9 | + for Checkstyle 8.36 or later | |
10 | 10 | |
11 | 11 | [ https://checkstyle.org/ ] |
12 | 12 |
@@ -197,6 +197,7 @@ | ||
197 | 197 | <module name="ParameterAssignment" /> |
198 | 198 | <module name="RequireThis"> |
199 | 199 | <property name="checkMethods" value="false" /> |
200 | + <property name="validateOnlyOverlapping" value="false" /> | |
200 | 201 | </module> |
201 | 202 | <module name="ReturnCount"> |
202 | 203 | <property name="max" value="5" /> |
@@ -234,6 +235,7 @@ | ||
234 | 235 | <module name="JavadocBlockTagLocation" /> |
235 | 236 | <module name="JavadocContentLocationCheck" /> |
236 | 237 | <module name="JavadocMethod" /> |
238 | + <module name="JavadocMissingWhitespaceAfterAsterisk" /> | |
237 | 239 | <module name="JavadocParagraph" /> |
238 | 240 | <module name="JavadocStyle"> |
239 | 241 | <property |
@@ -281,6 +283,7 @@ | ||
281 | 283 | <module name="Indentation"> |
282 | 284 | <property name="caseIndent" value="0" /> |
283 | 285 | </module> |
286 | + <module name="NoCodeInFile" /> | |
284 | 287 | <module name="OuterTypeFilename" /> |
285 | 288 | <module name="TodoComment"> |
286 | 289 | <property name="format" value="TODO" /> |
@@ -305,6 +308,7 @@ | ||
305 | 308 | <module name="CatchParameterName" /> |
306 | 309 | <module name="ClassTypeParameterName" /> |
307 | 310 | <module name="ConstantName" /> |
311 | + <module name="IllegalIdentifierName" /> | |
308 | 312 | <module name="InterfaceTypeParameterName" /> |
309 | 313 | <module name="LambdaParameterName" /> |
310 | 314 | <module name="LocalFinalVariableName" /> |
@@ -314,6 +318,8 @@ | ||
314 | 318 | <module name="MethodTypeParameterName" /> |
315 | 319 | <module name="PackageName" /> |
316 | 320 | <module name="ParameterName" /> |
321 | + <module name="PatternVariableName" /> | |
322 | + <module name="RecordTypeParameterName" /> | |
317 | 323 | <module name="StaticVariableName" /> |
318 | 324 | <module name="TypeName" /> |
319 | 325 |
@@ -344,6 +350,7 @@ | ||
344 | 350 | <module name="MethodLength" /> |
345 | 351 | <module name="OuterTypeNumber" /> |
346 | 352 | <module name="ParameterNumber" /> |
353 | + <module name="RecordComponentNumber" /> | |
347 | 354 | |
348 | 355 | |
349 | 356 | <!-- Whitespace --> |
@@ -16,7 +16,7 @@ | ||
16 | 16 | <groupId>jp.sourceforge.jindolf</groupId> |
17 | 17 | <artifactId>jindolf</artifactId> |
18 | 18 | |
19 | - <version>4.101.2</version> | |
19 | + <version>4.101.4</version> | |
20 | 20 | |
21 | 21 | <packaging>jar</packaging> |
22 | 22 | <name>Jindolf</name> |
@@ -121,7 +121,7 @@ | ||
121 | 121 | <dependency> |
122 | 122 | <groupId>jp.osdn.jindolf</groupId> |
123 | 123 | <artifactId>jinparser</artifactId> |
124 | - <version>2.102.2</version> | |
124 | + <version>2.102.4</version> | |
125 | 125 | <scope>compile</scope> |
126 | 126 | </dependency> |
127 | 127 |
@@ -132,6 +132,13 @@ | ||
132 | 132 | <scope>compile</scope> |
133 | 133 | </dependency> |
134 | 134 | |
135 | + <dependency> | |
136 | + <groupId>io.github.olyutorskii</groupId> | |
137 | + <artifactId>quetexj</artifactId> | |
138 | + <version>1.0.4</version> | |
139 | + <scope>compile</scope> | |
140 | + </dependency> | |
141 | + | |
135 | 142 | </dependencies> |
136 | 143 | |
137 | 144 | <repositories/> |
@@ -158,7 +165,7 @@ | ||
158 | 165 | <plugin> |
159 | 166 | <groupId>org.apache.maven.plugins</groupId> |
160 | 167 | <artifactId>maven-resources-plugin</artifactId> |
161 | - <version>3.1.0</version> | |
168 | + <version>3.2.0</version> | |
162 | 169 | </plugin> |
163 | 170 | |
164 | 171 | <plugin> |
@@ -170,19 +177,19 @@ | ||
170 | 177 | <plugin> |
171 | 178 | <groupId>org.apache.maven.plugins</groupId> |
172 | 179 | <artifactId>maven-surefire-plugin</artifactId> |
173 | - <version>3.0.0-M4</version> | |
180 | + <version>3.0.0-M5</version> | |
174 | 181 | </plugin> |
175 | 182 | |
176 | 183 | <plugin> |
177 | 184 | <groupId>org.apache.maven.plugins</groupId> |
178 | 185 | <artifactId>maven-surefire-report-plugin</artifactId> |
179 | - <version>3.0.0-M4</version> | |
186 | + <version>3.0.0-M5</version> | |
180 | 187 | </plugin> |
181 | 188 | |
182 | 189 | <plugin> |
183 | 190 | <groupId>org.jacoco</groupId> |
184 | 191 | <artifactId>jacoco-maven-plugin</artifactId> |
185 | - <version>0.8.5</version> | |
192 | + <version>0.8.6</version> | |
186 | 193 | </plugin> |
187 | 194 | |
188 | 195 | <plugin> |
@@ -194,7 +201,7 @@ | ||
194 | 201 | <plugin> |
195 | 202 | <groupId>org.apache.maven.plugins</groupId> |
196 | 203 | <artifactId>maven-shade-plugin</artifactId> |
197 | - <version>3.2.1</version> | |
204 | + <version>3.2.4</version> | |
198 | 205 | </plugin> |
199 | 206 | |
200 | 207 | <plugin> |
@@ -218,19 +225,19 @@ | ||
218 | 225 | <plugin> |
219 | 226 | <groupId>org.apache.maven.plugins</groupId> |
220 | 227 | <artifactId>maven-site-plugin</artifactId> |
221 | - <version>3.9.0</version> | |
228 | + <version>3.9.1</version> | |
222 | 229 | </plugin> |
223 | 230 | |
224 | 231 | <plugin> |
225 | 232 | <groupId>org.apache.maven.plugins</groupId> |
226 | 233 | <artifactId>maven-assembly-plugin</artifactId> |
227 | - <version>3.2.0</version> | |
234 | + <version>3.3.0</version> | |
228 | 235 | </plugin> |
229 | 236 | |
230 | 237 | <plugin> |
231 | 238 | <groupId>org.apache.maven.plugins</groupId> |
232 | 239 | <artifactId>maven-project-info-reports-plugin</artifactId> |
233 | - <version>3.0.0</version> | |
240 | + <version>3.1.1</version> | |
234 | 241 | </plugin> |
235 | 242 | |
236 | 243 | <plugin> |
@@ -253,7 +260,7 @@ | ||
253 | 260 | <dependency> |
254 | 261 | <groupId>com.puppycrawl.tools</groupId> |
255 | 262 | <artifactId>checkstyle</artifactId> |
256 | - <version>8.31</version> | |
263 | + <version>8.36.2</version> | |
257 | 264 | </dependency> |
258 | 265 | </dependencies> |
259 | 266 | </plugin> |
@@ -267,12 +274,12 @@ | ||
267 | 274 | <plugin> |
268 | 275 | <groupId>com.github.spotbugs</groupId> |
269 | 276 | <artifactId>spotbugs-maven-plugin</artifactId> |
270 | - <version>4.0.0</version> | |
277 | + <version>4.1.3</version> | |
271 | 278 | <dependencies> |
272 | 279 | <dependency> |
273 | 280 | <groupId>com.github.spotbugs</groupId> |
274 | 281 | <artifactId>spotbugs</artifactId> |
275 | - <version>4.0.2</version> | |
282 | + <version>4.1.3</version> | |
276 | 283 | </dependency> |
277 | 284 | </dependencies> |
278 | 285 | </plugin> |
@@ -440,6 +447,7 @@ | ||
440 | 447 | <groupId>org.apache.maven.plugins</groupId> |
441 | 448 | <artifactId>maven-assembly-plugin</artifactId> |
442 | 449 | <configuration> |
450 | + <tarLongFileMode>posix</tarLongFileMode> | |
443 | 451 | <descriptors> |
444 | 452 | <descriptor>src/assembly/src.xml</descriptor> |
445 | 453 | </descriptors> |
@@ -0,0 +1,177 @@ | ||
1 | +/* | |
2 | + * busy status manager | |
3 | + * | |
4 | + * License : The MIT License | |
5 | + * Copyright(c) 2020 olyutorskii | |
6 | + */ | |
7 | + | |
8 | +package jp.sfjp.jindolf; | |
9 | + | |
10 | +import java.awt.EventQueue; | |
11 | +import java.lang.reflect.InvocationTargetException; | |
12 | +import java.util.concurrent.Executor; | |
13 | +import java.util.concurrent.Executors; | |
14 | +import java.util.logging.Level; | |
15 | +import java.util.logging.Logger; | |
16 | +import jp.sfjp.jindolf.view.TopFrame; | |
17 | +import jp.sfjp.jindolf.view.TopView; | |
18 | + | |
19 | +/** | |
20 | + * ビジー状態の見た目を管理する。 | |
21 | + * | |
22 | + * <p>ビジー状態を伴うタスクの管理も行う。 | |
23 | + * | |
24 | + * <p>EDTで処理しきれない長時間タスクを実行している状況、 | |
25 | + * およびその間のGUI操作が抑止される期間をビジーと呼ぶ。 | |
26 | + */ | |
27 | +public class BusyStatus { | |
28 | + | |
29 | + private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
30 | + | |
31 | + | |
32 | + private final TopFrame topFrame; | |
33 | + private final Executor executor = Executors.newCachedThreadPool(); | |
34 | + | |
35 | + private boolean isBusy = false; | |
36 | + | |
37 | + | |
38 | + /** | |
39 | + * コンストラクタ。 | |
40 | + * | |
41 | + * @param topFrame TopFrameインスタンス | |
42 | + */ | |
43 | + public BusyStatus(TopFrame topFrame){ | |
44 | + super(); | |
45 | + this.topFrame = topFrame; | |
46 | + return; | |
47 | + } | |
48 | + | |
49 | + | |
50 | + /** | |
51 | + * ビジー状態か否か返す。 | |
52 | + * | |
53 | + * @return ビジーならtrue | |
54 | + */ | |
55 | + public boolean isBusy(){ | |
56 | + return this.isBusy; | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * ビジー状態を設定する。 | |
61 | + * | |
62 | + * <p>ヘビーなタスク実行をアピールするために、 | |
63 | + * プログレスバーとカーソルの設定を行う。 | |
64 | + * | |
65 | + * <p>ビジー中のトップフレームのマウス操作、キーボード入力は | |
66 | + * 全てグラブされるため無視される。 | |
67 | + * | |
68 | + * @param flag trueならプログレスバーのアニメ開始&WAITカーソル。 | |
69 | + * falseなら停止&通常カーソル。 | |
70 | + * @param msg フッタメッセージ。nullなら変更なし。 | |
71 | + */ | |
72 | + public void setBusy(boolean flag, String msg){ | |
73 | + if(EventQueue.isDispatchThread()){ | |
74 | + setBusyEdt(flag, msg); | |
75 | + return; | |
76 | + } | |
77 | + | |
78 | + try{ | |
79 | + EventQueue.invokeAndWait(() -> { | |
80 | + setBusyEdt(flag, msg); | |
81 | + }); | |
82 | + }catch(InterruptedException | InvocationTargetException e){ | |
83 | + LOGGER.log(Level.SEVERE, "ビジー処理で失敗", e); | |
84 | + } | |
85 | + | |
86 | + return; | |
87 | + } | |
88 | + | |
89 | + /** | |
90 | + * ビジー状態を設定する。 | |
91 | + * | |
92 | + * <p>原則EDTから呼ばねばならない。 | |
93 | + * | |
94 | + * @param flag trueならビジー | |
95 | + * @param msg メッセージ。nullなら変更なし。 | |
96 | + */ | |
97 | + public void setBusyEdt(boolean flag, String msg){ | |
98 | + assert EventQueue.isDispatchThread(); | |
99 | + | |
100 | + this.isBusy = flag; | |
101 | + | |
102 | + this.topFrame.setBusy(this.isBusy); | |
103 | + | |
104 | + if(msg != null){ | |
105 | + TopView topView = this.topFrame.getTopView(); | |
106 | + topView.updateSysMessage(msg); | |
107 | + } | |
108 | + | |
109 | + return; | |
110 | + } | |
111 | + | |
112 | + /** | |
113 | + * 軽量タスクをEDTで実行する。 | |
114 | + * | |
115 | + * <p>タスク実行中はビジー状態となる。 | |
116 | + * | |
117 | + * <p>軽量タスク実行中はイベントループが停止するので、 | |
118 | + * 入出力待ちを伴わなずに早急に終わるタスクでなければならない。 | |
119 | + * | |
120 | + * @param task 軽量タスク | |
121 | + * @param beforeMsg ビジー中ステータス文字列 | |
122 | + * @param afterMsg ビジー復帰時のステータス文字列 | |
123 | + */ | |
124 | + public void submitLightBusyTask(Runnable task, | |
125 | + String beforeMsg, | |
126 | + String afterMsg ){ | |
127 | + EventQueue.invokeLater(() -> { | |
128 | + setBusy(true, beforeMsg); | |
129 | + }); | |
130 | + | |
131 | + EventQueue.invokeLater(task); | |
132 | + | |
133 | + EventQueue.invokeLater(() -> { | |
134 | + setBusy(false, afterMsg); | |
135 | + }); | |
136 | + | |
137 | + return; | |
138 | + } | |
139 | + | |
140 | + /** | |
141 | + * 重量級タスクをEDTとは別のスレッドで実行する。 | |
142 | + * | |
143 | + * <p>タスク実行中はビジー状態となる。 | |
144 | + * | |
145 | + * @param heavyTask 重量級タスク | |
146 | + * @param beforeMsg ビジー中ステータス文字列 | |
147 | + * @param afterMsg ビジー復帰時のステータス文字列 | |
148 | + */ | |
149 | + public void submitHeavyBusyTask(final Runnable heavyTask, | |
150 | + final String beforeMsg, | |
151 | + final String afterMsg ){ | |
152 | + setBusy(true, beforeMsg); | |
153 | + | |
154 | + EventQueue.invokeLater(() -> { | |
155 | + fork(() -> { | |
156 | + try{ | |
157 | + heavyTask.run(); | |
158 | + }finally{ | |
159 | + setBusy(false, afterMsg); | |
160 | + } | |
161 | + }); | |
162 | + }); | |
163 | + | |
164 | + return; | |
165 | + } | |
166 | + | |
167 | + /** | |
168 | + * スレッドプールを用いて非EDTなタスクを投入する。 | |
169 | + * | |
170 | + * @param task タスク | |
171 | + */ | |
172 | + private void fork(Runnable task){ | |
173 | + this.executor.execute(task); | |
174 | + return; | |
175 | + } | |
176 | + | |
177 | +} |
@@ -16,12 +16,9 @@ import java.awt.event.WindowAdapter; | ||
16 | 16 | import java.awt.event.WindowEvent; |
17 | 17 | import java.io.File; |
18 | 18 | import java.io.IOException; |
19 | -import java.lang.reflect.InvocationTargetException; | |
20 | 19 | import java.net.URL; |
21 | 20 | import java.text.MessageFormat; |
22 | 21 | import java.util.List; |
23 | -import java.util.concurrent.Executor; | |
24 | -import java.util.concurrent.Executors; | |
25 | 22 | import java.util.logging.Handler; |
26 | 23 | import java.util.logging.Level; |
27 | 24 | import java.util.logging.Logger; |
@@ -45,6 +42,7 @@ import javax.swing.filechooser.FileNameExtensionFilter; | ||
45 | 42 | import javax.swing.tree.TreePath; |
46 | 43 | import jp.sfjp.jindolf.config.AppSetting; |
47 | 44 | import jp.sfjp.jindolf.config.ConfigStore; |
45 | +import jp.sfjp.jindolf.config.JsonIo; | |
48 | 46 | import jp.sfjp.jindolf.config.OptionInfo; |
49 | 47 | import jp.sfjp.jindolf.data.Anchor; |
50 | 48 | import jp.sfjp.jindolf.data.DialogPref; |
@@ -120,8 +118,7 @@ public class Controller | ||
120 | 118 | private final ChangeListener filterWatcher = |
121 | 119 | new FilterWatcher(); |
122 | 120 | |
123 | - private final Executor executor = Executors.newCachedThreadPool(); | |
124 | - private volatile boolean isBusyNow; | |
121 | + private final BusyStatus busyStatus; | |
125 | 122 | |
126 | 123 | |
127 | 124 | /** |
@@ -184,15 +181,18 @@ public class Controller | ||
184 | 181 | shutdown(); |
185 | 182 | } |
186 | 183 | }); |
184 | + this.busyStatus = new BusyStatus(topFrame); | |
187 | 185 | |
188 | 186 | filterPanel.addChangeListener(this.filterWatcher); |
189 | 187 | |
190 | 188 | Handler newHandler = logFrame.getHandler(); |
191 | - LogUtils.switchHandler(newHandler); | |
189 | + EventQueue.invokeLater(() -> { | |
190 | + LogUtils.switchHandler(newHandler); | |
191 | + }); | |
192 | 192 | |
193 | - ConfigStore config = this.appSetting.getConfigStore(); | |
193 | + JsonIo jsonIo = this.appSetting.getJsonIo(); | |
194 | 194 | |
195 | - JsObject history = config.loadHistoryConfig(); | |
195 | + JsObject history = jsonIo.loadHistoryConfig(); | |
196 | 196 | findPanel.putJson(history); |
197 | 197 | |
198 | 198 | FontInfo fontInfo = this.appSetting.getFontInfo(); |
@@ -323,34 +323,6 @@ public class Controller | ||
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
326 | - * ビジー状態の設定を行う。 | |
327 | - * | |
328 | - * <p>ヘビーなタスク実行をアピールするために、 | |
329 | - * プログレスバーとカーソルの設定を行う。 | |
330 | - * | |
331 | - * <p>ビジー中のActionコマンド受信は無視される。 | |
332 | - * | |
333 | - * <p>ビジー中のトップフレームのマウス操作、キーボード入力は | |
334 | - * 全てグラブされるため無視される。 | |
335 | - * | |
336 | - * @param isBusy trueならプログレスバーのアニメ開始&WAITカーソル。 | |
337 | - * falseなら停止&通常カーソル。 | |
338 | - * @param msg フッタメッセージ。nullなら変更なし。 | |
339 | - */ | |
340 | - private void setBusy(boolean isBusy, String msg){ | |
341 | - this.isBusyNow = isBusy; | |
342 | - | |
343 | - TopFrame topFrame = getTopFrame(); | |
344 | - | |
345 | - topFrame.setBusy(isBusy); | |
346 | - if(msg != null){ | |
347 | - this.topView.updateSysMessage(msg); | |
348 | - } | |
349 | - | |
350 | - return; | |
351 | - } | |
352 | - | |
353 | - /** | |
354 | 326 | * ステータスバーを更新する。 |
355 | 327 | * @param message メッセージ |
356 | 328 | */ |
@@ -360,91 +332,6 @@ public class Controller | ||
360 | 332 | } |
361 | 333 | |
362 | 334 | /** |
363 | - * ビジー状態を設定する。 | |
364 | - * | |
365 | - * <p>EDT以外から呼ばれると実際の処理が次回のEDT移行に遅延される。 | |
366 | - * | |
367 | - * @param isBusy ビジーならtrue | |
368 | - * @param message ステータスバー表示。nullなら変更なし | |
369 | - */ | |
370 | - public void submitBusyStatus(boolean isBusy, String message){ | |
371 | - Runnable task = () -> { | |
372 | - setBusy(isBusy, message); | |
373 | - }; | |
374 | - | |
375 | - if(EventQueue.isDispatchThread()){ | |
376 | - task.run(); | |
377 | - }else{ | |
378 | - try{ | |
379 | - EventQueue.invokeAndWait(task); | |
380 | - }catch(InvocationTargetException | InterruptedException e){ | |
381 | - LOGGER.log(Level.SEVERE, "ビジー処理で失敗", e); | |
382 | - } | |
383 | - } | |
384 | - | |
385 | - return; | |
386 | - } | |
387 | - | |
388 | - /** | |
389 | - * 軽量タスクをEDTで実行する。 | |
390 | - * | |
391 | - * <p>タスク実行中はビジー状態となる。 | |
392 | - * | |
393 | - * <p>軽量タスク実行中はイベントループが停止するので、 | |
394 | - * 入出力待ちを伴わなずに早急に終わるタスクでなければならない。 | |
395 | - * | |
396 | - * @param task 軽量タスク | |
397 | - * @param beforeMsg ビジー中ステータス文字列 | |
398 | - * @param afterMsg ビジー復帰時のステータス文字列 | |
399 | - */ | |
400 | - public void submitLightBusyTask(Runnable task, | |
401 | - String beforeMsg, | |
402 | - String afterMsg ){ | |
403 | - submitBusyStatus(true, beforeMsg); | |
404 | - EventQueue.invokeLater(task); | |
405 | - submitBusyStatus(false, afterMsg); | |
406 | - | |
407 | - return; | |
408 | - } | |
409 | - | |
410 | - /** | |
411 | - * 重量級タスクをEDTとは別のスレッドで実行する。 | |
412 | - * | |
413 | - * <p>タスク実行中はビジー状態となる。 | |
414 | - * | |
415 | - * @param heavyTask 重量級タスク | |
416 | - * @param beforeMsg ビジー中ステータス文字列 | |
417 | - * @param afterMsg ビジー復帰時のステータス文字列 | |
418 | - */ | |
419 | - public void submitHeavyBusyTask(final Runnable heavyTask, | |
420 | - final String beforeMsg, | |
421 | - final String afterMsg ){ | |
422 | - submitBusyStatus(true, beforeMsg); | |
423 | - | |
424 | - EventQueue.invokeLater(() -> { | |
425 | - fork(() -> { | |
426 | - try{ | |
427 | - heavyTask.run(); | |
428 | - }finally{ | |
429 | - submitBusyStatus(false, afterMsg); | |
430 | - } | |
431 | - }); | |
432 | - }); | |
433 | - | |
434 | - return; | |
435 | - } | |
436 | - | |
437 | - /** | |
438 | - * スレッドプールを用いて非EDTなタスクを投入する。 | |
439 | - * | |
440 | - * @param task タスク | |
441 | - */ | |
442 | - private void fork(Runnable task){ | |
443 | - this.executor.execute(task); | |
444 | - return; | |
445 | - } | |
446 | - | |
447 | - /** | |
448 | 335 | * About画面を表示する。 |
449 | 336 | */ |
450 | 337 | private void actionAbout(){ |
@@ -454,8 +341,7 @@ public class Controller | ||
454 | 341 | JOptionPane.DEFAULT_OPTION, |
455 | 342 | GUIUtils.getLogoIcon()); |
456 | 343 | |
457 | - JDialog dialog = pane.createDialog(getTopFrame(), | |
458 | - VerInfo.TITLE + "について"); | |
344 | + JDialog dialog = pane.createDialog(VerInfo.TITLE + "について"); | |
459 | 345 | |
460 | 346 | dialog.pack(); |
461 | 347 | dialog.setVisible(true); |
@@ -601,7 +487,7 @@ public class Controller | ||
601 | 487 | String className = this.actionManager.getSelectedLookAndFeel(); |
602 | 488 | if(className == null) return; |
603 | 489 | |
604 | - submitLightBusyTask( | |
490 | + this.busyStatus.submitLightBusyTask( | |
605 | 491 | () -> {taskChangeLaF(className);}, |
606 | 492 | "Look&Feelを更新中…", |
607 | 493 | "Look&Feelが更新されました" |
@@ -758,7 +644,7 @@ public class Controller | ||
758 | 644 | JOptionPane pane = new JOptionPane(message, |
759 | 645 | JOptionPane.WARNING_MESSAGE, |
760 | 646 | JOptionPane.DEFAULT_OPTION ); |
761 | - JDialog dialog = pane.createDialog(getTopFrame(), title); | |
647 | + JDialog dialog = pane.createDialog(title); | |
762 | 648 | dialog.pack(); |
763 | 649 | dialog.setVisible(true); |
764 | 650 | dialog.dispose(); |
@@ -776,7 +662,7 @@ public class Controller | ||
776 | 662 | }); |
777 | 663 | }; |
778 | 664 | |
779 | - submitHeavyBusyTask( | |
665 | + this.busyStatus.submitHeavyBusyTask( | |
780 | 666 | task, |
781 | 667 | "一括読み込み開始", |
782 | 668 | "一括読み込み完了" |
@@ -862,7 +748,7 @@ public class Controller | ||
862 | 748 | * 一括検索処理。 |
863 | 749 | */ |
864 | 750 | private void bulkSearch(){ |
865 | - submitHeavyBusyTask( | |
751 | + this.busyStatus.submitHeavyBusyTask( | |
866 | 752 | () -> {taskBulkSearch();}, |
867 | 753 | null, null |
868 | 754 | ); |
@@ -1016,7 +902,7 @@ public class Controller | ||
1016 | 902 | * 全日程の一括ロード。 |
1017 | 903 | */ |
1018 | 904 | private void actionLoadAllPeriod(){ |
1019 | - submitHeavyBusyTask( | |
905 | + this.busyStatus.submitHeavyBusyTask( | |
1020 | 906 | () -> {taskLoadAllPeriod();}, |
1021 | 907 | "一括読み込み開始", |
1022 | 908 | "一括読み込み完了" |
@@ -1182,7 +1068,7 @@ public class Controller | ||
1182 | 1068 | |
1183 | 1069 | }; |
1184 | 1070 | |
1185 | - submitHeavyBusyTask( | |
1071 | + this.busyStatus.submitHeavyBusyTask( | |
1186 | 1072 | task, |
1187 | 1073 | "ジャンプ先の読み込み中…", |
1188 | 1074 | null |
@@ -1199,7 +1085,7 @@ public class Controller | ||
1199 | 1085 | if(result != JFileChooser.APPROVE_OPTION) return; |
1200 | 1086 | File selected = this.xmlFileChooser.getSelectedFile(); |
1201 | 1087 | |
1202 | - submitHeavyBusyTask(() -> { | |
1088 | + this.busyStatus.submitHeavyBusyTask(() -> { | |
1203 | 1089 | Village village; |
1204 | 1090 | |
1205 | 1091 | try{ |
@@ -1237,7 +1123,7 @@ public class Controller | ||
1237 | 1123 | * @param land 国 |
1238 | 1124 | */ |
1239 | 1125 | private void submitReloadVillageList(final Land land){ |
1240 | - submitHeavyBusyTask( | |
1126 | + this.busyStatus.submitHeavyBusyTask( | |
1241 | 1127 | () -> {taskReloadVillageList(land);}, |
1242 | 1128 | "村一覧を読み込み中…", |
1243 | 1129 | "村一覧の読み込み完了" |
@@ -1303,7 +1189,7 @@ public class Controller | ||
1303 | 1189 | }); |
1304 | 1190 | }; |
1305 | 1191 | |
1306 | - submitHeavyBusyTask( | |
1192 | + this.busyStatus.submitHeavyBusyTask( | |
1307 | 1193 | task, |
1308 | 1194 | "会話の読み込み中", |
1309 | 1195 | "会話の表示が完了" |
@@ -1362,7 +1248,7 @@ public class Controller | ||
1362 | 1248 | JOptionPane.DEFAULT_OPTION ); |
1363 | 1249 | |
1364 | 1250 | String title = VerInfo.getFrameTitle("通信異常発生"); |
1365 | - JDialog dialog = pane.createDialog(getTopFrame(), title); | |
1251 | + JDialog dialog = pane.createDialog(title); | |
1366 | 1252 | |
1367 | 1253 | dialog.pack(); |
1368 | 1254 | dialog.setVisible(true); |
@@ -1416,7 +1302,7 @@ public class Controller | ||
1416 | 1302 | }); |
1417 | 1303 | }; |
1418 | 1304 | |
1419 | - submitHeavyBusyTask( | |
1305 | + this.busyStatus.submitHeavyBusyTask( | |
1420 | 1306 | task, |
1421 | 1307 | "村情報を読み込み中…", |
1422 | 1308 | "村情報の読み込み完了" |
@@ -1436,7 +1322,7 @@ public class Controller | ||
1436 | 1322 | */ |
1437 | 1323 | @Override |
1438 | 1324 | public void actionPerformed(ActionEvent ev){ |
1439 | - if(this.isBusyNow) return; | |
1325 | + if(this.busyStatus.isBusy()) return; | |
1440 | 1326 | |
1441 | 1327 | String cmd = ev.getActionCommand(); |
1442 | 1328 | if(cmd == null) return; |
@@ -1571,7 +1457,7 @@ public class Controller | ||
1571 | 1457 | } |
1572 | 1458 | }; |
1573 | 1459 | |
1574 | - submitHeavyBusyTask( | |
1460 | + this.busyStatus.submitHeavyBusyTask( | |
1575 | 1461 | task, |
1576 | 1462 | "アンカーの展開中…", |
1577 | 1463 | null |
@@ -1584,12 +1470,12 @@ public class Controller | ||
1584 | 1470 | * アプリ正常終了処理。 |
1585 | 1471 | */ |
1586 | 1472 | private void shutdown(){ |
1587 | - ConfigStore configStore = this.appSetting.getConfigStore(); | |
1473 | + JsonIo jsonIo = this.appSetting.getJsonIo(); | |
1588 | 1474 | |
1589 | 1475 | FindPanel findPanel = this.windowManager.getFindPanel(); |
1590 | 1476 | JsObject findConf = findPanel.getJson(); |
1591 | 1477 | if( ! findPanel.hasConfChanged(findConf) ){ |
1592 | - configStore.saveHistoryConfig(findConf); | |
1478 | + jsonIo.saveHistoryConfig(findConf); | |
1593 | 1479 | } |
1594 | 1480 | |
1595 | 1481 | this.appSetting.saveConfig(); |
@@ -12,14 +12,17 @@ import java.awt.EventQueue; | ||
12 | 12 | import java.io.PrintStream; |
13 | 13 | import java.lang.reflect.InvocationTargetException; |
14 | 14 | import java.text.MessageFormat; |
15 | +import java.util.Locale; | |
15 | 16 | import java.util.logging.Level; |
16 | 17 | import java.util.logging.Logger; |
17 | 18 | import javax.swing.JFrame; |
18 | 19 | import javax.swing.UIManager; |
19 | 20 | import jp.sfjp.jindolf.config.AppSetting; |
20 | 21 | import jp.sfjp.jindolf.config.CmdOption; |
22 | +import jp.sfjp.jindolf.config.ConfigDirUi; | |
21 | 23 | import jp.sfjp.jindolf.config.ConfigStore; |
22 | 24 | import jp.sfjp.jindolf.config.EnvInfo; |
25 | +import jp.sfjp.jindolf.config.FileUtils; | |
23 | 26 | import jp.sfjp.jindolf.config.OptionInfo; |
24 | 27 | import jp.sfjp.jindolf.data.LandsTreeModel; |
25 | 28 | import jp.sfjp.jindolf.log.LogUtils; |
@@ -103,9 +106,8 @@ public final class JindolfMain { | ||
103 | 106 | |
104 | 107 | /** |
105 | 108 | * 起動時の諸々の情報をログ出力する。 |
106 | - * @param appSetting アプリ設定 | |
107 | 109 | */ |
108 | - private static void dumpBootInfo(AppSetting appSetting){ | |
110 | + private static void logBootInfo(){ | |
109 | 111 | Object[] logArgs; |
110 | 112 | |
111 | 113 | logArgs = new Object[]{ |
@@ -125,28 +127,59 @@ public final class JindolfMain { | ||
125 | 127 | }; |
126 | 128 | LOGGER.log(Level.INFO, LOG_HEAP, logArgs); |
127 | 129 | |
128 | - OptionInfo optinfo = appSetting.getOptionInfo(); | |
130 | + if(FileUtils.isWindowsOSFs()){ | |
131 | + LOGGER.info("Windows環境と認識されました。"); | |
132 | + } | |
133 | + | |
134 | + if(FileUtils.isMacOSXFs()){ | |
135 | + LOGGER.info("macOS環境と認識されました。"); | |
136 | + } | |
137 | + | |
138 | + Locale locale = Locale.getDefault(); | |
139 | + String localeTxt = locale.toString(); | |
140 | + LOGGER.log(Level.INFO, "ロケールに{0}が用いられます。", localeTxt); | |
141 | + | |
142 | + return; | |
143 | + } | |
144 | + | |
145 | + /** | |
146 | + * 起動時の諸々の情報をログ出力する。 | |
147 | + * | |
148 | + * @param optinfo コマンドラインオプション | |
149 | + */ | |
150 | + private static void logBootInfo(OptionInfo optinfo){ | |
129 | 151 | StringBuilder bootArgs = new StringBuilder(); |
152 | + | |
130 | 153 | bootArgs.append("\n\n").append("起動時引数:\n"); |
131 | - for(String arg : optinfo.getInvokeArgList()){ | |
132 | - bootArgs.append("\u0020\u0020").append(arg).append('\n'); | |
133 | - } | |
154 | + optinfo.getInvokeArgList().forEach(arg -> | |
155 | + bootArgs.append("\u0020\u0020").append(arg).append('\n') | |
156 | + ); | |
134 | 157 | bootArgs.append('\n'); |
158 | + | |
135 | 159 | bootArgs.append(EnvInfo.getVMInfo()); |
160 | + | |
136 | 161 | LOGGER.info(bootArgs.toString()); |
137 | 162 | |
138 | - ConfigStore configStore = appSetting.getConfigStore(); | |
163 | + return; | |
164 | + } | |
165 | + | |
166 | + /** | |
167 | + * 起動時の諸々の情報をログ出力する。 | |
168 | + * | |
169 | + * @param configStore 設定ディレクトリ情報 | |
170 | + */ | |
171 | + private static void logBootInfo(ConfigStore configStore){ | |
139 | 172 | if(configStore.useStoreFile()){ |
140 | 173 | LOGGER.log(Level.INFO, LOG_CONF, configStore.getConfigDir()); |
141 | 174 | }else{ |
142 | 175 | LOGGER.info(LOG_NOCONF); |
143 | 176 | } |
144 | - | |
145 | 177 | return; |
146 | 178 | } |
147 | 179 | |
148 | 180 | /** |
149 | 181 | * JindolfMain のスタートアップエントリ。 |
182 | + * | |
150 | 183 | * @param args コマンドライン引数 |
151 | 184 | * @return 起動に成功すれば0。失敗したら0以外。 |
152 | 185 | */ |
@@ -175,6 +208,7 @@ public final class JindolfMain { | ||
175 | 208 | |
176 | 209 | /** |
177 | 210 | * JindolfMain のスタートアップエントリ。 |
211 | + * | |
178 | 212 | * @param optinfo コマンドライン引数情報 |
179 | 213 | * @return 起動に成功すれば0。失敗したら0以外。 |
180 | 214 | */ |
@@ -229,44 +263,26 @@ public final class JindolfMain { | ||
229 | 263 | LogUtils.initRootLogger(optinfo.hasOption(CmdOption.OPT_CONSOLELOG)); |
230 | 264 | // ここからロギング解禁 |
231 | 265 | |
232 | - final AppSetting appSetting = new AppSetting(optinfo); | |
233 | - dumpBootInfo(appSetting); | |
266 | + logBootInfo(); | |
267 | + logBootInfo(optinfo); | |
234 | 268 | |
269 | + final AppSetting appSetting = new AppSetting(optinfo); | |
235 | 270 | ConfigStore configStore = appSetting.getConfigStore(); |
236 | - configStore.prepareConfigDir(); | |
237 | - configStore.tryLock(); | |
271 | + logBootInfo(configStore); | |
272 | + | |
273 | + ConfigDirUi.prepareConfigDir(configStore); | |
274 | + ConfigDirUi.tryLock(configStore); | |
238 | 275 | // ここから設定格納ディレクトリ解禁 |
239 | 276 | |
240 | 277 | appSetting.loadConfig(); |
241 | 278 | |
242 | - final Runtime runtime = Runtime.getRuntime(); | |
243 | - runtime.addShutdownHook(new Thread(){ | |
244 | - /** {@inheritDoc} */ | |
245 | - @Override | |
246 | - @SuppressWarnings("CallToThreadYield") | |
247 | - public void run(){ | |
248 | - LOGGER.info("シャットダウン処理に入ります…"); | |
249 | - flush(); | |
250 | - runtime.gc(); | |
251 | - Thread.yield(); | |
252 | - runtime.runFinalization(); // 危険? | |
253 | - Thread.yield(); | |
254 | - return; | |
255 | - } | |
256 | - }); | |
257 | - | |
258 | 279 | LoggingDispatcher.replaceEventQueue(); |
259 | 280 | |
260 | 281 | int exitCode = 0; |
261 | 282 | try{ |
262 | - EventQueue.invokeAndWait(new Runnable(){ | |
263 | - /** {@inheritDoc} */ | |
264 | - @Override | |
265 | - public void run(){ | |
266 | - startGUI(appSetting); | |
267 | - return; | |
268 | - } | |
269 | - }); | |
283 | + EventQueue.invokeAndWait(() -> | |
284 | + startGUI(appSetting) | |
285 | + ); | |
270 | 286 | }catch(InvocationTargetException | InterruptedException e){ |
271 | 287 | LOGGER.log(Level.SEVERE, FATALMSG_INITFAIL, e); |
272 | 288 | e.printStackTrace(STDERR); |
@@ -278,35 +294,38 @@ public final class JindolfMain { | ||
278 | 294 | |
279 | 295 | /** |
280 | 296 | * AWTイベントディスパッチスレッド版スタートアップエントリ。 |
297 | + * | |
281 | 298 | * @param appSetting アプリ設定 |
282 | 299 | */ |
283 | 300 | private static void startGUI(AppSetting appSetting){ |
284 | 301 | JFrame topFrame = buildMVC(appSetting); |
285 | - | |
286 | 302 | GUIUtils.modifyWindowAttributes(topFrame, true, false, true); |
287 | - | |
288 | 303 | topFrame.pack(); |
289 | 304 | |
290 | - Dimension initGeometry = | |
291 | - new Dimension(appSetting.initialFrameWidth(), | |
292 | - appSetting.initialFrameHeight()); | |
305 | + int frameWidth = appSetting.initialFrameWidth(); | |
306 | + int frameHeight = appSetting.initialFrameHeight(); | |
307 | + Dimension initGeometry = new Dimension(frameWidth, frameHeight); | |
293 | 308 | topFrame.setSize(initGeometry); |
294 | 309 | |
295 | - if( appSetting.initialFrameXpos() <= Integer.MIN_VALUE | |
296 | - || appSetting.initialFrameYpos() <= Integer.MIN_VALUE ){ | |
310 | + int frameXpos = appSetting.initialFrameXpos(); | |
311 | + int frameYpos = appSetting.initialFrameYpos(); | |
312 | + | |
313 | + if( frameXpos <= Integer.MIN_VALUE | |
314 | + || frameYpos <= Integer.MIN_VALUE ){ | |
297 | 315 | topFrame.setLocationByPlatform(true); |
298 | 316 | }else{ |
299 | - topFrame.setLocation(appSetting.initialFrameXpos(), | |
300 | - appSetting.initialFrameYpos() ); | |
317 | + topFrame.setLocation(frameXpos, frameYpos); | |
301 | 318 | } |
302 | 319 | |
303 | 320 | topFrame.setVisible(true); |
304 | 321 | |
322 | + // GOOD BYE BUT EVENT-LOOP WILL CONTINUE | |
305 | 323 | return; |
306 | 324 | } |
307 | 325 | |
308 | 326 | /** |
309 | 327 | * モデル・ビュー・コントローラの結合。 |
328 | + * | |
310 | 329 | * @param appSetting アプリ設定 |
311 | 330 | * @return アプリケーションのトップフレーム |
312 | 331 | */ |
@@ -315,8 +334,6 @@ public final class JindolfMain { | ||
315 | 334 | WindowManager windowManager = new WindowManager(); |
316 | 335 | ActionManager actionManager = new ActionManager(); |
317 | 336 | |
318 | - model.loadLandList(); | |
319 | - | |
320 | 337 | Controller controller = new Controller(model, |
321 | 338 | windowManager, |
322 | 339 | actionManager, |
@@ -59,6 +59,7 @@ public class AppSetting{ | ||
59 | 59 | |
60 | 60 | private final OptionInfo optInfo; |
61 | 61 | private final ConfigStore configStore; |
62 | + private final JsonIo jsonIo; | |
62 | 63 | private final Rectangle frameRect; |
63 | 64 | |
64 | 65 | private FontInfo fontInfo; |
@@ -83,6 +84,7 @@ public class AppSetting{ | ||
83 | 84 | |
84 | 85 | this.optInfo = info; |
85 | 86 | this.configStore = parseConfigStore(this.optInfo); |
87 | + this.jsonIo = new JsonIo(this.configStore); | |
86 | 88 | this.frameRect = parseGeometrySetting(this.optInfo); |
87 | 89 | |
88 | 90 | return; |
@@ -97,29 +99,27 @@ public class AppSetting{ | ||
97 | 99 | private static ConfigStore parseConfigStore(OptionInfo option){ |
98 | 100 | CmdOption opt = option.getExclusiveOption(CmdOption.OPT_CONFDIR, |
99 | 101 | CmdOption.OPT_NOCONF ); |
100 | - | |
101 | - boolean useConfig; | |
102 | - boolean isImplicitPath; | |
103 | - File configPath; | |
104 | - | |
105 | - if(opt == CmdOption.OPT_NOCONF){ | |
106 | - useConfig = false; | |
107 | - isImplicitPath = true; | |
108 | - configPath = null; | |
109 | - }else if(opt == CmdOption.OPT_CONFDIR){ | |
110 | - useConfig = true; | |
111 | - isImplicitPath = false; | |
112 | - String optPath = option.getStringArg(opt); | |
113 | - configPath = FileUtils.supplyFullPath(new File(optPath)); | |
102 | + ConfigStore result; | |
103 | + if(opt == null){ | |
104 | + result = new ConfigStore(null); | |
114 | 105 | }else{ |
115 | - useConfig = true; | |
116 | - isImplicitPath = true; | |
117 | - configPath = ConfigFile.getImplicitConfigDirectory(); | |
106 | + switch(opt){ | |
107 | + case OPT_NOCONF: | |
108 | + result = new ConfigStore(); | |
109 | + break; | |
110 | + case OPT_CONFDIR: | |
111 | + String optArg = option.getStringArg(opt); | |
112 | + Path configPath = Paths.get(optArg); | |
113 | + configPath = configPath.toAbsolutePath(); | |
114 | + result = new ConfigStore(configPath); | |
115 | + break; | |
116 | + default: | |
117 | + result = null; | |
118 | + assert false; | |
119 | + break; | |
120 | + } | |
118 | 121 | } |
119 | 122 | |
120 | - ConfigStore result = | |
121 | - new ConfigStore(useConfig, isImplicitPath, configPath); | |
122 | - | |
123 | 123 | return result; |
124 | 124 | } |
125 | 125 |
@@ -203,6 +203,15 @@ public class AppSetting{ | ||
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | + * JSON入出力設定を返す。 | |
207 | + * | |
208 | + * @return 入出力設定 | |
209 | + */ | |
210 | + public JsonIo getJsonIo(){ | |
211 | + return this.jsonIo; | |
212 | + } | |
213 | + | |
214 | + /** | |
206 | 215 | * 初期のフレーム幅を返す。 |
207 | 216 | * @return 初期のフレーム幅 |
208 | 217 | */ |
@@ -300,7 +309,7 @@ public class AppSetting{ | ||
300 | 309 | * ネットワーク設定をロードする。 |
301 | 310 | */ |
302 | 311 | private void loadNetConfig(){ |
303 | - JsObject root = this.configStore.loadNetConfig(); | |
312 | + JsObject root = this.jsonIo.loadNetConfig(); | |
304 | 313 | if(root == null) return; |
305 | 314 | this.loadedNetConfig = root; |
306 | 315 |
@@ -319,7 +328,7 @@ public class AppSetting{ | ||
319 | 328 | * 会話表示設定をロードする。 |
320 | 329 | */ |
321 | 330 | private void loadTalkConfig(){ |
322 | - JsObject root = this.configStore.loadTalkConfig(); | |
331 | + JsObject root = this.jsonIo.loadTalkConfig(); | |
323 | 332 | if(root == null) return; |
324 | 333 | this.loadedTalkConfig = root; |
325 | 334 |
@@ -411,7 +420,7 @@ public class AppSetting{ | ||
411 | 420 | * ローカル画像設定をロードする。 |
412 | 421 | */ |
413 | 422 | private void loadLocalImageConfig(){ |
414 | - JsObject root = this.configStore.loadLocalImgConfig(); | |
423 | + JsObject root = this.jsonIo.loadLocalImgConfig(); | |
415 | 424 | if(root == null) return; |
416 | 425 | |
417 | 426 | JsValue faceConfig = root.getValue("avatarFace"); |
@@ -482,7 +491,7 @@ public class AppSetting{ | ||
482 | 491 | if(this.loadedNetConfig.equals(root)) return; |
483 | 492 | } |
484 | 493 | |
485 | - this.configStore.saveNetConfig(root); | |
494 | + this.jsonIo.saveNetConfig(root); | |
486 | 495 | |
487 | 496 | return; |
488 | 497 | } |
@@ -516,7 +525,7 @@ public class AppSetting{ | ||
516 | 525 | if(this.loadedTalkConfig.equals(root)) return; |
517 | 526 | } |
518 | 527 | |
519 | - this.configStore.saveTalkConfig(root); | |
528 | + this.jsonIo.saveTalkConfig(root); | |
520 | 529 | |
521 | 530 | return; |
522 | 531 | } |
@@ -15,6 +15,10 @@ import jp.sfjp.jindolf.ResourceManager; | ||
15 | 15 | |
16 | 16 | /** |
17 | 17 | * コマンドラインオプションの列挙。 |
18 | + * | |
19 | + * <p>1オプションは複数の別名を持ちうる。 | |
20 | + * | |
21 | + * <p>1引数を持つオプションと持たないオプションは区別される。 | |
18 | 22 | */ |
19 | 23 | public enum CmdOption { |
20 | 24 |
@@ -58,7 +62,8 @@ public enum CmdOption { | ||
58 | 62 | OPT_FRACTIONAL |
59 | 63 | ); |
60 | 64 | |
61 | - private static final String RES_HELPTEXT = "resources/help.txt"; | |
65 | + private static final String RES_DIR = "resources"; | |
66 | + private static final String RES_HELPTEXT = RES_DIR + "/help.txt"; | |
62 | 67 | |
63 | 68 | |
64 | 69 | private final List<String> nameList; |
@@ -66,6 +71,7 @@ public enum CmdOption { | ||
66 | 71 | |
67 | 72 | /** |
68 | 73 | * コンストラクタ。 |
74 | + * | |
69 | 75 | * @param names オプション名の一覧 |
70 | 76 | */ |
71 | 77 | private CmdOption(String ... names){ |
@@ -77,6 +83,7 @@ public enum CmdOption { | ||
77 | 83 | |
78 | 84 | /** |
79 | 85 | * ヘルプメッセージ(オプションの説明)を返す。 |
86 | + * | |
80 | 87 | * @return ヘルプメッセージ |
81 | 88 | */ |
82 | 89 | public static String getHelpText(){ |
@@ -86,6 +93,7 @@ public enum CmdOption { | ||
86 | 93 | |
87 | 94 | /** |
88 | 95 | * オプション名に合致するEnumを返す。 |
96 | + * | |
89 | 97 | * @param arg 個別のコマンドライン引数 |
90 | 98 | * @return 合致したEnum。どれとも合致しなければnull |
91 | 99 | */ |
@@ -96,40 +104,43 @@ public enum CmdOption { | ||
96 | 104 | return null; |
97 | 105 | } |
98 | 106 | |
107 | + | |
99 | 108 | /** |
100 | 109 | * 任意のオプション文字列がこのオプションに合致するか判定する。 |
110 | + * | |
101 | 111 | * @param option ハイフンの付いたオプション文字列 |
102 | 112 | * @return 合致すればtrue |
103 | 113 | */ |
104 | 114 | public boolean matches(String option){ |
105 | - for(String name : this.nameList){ | |
106 | - if(option.equals(name)) return true; | |
107 | - } | |
108 | - | |
109 | - return false; | |
115 | + boolean result = this.nameList.contains(option); | |
116 | + return result; | |
110 | 117 | } |
111 | 118 | |
112 | 119 | /** |
113 | 120 | * 単体で意味をなすオプションか判定する。 |
121 | + * | |
114 | 122 | * @return 単体で意味をなすならtrue |
115 | 123 | */ |
116 | 124 | public boolean isIndepOption(){ |
117 | - if(OPTS_INDEPENDENT.contains(this)) return true; | |
118 | - return false; | |
125 | + boolean result = OPTS_INDEPENDENT.contains(this); | |
126 | + return result; | |
119 | 127 | } |
120 | 128 | |
121 | 129 | /** |
122 | 130 | * 真偽指定を一つ必要とするオプションか判定する。 |
131 | + * | |
123 | 132 | * @return 真偽指定を一つ必要とするオプションならtrue |
124 | 133 | */ |
125 | 134 | public boolean isBooleanOption(){ |
126 | - if(OPTS_BOOLEAN.contains(this)) return true; | |
127 | - return false; | |
135 | + boolean result = OPTS_BOOLEAN.contains(this); | |
136 | + return result; | |
128 | 137 | } |
129 | 138 | |
130 | 139 | /** |
131 | 140 | * オプション名を返す。 |
132 | - * オプション別名が複数指定されている場合は最初のオプション名 | |
141 | + * | |
142 | + * <p>オプション別名が複数指定されている場合は最初のオプション名 | |
143 | + * | |
133 | 144 | * @return オプション名 |
134 | 145 | */ |
135 | 146 | @Override |
@@ -0,0 +1,526 @@ | ||
1 | +/* | |
2 | + * configuration file & directory UI | |
3 | + * | |
4 | + * License : The MIT License | |
5 | + * Copyright(c) 2009 olyutorskii | |
6 | + */ | |
7 | + | |
8 | +package jp.sfjp.jindolf.config; | |
9 | + | |
10 | +import java.io.BufferedInputStream; | |
11 | +import java.io.File; | |
12 | +import java.io.IOException; | |
13 | +import java.io.InputStream; | |
14 | +import java.nio.file.Files; | |
15 | +import java.nio.file.Path; | |
16 | +import java.nio.file.Paths; | |
17 | +import java.text.MessageFormat; | |
18 | +import java.util.logging.Level; | |
19 | +import java.util.logging.Logger; | |
20 | +import javax.swing.JDialog; | |
21 | +import javax.swing.JOptionPane; | |
22 | +import jp.sfjp.jindolf.ResourceManager; | |
23 | +import jp.sfjp.jindolf.VerInfo; | |
24 | +import jp.sfjp.jindolf.view.LockErrorPane; | |
25 | + | |
26 | +/** | |
27 | + * ユーザとのインタラクションを伴う、 | |
28 | + * 設定格納ディレクトリに関する各種操作。 | |
29 | + * | |
30 | + * <p>ディレクトリ作成やロック確保に伴う、 | |
31 | + * 各種異常系に対する判断をユーザーに求める。 | |
32 | + * | |
33 | + * <p>場合によってはそのままVMごと終了し、呼び出し元に制御を返さない。 | |
34 | + * | |
35 | + * <p>ユーザとの各種インタラクションは、 | |
36 | + * アプリのメインウィンドウが表示される前に行われる。 | |
37 | + */ | |
38 | +public final class ConfigDirUi{ | |
39 | + | |
40 | + private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
41 | + | |
42 | + private static final String TITLE_BUILDCONF = | |
43 | + VerInfo.TITLE + "設定格納ディレクトリの設定"; | |
44 | + | |
45 | + private static final Path FILE_README = Paths.get("README.txt"); | |
46 | + private static final Path FILE_AVATARJSON = Paths.get("avatarCache.json"); | |
47 | + | |
48 | + private static final String RES_DIR = "resources"; | |
49 | + private static final String RES_README = RES_DIR + "/README.txt"; | |
50 | + private static final String RES_IMGDIR = RES_DIR + "/image"; | |
51 | + private static final String RES_AVATARJSON = | |
52 | + RES_IMGDIR + "/avatarCache.json"; | |
53 | + | |
54 | + private static final String MSG_POST = | |
55 | + "<ul>" | |
56 | + + "<li><code>" + CmdOption.OPT_CONFDIR + "</code>" | |
57 | + + " オプション指定により、<br/>" | |
58 | + + "任意の設定格納ディレクトリを指定することができます。<br/>" | |
59 | + + "<li><code>" + CmdOption.OPT_NOCONF + "</code>" | |
60 | + + " オプション指定により、<br/>" | |
61 | + + "設定格納ディレクトリを使わずに起動することができます。<br/>" | |
62 | + + "</ul>"; | |
63 | + private static final String MSG_NOCONF = | |
64 | + "<html>" | |
65 | + + "設定ディレクトリを使わずに起動を続行します。<br/>" | |
66 | + + "今回、各種設定の読み込み・保存はできません。<br/>" | |
67 | + + "<code>" | |
68 | + + CmdOption.OPT_NOCONF | |
69 | + + "</code> オプション" | |
70 | + + "を使うとこの警告は出なくなります。" | |
71 | + + "</html>"; | |
72 | + private static final String MSG_ABORT = | |
73 | + "<html>" | |
74 | + + "設定ディレクトリの作成をせずに起動を中止します。<br/>" | |
75 | + + MSG_POST | |
76 | + + "</html>"; | |
77 | + private static final String FORM_FAILRM = | |
78 | + "<html>" | |
79 | + + "ロックファイルの強制解除に失敗しました。<br/>" | |
80 | + + "他に動いているJindolf" | |
81 | + + "が見つからないのであれば、<br/>" | |
82 | + + "なんとかしてロックファイル<br/>" | |
83 | + + "{0}" | |
84 | + + "を削除してください。<br/>" | |
85 | + + "起動を中止します。" | |
86 | + + "</html>"; | |
87 | + private static final String FORM_ILLLOCK = | |
88 | + "<html>" | |
89 | + + "ロックファイル<br/>" | |
90 | + + "{0}" | |
91 | + + "を確保することができません。<br/>" | |
92 | + + "起動を中止します。" | |
93 | + + "</html>"; | |
94 | + private static final String FORM_MKDIRFAIL = | |
95 | + "<html>" | |
96 | + + "ディレクトリ<br/>" | |
97 | + + "{0}" | |
98 | + + "の作成に失敗しました。" | |
99 | + + "起動を中止します。<br/>" | |
100 | + + MSG_POST | |
101 | + + "</html>"; | |
102 | + private static final String FORM_ACCERR = | |
103 | + "<html>" | |
104 | + + "ディレクトリ<br/>" | |
105 | + + "{0}" | |
106 | + + "へのアクセスができません。" | |
107 | + + "起動を中止します。<br/>" | |
108 | + + "このディレクトリへのアクセス権を調整し" | |
109 | + + "読み書きできるようにしてください。<br/>" | |
110 | + + MSG_POST | |
111 | + + "</html>"; | |
112 | + private static final String FORM_WRITEERR = | |
113 | + "<html>" | |
114 | + + "ファイル<br/>" | |
115 | + + "{0}" | |
116 | + + "への書き込みができません。" | |
117 | + + "起動を中止します。<br/>" | |
118 | + + "</html>"; | |
119 | + private static final String FORM_MKCONF = | |
120 | + "<html>" | |
121 | + + "設定ファイル格納ディレクトリ<br/>" | |
122 | + + "{0}を作成します。<br/>" | |
123 | + + "このディレクトリを今から作成して構いませんか?<br/>" | |
124 | + + "このディレクトリ名は、後からいつでもヘルプウィンドウで<br/>" | |
125 | + + "確認することができます。" | |
126 | + + "</html>"; | |
127 | + | |
128 | + private static final String LOG_MKDIRERR = | |
129 | + "ディレクトリ{0}を生成できません"; | |
130 | + private static final String LOG_CREATEERR = | |
131 | + "ファイル{0}を生成できません"; | |
132 | + private static final String LOG_RESCPY = | |
133 | + "内部リソースから{0}へコピーが行われました。"; | |
134 | + | |
135 | + private static final int ERR_ABORT = 1; | |
136 | + | |
137 | + | |
138 | + /** | |
139 | + * 隠れコンストラクタ。 | |
140 | + */ | |
141 | + private ConfigDirUi(){ | |
142 | + assert false; | |
143 | + } | |
144 | + | |
145 | + | |
146 | + /** | |
147 | + * VMごとアプリを異常終了させる。 | |
148 | + * | |
149 | + * <p>終了コードは1。 | |
150 | + */ | |
151 | + private static void abort(){ | |
152 | + System.exit(ERR_ABORT); | |
153 | + assert false; | |
154 | + return; | |
155 | + } | |
156 | + | |
157 | + /** | |
158 | + * ダイアログを表示し、閉じられるまで待つ。 | |
159 | + * | |
160 | + * @param pane ダイアログの元となるペイン | |
161 | + */ | |
162 | + private static void showDialog(JOptionPane pane){ | |
163 | + JDialog dialog = pane.createDialog(TITLE_BUILDCONF); | |
164 | + dialog.setResizable(true); | |
165 | + dialog.pack(); | |
166 | + | |
167 | + dialog.setVisible(true); | |
168 | + dialog.dispose(); | |
169 | + | |
170 | + return; | |
171 | + } | |
172 | + | |
173 | + /** | |
174 | + * 設定ディレクトリ操作の | |
175 | + * 共通エラーメッセージ確認ダイアログを表示する。 | |
176 | + * | |
177 | + * <p>閉じるまで待つ。 | |
178 | + * | |
179 | + * @param txt メッセージ | |
180 | + */ | |
181 | + private static void showErrorMessage(String txt){ | |
182 | + JOptionPane pane = new JOptionPane( | |
183 | + txt, JOptionPane.ERROR_MESSAGE); | |
184 | + showDialog(pane); | |
185 | + return; | |
186 | + } | |
187 | + | |
188 | + /** | |
189 | + * センタリングされたファイル名表示のHTML表記を出力する。 | |
190 | + * | |
191 | + * @param path ファイル | |
192 | + * @return HTML表記 | |
193 | + */ | |
194 | + private static String getCenteredFileName(Path path){ | |
195 | + String form = "<center>[ {0} ]</center><br/>"; | |
196 | + String fileName = FileUtils.getHtmledFileName(path); | |
197 | + String result = MessageFormat.format(form, fileName); | |
198 | + return result; | |
199 | + } | |
200 | + | |
201 | + /** | |
202 | + * ディレクトリが生成できないエラーをダイアログで提示し、 | |
203 | + * VM終了する。 | |
204 | + * | |
205 | + * @param path 生成できなかったディレクトリ | |
206 | + */ | |
207 | + private static void abortCantBuildDir(Path path){ | |
208 | + String fileName = getCenteredFileName(path); | |
209 | + String msg = MessageFormat.format(FORM_MKDIRFAIL, fileName); | |
210 | + | |
211 | + showErrorMessage(msg); | |
212 | + abort(); | |
213 | + assert false; | |
214 | + | |
215 | + return; | |
216 | + } | |
217 | + | |
218 | + /** | |
219 | + * ディレクトリへアクセスできないエラーをダイアログで提示し、 | |
220 | + * VM終了する。 | |
221 | + * | |
222 | + * @param path アクセスできないディレクトリ | |
223 | + */ | |
224 | + private static void abortCantAccessDir(Path path){ | |
225 | + String fileName = getCenteredFileName(path); | |
226 | + String msg = MessageFormat.format(FORM_ACCERR, fileName); | |
227 | + | |
228 | + showErrorMessage(msg); | |
229 | + abort(); | |
230 | + assert false; | |
231 | + | |
232 | + return; | |
233 | + } | |
234 | + | |
235 | + /** | |
236 | + * ディレクトリが生成できない異常系をログ出力する。 | |
237 | + * | |
238 | + * @param dirPath 生成できなかったディレクトリ | |
239 | + * @param cause 異常系原因 | |
240 | + */ | |
241 | + private static void logMkdirErr(Path dirPath, Throwable cause){ | |
242 | + String pathTxt = dirPath.toString(); | |
243 | + String msg = MessageFormat.format(LOG_MKDIRERR, pathTxt); | |
244 | + LOGGER.log(Level.SEVERE, msg, cause); | |
245 | + return; | |
246 | + } | |
247 | + | |
248 | + /** | |
249 | + * リソースからローカルファイルへコピーする。 | |
250 | + * | |
251 | + * @param resource リソース名 | |
252 | + * @param dest ローカルファイル | |
253 | + */ | |
254 | + private static void copyResource(String resource, Path dest){ | |
255 | + try(InputStream ris = | |
256 | + ResourceManager.getResourceAsStream(resource)){ | |
257 | + InputStream is = new BufferedInputStream(ris); | |
258 | + Files.copy(is, dest); | |
259 | + }catch(IOException | SecurityException e){ | |
260 | + String destName = dest.toString(); | |
261 | + String logMsg = MessageFormat.format(LOG_CREATEERR, destName); | |
262 | + LOGGER.log(Level.SEVERE, logMsg, e); | |
263 | + | |
264 | + String destHtml = getCenteredFileName(dest); | |
265 | + String diagMsg = MessageFormat.format(FORM_WRITEERR, destHtml); | |
266 | + showErrorMessage(diagMsg); | |
267 | + abort(); | |
268 | + | |
269 | + assert false; | |
270 | + } | |
271 | + | |
272 | + String destName = dest.toString(); | |
273 | + String msg = MessageFormat.format(LOG_RESCPY, destName); | |
274 | + LOGGER.info(msg); | |
275 | + | |
276 | + return; | |
277 | + } | |
278 | + | |
279 | + /** | |
280 | + * 設定ディレクトリがアクセス可能でなければ | |
281 | + * エラーダイアログを出してVM終了する。 | |
282 | + * | |
283 | + * @param confDir 設定ディレクトリ | |
284 | + */ | |
285 | + private static void checkDirPerm(Path confDir){ | |
286 | + if( ! FileUtils.isAccessibleDirectory(confDir) ){ | |
287 | + abortCantAccessDir(confDir); | |
288 | + } | |
289 | + | |
290 | + return; | |
291 | + } | |
292 | + | |
293 | + /** | |
294 | + * 設定ディレクトリの存在を確認し、なければ作る。 | |
295 | + * | |
296 | + * <p>設定ディレクトリを使わない場合は何もしない。 | |
297 | + * | |
298 | + * @param configStore 設定ディレクトリ情報 | |
299 | + */ | |
300 | + public static void prepareConfigDir(ConfigStore configStore){ | |
301 | + if( ! configStore.useStoreFile() ) return; | |
302 | + | |
303 | + Path conf = configStore.getConfigDir(); | |
304 | + if(Files.exists(conf)){ | |
305 | + checkDirPerm(conf); | |
306 | + }else{ | |
307 | + buildConfDirPath(conf); | |
308 | + } | |
309 | + | |
310 | + Path imgDir = configStore.getLocalImgDir(); | |
311 | + if(Files.exists(imgDir)){ | |
312 | + checkDirPerm(imgDir); | |
313 | + }else{ | |
314 | + buildImageCacheDir(imgDir); | |
315 | + } | |
316 | + | |
317 | + return; | |
318 | + } | |
319 | + | |
320 | + /** | |
321 | + * まだ存在しない設定格納ディレクトリを新規に作成する。 | |
322 | + * | |
323 | + * <p>エラーがあればダイアログ提示とともにVM終了する。 | |
324 | + * | |
325 | + * <p>既に存在すればなにもしない。 | |
326 | + * | |
327 | + * @param confPath 設定格納ディレクトリ | |
328 | + * @return 新規に作成した設定格納ディレクトリの絶対パス | |
329 | + */ | |
330 | + private static Path buildConfDirPath(Path confPath){ | |
331 | + assert confPath.isAbsolute(); | |
332 | + if(Files.exists(confPath)) return confPath; | |
333 | + | |
334 | + boolean confirmed = confirmBuildConfigDir(confPath); | |
335 | + if( ! confirmed ){ | |
336 | + JOptionPane pane = new JOptionPane( | |
337 | + MSG_ABORT, JOptionPane.WARNING_MESSAGE); | |
338 | + showDialog(pane); | |
339 | + abort(); | |
340 | + assert false; | |
341 | + } | |
342 | + | |
343 | + try{ | |
344 | + Files.createDirectories(confPath); | |
345 | + }catch(IOException | SecurityException e){ | |
346 | + logMkdirErr(confPath, e); | |
347 | + abortCantBuildDir(confPath); | |
348 | + assert false; | |
349 | + } | |
350 | + | |
351 | + // FileUtils.setOwnerOnlyAccess(absPath); | |
352 | + | |
353 | + checkDirPerm(confPath); | |
354 | + | |
355 | + Path readme = confPath.resolve(FILE_README); | |
356 | + copyResource(RES_README, readme); | |
357 | + | |
358 | + return confPath; | |
359 | + } | |
360 | + | |
361 | + /** | |
362 | + * 設定ディレクトリを新規に生成してよいかダイアログで問い合わせる。 | |
363 | + * | |
364 | + * @param confDir 設定ディレクトリ | |
365 | + * @return 生成してよいと指示があればtrue | |
366 | + */ | |
367 | + private static boolean confirmBuildConfigDir(Path confDir){ | |
368 | + String confName = getCenteredFileName(confDir); | |
369 | + String msg = MessageFormat.format(FORM_MKCONF, confName); | |
370 | + | |
371 | + JOptionPane pane; | |
372 | + pane = new JOptionPane(msg, | |
373 | + JOptionPane.QUESTION_MESSAGE, | |
374 | + JOptionPane.YES_NO_OPTION); | |
375 | + showDialog(pane); | |
376 | + | |
377 | + Object val = pane.getValue(); | |
378 | + if( ! (val instanceof Integer) ) return false; | |
379 | + int ival = (int) val; | |
380 | + boolean result = ival == JOptionPane.YES_OPTION; | |
381 | + | |
382 | + return result; | |
383 | + } | |
384 | + | |
385 | + /** | |
386 | + * ローカル画像キャッシュディレクトリを作る。 | |
387 | + * | |
388 | + * <p>作られたディレクトリ内に | |
389 | + * ファイルavatarCache.jsonが作られる。 | |
390 | + * | |
391 | + * @param imgCacheDir ローカル画像キャッシュディレクトリ | |
392 | + */ | |
393 | + private static void buildImageCacheDir(Path imgCacheDir){ | |
394 | + assert imgCacheDir.isAbsolute(); | |
395 | + if(Files.exists(imgCacheDir)) return; | |
396 | + | |
397 | + try{ | |
398 | + Files.createDirectories(imgCacheDir); | |
399 | + }catch(IOException | SecurityException e){ | |
400 | + logMkdirErr(imgCacheDir, e); | |
401 | + abortCantBuildDir(imgCacheDir); | |
402 | + assert false; | |
403 | + } | |
404 | + | |
405 | + checkDirPerm(imgCacheDir); | |
406 | + | |
407 | + Path jsonPath = imgCacheDir.resolve(FILE_AVATARJSON); | |
408 | + copyResource(RES_AVATARJSON, jsonPath); | |
409 | + | |
410 | + return; | |
411 | + } | |
412 | + | |
413 | + /** | |
414 | + * ロックファイルの取得を試みる。 | |
415 | + * | |
416 | + * <p>ロックに失敗したが処理を続行する場合、 | |
417 | + * 設定ディレクトリは使わないものとして続行する。 | |
418 | + * | |
419 | + * @param configStore 設定ディレクトリ情報 | |
420 | + */ | |
421 | + public static void tryLock(ConfigStore configStore){ | |
422 | + if( ! configStore.useStoreFile() ) return; | |
423 | + | |
424 | + Path lockPath = configStore.getLockFile(); | |
425 | + File lockFile = lockPath.toFile(); | |
426 | + InterVMLock lock = new InterVMLock(lockFile); | |
427 | + | |
428 | + lock.tryLock(); | |
429 | + | |
430 | + if( ! lock.isFileOwner() ){ | |
431 | + confirmLockError(lock); | |
432 | + if( ! lock.isFileOwner() ){ | |
433 | + configStore.setNoConf(); | |
434 | + } | |
435 | + } | |
436 | + | |
437 | + return; | |
438 | + } | |
439 | + | |
440 | + /** | |
441 | + * ロックエラーダイアログの表示。 | |
442 | + * | |
443 | + * <p>呼び出しから戻ってもまだロックオブジェクトが | |
444 | + * ロックファイルのオーナーでない場合、 | |
445 | + * 今後設定ディレクトリは一切使わずに起動を続行するものとする。 | |
446 | + * | |
447 | + * <p>ロックファイルの強制解除に失敗した場合はVM終了する。 | |
448 | + * | |
449 | + * @param lock エラーを起こしたロック | |
450 | + */ | |
451 | + private static void confirmLockError(InterVMLock lock){ | |
452 | + File lockFile = lock.getLockFile(); | |
453 | + | |
454 | + LockErrorPane lockPane = new LockErrorPane(lockFile.toPath()); | |
455 | + JDialog lockDialog = lockPane.createDialog(TITLE_BUILDCONF); | |
456 | + | |
457 | + lockDialog.setResizable(true); | |
458 | + lockDialog.pack(); | |
459 | + | |
460 | + do{ | |
461 | + lockDialog.setVisible(true); | |
462 | + | |
463 | + Object result = lockPane.getValue(); | |
464 | + boolean aborted = LockErrorPane.isAborted(result); | |
465 | + boolean windowClosed = result == null; | |
466 | + | |
467 | + if(aborted || windowClosed){ | |
468 | + abort(); | |
469 | + assert false; | |
470 | + break; | |
471 | + } | |
472 | + | |
473 | + if(lockPane.isRadioRetry()){ | |
474 | + lock.tryLock(); | |
475 | + }else if(lockPane.isRadioContinue()){ | |
476 | + JOptionPane pane = new JOptionPane( | |
477 | + MSG_NOCONF, JOptionPane.INFORMATION_MESSAGE); | |
478 | + showDialog(pane); | |
479 | + break; | |
480 | + }else if(lockPane.isRadioForce()){ | |
481 | + forceRemove(lock); | |
482 | + break; | |
483 | + } | |
484 | + }while( ! lock.isFileOwner()); | |
485 | + | |
486 | + lockDialog.dispose(); | |
487 | + | |
488 | + return; | |
489 | + } | |
490 | + | |
491 | + /** | |
492 | + * ロックファイルの強制削除を試みる。 | |
493 | + * | |
494 | + * <p>削除とそれに後続する再ロック取得に成功したときだけ制御を戻す。 | |
495 | + * | |
496 | + * <p>削除できないまたは再ロックできない場合は、 | |
497 | + * 制御を戻さずVMごとアプリを終了する。 | |
498 | + * | |
499 | + * @param lock ロック | |
500 | + */ | |
501 | + private static void forceRemove(InterVMLock lock){ | |
502 | + File lockFile = lock.getLockFile(); | |
503 | + | |
504 | + lock.forceRemove(); | |
505 | + if(lock.isExistsFile()){ | |
506 | + String fileName = getCenteredFileName(lockFile.toPath()); | |
507 | + String msg = MessageFormat.format(FORM_FAILRM, fileName); | |
508 | + showErrorMessage(msg); | |
509 | + abort(); | |
510 | + assert false; | |
511 | + return; | |
512 | + } | |
513 | + | |
514 | + lock.tryLock(); | |
515 | + if(lock.isFileOwner()) return; | |
516 | + | |
517 | + String fileName = getCenteredFileName(lockFile.toPath()); | |
518 | + String msg = MessageFormat.format(FORM_ILLLOCK, fileName); | |
519 | + showErrorMessage(msg); | |
520 | + abort(); | |
521 | + assert false; | |
522 | + | |
523 | + return; | |
524 | + } | |
525 | + | |
526 | +} |
@@ -1,573 +0,0 @@ | ||
1 | -/* | |
2 | - * configuration file & directory | |
3 | - * | |
4 | - * License : The MIT License | |
5 | - * Copyright(c) 2009 olyutorskii | |
6 | - */ | |
7 | - | |
8 | -package jp.sfjp.jindolf.config; | |
9 | - | |
10 | -import java.io.File; | |
11 | -import java.io.FileOutputStream; | |
12 | -import java.io.IOException; | |
13 | -import java.io.InputStream; | |
14 | -import java.io.OutputStream; | |
15 | -import java.io.OutputStreamWriter; | |
16 | -import java.io.PrintWriter; | |
17 | -import java.io.Writer; | |
18 | -import java.nio.charset.Charset; | |
19 | -import java.nio.charset.StandardCharsets; | |
20 | -import java.nio.file.Files; | |
21 | -import java.nio.file.Path; | |
22 | -import java.nio.file.Paths; | |
23 | -import javax.swing.JDialog; | |
24 | -import javax.swing.JOptionPane; | |
25 | -import jp.sfjp.jindolf.ResourceManager; | |
26 | -import jp.sfjp.jindolf.VerInfo; | |
27 | -import jp.sfjp.jindolf.view.LockErrorPane; | |
28 | - | |
29 | -/** | |
30 | - * Jindolf設定格納ディレクトリに関するあれこれ。 | |
31 | - */ | |
32 | -public final class ConfigFile{ | |
33 | - | |
34 | - private static final String TITLE_BUILDCONF = | |
35 | - VerInfo.TITLE + "設定格納ディレクトリの設定"; | |
36 | - | |
37 | - private static final String JINCONF = "Jindolf"; | |
38 | - private static final String JINCONF_DOT = ".jindolf"; | |
39 | - private static final String FILE_README = "README.txt"; | |
40 | - private static final Charset CHARSET_README = StandardCharsets.UTF_8; | |
41 | - | |
42 | - private static final String MSG_POST = | |
43 | - "<ul>" | |
44 | - + "<li><code>" + CmdOption.OPT_CONFDIR + "</code>" | |
45 | - + " オプション指定により、<br>" | |
46 | - + "任意の設定格納ディレクトリを指定することができます。<br>" | |
47 | - + "<li><code>" + CmdOption.OPT_NOCONF + "</code>" | |
48 | - + " オプション指定により、<br>" | |
49 | - + "設定格納ディレクトリを使わずに起動することができます。<br>" | |
50 | - + "</ul>"; | |
51 | - | |
52 | - | |
53 | - /** | |
54 | - * 隠れコンストラクタ。 | |
55 | - */ | |
56 | - private ConfigFile(){ | |
57 | - assert false; | |
58 | - return; | |
59 | - } | |
60 | - | |
61 | - | |
62 | - /** | |
63 | - * 暗黙的な設定格納ディレクトリを返す。 | |
64 | - * | |
65 | - * <ul> | |
66 | - * | |
67 | - * <li>起動元JARファイルと同じディレクトリに、 | |
68 | - * アクセス可能なディレクトリ"Jindolf"が | |
69 | - * すでに存在していればそれを返す。 | |
70 | - * | |
71 | - * <li>起動元JARファイルおよび"Jindolf"が発見できなければ、 | |
72 | - * MacOSX環境の場合"~/Library/Application Support/Jindolf/"を返す。 | |
73 | - * Windows環境の場合"%USERPROFILE%\Jindolf\"を返す。 | |
74 | - * | |
75 | - * <li>それ以外の環境(Linux,etc?)の場合"~/.jindolf/"を返す。 | |
76 | - * | |
77 | - * </ul> | |
78 | - * | |
79 | - * <p>返すディレクトリが存在しているか否か、 | |
80 | - * アクセス可能か否かは呼び出し元で判断せよ。 | |
81 | - * | |
82 | - * @return 設定格納ディレクトリ | |
83 | - */ | |
84 | - public static File getImplicitConfigDirectory(){ | |
85 | - File result; | |
86 | - | |
87 | - File jarParent = FileUtils.getJarDirectory(); | |
88 | - if(jarParent != null && FileUtils.isAccessibleDirectory(jarParent)){ | |
89 | - result = new File(jarParent, JINCONF); | |
90 | - if(FileUtils.isAccessibleDirectory(result)){ | |
91 | - return result; | |
92 | - } | |
93 | - } | |
94 | - | |
95 | - File appset = FileUtils.getAppSetDir(); | |
96 | - if(appset == null) return null; | |
97 | - | |
98 | - if(FileUtils.isMacOSXFs() || FileUtils.isWindowsOSFs()){ | |
99 | - result = new File(appset, JINCONF); | |
100 | - }else{ | |
101 | - result = new File(appset, JINCONF_DOT); | |
102 | - } | |
103 | - | |
104 | - return result; | |
105 | - } | |
106 | - | |
107 | - /** | |
108 | - * まだ存在しない設定格納ディレクトリを新規に作成する。 | |
109 | - * | |
110 | - * <p>エラーがあればダイアログ提示とともにVM終了する。 | |
111 | - * | |
112 | - * @param confPath 設定格納ディレクトリ | |
113 | - * @param isImplicitPath ディレクトリが暗黙的に指定されたものならtrue。 | |
114 | - * @return 新規に作成した設定格納ディレクトリ | |
115 | - * @throws IllegalArgumentException すでにそのディレクトリは存在する。 | |
116 | - */ | |
117 | - public static File buildConfigDirectory(File confPath, | |
118 | - boolean isImplicitPath ) | |
119 | - throws IllegalArgumentException{ | |
120 | - if(confPath.exists()) throw new IllegalArgumentException(); | |
121 | - | |
122 | - File absPath = FileUtils.supplyFullPath(confPath); | |
123 | - | |
124 | - String preErrMessage = | |
125 | - "設定格納ディレクトリ<br>" | |
126 | - + getCenteredFileName(absPath) | |
127 | - + "の作成に失敗しました。"; | |
128 | - if( ! isImplicitPath ){ | |
129 | - preErrMessage = | |
130 | - "<code>" | |
131 | - + CmdOption.OPT_CONFDIR | |
132 | - + "</code> オプション" | |
133 | - + "で指定された、<br>" | |
134 | - + preErrMessage; | |
135 | - } | |
136 | - | |
137 | - File existsAncestor = FileUtils.findExistsAncestor(absPath); | |
138 | - if(existsAncestor == null){ | |
139 | - abortNoRoot(absPath, preErrMessage); | |
140 | - }else if( ! existsAncestor.canWrite() ){ | |
141 | - abortCantWriteAncestor(existsAncestor, preErrMessage); | |
142 | - } | |
143 | - | |
144 | - String prompt = | |
145 | - "設定ファイル格納ディレクトリ<br>" | |
146 | - + getCenteredFileName(absPath) | |
147 | - + "を作成します。"; | |
148 | - boolean confirmed = confirmBuildConfigDir(existsAncestor, prompt); | |
149 | - if( ! confirmed ){ | |
150 | - abortQuitBuildConfigDir(); | |
151 | - } | |
152 | - | |
153 | - boolean success; | |
154 | - try{ | |
155 | - success = absPath.mkdirs(); | |
156 | - }catch(SecurityException e){ | |
157 | - success = false; | |
158 | - } | |
159 | - | |
160 | - if( ! success || ! absPath.exists() ){ | |
161 | - abortCantBuildConfigDir(absPath); | |
162 | - } | |
163 | - | |
164 | - FileUtils.setOwnerOnlyAccess(absPath); | |
165 | - | |
166 | - checkAccessibility(absPath); | |
167 | - | |
168 | - touchReadme(absPath); | |
169 | - | |
170 | - return absPath; | |
171 | - } | |
172 | - | |
173 | - /** | |
174 | - * ローカル画像キャッシュディレクトリを作る。 | |
175 | - * | |
176 | - * <p>作られたディレクトリ内に | |
177 | - * ファイルavatarCache.jsonが作られる。 | |
178 | - * | |
179 | - * @param imgCacheDir ローカル画像キャッシュディレクトリ | |
180 | - */ | |
181 | - public static void buildImageCacheDir(File imgCacheDir){ | |
182 | - if(imgCacheDir.exists()) return; | |
183 | - | |
184 | - String jsonRes = "resources/image/avatarCache.json"; | |
185 | - InputStream is = ResourceManager.getResourceAsStream(jsonRes); | |
186 | - if(is == null) return; | |
187 | - | |
188 | - imgCacheDir.mkdirs(); | |
189 | - ConfigFile.checkAccessibility(imgCacheDir); | |
190 | - | |
191 | - Path cachePath = imgCacheDir.toPath(); | |
192 | - Path jsonLeaf = Paths.get("avatarCache.json"); | |
193 | - Path path = cachePath.resolve(jsonLeaf); | |
194 | - try{ | |
195 | - Files.copy(is, path); | |
196 | - }catch(IOException e){ | |
197 | - abortCantAccessConfigDir(path.toFile()); | |
198 | - } | |
199 | - | |
200 | - return; | |
201 | - } | |
202 | - | |
203 | - /** | |
204 | - * 設定ディレクトリ操作の | |
205 | - * 共通エラーメッセージ確認ダイアログを表示する。 | |
206 | - * | |
207 | - * <p>閉じるまで待つ。 | |
208 | - * | |
209 | - * @param seq メッセージ | |
210 | - */ | |
211 | - private static void showErrorMessage(CharSequence seq){ | |
212 | - JOptionPane pane = | |
213 | - new JOptionPane(seq.toString(), | |
214 | - JOptionPane.ERROR_MESSAGE); | |
215 | - showDialog(pane); | |
216 | - return; | |
217 | - } | |
218 | - | |
219 | - /** | |
220 | - * 設定ディレクトリ操作の | |
221 | - * 共通エラーメッセージ確認ダイアログを表示する。 | |
222 | - * | |
223 | - * <p>閉じるまで待つ。 | |
224 | - * | |
225 | - * @param seq メッセージ | |
226 | - */ | |
227 | - private static void showWarnMessage(CharSequence seq){ | |
228 | - JOptionPane pane = | |
229 | - new JOptionPane(seq.toString(), | |
230 | - JOptionPane.WARNING_MESSAGE); | |
231 | - showDialog(pane); | |
232 | - return; | |
233 | - } | |
234 | - | |
235 | - /** | |
236 | - * 設定ディレクトリ操作の | |
237 | - * 情報提示メッセージ確認ダイアログを表示する。 | |
238 | - * | |
239 | - * <p>閉じるまで待つ。 | |
240 | - * | |
241 | - * @param seq メッセージ | |
242 | - */ | |
243 | - private static void showInfoMessage(CharSequence seq){ | |
244 | - JOptionPane pane = | |
245 | - new JOptionPane(seq.toString(), | |
246 | - JOptionPane.INFORMATION_MESSAGE); | |
247 | - showDialog(pane); | |
248 | - return; | |
249 | - } | |
250 | - | |
251 | - /** | |
252 | - * ダイアログを表示し、閉じられるまで待つ。 | |
253 | - * | |
254 | - * @param pane ダイアログの元となるペイン | |
255 | - */ | |
256 | - private static void showDialog(JOptionPane pane){ | |
257 | - JDialog dialog = pane.createDialog(null, TITLE_BUILDCONF); | |
258 | - dialog.setResizable(true); | |
259 | - dialog.pack(); | |
260 | - | |
261 | - dialog.setVisible(true); | |
262 | - dialog.dispose(); | |
263 | - | |
264 | - return; | |
265 | - } | |
266 | - | |
267 | - /** | |
268 | - * VMを異常終了させる。 | |
269 | - */ | |
270 | - private static void abort(){ | |
271 | - System.exit(1); | |
272 | - assert false; | |
273 | - return; | |
274 | - } | |
275 | - | |
276 | - /** | |
277 | - * 設定ディレクトリのルートファイルシステムもしくはドライブレターに | |
278 | - * アクセスできないエラーをダイアログに提示し、VM終了する。 | |
279 | - * | |
280 | - * @param path 設定ディレクトリ | |
281 | - * @param preMessage メッセージ前半 | |
282 | - */ | |
283 | - private static void abortNoRoot(File path, String preMessage){ | |
284 | - File root = FileUtils.findRootFile(path); | |
285 | - showErrorMessage( | |
286 | - "<html>" | |
287 | - + preMessage + "<br>" | |
288 | - + getCenteredFileName(root) | |
289 | - + "を用意する方法が不明です。<br>" | |
290 | - + "起動を中止します。<br>" | |
291 | - + MSG_POST | |
292 | - + "</html>" ); | |
293 | - abort(); | |
294 | - return; | |
295 | - } | |
296 | - | |
297 | - /** | |
298 | - * 設定ディレクトリの祖先に書き込めないエラーをダイアログで提示し、 | |
299 | - * VM終了する。 | |
300 | - * | |
301 | - * @param existsAncestor 存在するもっとも近い祖先 | |
302 | - * @param preMessage メッセージ前半 | |
303 | - */ | |
304 | - private static void abortCantWriteAncestor(File existsAncestor, | |
305 | - String preMessage ){ | |
306 | - showErrorMessage( | |
307 | - "<html>" | |
308 | - + preMessage + "<br>" | |
309 | - + getCenteredFileName(existsAncestor) | |
310 | - + "への書き込みができないため、" | |
311 | - + "処理の続行は不可能です。<br>" | |
312 | - + "起動を中止します。<br>" | |
313 | - + MSG_POST | |
314 | - + "</html>" ); | |
315 | - abort(); | |
316 | - return; | |
317 | - } | |
318 | - | |
319 | - /** | |
320 | - * 設定ディレクトリを新規に生成してよいかダイアログで問い合わせる。 | |
321 | - * | |
322 | - * @param existsAncestor 存在するもっとも近い祖先 | |
323 | - * @param preMessage メッセージ前半 | |
324 | - * @return 生成してよいと指示があればtrue | |
325 | - */ | |
326 | - private static boolean confirmBuildConfigDir(File existsAncestor, | |
327 | - String preMessage){ | |
328 | - String message = | |
329 | - "<html>" | |
330 | - + preMessage + "<br>" | |
331 | - + "このディレクトリを今から<br>" | |
332 | - + getCenteredFileName(existsAncestor) | |
333 | - + "に作成して構いませんか?<br>" | |
334 | - + "このディレクトリ名は、後からいつでもヘルプウィンドウで<br>" | |
335 | - + "確認することができます。" | |
336 | - + "</html>"; | |
337 | - | |
338 | - JOptionPane pane = | |
339 | - new JOptionPane(message, | |
340 | - JOptionPane.QUESTION_MESSAGE, | |
341 | - JOptionPane.YES_NO_OPTION); | |
342 | - | |
343 | - showDialog(pane); | |
344 | - | |
345 | - Object result = pane.getValue(); | |
346 | - if(result == null) return false; | |
347 | - else if( ! (result instanceof Integer) ) return false; | |
348 | - | |
349 | - int ival = (Integer) result; | |
350 | - if(ival == JOptionPane.YES_OPTION) return true; | |
351 | - | |
352 | - return false; | |
353 | - } | |
354 | - | |
355 | - /** | |
356 | - * 設定ディレクトリ生成をやめた操作への警告をダイアログで提示し、 | |
357 | - * VM終了する。 | |
358 | - */ | |
359 | - private static void abortQuitBuildConfigDir(){ | |
360 | - showWarnMessage( | |
361 | - "<html>" | |
362 | - + "設定ディレクトリの作成をせずに起動を中止します。<br>" | |
363 | - + MSG_POST | |
364 | - + "</html>" ); | |
365 | - abort(); | |
366 | - return; | |
367 | - } | |
368 | - | |
369 | - /** | |
370 | - * 設定ディレクトリが生成できないエラーをダイアログで提示し、 | |
371 | - * VM終了する。 | |
372 | - * | |
373 | - * @param path 生成できなかったディレクトリ | |
374 | - */ | |
375 | - private static void abortCantBuildConfigDir(File path){ | |
376 | - showErrorMessage( | |
377 | - "<html>" | |
378 | - + "設定ディレクトリ<br>" | |
379 | - + getCenteredFileName(path) | |
380 | - + "の作成に失敗しました。" | |
381 | - + "起動を中止します。<br>" | |
382 | - + MSG_POST | |
383 | - + "</html>" ); | |
384 | - abort(); | |
385 | - return; | |
386 | - } | |
387 | - | |
388 | - /** | |
389 | - * 設定ディレクトリへアクセスできないエラーをダイアログで提示し、 | |
390 | - * VM終了する。 | |
391 | - * | |
392 | - * @param path アクセスできないディレクトリ | |
393 | - */ | |
394 | - private static void abortCantAccessConfigDir(File path){ | |
395 | - showErrorMessage( | |
396 | - "<html>" | |
397 | - + "設定ディレクトリ<br>" | |
398 | - + getCenteredFileName(path) | |
399 | - + "へのアクセスができません。" | |
400 | - + "起動を中止します。<br>" | |
401 | - + "このディレクトリへのアクセス権を調整し" | |
402 | - + "読み書きできるようにしてください。<br>" | |
403 | - + MSG_POST | |
404 | - + "</html>" ); | |
405 | - abort(); | |
406 | - return; | |
407 | - } | |
408 | - | |
409 | - /** | |
410 | - * ファイルに書き込めないエラーをダイアログで提示し、VM終了する。 | |
411 | - * | |
412 | - * @param file 書き込めなかったファイル | |
413 | - */ | |
414 | - private static void abortCantWrite(File file){ | |
415 | - showErrorMessage( | |
416 | - "<html>" | |
417 | - + "ファイル<br>" | |
418 | - + getCenteredFileName(file) | |
419 | - + "への書き込みができません。" | |
420 | - + "起動を中止します。<br>" | |
421 | - + "</html>" ); | |
422 | - abort(); | |
423 | - return; | |
424 | - } | |
425 | - | |
426 | - /** | |
427 | - * 指定されたディレクトリにREADMEファイルを生成する。 | |
428 | - * | |
429 | - * <p>生成できなければダイアログ表示とともにVM終了する。 | |
430 | - * | |
431 | - * @param path READMEの格納ディレクトリ | |
432 | - */ | |
433 | - private static void touchReadme(File path){ | |
434 | - File file = new File(path, FILE_README); | |
435 | - | |
436 | - try{ | |
437 | - file.createNewFile(); | |
438 | - }catch(IOException e){ | |
439 | - abortCantAccessConfigDir(path); | |
440 | - } | |
441 | - | |
442 | - PrintWriter writer = null; | |
443 | - try{ | |
444 | - OutputStream ostream = new FileOutputStream(file); | |
445 | - Writer owriter = new OutputStreamWriter(ostream, CHARSET_README); | |
446 | - writer = new PrintWriter(owriter); | |
447 | - writer.println(CHARSET_README.name() + " Japanese"); | |
448 | - writer.println( | |
449 | - "このディレクトリは、" | |
450 | - + "Jindolfの各種設定が格納されるディレクトリです。"); | |
451 | - writer.println( | |
452 | - "Jindolfの詳細は " | |
453 | - + "http://jindolf.osdn.jp/" | |
454 | - + " を参照してください。"); | |
455 | - writer.println( | |
456 | - "このディレクトリを" | |
457 | - + "「" + JINCONF + "」" | |
458 | - + "の名前で起動元JARファイルと" | |
459 | - + "同じ位置に"); | |
460 | - writer.println( | |
461 | - "コピーすれば、そちらの設定が優先して使われます。"); | |
462 | - writer.println( | |
463 | - "「lock」の名前を持つファイルはロックファイルです。"); | |
464 | - }catch(IOException | SecurityException e){ | |
465 | - abortCantWrite(file); | |
466 | - }finally{ | |
467 | - if(writer != null){ | |
468 | - writer.close(); | |
469 | - } | |
470 | - } | |
471 | - | |
472 | - return; | |
473 | - } | |
474 | - | |
475 | - /** | |
476 | - * 設定ディレクトリがアクセス可能でなければ | |
477 | - * エラーダイアログを出してVM終了する。 | |
478 | - * | |
479 | - * @param confDir 設定ディレクトリ | |
480 | - */ | |
481 | - public static void checkAccessibility(File confDir){ | |
482 | - if( ! FileUtils.isAccessibleDirectory(confDir) ){ | |
483 | - abortCantAccessConfigDir(confDir); | |
484 | - } | |
485 | - | |
486 | - return; | |
487 | - } | |
488 | - | |
489 | - /** | |
490 | - * センタリングされたファイル名表示のHTML表記を出力する。 | |
491 | - * | |
492 | - * @param path ファイル | |
493 | - * @return HTML表記 | |
494 | - */ | |
495 | - public static String getCenteredFileName(File path){ | |
496 | - return "<center>[ " | |
497 | - + FileUtils.getHtmledFileName(path) | |
498 | - + " ]</center>" | |
499 | - + "<br>"; | |
500 | - } | |
501 | - | |
502 | - /** | |
503 | - * ロックエラーダイアログの表示。 | |
504 | - * | |
505 | - * <p>呼び出しから戻ってもまだロックオブジェクトが | |
506 | - * ロックファイルのオーナーでない場合、 | |
507 | - * 今後設定ディレクトリは一切使わずに起動を続行するものとする。 | |
508 | - * | |
509 | - * <p>ロックファイルの強制解除に失敗した場合はVM終了する。 | |
510 | - * | |
511 | - * @param lock エラーを起こしたロック | |
512 | - */ | |
513 | - public static void confirmLockError(InterVMLock lock){ | |
514 | - LockErrorPane pane = new LockErrorPane(lock); | |
515 | - JDialog dialog = pane.createDialog(null, TITLE_BUILDCONF); | |
516 | - dialog.setResizable(true); | |
517 | - dialog.pack(); | |
518 | - | |
519 | - for(;;){ | |
520 | - dialog.setVisible(true); | |
521 | - dialog.dispose(); | |
522 | - | |
523 | - if(pane.isAborted() || pane.getValue() == null){ | |
524 | - abort(); | |
525 | - break; | |
526 | - }else if(pane.isRadioRetry()){ | |
527 | - lock.tryLock(); | |
528 | - if(lock.isFileOwner()) break; | |
529 | - }else if(pane.isRadioContinue()){ | |
530 | - showInfoMessage( | |
531 | - "<html>" | |
532 | - + "設定ディレクトリを使わずに起動を続行します。<br>" | |
533 | - + "今回、各種設定の読み込み・保存はできません。<br>" | |
534 | - + "<code>" | |
535 | - + CmdOption.OPT_NOCONF | |
536 | - + "</code> オプション" | |
537 | - + "を使うとこの警告は出なくなります。" | |
538 | - + "</html>"); | |
539 | - break; | |
540 | - }else if(pane.isRadioForce()){ | |
541 | - lock.forceRemove(); | |
542 | - if(lock.isExistsFile()){ | |
543 | - showErrorMessage( | |
544 | - "<html>" | |
545 | - + "ロックファイルの強制解除に失敗しました。<br>" | |
546 | - + "他に動いているJindolf" | |
547 | - + "が見つからないのであれば、<br>" | |
548 | - + "なんとかしてロックファイル<br>" | |
549 | - + getCenteredFileName(lock.getLockFile()) | |
550 | - + "を削除してください。<br>" | |
551 | - + "起動を中止します。" | |
552 | - + "</html>"); | |
553 | - abort(); | |
554 | - break; | |
555 | - } | |
556 | - lock.tryLock(); | |
557 | - if(lock.isFileOwner()) break; | |
558 | - showErrorMessage( | |
559 | - "<html>" | |
560 | - + "ロックファイル<br>" | |
561 | - + getCenteredFileName(lock.getLockFile()) | |
562 | - + "を確保することができません。<br>" | |
563 | - + "起動を中止します。" | |
564 | - + "</html>"); | |
565 | - abort(); | |
566 | - break; | |
567 | - } | |
568 | - } | |
569 | - | |
570 | - return; | |
571 | - } | |
572 | - | |
573 | -} |
@@ -7,457 +7,265 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.jindolf.config; |
9 | 9 | |
10 | -import java.io.BufferedInputStream; | |
11 | -import java.io.BufferedOutputStream; | |
12 | -import java.io.BufferedReader; | |
13 | -import java.io.BufferedWriter; | |
14 | -import java.io.File; | |
15 | -import java.io.FileInputStream; | |
16 | -import java.io.FileNotFoundException; | |
17 | -import java.io.FileOutputStream; | |
18 | -import java.io.IOException; | |
19 | -import java.io.InputStream; | |
20 | -import java.io.InputStreamReader; | |
21 | -import java.io.OutputStream; | |
22 | -import java.io.OutputStreamWriter; | |
23 | -import java.io.Reader; | |
24 | -import java.io.Writer; | |
25 | -import java.nio.charset.Charset; | |
26 | -import java.nio.charset.StandardCharsets; | |
27 | 10 | import java.nio.file.Path; |
28 | 11 | import java.nio.file.Paths; |
29 | -import java.util.logging.Level; | |
30 | -import java.util.logging.Logger; | |
31 | -import jp.sourceforge.jovsonz.JsComposition; | |
32 | -import jp.sourceforge.jovsonz.JsObject; | |
33 | -import jp.sourceforge.jovsonz.JsParseException; | |
34 | -import jp.sourceforge.jovsonz.JsTypes; | |
35 | -import jp.sourceforge.jovsonz.JsVisitException; | |
36 | -import jp.sourceforge.jovsonz.Json; | |
37 | 12 | |
38 | 13 | /** |
39 | - * 各種設定の永続化関連。 | |
14 | + * Jindolf設定ディレクトリの管理を行う。 | |
15 | + * | |
16 | + * <p>デフォルトの設定ディレクトリや | |
17 | + * アプリのコマンドライン引数から構成された、 | |
18 | + * 設定ディレクトリに関する情報が保持管理される。 | |
19 | + * | |
20 | + * <p>基本的に1アプリのみが設定ディレクトリへの入出力を許される。 | |
21 | + * | |
22 | + * <p>インスタンス生成後に | |
23 | + * 設定ディレクトリを使わない設定に変更することが可能。 | |
24 | + * (※ロック確保失敗後の続行等を想定) | |
25 | + * | |
26 | + * <p>設定ディレクトリには | |
27 | + * | |
28 | + * <ul> | |
29 | + * <li>ロックファイル | |
30 | + * <li>JSON設定ファイル | |
31 | + * <li>Avatar代替イメージ格納ディレクトリ | |
32 | + * </ul> | |
33 | + * | |
34 | + * <p>などが配置される。 | |
35 | + * | |
36 | + * <p>コンストラクタに与えられるディレクトリは | |
37 | + * 絶対パスでなければならない。 | |
38 | + * | |
39 | + * <p>ロックファイル取得の失敗、 | |
40 | + * およびその後のユーザインタラクションによっては、 | |
41 | + * 設定ディレクトリを使わない設定に上書きされた後 | |
42 | + * 起動処理が続行される場合がありうる。 | |
40 | 43 | */ |
41 | 44 | public class ConfigStore { |
42 | 45 | |
43 | - /** 検索履歴ファイル。 */ | |
44 | - public static final File HIST_FILE = new File("searchHistory.json"); | |
45 | - /** ネットワーク設定ファイル。 */ | |
46 | - public static final File NETCONFIG_FILE = new File("netconfig.json"); | |
47 | - /** 台詞表示設定ファイル。 */ | |
48 | - public static final File TALKCONFIG_FILE = new File("talkconfig.json"); | |
49 | - /** ローカル画像格納ディレクトリ。 */ | |
50 | - public static final Path LOCALIMG_DIR = Paths.get("img"); | |
51 | - /** ローカル画像設定ファイル。 */ | |
52 | - public static final Path LOCALIMGCONFIG_PATH = | |
53 | - Paths.get("avatarCache.json"); | |
46 | + private static final Path JINCONF = Paths.get("Jindolf"); | |
47 | + private static final Path JINCONF_DOT = Paths.get(".jindolf"); | |
48 | + private static final Path LOCKFILE = Paths.get("lock"); | |
49 | + private static final Path LOCALIMG_DIR = Paths.get("img"); | |
54 | 50 | |
55 | - private static final String LOCKFILE = "lock"; | |
56 | - | |
57 | - private static final Charset CHARSET_JSON = StandardCharsets.UTF_8; | |
58 | - | |
59 | - private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
51 | + private static final Path MAC_LIB = Paths.get("Library"); | |
52 | + private static final Path MAC_APPSUPP = Paths.get("Application Support"); | |
60 | 53 | |
61 | 54 | |
62 | 55 | private boolean useStoreFile; |
63 | - private boolean isImplicitPath; | |
64 | - private File configDir; | |
56 | + private Path configDir; | |
65 | 57 | |
66 | 58 | |
67 | 59 | /** |
68 | 60 | * コンストラクタ。 |
69 | 61 | * |
70 | - * @param useStoreFile 設定ディレクトリ内への | |
71 | - * セーブデータ機能を使うならtrue | |
72 | - * @param isImplicitPath 起動コマンドラインから指定された | |
73 | - * 設定ディレクトリの場合false | |
74 | - * @param configDirPath 設定ディレクトリ。 | |
75 | - * 設定ディレクトリを使わない場合は無視される。 | |
62 | + * <p>このインスタンスでは、 | |
63 | + * 設定ディレクトリへの入出力を行わない。 | |
76 | 64 | */ |
77 | - public ConfigStore(boolean useStoreFile, | |
78 | - boolean isImplicitPath, | |
79 | - File configDirPath ){ | |
80 | - super(); | |
81 | - | |
82 | - this.useStoreFile = useStoreFile; | |
83 | - | |
84 | - if(this.useStoreFile){ | |
85 | - this.isImplicitPath = isImplicitPath; | |
86 | - this.configDir = configDirPath; | |
87 | - }else{ | |
88 | - this.isImplicitPath = true; | |
89 | - this.configDir = null; | |
90 | - } | |
91 | - | |
65 | + public ConfigStore(){ | |
66 | + this(false, null); | |
92 | 67 | return; |
93 | 68 | } |
94 | 69 | |
95 | - | |
96 | 70 | /** |
97 | - * 設定ディレクトリを使うか否か判定する。 | |
71 | + * コンストラクタ。 | |
98 | 72 | * |
99 | - * @return 設定ディレクトリを使うならtrue。 | |
100 | - */ | |
101 | - public boolean useStoreFile(){ | |
102 | - return this.useStoreFile; | |
103 | - } | |
104 | - | |
105 | - /** | |
106 | - * 設定ディレクトリを返す。 | |
73 | + * <p>このインスタンスでは、 | |
74 | + * 設定ディレクトリへの入出力を行うが、 | |
75 | + * デフォルトではない明示されたディレクトリが用いられる。 | |
107 | 76 | * |
108 | - * @return 設定ディレクトリ。設定ディレクトリを使わない場合はnull | |
77 | + * @param configDirPath 設定ディレクトリの絶対パス。 | |
78 | + * nullの場合はデフォルトの設定ディレクトリが用いられる。 | |
79 | + * @throws IllegalArgumentException 絶対パスではない。 | |
109 | 80 | */ |
110 | - public File getConfigDir(){ | |
111 | - return this.configDir; | |
81 | + public ConfigStore(Path configDirPath) throws IllegalArgumentException{ | |
82 | + this(true, configDirPath); | |
83 | + return; | |
112 | 84 | } |
113 | 85 | |
114 | 86 | /** |
115 | - * ローカル画像格納ディレクトリを返す。 | |
87 | + * コンストラクタ。 | |
116 | 88 | * |
117 | - * @return 格納ディレクトリ。格納ディレクトリを使わない場合はnull | |
89 | + * @param useStoreFile 設定ディレクトリ内への | |
90 | + * 入出力機能を使うならtrue | |
91 | + * @param configDirPath 設定ディレクトリの絶対パス。 | |
92 | + * 設定ディレクトリを使わない場合は無視される。 | |
93 | + * この時点でのディレクトリ存在の有無は関知しない。 | |
94 | + * 既存ディレクトリの各種属性チェックは後にチェックするものとする。 | |
95 | + * nullの場合デフォルトの設定ディレクトリが用いられる。 | |
96 | + * @throws IllegalArgumentException 絶対パスではない。 | |
118 | 97 | */ |
119 | - public Path getLocalImgDir(){ | |
120 | - if(this.configDir == null) return null; | |
121 | - | |
122 | - Path configPath = this.configDir.toPath(); | |
123 | - Path result = configPath.resolve(LOCALIMG_DIR); | |
98 | + protected ConfigStore(boolean useStoreFile, | |
99 | + Path configDirPath ) | |
100 | + throws IllegalArgumentException{ | |
101 | + super(); | |
124 | 102 | |
125 | - return result; | |
126 | - } | |
103 | + this.useStoreFile = useStoreFile; | |
127 | 104 | |
128 | - /** | |
129 | - * 設定ディレクトリの存在を確認し、なければ作る。 | |
130 | - * | |
131 | - * <p>設定ディレクトリを使わない場合は何もしない。 | |
132 | - */ | |
133 | - public void prepareConfigDir(){ | |
134 | - if( ! this.useStoreFile ) return; | |
135 | - | |
136 | - if( ! this.configDir.exists() ){ | |
137 | - File created = | |
138 | - ConfigFile.buildConfigDirectory(this.configDir, | |
139 | - this.isImplicitPath ); | |
140 | - ConfigFile.checkAccessibility(created); | |
105 | + if(this.useStoreFile){ | |
106 | + if(configDirPath != null){ | |
107 | + if( ! configDirPath.isAbsolute()){ | |
108 | + throw new IllegalArgumentException(); | |
109 | + } | |
110 | + this.configDir = configDirPath; | |
111 | + }else{ | |
112 | + this.configDir = getDefaultConfDirPath(); | |
113 | + } | |
141 | 114 | }else{ |
142 | - ConfigFile.checkAccessibility(this.configDir); | |
115 | + this.configDir = null; | |
143 | 116 | } |
144 | 117 | |
145 | - File imgDir = new File(this.configDir, "img"); | |
146 | - if( ! imgDir.exists()){ | |
147 | - ConfigFile.buildImageCacheDir(imgDir); | |
148 | - } | |
118 | + assert ( this.useStoreFile && this.configDir != null) | |
119 | + || ( ( ! this.useStoreFile) && this.configDir == null); | |
149 | 120 | |
150 | 121 | return; |
151 | 122 | } |
152 | 123 | |
124 | + | |
153 | 125 | /** |
154 | - * ロックファイルの取得を試みる。 | |
126 | + * 暗黙的な設定格納ディレクトリを絶対パスで返す。 | |
127 | + * | |
128 | + * <ul> | |
129 | + * | |
130 | + * <li>起動元JARファイルと同じディレクトリに、 | |
131 | + * アクセス可能なディレクトリ"Jindolf"が | |
132 | + * すでに存在していればそれを返す。 | |
133 | + * | |
134 | + * <li>起動元JARファイルおよび"Jindolf"が発見できなければ、 | |
135 | + * MacOSX環境の場合"~/Library/Application Support/Jindolf/"を返す。 | |
136 | + * Windows環境の場合"%USERPROFILE%\Jindolf\"を返す。 | |
137 | + * | |
138 | + * <li>それ以外の環境(Linux,etc?)の場合"~/.jindolf/"を返す。 | |
139 | + * | |
140 | + * </ul> | |
155 | 141 | * |
156 | - * <p>ロックに失敗したが処理を続行する場合、 | |
157 | - * 設定ディレクトリは使わないものとして続行する。 | |
142 | + * <p>返すディレクトリが存在しているか否か、 | |
143 | + * アクセス可能か否かは呼び出し元で判断せよ。 | |
144 | + * | |
145 | + * @return 設定格納ディレクトリの絶対パス | |
158 | 146 | */ |
159 | - public void tryLock(){ | |
160 | - if( ! this.useStoreFile ) return; | |
161 | - | |
162 | - File lockFile = new File(this.configDir, LOCKFILE); | |
163 | - InterVMLock lock = new InterVMLock(lockFile); | |
164 | - | |
165 | - lock.tryLock(); | |
166 | - | |
167 | - if( ! lock.isFileOwner() ){ | |
168 | - ConfigFile.confirmLockError(lock); | |
169 | - if( ! lock.isFileOwner() ){ | |
170 | - this.useStoreFile = false; | |
171 | - this.isImplicitPath = true; | |
172 | - this.configDir = null; | |
147 | + public static Path getDefaultConfDirPath(){ | |
148 | + Path jarParent = FileUtils.getJarDirectory(); | |
149 | + if(FileUtils.isAccessibleDirectory(jarParent)){ | |
150 | + Path confPath = jarParent.resolve(JINCONF); | |
151 | + if(FileUtils.isAccessibleDirectory(confPath)){ | |
152 | + assert confPath.isAbsolute(); | |
153 | + return confPath; | |
173 | 154 | } |
174 | 155 | } |
175 | 156 | |
176 | - return; | |
177 | - } | |
157 | + Path appset = getAppSetDir(); | |
178 | 158 | |
179 | - /** | |
180 | - * 設定ディレクトリ上のOBJECT型JSONファイルを読み込む。 | |
181 | - * | |
182 | - * @param file JSONファイルの相対パス。 | |
183 | - * @return JSON object。 | |
184 | - * 設定ディレクトリを使わない設定、 | |
185 | - * もしくはJSONファイルが存在しない、 | |
186 | - * もしくはOBJECT型でなかった、 | |
187 | - * もしくは入力エラーがあればnull | |
188 | - */ | |
189 | - public JsObject loadJsObject(File file){ | |
190 | - JsComposition<?> root = loadJson(file); | |
191 | - if(root == null || root.getJsTypes() != JsTypes.OBJECT) return null; | |
192 | - JsObject result = (JsObject) root; | |
193 | - return result; | |
194 | - } | |
195 | - | |
196 | - /** | |
197 | - * 設定ディレクトリ上のJSONファイルを読み込む。 | |
198 | - * | |
199 | - * @param file JSONファイルの相対パス | |
200 | - * @return JSON objectまたはarray。 | |
201 | - * 設定ディレクトリを使わない設定、 | |
202 | - * もしくはJSONファイルが存在しない、 | |
203 | - * もしくは入力エラーがあればnull | |
204 | - */ | |
205 | - public JsComposition<?> loadJson(File file){ | |
206 | - if( ! this.useStoreFile ) return null; | |
207 | - | |
208 | - File absFile; | |
209 | - if(file.isAbsolute()){ | |
210 | - absFile = file; | |
159 | + Path leaf; | |
160 | + if(FileUtils.isMacOSXFs() || FileUtils.isWindowsOSFs()){ | |
161 | + leaf = JINCONF; | |
211 | 162 | }else{ |
212 | - if(this.configDir == null) return null; | |
213 | - absFile = new File(this.configDir, file.getPath()); | |
214 | - if( ! absFile.exists() ) return null; | |
215 | - if( ! absFile.isAbsolute() ) return null; | |
216 | - } | |
217 | - String absPath = absFile.getPath(); | |
218 | - | |
219 | - InputStream istream; | |
220 | - try{ | |
221 | - istream = new FileInputStream(absFile); | |
222 | - }catch(FileNotFoundException e){ | |
223 | - assert false; | |
224 | - return null; | |
225 | - } | |
226 | - istream = new BufferedInputStream(istream); | |
227 | - | |
228 | - JsComposition<?> root; | |
229 | - try{ | |
230 | - root = loadJson(istream); | |
231 | - }catch(IOException e){ | |
232 | - LOGGER.log(Level.SEVERE, | |
233 | - "JSONファイル[" | |
234 | - + absPath | |
235 | - + "]の読み込み時に支障がありました。", e); | |
236 | - return null; | |
237 | - }catch(JsParseException e){ | |
238 | - LOGGER.log(Level.SEVERE, | |
239 | - "JSONファイル[" | |
240 | - + absPath | |
241 | - + "]の内容に不備があります。", e); | |
242 | - return null; | |
243 | - }finally{ | |
244 | - try{ | |
245 | - istream.close(); | |
246 | - }catch(IOException e){ | |
247 | - LOGGER.log(Level.SEVERE, | |
248 | - "JSONファイル[" | |
249 | - + absPath | |
250 | - + "]を閉じることができません。", e); | |
251 | - return null; | |
252 | - } | |
163 | + leaf = JINCONF_DOT; | |
253 | 164 | } |
254 | 165 | |
255 | - return root; | |
166 | + Path result = appset.resolve(leaf); | |
167 | + assert result.isAbsolute(); | |
168 | + | |
169 | + return result; | |
256 | 170 | } |
257 | 171 | |
258 | 172 | /** |
259 | - * バイトストリーム上のJSONデータを読み込む。 | |
173 | + * アプリケーション設定ディレクトリを絶対パスで返す。 | |
260 | 174 | * |
261 | - * <p>バイトストリームはUTF-8と解釈される。 | |
175 | + * <p>存在の有無、アクセスの可否は関知しない。 | |
262 | 176 | * |
263 | - * @param is バイトストリーム | |
264 | - * @return JSON objectまたはarray。 | |
265 | - * @throws IOException 入力エラー | |
266 | - * @throws JsParseException 構文エラー | |
267 | - */ | |
268 | - protected JsComposition<?> loadJson(InputStream is) | |
269 | - throws IOException, JsParseException { | |
270 | - Reader reader = new InputStreamReader(is, CHARSET_JSON); | |
271 | - reader = new BufferedReader(reader); | |
272 | - JsComposition<?> root = loadJson(reader); | |
273 | - return root; | |
274 | - } | |
275 | - | |
276 | - /** | |
277 | - * 文字ストリーム上のJSONデータを読み込む。 | |
177 | + * <p>WindowsやLinuxではホームディレクトリ。 | |
178 | + * Mac OS X ではさらにホームディレクトリの下の | |
179 | + * "Library/Application Support/" | |
278 | 180 | * |
279 | - * @param reader 文字ストリーム | |
280 | - * @return JSON objectまたはarray。 | |
281 | - * @throws IOException 入力エラー | |
282 | - * @throws JsParseException 構文エラー | |
181 | + * @return アプリケーション設定ディレクトリの絶対パス | |
283 | 182 | */ |
284 | - protected JsComposition<?> loadJson(Reader reader) | |
285 | - throws IOException, JsParseException { | |
286 | - JsComposition<?> root = Json.parseJson(reader); | |
287 | - return root; | |
288 | - } | |
183 | + private static Path getAppSetDir(){ | |
184 | + Path home = getHomeDirectory(); | |
289 | 185 | |
290 | - /** | |
291 | - * 設定ディレクトリ上のJSONファイルに書き込む。 | |
292 | - * | |
293 | - * @param file JSONファイルの相対パス | |
294 | - * @param root JSON objectまたはarray | |
295 | - * @return 正しくセーブが行われればtrue。 | |
296 | - * 何らかの理由でセーブが完了できなければfalse | |
297 | - */ | |
298 | - public boolean saveJson(File file, JsComposition<?> root){ | |
299 | - if( ! this.useStoreFile ) return false; | |
300 | - | |
301 | - // TODO テンポラリファイルを用いたより安全なファイル更新 | |
302 | - File absFile = new File(this.configDir, file.getPath()); | |
303 | - String absPath = absFile.getPath(); | |
304 | - | |
305 | - absFile.delete(); | |
306 | - try{ | |
307 | - if(absFile.createNewFile() != true) return false; | |
308 | - }catch(IOException e){ | |
309 | - LOGGER.log(Level.SEVERE, | |
310 | - "JSONファイル[" | |
311 | - + absPath | |
312 | - + "]の新規生成ができません。", e); | |
313 | - return false; | |
314 | - } | |
186 | + Path result = home; | |
315 | 187 | |
316 | - OutputStream ostream; | |
317 | - try{ | |
318 | - ostream = new FileOutputStream(absFile); | |
319 | - }catch(FileNotFoundException e){ | |
320 | - assert false; | |
321 | - return false; | |
322 | - } | |
323 | - ostream = new BufferedOutputStream(ostream); | |
324 | - | |
325 | - try{ | |
326 | - saveJson(ostream, root); | |
327 | - }catch(JsVisitException e){ | |
328 | - LOGGER.log(Level.SEVERE, | |
329 | - "JSONファイル[" | |
330 | - + absPath | |
331 | - + "]の出力処理で支障がありました。", e); | |
332 | - return false; | |
333 | - }catch(IOException e){ | |
334 | - LOGGER.log(Level.SEVERE, | |
335 | - "JSONファイル[" | |
336 | - + absPath | |
337 | - + "]の書き込み時に支障がありました。", e); | |
338 | - return false; | |
339 | - }finally{ | |
340 | - try{ | |
341 | - ostream.close(); | |
342 | - }catch(IOException e){ | |
343 | - LOGGER.log(Level.SEVERE, | |
344 | - "JSONファイル[" | |
345 | - + absPath | |
346 | - + "]を閉じることができません。", e); | |
347 | - return false; | |
348 | - } | |
188 | + if(FileUtils.isMacOSXFs()){ | |
189 | + result = result.resolve(MAC_LIB); | |
190 | + result = result.resolve(MAC_APPSUPP); | |
349 | 191 | } |
350 | 192 | |
351 | - return true; | |
193 | + return result; | |
352 | 194 | } |
353 | 195 | |
354 | 196 | /** |
355 | - * バイトストリームにJSONデータを書き込む。 | |
197 | + * ホームディレクトリを得る。 | |
356 | 198 | * |
357 | - * <p>バイトストリームはUTF-8と解釈される。 | |
199 | + * <p>システムプロパティuser.homeで示されたホームディレクトリを | |
200 | + * 絶対パスで返す。 | |
358 | 201 | * |
359 | - * @param os バイトストリーム出力 | |
360 | - * @param root JSON objectまたはarray | |
361 | - * @throws IOException 出力エラー | |
362 | - * @throws JsVisitException 構造エラー | |
202 | + * @return ホームディレクトリの絶対パス。 | |
363 | 203 | */ |
364 | - protected void saveJson(OutputStream os, JsComposition<?> root) | |
365 | - throws IOException, JsVisitException { | |
366 | - Writer writer = new OutputStreamWriter(os, CHARSET_JSON); | |
367 | - writer = new BufferedWriter(writer); | |
368 | - saveJson(writer, root); | |
369 | - return; | |
204 | + private static Path getHomeDirectory(){ | |
205 | + String homeProp = System.getProperty("user.home"); | |
206 | + Path result = Paths.get(homeProp); | |
207 | + result = result.toAbsolutePath(); | |
208 | + return result; | |
370 | 209 | } |
371 | 210 | |
372 | - /** | |
373 | - * 文字ストリームにJSONデータを書き込む。 | |
374 | - * | |
375 | - * @param writer 文字ストリーム出力 | |
376 | - * @param root JSON objectまたはarray | |
377 | - * @throws IOException 出力エラー | |
378 | - * @throws JsVisitException 構造エラー | |
379 | - */ | |
380 | - protected void saveJson(Writer writer, JsComposition<?> root) | |
381 | - throws IOException, JsVisitException { | |
382 | - Json.dumpJson(writer, root); | |
383 | - return; | |
384 | - } | |
385 | 211 | |
386 | 212 | /** |
387 | - * 検索履歴ファイルを読み込む。 | |
213 | + * 設定ディレクトリを使うか否か判定する。 | |
388 | 214 | * |
389 | - * @return 履歴データ。履歴を読まないもしくは読めない場合はnull | |
215 | + * @return 設定ディレクトリを使うならtrue。 | |
390 | 216 | */ |
391 | - public JsObject loadHistoryConfig(){ | |
392 | - JsObject result = loadJsObject(HIST_FILE); | |
393 | - return result; | |
217 | + public boolean useStoreFile(){ | |
218 | + return this.useStoreFile; | |
394 | 219 | } |
395 | 220 | |
396 | 221 | /** |
397 | - * ネットワーク設定ファイルを読み込む。 | |
222 | + * 設定ディレクトリを絶対パスで返す。 | |
398 | 223 | * |
399 | - * @return ネットワーク設定データ。 | |
400 | - * 設定を読まないもしくは読めない場合はnull | |
224 | + * @return 設定ディレクトリの絶対パス。 | |
225 | + * 設定ディレクトリを使わない場合はnull | |
401 | 226 | */ |
402 | - public JsObject loadNetConfig(){ | |
403 | - JsObject result = loadJsObject(NETCONFIG_FILE); | |
404 | - return result; | |
227 | + public Path getConfigDir(){ | |
228 | + return this.configDir; | |
405 | 229 | } |
406 | 230 | |
407 | 231 | /** |
408 | - * 台詞表示設定ファイルを読み込む。 | |
409 | - * | |
410 | - * @return 台詞表示設定データ。 | |
411 | - * 設定を読まないもしくは読めない場合はnull | |
232 | + * 設定ディレクトリを使わない設定に変更する。 | |
412 | 233 | */ |
413 | - public JsObject loadTalkConfig(){ | |
414 | - JsObject result = loadJsObject(TALKCONFIG_FILE); | |
415 | - return result; | |
234 | + public void setNoConf(){ | |
235 | + this.useStoreFile = false; | |
236 | + this.configDir = null; | |
237 | + return; | |
416 | 238 | } |
417 | 239 | |
418 | 240 | /** |
419 | - * ローカル画像設定ファイルを読み込む。 | |
241 | + * ローカル画像格納ディレクトリを絶対パスで返す。 | |
420 | 242 | * |
421 | - * @return ローカル画像設定データ。 | |
422 | - * 設定を読まないもしくは読めない場合はnull | |
243 | + * @return 格納ディレクトリの絶対パス。 | |
244 | + * 格納ディレクトリを使わない場合はnull | |
423 | 245 | */ |
424 | - public JsObject loadLocalImgConfig(){ | |
425 | - Path path = LOCALIMG_DIR.resolve(LOCALIMGCONFIG_PATH); | |
426 | - JsObject result = loadJsObject(path.toFile()); | |
427 | - return result; | |
428 | - } | |
246 | + public Path getLocalImgDir(){ | |
247 | + if( ! this.useStoreFile ) return null; | |
248 | + if(this.configDir == null) return null; | |
429 | 249 | |
430 | - /** | |
431 | - * 検索履歴ファイルに書き込む。 | |
432 | - * | |
433 | - * @param root 履歴データ | |
434 | - * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
435 | - */ | |
436 | - public boolean saveHistoryConfig(JsComposition<?> root){ | |
437 | - boolean result = saveJson(HIST_FILE, root); | |
438 | - return result; | |
439 | - } | |
250 | + Path result = this.configDir.resolve(LOCALIMG_DIR); | |
251 | + assert result.isAbsolute(); | |
440 | 252 | |
441 | - /** | |
442 | - * ネットワーク設定ファイルに書き込む。 | |
443 | - * | |
444 | - * @param root ネットワーク設定 | |
445 | - * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
446 | - */ | |
447 | - public boolean saveNetConfig(JsComposition<?> root){ | |
448 | - boolean result = saveJson(NETCONFIG_FILE, root); | |
449 | 253 | return result; |
450 | 254 | } |
451 | 255 | |
452 | 256 | /** |
453 | - * 台詞表示設定ファイルに書き込む。 | |
257 | + * ロックファイルを絶対パスで返す。 | |
454 | 258 | * |
455 | - * @param root 台詞表示設定 | |
456 | - * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
259 | + * @return ロックファイルの絶対パス。 | |
260 | + * 格納ディレクトリを使わない場合はnull | |
457 | 261 | */ |
458 | - public boolean saveTalkConfig(JsComposition<?> root){ | |
459 | - boolean result = saveJson(TALKCONFIG_FILE, root); | |
460 | - return result; | |
262 | + public Path getLockFile(){ | |
263 | + if( ! this.useStoreFile ) return null; | |
264 | + if(this.configDir == null) return null; | |
265 | + | |
266 | + Path lockFile = this.configDir.resolve(LOCKFILE); | |
267 | + | |
268 | + return lockFile; | |
461 | 269 | } |
462 | 270 | |
463 | 271 | } |
@@ -8,8 +8,10 @@ | ||
8 | 8 | package jp.sfjp.jindolf.config; |
9 | 9 | |
10 | 10 | import java.io.File; |
11 | -import java.text.NumberFormat; | |
12 | -import java.util.Set; | |
11 | +import java.text.MessageFormat; | |
12 | +import java.util.Arrays; | |
13 | +import java.util.Collections; | |
14 | +import java.util.List; | |
13 | 15 | import java.util.SortedMap; |
14 | 16 | import java.util.TreeMap; |
15 | 17 |
@@ -32,36 +34,48 @@ public final class EnvInfo{ | ||
32 | 34 | /** 最大ヒープメモリ。 */ |
33 | 35 | public static final long MAX_MEMORY; |
34 | 36 | |
35 | - private static final SortedMap<String, String> PROPERTY_MAP = | |
36 | - new TreeMap<>(); | |
37 | - | |
38 | - private static final SortedMap<String, String> ENVIRONMENT_MAP = | |
39 | - new TreeMap<>(); | |
40 | - | |
41 | - private static final String[] CLASSPATHS; | |
37 | + private static final SortedMap<String, String> PROPERTY_MAP; | |
38 | + private static final SortedMap<String, String> ENVIRONMENT_MAP; | |
39 | + | |
40 | + private static final List<String> CLASSPATHS; | |
41 | + | |
42 | + private static final String[] PROPNAMES = { | |
43 | + "os.name", | |
44 | + "os.version", | |
45 | + "os.arch", | |
46 | + "java.vendor", | |
47 | + "java.version", | |
48 | + "java.class.path", | |
49 | + }; | |
50 | + | |
51 | + private static final String[] ENVNAMES = { | |
52 | + "LANG", | |
53 | + "DISPLAY", | |
54 | + //"PATH", | |
55 | + //"TEMP", | |
56 | + //"USER", | |
57 | + }; | |
58 | + | |
59 | + private static final String FORM_MEM = | |
60 | + "最大ヒープメモリ量: {0,number} bytes\n"; | |
61 | + private static final String INDENT = "\u0020\u0020"; | |
62 | + private static final char NL = '\n'; | |
42 | 63 | |
43 | 64 | static{ |
44 | - OS_NAME = getSecureProperty("os.name"); | |
45 | - OS_VERSION = getSecureProperty("os.version"); | |
46 | - OS_ARCH = getSecureProperty("os.arch"); | |
47 | - JAVA_VENDOR = getSecureProperty("java.vendor"); | |
48 | - JAVA_VERSION = getSecureProperty("java.version"); | |
49 | - | |
50 | - getSecureEnvironment("LANG"); | |
51 | - getSecureEnvironment("DISPLAY"); | |
52 | - | |
53 | 65 | Runtime runtime = Runtime.getRuntime(); |
54 | 66 | MAX_MEMORY = runtime.maxMemory(); |
55 | 67 | |
56 | - String classpath = getSecureProperty("java.class.path"); | |
57 | - String[] pathVec; | |
58 | - if(classpath != null){ | |
59 | - pathVec = classpath.split(File.pathSeparator); | |
60 | - }else{ | |
61 | - pathVec = new String[0]; | |
62 | - } | |
63 | - CLASSPATHS = pathVec; | |
68 | + ENVIRONMENT_MAP = buildEnvMap(); | |
69 | + | |
70 | + PROPERTY_MAP = buildPropMap(); | |
71 | + OS_NAME = PROPERTY_MAP.get("os.name"); | |
72 | + OS_VERSION = PROPERTY_MAP.get("os.version"); | |
73 | + OS_ARCH = PROPERTY_MAP.get("os.arch"); | |
74 | + JAVA_VENDOR = PROPERTY_MAP.get("java.vendor"); | |
75 | + JAVA_VERSION = PROPERTY_MAP.get("java.version"); | |
64 | 76 | |
77 | + String classpath = PROPERTY_MAP.get("java.class.path"); | |
78 | + CLASSPATHS = buildClassPathList(classpath); | |
65 | 79 | } |
66 | 80 | |
67 | 81 |
@@ -69,39 +83,78 @@ public final class EnvInfo{ | ||
69 | 83 | * 隠れコンストラクタ。 |
70 | 84 | */ |
71 | 85 | private EnvInfo(){ |
72 | - throw new AssertionError(); | |
86 | + assert false; | |
73 | 87 | } |
74 | 88 | |
75 | 89 | |
76 | 90 | /** |
77 | - * 可能ならシステムプロパティを読み込む。 | |
78 | - * @param key キー | |
79 | - * @return プロパティ値。セキュリティ上読み込み禁止の場合はnull。 | |
91 | + * 主要環境変数マップを作成する。 | |
92 | + * | |
93 | + * @return 主要環境変数マップ | |
80 | 94 | */ |
81 | - private static String getSecureProperty(String key){ | |
82 | - String result; | |
83 | - try{ | |
84 | - result = System.getProperty(key); | |
85 | - if(result != null) PROPERTY_MAP.put(key, result); | |
86 | - }catch(SecurityException e){ | |
87 | - result = null; | |
95 | + private static SortedMap<String, String> buildEnvMap(){ | |
96 | + SortedMap<String, String> envmap = new TreeMap<>(); | |
97 | + | |
98 | + for(String name : ENVNAMES){ | |
99 | + String val; | |
100 | + try{ | |
101 | + val = System.getenv(name); | |
102 | + }catch(SecurityException e){ | |
103 | + continue; | |
104 | + } | |
105 | + if(val == null) continue; | |
106 | + envmap.put(name, val); | |
88 | 107 | } |
108 | + | |
109 | + SortedMap<String, String> result; | |
110 | + result = Collections.unmodifiableSortedMap(envmap); | |
111 | + | |
89 | 112 | return result; |
90 | 113 | } |
91 | 114 | |
92 | 115 | /** |
93 | - * 可能なら環境変数を読み込む。 | |
94 | - * @param name 環境変数名 | |
95 | - * @return 環境変数値。セキュリティ上読み込み禁止の場合はnull。 | |
116 | + * 主要システムプロパティ値マップを作成する。 | |
117 | + * | |
118 | + * @return 主要システムプロパティ値マップ | |
96 | 119 | */ |
97 | - private static String getSecureEnvironment(String name){ | |
98 | - String result; | |
99 | - try{ | |
100 | - result = System.getenv(name); | |
101 | - if(result != null) ENVIRONMENT_MAP.put(name, result); | |
102 | - }catch(SecurityException e){ | |
103 | - result = null; | |
120 | + private static SortedMap<String, String> buildPropMap(){ | |
121 | + SortedMap<String, String> propmap = new TreeMap<>(); | |
122 | + | |
123 | + for(String name : PROPNAMES){ | |
124 | + String val; | |
125 | + try{ | |
126 | + val = System.getProperty(name); | |
127 | + }catch(SecurityException e){ | |
128 | + continue; | |
129 | + } | |
130 | + if(val == null) continue; | |
131 | + propmap.put(name, val); | |
104 | 132 | } |
133 | + | |
134 | + SortedMap<String, String> result; | |
135 | + result = Collections.unmodifiableSortedMap(propmap); | |
136 | + | |
137 | + return result; | |
138 | + } | |
139 | + | |
140 | + /** | |
141 | + * クラスパスリストを作成する。 | |
142 | + * | |
143 | + * @param classpath 連結クラスパス値 | |
144 | + * @return クラスパスリスト | |
145 | + */ | |
146 | + private static List<String> buildClassPathList(String classpath){ | |
147 | + String[] pathArray; | |
148 | + if(classpath != null){ | |
149 | + pathArray = classpath.split(File.pathSeparator); | |
150 | + }else{ | |
151 | + pathArray = new String[0]; | |
152 | + } | |
153 | + | |
154 | + List<String> result; | |
155 | + result = Arrays.asList(pathArray); | |
156 | + result = Collections.unmodifiableList(result); | |
157 | + | |
105 | 158 | return result; |
106 | 159 | } |
107 | 160 |
@@ -111,44 +164,74 @@ public final class EnvInfo{ | ||
111 | 164 | */ |
112 | 165 | public static String getVMInfo(){ |
113 | 166 | StringBuilder result = new StringBuilder(); |
114 | - NumberFormat nform = NumberFormat.getNumberInstance(); | |
115 | 167 | |
116 | - result.append("最大ヒープメモリ量: ") | |
117 | - .append(nform.format(MAX_MEMORY)) | |
118 | - .append(" bytes\n"); | |
168 | + String memform = MessageFormat.format(FORM_MEM, MAX_MEMORY); | |
169 | + result.append(memform).append(NL); | |
170 | + | |
171 | + result.append(getSysPropInfo()).append(NL); | |
172 | + result.append(getEnvInfo()).append(NL); | |
173 | + result.append(getClassPathInfo()).append(NL); | |
119 | 174 | |
120 | - result.append("\n"); | |
175 | + return result.toString(); | |
176 | + } | |
121 | 177 | |
178 | + /** | |
179 | + * システムプロパティ要覧を返す。 | |
180 | + * | |
181 | + * <p>java.class.pathの値は除く。 | |
182 | + * | |
183 | + * @return システムプロパティ要覧 | |
184 | + */ | |
185 | + private static CharSequence getSysPropInfo(){ | |
186 | + StringBuilder result = new StringBuilder(); | |
122 | 187 | result.append("主要システムプロパティ:\n"); |
123 | - Set<String> propKeys = PROPERTY_MAP.keySet(); | |
124 | - for(String propKey : propKeys){ | |
125 | - if(propKey.equals("java.class.path")) continue; | |
126 | - String value = PROPERTY_MAP.get(propKey); | |
127 | - result.append(" "); | |
128 | - result.append(propKey).append("=").append(value).append("\n"); | |
129 | - } | |
130 | 188 | |
131 | - result.append("\n"); | |
189 | + PROPERTY_MAP.entrySet().stream() | |
190 | + .filter(entry -> ! entry.getKey().equals("java.class.path")) | |
191 | + .forEachOrdered(entry -> { | |
192 | + result.append(INDENT); | |
193 | + result.append(entry.getKey()); | |
194 | + result.append('='); | |
195 | + result.append(entry.getValue()); | |
196 | + result.append(NL); | |
197 | + }); | |
132 | 198 | |
133 | - result.append("主要環境変数:\n"); | |
134 | - Set<String> envKeys = ENVIRONMENT_MAP.keySet(); | |
135 | - for(String envKey : envKeys){ | |
136 | - String value = ENVIRONMENT_MAP.get(envKey); | |
137 | - result.append(" "); | |
138 | - result.append(envKey).append("=").append(value).append("\n"); | |
139 | - } | |
199 | + return result; | |
200 | + } | |
140 | 201 | |
141 | - result.append("\n"); | |
202 | + /** | |
203 | + * 環境変数要覧を返す。 | |
204 | + * | |
205 | + * @return 環境変数要覧 | |
206 | + */ | |
207 | + private static CharSequence getEnvInfo(){ | |
208 | + StringBuilder result = new StringBuilder("主要環境変数:\n"); | |
209 | + | |
210 | + ENVIRONMENT_MAP.entrySet().stream() | |
211 | + .forEachOrdered(entry -> { | |
212 | + result.append(INDENT); | |
213 | + result.append(entry.getKey()); | |
214 | + result.append('='); | |
215 | + result.append(entry.getValue()); | |
216 | + result.append(NL); | |
217 | + }); | |
142 | 218 | |
143 | - result.append("クラスパス:\n"); | |
144 | - for(String path : CLASSPATHS){ | |
145 | - result.append(" "); | |
146 | - result.append(path).append("\n"); | |
147 | - } | |
219 | + return result; | |
220 | + } | |
148 | 221 | |
149 | - result.append("\n"); | |
222 | + /** | |
223 | + * クラスパス情報要覧を返す。 | |
224 | + * | |
225 | + * @return クラスパス情報要覧 | |
226 | + */ | |
227 | + private static CharSequence getClassPathInfo(){ | |
228 | + StringBuilder result = new StringBuilder("クラスパス:\n"); | |
150 | 229 | |
151 | - return result.toString(); | |
230 | + CLASSPATHS.stream().forEachOrdered(path -> { | |
231 | + result.append(INDENT).append(path).append(NL); | |
232 | + }); | |
233 | + | |
234 | + return result; | |
152 | 235 | } |
153 | 236 | |
154 | 237 | } |
@@ -11,6 +11,9 @@ import java.io.File; | ||
11 | 11 | import java.net.URI; |
12 | 12 | import java.net.URISyntaxException; |
13 | 13 | import java.net.URL; |
14 | +import java.nio.file.Files; | |
15 | +import java.nio.file.Path; | |
16 | +import java.nio.file.Paths; | |
14 | 17 | import java.security.CodeSource; |
15 | 18 | import java.security.ProtectionDomain; |
16 | 19 | import java.util.Locale; |
@@ -44,79 +47,6 @@ public final class FileUtils{ | ||
44 | 47 | |
45 | 48 | |
46 | 49 | /** |
47 | - * なるべく自分にだけ読み書き許可を与え | |
48 | - * 自分以外には読み書き許可を与えないように | |
49 | - * ファイル属性を操作する。 | |
50 | - * | |
51 | - * @param file 操作対象ファイル | |
52 | - * @return 成功すればtrue | |
53 | - * @throws SecurityException セキュリティ上の許可が無い場合 | |
54 | - */ | |
55 | - public static boolean setOwnerOnlyAccess(File file) | |
56 | - throws SecurityException{ | |
57 | - boolean result = true; | |
58 | - | |
59 | - result &= file.setReadable(false, false); | |
60 | - result &= file.setReadable(true, true); | |
61 | - | |
62 | - result &= file.setWritable(false, false); | |
63 | - result &= file.setWritable(true, true); | |
64 | - | |
65 | - return result; | |
66 | - } | |
67 | - | |
68 | - /** | |
69 | - * 任意の絶対パスの祖先の内、存在するもっとも近い祖先を返す。 | |
70 | - * | |
71 | - * @param file 任意の絶対パス | |
72 | - * @return 存在するもっとも近い祖先。一つも存在しなければnull。 | |
73 | - * @throws IllegalArgumentException 引数が絶対パスでない | |
74 | - */ | |
75 | - public static File findExistsAncestor(File file) | |
76 | - throws IllegalArgumentException{ | |
77 | - if(file == null) return null; | |
78 | - if( ! file.isAbsolute() ) throw new IllegalArgumentException(); | |
79 | - if(file.exists()) return file; | |
80 | - File parent = file.getParentFile(); | |
81 | - return findExistsAncestor(parent); | |
82 | - } | |
83 | - | |
84 | - /** | |
85 | - * 任意の絶対パスのルートファイルシステムもしくはドライブレターを返す。 | |
86 | - * | |
87 | - * @param file 任意の絶対パス | |
88 | - * @return ルートファイルシステムもしくはドライブレター | |
89 | - * @throws IllegalArgumentException 引数が絶対パスでない | |
90 | - */ | |
91 | - public static File findRootFile(File file) | |
92 | - throws IllegalArgumentException{ | |
93 | - if( ! file.isAbsolute() ) throw new IllegalArgumentException(); | |
94 | - File parent = file.getParentFile(); | |
95 | - if(parent == null) return file; | |
96 | - return findRootFile(parent); | |
97 | - } | |
98 | - | |
99 | - /** | |
100 | - * 相対パスの絶対パス化を試みる。 | |
101 | - * | |
102 | - * @param file 対象パス | |
103 | - * @return 絶対パス。絶対化に失敗した場合は元の引数。 | |
104 | - */ | |
105 | - public static File supplyFullPath(File file){ | |
106 | - if(file.isAbsolute()) return file; | |
107 | - | |
108 | - File absFile; | |
109 | - | |
110 | - try{ | |
111 | - absFile = file.getAbsoluteFile(); | |
112 | - }catch(SecurityException e){ | |
113 | - return file; | |
114 | - } | |
115 | - | |
116 | - return absFile; | |
117 | - } | |
118 | - | |
119 | - /** | |
120 | 50 | * 任意のディレクトリがアクセス可能な状態にあるか判定する。 |
121 | 51 | * |
122 | 52 | * <p>アクセス可能の条件を満たすためには、与えられたパスが |
@@ -131,39 +61,49 @@ public final class FileUtils{ | ||
131 | 61 | * @param path 任意のディレクトリ |
132 | 62 | * @return アクセス可能ならtrue |
133 | 63 | */ |
134 | - public static boolean isAccessibleDirectory(File path){ | |
64 | + public static boolean isAccessibleDirectory(Path path){ | |
135 | 65 | if(path == null) return false; |
136 | 66 | |
137 | - boolean result = true; | |
138 | - | |
139 | - if ( ! path.exists() ) result = false; | |
140 | - else if( ! path.isDirectory() ) result = false; | |
141 | - else if( ! path.canRead() ) result = false; | |
142 | - else if( ! path.canWrite() ) result = false; | |
67 | + boolean result = | |
68 | + Files.exists(path) | |
69 | + && Files.isDirectory(path) | |
70 | + && Files.isReadable(path) | |
71 | + && Files.isWritable(path); | |
143 | 72 | |
144 | 73 | return result; |
145 | 74 | } |
146 | 75 | |
147 | 76 | /** |
148 | - * クラスがローカルファイルからロードされたのであれば | |
149 | - * そのファイルを返す。 | |
77 | + * クラスのロード元のURLを返す。 | |
150 | 78 | * |
151 | - * @param klass 任意のクラス | |
152 | - * @return ロード元ファイル。見つからなければnull。 | |
79 | + * @param klass クラス | |
80 | + * @return ロード元URL。不明ならnull | |
153 | 81 | */ |
154 | - public static File getClassSourceFile(Class<?> klass){ | |
155 | - ProtectionDomain domain; | |
156 | - try{ | |
157 | - domain = klass.getProtectionDomain(); | |
158 | - }catch(SecurityException e){ | |
159 | - return null; | |
160 | - } | |
82 | + public static URL getClassSourceUrl(Class<?> klass){ | |
83 | + ProtectionDomain domain = klass.getProtectionDomain(); | |
84 | + if(domain == null) return null; | |
161 | 85 | |
162 | 86 | CodeSource src = domain.getCodeSource(); |
87 | + if(src == null) return null; | |
163 | 88 | |
164 | 89 | URL location = src.getLocation(); |
90 | + | |
91 | + return location; | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * クラスがローカルファイルからロードされたのであれば | |
96 | + * その絶対パスを返す。 | |
97 | + * | |
98 | + * @param klass 任意のクラス | |
99 | + * @return ロード元ファイルの絶対パス。見つからなければnull。 | |
100 | + */ | |
101 | + public static Path getClassSourcePath(Class<?> klass){ | |
102 | + URL location = getClassSourceUrl(klass); | |
103 | + if(location == null) return null; | |
104 | + | |
165 | 105 | String scheme = location.getProtocol(); |
166 | - if( ! scheme.equals(SCHEME_FILE) ) return null; | |
106 | + if( ! SCHEME_FILE.equalsIgnoreCase(scheme) ) return null; | |
167 | 107 | |
168 | 108 | URI uri; |
169 | 109 | try{ |
@@ -173,81 +113,68 @@ public final class FileUtils{ | ||
173 | 113 | return null; |
174 | 114 | } |
175 | 115 | |
176 | - File file = new File(uri); | |
116 | + Path result = Paths.get(uri); | |
117 | + result = result.toAbsolutePath(); | |
177 | 118 | |
178 | - return file; | |
119 | + return result; | |
179 | 120 | } |
180 | 121 | |
181 | 122 | /** |
182 | 123 | * すでに存在するJARファイルか判定する。 |
183 | 124 | * |
184 | - * @param file 任意のファイル | |
125 | + * <p>ファイルがすでに通常ファイルとしてローカルに存在し、 | |
126 | + * ファイル名の拡張子が「.jar」であれば真と判定される。 | |
127 | + * | |
128 | + * @param path 任意のファイル | |
185 | 129 | * @return すでに存在するJARファイルであればtrue |
186 | 130 | */ |
187 | - public static boolean isExistsJarFile(File file){ | |
188 | - if(file == null) return false; | |
189 | - if( ! file.exists() ) return false; | |
190 | - if( ! file.isFile() ) return false; | |
191 | - | |
192 | - String name = file.getName(); | |
193 | - if( ! name.matches("^.+\\.[jJ][aA][rR]$") ) return false; | |
131 | + public static boolean isExistsJarFile(Path path){ | |
132 | + if(path == null) return false; | |
133 | + if( ! Files.exists(path) ) return false; | |
134 | + if( ! Files.isRegularFile(path) ) return false; | |
194 | 135 | |
195 | - // TODO ファイル先頭マジックナンバーのテストも必要? | |
136 | + Path leaf = path.getFileName(); | |
137 | + assert leaf != null; | |
138 | + String leafName = leaf.toString(); | |
139 | + boolean result = leafName.matches("^.+\\.[jJ][aA][rR]$"); | |
196 | 140 | |
197 | - return true; | |
141 | + return result; | |
198 | 142 | } |
199 | 143 | |
200 | 144 | /** |
201 | 145 | * クラスがローカルJARファイルからロードされたのであれば |
202 | - * その格納ディレクトリを返す。 | |
146 | + * その格納ディレクトリの絶対パスを返す。 | |
203 | 147 | * |
204 | 148 | * @param klass 任意のクラス |
205 | - * @return ロード元JARファイルの格納ディレクトリ。 | |
149 | + * @return ロード元JARファイルの格納ディレクトリの絶対パス。 | |
206 | 150 | * JARが見つからない、もしくはロード元がJARファイルでなければnull。 |
207 | 151 | */ |
208 | - public static File getJarDirectory(Class<?> klass){ | |
209 | - File jarFile = getClassSourceFile(klass); | |
152 | + public static Path getJarDirectory(Class<?> klass){ | |
153 | + Path jarFile = getClassSourcePath(klass); | |
210 | 154 | if(jarFile == null) return null; |
211 | 155 | |
212 | 156 | if( ! isExistsJarFile(jarFile) ){ |
213 | 157 | return null; |
214 | 158 | } |
215 | 159 | |
216 | - return jarFile.getParentFile(); | |
160 | + Path result = jarFile.getParent(); | |
161 | + assert result.isAbsolute(); | |
162 | + | |
163 | + return result; | |
217 | 164 | } |
218 | 165 | |
219 | 166 | /** |
220 | 167 | * このクラスがローカルJARファイルからロードされたのであれば |
221 | - * その格納ディレクトリを返す。 | |
168 | + * その格納ディレクトリの絶対パスを返す。 | |
222 | 169 | * |
223 | - * @return ロード元JARファイルの格納ディレクトリ。 | |
170 | + * @return ロード元JARファイルの格納ディレクトリの絶対パス。 | |
224 | 171 | * JARが見つからない、もしくはロード元がJARファイルでなければnull。 |
225 | 172 | */ |
226 | - public static File getJarDirectory(){ | |
173 | + public static Path getJarDirectory(){ | |
227 | 174 | return getJarDirectory(THISKLASS); |
228 | 175 | } |
229 | 176 | |
230 | 177 | /** |
231 | - * ホームディレクトリを得る。 | |
232 | - * | |
233 | - * <p>システムプロパティuser.homeで示されたホームディレクトリを返す。 | |
234 | - * | |
235 | - * @return ホームディレクトリ。何らかの事情でnullを返す場合もあり。 | |
236 | - */ | |
237 | - public static File getHomeDirectory(){ | |
238 | - String homeProp; | |
239 | - try{ | |
240 | - homeProp = System.getProperty("user.home"); | |
241 | - }catch(SecurityException e){ | |
242 | - return null; | |
243 | - } | |
244 | - | |
245 | - File homeFile = new File(homeProp); | |
246 | - | |
247 | - return homeFile; | |
248 | - } | |
249 | - | |
250 | - /** | |
251 | 178 | * MacOSX環境か否か判定する。 |
252 | 179 | * |
253 | 180 | * @return MacOSX環境ならtrue |
@@ -255,22 +182,13 @@ public final class FileUtils{ | ||
255 | 182 | public static boolean isMacOSXFs(){ |
256 | 183 | if(File.separatorChar != '/') return false; |
257 | 184 | |
258 | - String osName; | |
259 | - try{ | |
260 | - osName = System.getProperty(SYSPROP_OSNAME); | |
261 | - }catch(SecurityException e){ | |
262 | - return false; | |
263 | - } | |
264 | - | |
185 | + String osName = System.getProperty(SYSPROP_OSNAME); | |
265 | 186 | if(osName == null) return false; |
266 | 187 | |
267 | 188 | osName = osName.toLowerCase(Locale.ROOT); |
268 | 189 | |
269 | - if(osName.startsWith("mac os x")){ | |
270 | - return true; | |
271 | - } | |
272 | - | |
273 | - return false; | |
190 | + boolean result = osName.startsWith("mac os x"); | |
191 | + return result; | |
274 | 192 | } |
275 | 193 | |
276 | 194 | /** |
@@ -281,48 +199,12 @@ public final class FileUtils{ | ||
281 | 199 | public static boolean isWindowsOSFs(){ |
282 | 200 | if(File.separatorChar != '\\') return false; |
283 | 201 | |
284 | - String osName; | |
285 | - try{ | |
286 | - osName = System.getProperty(SYSPROP_OSNAME); | |
287 | - }catch(SecurityException e){ | |
288 | - return false; | |
289 | - } | |
290 | - | |
202 | + String osName = System.getProperty(SYSPROP_OSNAME); | |
291 | 203 | if(osName == null) return false; |
292 | 204 | |
293 | 205 | osName = osName.toLowerCase(Locale.ROOT); |
294 | 206 | |
295 | - if(osName.startsWith("windows")){ | |
296 | - return true; | |
297 | - } | |
298 | - | |
299 | - return false; | |
300 | - } | |
301 | - | |
302 | - /** | |
303 | - * アプリケーション設定ディレクトリを返す。 | |
304 | - * | |
305 | - * <p>存在の有無、アクセスの可否は関知しない。 | |
306 | - * | |
307 | - * <p>WindowsやLinuxではホームディレクトリ。 | |
308 | - * Mac OS X ではさらにホームディレクトリの下の | |
309 | - * "Library/Application Support/" | |
310 | - * | |
311 | - * @return アプリケーション設定ディレクトリ | |
312 | - */ | |
313 | - public static File getAppSetDir(){ | |
314 | - File home = getHomeDirectory(); | |
315 | - if(home == null) return null; | |
316 | - | |
317 | - File result = home; | |
318 | - | |
319 | - if(isMacOSXFs()){ | |
320 | - result = new File(result, "Library"); | |
321 | - result = new File(result, "Application Support"); | |
322 | - } | |
323 | - | |
324 | - // TODO Win環境での%APPDATA%サポート | |
325 | - | |
207 | + boolean result = osName.startsWith("windows"); | |
326 | 208 | return result; |
327 | 209 | } |
328 | 210 |
@@ -331,11 +213,11 @@ public final class FileUtils{ | ||
331 | 213 | * |
332 | 214 | * <p>Windows日本語環境では、バックスラッシュ記号が円通貨記号に置換される。 |
333 | 215 | * |
334 | - * @param file 対象ファイル | |
216 | + * @param path 対象ファイル | |
335 | 217 | * @return HTML文字列断片 |
336 | 218 | */ |
337 | - public static String getHtmledFileName(File file){ | |
338 | - String pathName = file.getPath(); | |
219 | + public static String getHtmledFileName(Path path){ | |
220 | + String pathName = path.toString(); | |
339 | 221 | |
340 | 222 | Locale locale = Locale.getDefault(); |
341 | 223 | String lang = locale.getLanguage(); |
@@ -0,0 +1,339 @@ | ||
1 | +/* | |
2 | + * JSON I/O | |
3 | + * | |
4 | + * License : The MIT License | |
5 | + * Copyright(c) 2020 olyutorskii | |
6 | + */ | |
7 | + | |
8 | +package jp.sfjp.jindolf.config; | |
9 | + | |
10 | +import java.io.BufferedInputStream; | |
11 | +import java.io.BufferedOutputStream; | |
12 | +import java.io.BufferedReader; | |
13 | +import java.io.BufferedWriter; | |
14 | +import java.io.IOException; | |
15 | +import java.io.InputStream; | |
16 | +import java.io.InputStreamReader; | |
17 | +import java.io.OutputStream; | |
18 | +import java.io.OutputStreamWriter; | |
19 | +import java.io.Reader; | |
20 | +import java.io.Writer; | |
21 | +import java.nio.charset.Charset; | |
22 | +import java.nio.charset.StandardCharsets; | |
23 | +import java.nio.file.Files; | |
24 | +import java.nio.file.Path; | |
25 | +import java.nio.file.Paths; | |
26 | +import java.util.Objects; | |
27 | +import java.util.logging.Level; | |
28 | +import java.util.logging.Logger; | |
29 | +import jp.sourceforge.jovsonz.JsComposition; | |
30 | +import jp.sourceforge.jovsonz.JsObject; | |
31 | +import jp.sourceforge.jovsonz.JsParseException; | |
32 | +import jp.sourceforge.jovsonz.JsTypes; | |
33 | +import jp.sourceforge.jovsonz.JsVisitException; | |
34 | +import jp.sourceforge.jovsonz.Json; | |
35 | + | |
36 | +/** | |
37 | + * JSONファイルの入出力。 | |
38 | + */ | |
39 | +public class JsonIo { | |
40 | + | |
41 | + /** 検索履歴ファイル。 */ | |
42 | + public static final Path HIST_FILE = Paths.get("searchHistory.json"); | |
43 | + /** ネットワーク設定ファイル。 */ | |
44 | + public static final Path NETCONFIG_FILE = Paths.get("netconfig.json"); | |
45 | + /** 台詞表示設定ファイル。 */ | |
46 | + public static final Path TALKCONFIG_FILE = Paths.get("talkconfig.json"); | |
47 | + | |
48 | + /** ローカル画像設定ファイル。 */ | |
49 | + public static final Path LOCALIMGCONFIG_PATH = | |
50 | + Paths.get("avatarCache.json"); | |
51 | + | |
52 | + | |
53 | + private static final Charset CHARSET_JSON = StandardCharsets.UTF_8; | |
54 | + private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
55 | + | |
56 | + | |
57 | + private final ConfigStore configStore; | |
58 | + | |
59 | + | |
60 | + /** | |
61 | + * Constructor. | |
62 | + * | |
63 | + * @param configStore 設定ディレクトリ | |
64 | + */ | |
65 | + public JsonIo(ConfigStore configStore){ | |
66 | + super(); | |
67 | + Objects.nonNull(configStore); | |
68 | + this.configStore = configStore; | |
69 | + return; | |
70 | + } | |
71 | + | |
72 | + | |
73 | + /** | |
74 | + * 設定ディレクトリ上のOBJECT型JSONファイルを読み込む。 | |
75 | + * | |
76 | + * @param file JSONファイルの相対パス。 | |
77 | + * @return JSON object。 | |
78 | + * 設定ディレクトリを使わない設定、 | |
79 | + * もしくはJSONファイルが存在しない、 | |
80 | + * もしくはOBJECT型でなかった、 | |
81 | + * もしくは入力エラーがあればnull | |
82 | + */ | |
83 | + public JsObject loadJsObject(Path file){ | |
84 | + if( ! this.configStore.useStoreFile()){ | |
85 | + return null; | |
86 | + } | |
87 | + | |
88 | + JsComposition<?> root = loadJson(file); | |
89 | + if(root == null || root.getJsTypes() != JsTypes.OBJECT) return null; | |
90 | + JsObject result = (JsObject) root; | |
91 | + return result; | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * 設定ディレクトリ上のJSONファイルを読み込む。 | |
96 | + * | |
97 | + * @param file JSONファイルの相対パス | |
98 | + * @return JSON objectまたはarray。 | |
99 | + * 設定ディレクトリを使わない設定、 | |
100 | + * もしくはJSONファイルが存在しない、 | |
101 | + * もしくは入力エラーがあればnull | |
102 | + */ | |
103 | + protected JsComposition<?> loadJson(Path file){ | |
104 | + Path absFile; | |
105 | + if(file.isAbsolute()){ | |
106 | + absFile = file; | |
107 | + }else{ | |
108 | + Path configDir = this.configStore.getConfigDir(); | |
109 | + if(configDir == null) return null; | |
110 | + absFile = configDir.resolve(file); | |
111 | + if( ! Files.exists(absFile) ) return null; | |
112 | + if( ! absFile.isAbsolute() ) return null; | |
113 | + } | |
114 | + String absPath = absFile.toString(); | |
115 | + | |
116 | + JsComposition<?> root; | |
117 | + try(InputStream is = Files.newInputStream(absFile)){ | |
118 | + InputStream bis = new BufferedInputStream(is); | |
119 | + root = loadJson(bis); | |
120 | + }catch(IOException e){ | |
121 | + LOGGER.log(Level.SEVERE, | |
122 | + "JSONファイル[" | |
123 | + + absPath | |
124 | + + "]の読み込み時に支障がありました。", e); | |
125 | + return null; | |
126 | + }catch(JsParseException e){ | |
127 | + LOGGER.log(Level.SEVERE, | |
128 | + "JSONファイル[" | |
129 | + + absPath | |
130 | + + "]の内容に不備があります。", e); | |
131 | + return null; | |
132 | + } | |
133 | + | |
134 | + return root; | |
135 | + } | |
136 | + | |
137 | + /** | |
138 | + * バイトストリーム上のJSONデータを読み込む。 | |
139 | + * | |
140 | + * <p>バイトストリームはUTF-8と解釈される。 | |
141 | + * | |
142 | + * @param is バイトストリーム | |
143 | + * @return JSON objectまたはarray。 | |
144 | + * @throws IOException 入力エラー | |
145 | + * @throws JsParseException 構文エラー | |
146 | + */ | |
147 | + protected JsComposition<?> loadJson(InputStream is) | |
148 | + throws IOException, JsParseException { | |
149 | + Reader reader = new InputStreamReader(is, CHARSET_JSON); | |
150 | + reader = new BufferedReader(reader); | |
151 | + JsComposition<?> root = loadJson(reader); | |
152 | + return root; | |
153 | + } | |
154 | + | |
155 | + /** | |
156 | + * 文字ストリーム上のJSONデータを読み込む。 | |
157 | + * | |
158 | + * @param reader 文字ストリーム | |
159 | + * @return JSON objectまたはarray。 | |
160 | + * @throws IOException 入力エラー | |
161 | + * @throws JsParseException 構文エラー | |
162 | + */ | |
163 | + protected JsComposition<?> loadJson(Reader reader) | |
164 | + throws IOException, JsParseException { | |
165 | + JsComposition<?> root = Json.parseJson(reader); | |
166 | + return root; | |
167 | + } | |
168 | + | |
169 | + /** | |
170 | + * 設定ディレクトリ上のJSONファイルに書き込む。 | |
171 | + * | |
172 | + * @param file JSONファイルの相対パス | |
173 | + * @param root JSON objectまたはarray | |
174 | + * @return 正しくセーブが行われればtrue。 | |
175 | + * 何らかの理由でセーブが完了できなければfalse | |
176 | + */ | |
177 | + public boolean saveJson(Path file, JsComposition<?> root){ | |
178 | + if( ! this.configStore.useStoreFile()){ | |
179 | + return false; | |
180 | + } | |
181 | + | |
182 | + // TODO テンポラリファイルを用いたより安全なファイル更新 | |
183 | + Path configDir = this.configStore.getConfigDir(); | |
184 | + Path absFile = configDir.resolve(file); | |
185 | + String absPath = absFile.toString(); | |
186 | + | |
187 | + try{ | |
188 | + Files.deleteIfExists(absFile); | |
189 | + }catch(IOException e){ | |
190 | + // NOTHING | |
191 | + assert true; | |
192 | + } | |
193 | + | |
194 | + try{ | |
195 | + Files.createFile(absFile); | |
196 | + }catch(IOException e){ | |
197 | + LOGGER.log(Level.SEVERE, | |
198 | + "JSONファイル[" | |
199 | + + absPath | |
200 | + + "]の新規生成ができません。", e); | |
201 | + return false; | |
202 | + } | |
203 | + | |
204 | + try(OutputStream os = Files.newOutputStream(absFile)){ | |
205 | + OutputStream bos = new BufferedOutputStream(os); | |
206 | + saveJson(bos, root); | |
207 | + }catch(IOException e){ | |
208 | + LOGGER.log(Level.SEVERE, | |
209 | + "JSONファイル[" | |
210 | + + absPath | |
211 | + + "]の書き込み時に支障がありました。", e); | |
212 | + return false; | |
213 | + }catch(JsVisitException e){ | |
214 | + LOGGER.log(Level.SEVERE, | |
215 | + "JSONファイル[" | |
216 | + + absPath | |
217 | + + "]の出力処理で支障がありました。", e); | |
218 | + return false; | |
219 | + } | |
220 | + | |
221 | + return true; | |
222 | + } | |
223 | + | |
224 | + /** | |
225 | + * バイトストリームにJSONデータを書き込む。 | |
226 | + * | |
227 | + * <p>バイトストリームはUTF-8と解釈される。 | |
228 | + * | |
229 | + * @param os バイトストリーム出力 | |
230 | + * @param root JSON objectまたはarray | |
231 | + * @throws IOException 出力エラー | |
232 | + * @throws JsVisitException 構造エラー | |
233 | + */ | |
234 | + protected void saveJson(OutputStream os, JsComposition<?> root) | |
235 | + throws IOException, JsVisitException { | |
236 | + Writer writer = new OutputStreamWriter(os, CHARSET_JSON); | |
237 | + writer = new BufferedWriter(writer); | |
238 | + saveJson(writer, root); | |
239 | + return; | |
240 | + } | |
241 | + | |
242 | + /** | |
243 | + * 文字ストリームにJSONデータを書き込む。 | |
244 | + * | |
245 | + * @param writer 文字ストリーム出力 | |
246 | + * @param root JSON objectまたはarray | |
247 | + * @throws IOException 出力エラー | |
248 | + * @throws JsVisitException 構造エラー | |
249 | + */ | |
250 | + protected void saveJson(Writer writer, JsComposition<?> root) | |
251 | + throws IOException, JsVisitException { | |
252 | + Json.dumpJson(writer, root); | |
253 | + return; | |
254 | + } | |
255 | + | |
256 | + /** | |
257 | + * 検索履歴ファイルを読み込む。 | |
258 | + * | |
259 | + * @return 履歴データ。履歴を読まないもしくは読めない場合はnull | |
260 | + */ | |
261 | + public JsObject loadHistoryConfig(){ | |
262 | + JsObject result = loadJsObject(HIST_FILE); | |
263 | + return result; | |
264 | + } | |
265 | + | |
266 | + /** | |
267 | + * ネットワーク設定ファイルを読み込む。 | |
268 | + * | |
269 | + * @return ネットワーク設定データ。 | |
270 | + * 設定を読まないもしくは読めない場合はnull | |
271 | + */ | |
272 | + public JsObject loadNetConfig(){ | |
273 | + JsObject result = loadJsObject(NETCONFIG_FILE); | |
274 | + return result; | |
275 | + } | |
276 | + | |
277 | + /** | |
278 | + * 台詞表示設定ファイルを読み込む。 | |
279 | + * | |
280 | + * @return 台詞表示設定データ。 | |
281 | + * 設定を読まないもしくは読めない場合はnull | |
282 | + */ | |
283 | + public JsObject loadTalkConfig(){ | |
284 | + JsObject result = loadJsObject(TALKCONFIG_FILE); | |
285 | + return result; | |
286 | + } | |
287 | + | |
288 | + /** | |
289 | + * ローカル画像設定ファイルを読み込む。 | |
290 | + * | |
291 | + * @return ローカル画像設定データ。 | |
292 | + * 設定を読まないもしくは読めない場合はnull | |
293 | + */ | |
294 | + public JsObject loadLocalImgConfig(){ | |
295 | + if( ! this.configStore.useStoreFile()){ | |
296 | + return null; | |
297 | + } | |
298 | + | |
299 | + Path imgDir = this.configStore.getLocalImgDir(); | |
300 | + Path path = imgDir.resolve(LOCALIMGCONFIG_PATH); | |
301 | + JsObject result = loadJsObject(path); | |
302 | + | |
303 | + return result; | |
304 | + } | |
305 | + | |
306 | + /** | |
307 | + * 検索履歴ファイルに書き込む。 | |
308 | + * | |
309 | + * @param root 履歴データ | |
310 | + * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
311 | + */ | |
312 | + public boolean saveHistoryConfig(JsComposition<?> root){ | |
313 | + boolean result = saveJson(HIST_FILE, root); | |
314 | + return result; | |
315 | + } | |
316 | + | |
317 | + /** | |
318 | + * ネットワーク設定ファイルに書き込む。 | |
319 | + * | |
320 | + * @param root ネットワーク設定 | |
321 | + * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
322 | + */ | |
323 | + public boolean saveNetConfig(JsComposition<?> root){ | |
324 | + boolean result = saveJson(NETCONFIG_FILE, root); | |
325 | + return result; | |
326 | + } | |
327 | + | |
328 | + /** | |
329 | + * 台詞表示設定ファイルに書き込む。 | |
330 | + * | |
331 | + * @param root 台詞表示設定 | |
332 | + * @return 書き込まなかったもしくは書き込めなかった場合はfalse | |
333 | + */ | |
334 | + public boolean saveTalkConfig(JsComposition<?> root){ | |
335 | + boolean result = saveJson(TALKCONFIG_FILE, root); | |
336 | + return result; | |
337 | + } | |
338 | + | |
339 | +} |
@@ -24,6 +24,10 @@ import java.util.regex.Pattern; | ||
24 | 24 | */ |
25 | 25 | public class OptionInfo{ |
26 | 26 | |
27 | + /* | |
28 | + ex) 1000x800 | |
29 | + ex) 1290x1024-256+128 | |
30 | + */ | |
27 | 31 | private static final String REGEX_DIMNO = |
28 | 32 | "([1-9][0-9]{0,5})"; |
29 | 33 | private static final String REGEX_SIGN = |
@@ -96,9 +100,9 @@ public class OptionInfo{ | ||
96 | 100 | * @throws IllegalArgumentException 引数の構文エラー |
97 | 101 | */ |
98 | 102 | private static void parseBooleanSwitch(OptionInfo info, |
99 | - CmdOption option, | |
100 | - String optTxt, | |
101 | - String onoff ) | |
103 | + CmdOption option, | |
104 | + String optTxt, | |
105 | + String onoff ) | |
102 | 106 | throws IllegalArgumentException{ |
103 | 107 | Boolean flag; |
104 | 108 |
@@ -128,8 +132,8 @@ public class OptionInfo{ | ||
128 | 132 | * @throws IllegalArgumentException 引数の構文エラー |
129 | 133 | */ |
130 | 134 | private static void parseGeometry(OptionInfo info, |
131 | - String optTxt, | |
132 | - String geometry ) | |
135 | + String optTxt, | |
136 | + String geometry ) | |
133 | 137 | throws IllegalArgumentException{ |
134 | 138 | Matcher matcher = PATTERN_GEOMETRY.matcher(geometry); |
135 | 139 | if( ! matcher.matches() ){ |
@@ -176,18 +180,17 @@ public class OptionInfo{ | ||
176 | 180 | * @throws IllegalArgumentException オプションの引数がない |
177 | 181 | */ |
178 | 182 | private static void parseOptionArg(OptionInfo info, |
179 | - String optTxt, | |
180 | - CmdOption option, | |
181 | - Iterator<String> iterator ) | |
183 | + String optTxt, | |
184 | + CmdOption option, | |
185 | + Iterator<String> iterator ) | |
182 | 186 | throws IllegalArgumentException { |
183 | - String nextArg; | |
184 | - if(iterator.hasNext()){ | |
185 | - nextArg = iterator.next(); | |
186 | - }else{ | |
187 | + if( ! iterator.hasNext()){ | |
187 | 188 | String errMsg = MessageFormat.format(ERRFORM_NOARG, optTxt); |
188 | 189 | throw new IllegalArgumentException(errMsg); |
189 | 190 | } |
190 | 191 | |
192 | + String nextArg = iterator.next(); | |
193 | + | |
191 | 194 | if(option == CmdOption.OPT_GEOMETRY){ |
192 | 195 | parseGeometry(info, optTxt, nextArg); |
193 | 196 | }else if(option.isBooleanOption()){ |
@@ -254,8 +257,8 @@ public class OptionInfo{ | ||
254 | 257 | * @return 指定されていたらtrue |
255 | 258 | */ |
256 | 259 | public boolean hasOption(CmdOption option){ |
257 | - if(this.optionList.contains(option)) return true; | |
258 | - return false; | |
260 | + boolean result = this.optionList.contains(option); | |
261 | + return result; | |
259 | 262 | } |
260 | 263 | |
261 | 264 | /** |
@@ -12,8 +12,8 @@ import java.io.IOException; | ||
12 | 12 | import java.net.MalformedURLException; |
13 | 13 | import java.net.URI; |
14 | 14 | import java.net.URL; |
15 | +import java.util.ArrayList; | |
15 | 16 | import java.util.Collections; |
16 | -import java.util.LinkedList; | |
17 | 17 | import java.util.List; |
18 | 18 | import java.util.logging.Level; |
19 | 19 | import java.util.logging.Logger; |
@@ -22,6 +22,8 @@ import jp.sourceforge.jindolf.corelib.LandDef; | ||
22 | 22 | |
23 | 23 | /** |
24 | 24 | * いわゆる「国」。 |
25 | + * | |
26 | + * 人狼BBSのサーバと1:1の概念。 | |
25 | 27 | */ |
26 | 28 | public class Land { |
27 | 29 |
@@ -31,11 +33,12 @@ public class Land { | ||
31 | 33 | private final LandDef landDef; |
32 | 34 | private final ServerAccess serverAccess; |
33 | 35 | |
34 | - private final List<Village> villageList = new LinkedList<>(); | |
36 | + private final List<Village> villageList = new ArrayList<>(1000); | |
35 | 37 | |
36 | 38 | |
37 | 39 | /** |
38 | 40 | * コンストラクタ。 |
41 | + * | |
39 | 42 | * @param landDef 国定義 |
40 | 43 | * @throws java.lang.IllegalArgumentException 不正な国定義 |
41 | 44 | */ |
@@ -58,6 +61,7 @@ public class Land { | ||
58 | 61 | |
59 | 62 | /** |
60 | 63 | * 国定義を得る。 |
64 | + * | |
61 | 65 | * @return 国定義 |
62 | 66 | */ |
63 | 67 | public LandDef getLandDef(){ |
@@ -66,6 +70,7 @@ public class Land { | ||
66 | 70 | |
67 | 71 | /** |
68 | 72 | * サーバ接続を返す。 |
73 | + * | |
69 | 74 | * @return ServerAccessインスタンス |
70 | 75 | */ |
71 | 76 | public ServerAccess getServerAccess(){ |
@@ -74,6 +79,7 @@ public class Land { | ||
74 | 79 | |
75 | 80 | /** |
76 | 81 | * 指定されたインデックス位置の村を返す。 |
82 | + * | |
77 | 83 | * @param index 0から始まるインデックス値 |
78 | 84 | * @return 村 |
79 | 85 | */ |
@@ -87,6 +93,7 @@ public class Land { | ||
87 | 93 | |
88 | 94 | /** |
89 | 95 | * 村の総数を返す。 |
96 | + * | |
90 | 97 | * @return 村の総数 |
91 | 98 | */ |
92 | 99 | public int getVillageCount(){ |
@@ -96,6 +103,7 @@ public class Land { | ||
96 | 103 | |
97 | 104 | /** |
98 | 105 | * 村のリストを返す。 |
106 | + * | |
99 | 107 | * @return 村のリスト |
100 | 108 | */ |
101 | 109 | // TODO インスタンス変数でいいはず。 |
@@ -105,7 +113,9 @@ public class Land { | ||
105 | 113 | |
106 | 114 | /** |
107 | 115 | * 絶対または相対URLの指すパーマネントなイメージ画像をダウンロードする。 |
108 | - * ※ A,B,D 国の顔アイコンは絶対パスらしい…。 | |
116 | + * | |
117 | + * <p>※ A,B,D 国の顔アイコンは絶対パスらしい…。 | |
118 | + * | |
109 | 119 | * @param imageURL 画像URL文字列 |
110 | 120 | * @return 画像イメージ |
111 | 121 | */ |
@@ -126,6 +136,7 @@ public class Land { | ||
126 | 136 | |
127 | 137 | /** |
128 | 138 | * 墓アイコンイメージを取得する。 |
139 | + * | |
129 | 140 | * @return 墓アイコンイメージ |
130 | 141 | */ |
131 | 142 | public BufferedImage getGraveIconImage(){ |
@@ -136,6 +147,7 @@ public class Land { | ||
136 | 147 | |
137 | 148 | /** |
138 | 149 | * 墓アイコンイメージ(大)を取得する。 |
150 | + * | |
139 | 151 | * @return 墓アイコンイメージ(大) |
140 | 152 | */ |
141 | 153 | public BufferedImage getGraveBodyImage(){ |
@@ -146,6 +158,7 @@ public class Land { | ||
146 | 158 | |
147 | 159 | /** |
148 | 160 | * 村リストを更新する。 |
161 | + * | |
149 | 162 | * @param vset ソート済みの村一覧 |
150 | 163 | */ |
151 | 164 | public void updateVillageList(List<Village> vset){ |
@@ -157,6 +170,7 @@ public class Land { | ||
157 | 170 | |
158 | 171 | /** |
159 | 172 | * 国の文字列表現を返す。 |
173 | + * | |
160 | 174 | * @return 文字列表現 |
161 | 175 | */ |
162 | 176 | @Override |
@@ -7,12 +7,13 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.jindolf.data; |
9 | 9 | |
10 | +import java.text.MessageFormat; | |
11 | +import java.util.ArrayList; | |
10 | 12 | import java.util.Collections; |
11 | 13 | import java.util.HashMap; |
12 | -import java.util.LinkedList; | |
13 | 14 | import java.util.List; |
14 | 15 | import java.util.Map; |
15 | -import java.util.logging.Logger; | |
16 | +import java.util.Objects; | |
16 | 17 | import javax.swing.event.EventListenerList; |
17 | 18 | import javax.swing.event.TreeModelEvent; |
18 | 19 | import javax.swing.event.TreeModelListener; |
@@ -21,101 +22,161 @@ import javax.swing.tree.TreePath; | ||
21 | 22 | import jp.sourceforge.jindolf.corelib.LandDef; |
22 | 23 | |
23 | 24 | /** |
24 | - * 国の集合。あらゆるデータモデルの大元。 | |
25 | - * 国一覧と村一覧を管理。 | |
26 | - * JTreeのモデルも兼用。 | |
25 | + * {@link javax.swing.JTree}のモデルとして国一覧と村一覧を管理。 | |
26 | + * | |
27 | + * <p>ツリー階層は ROOT - 国 - 範囲セクション - 村 の4階層。 | |
28 | + * | |
29 | + * <p>昇順/降順の切り替えをサポート。 | |
27 | 30 | */ |
28 | -public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付けるか? | |
31 | +public class LandsTreeModel implements TreeModel{ | |
29 | 32 | |
30 | - private static final String ROOT = "ROOT"; | |
33 | + private static final Object ROOT = new Object(); | |
31 | 34 | private static final int SECTION_INTERVAL = 100; |
32 | 35 | |
33 | - private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
34 | - | |
35 | 36 | |
36 | - private final List<Land> landList = new LinkedList<>(); | |
37 | - private final List<Land> unmodList = | |
38 | - Collections.unmodifiableList(this.landList); | |
39 | - private final Map<Land, List<VillageSection>> sectionMap = | |
40 | - new HashMap<>(); | |
41 | - private boolean isLandListLoaded = false; | |
37 | + private final EventListenerList listeners; | |
42 | 38 | |
43 | - private final EventListenerList listeners = new EventListenerList(); | |
39 | + private final List<Land> landList; | |
40 | + private final Map<Land, List<VillageSection> > sectionMap; | |
44 | 41 | |
45 | 42 | private boolean ascending = false; |
46 | 43 | |
44 | + | |
47 | 45 | /** |
48 | 46 | * コンストラクタ。 |
49 | - * この時点ではまだ国一覧が読み込まれない。 | |
50 | 47 | */ |
51 | 48 | public LandsTreeModel(){ |
52 | 49 | super(); |
50 | + | |
51 | + this.listeners = new EventListenerList(); | |
52 | + | |
53 | + this.landList = buildLandList(); | |
54 | + this.sectionMap = new HashMap<>(); | |
55 | + | |
53 | 56 | return; |
54 | 57 | } |
55 | 58 | |
59 | + | |
56 | 60 | /** |
57 | - * 指定した国の村一覧を更新しイベントを投げる。 | |
58 | - * @param land 国 | |
61 | + * ツリーのルートオブジェクトか否か判定する。 | |
62 | + * | |
63 | + * @param obj オブジェクト | |
64 | + * @return ルートならtrue | |
59 | 65 | */ |
60 | - public void updateVillageList(Land land){ | |
61 | - List<VillageSection> sectionList = | |
62 | - VillageSection.getSectionList(land, SECTION_INTERVAL); | |
63 | - this.sectionMap.put(land, sectionList); | |
66 | + private static boolean isRoot(Object obj){ | |
67 | + boolean result = Objects.equals(ROOT, obj); | |
68 | + return result; | |
69 | + } | |
64 | 70 | |
65 | - int[] childIndices = new int[sectionList.size()]; | |
66 | - for(int ct = 0; ct < childIndices.length; ct++){ | |
67 | - childIndices[ct] = ct; | |
68 | - } | |
69 | - Object[] children = sectionList.toArray(); | |
71 | + /** | |
72 | + * 国一覧を読み込む。 | |
73 | + * | |
74 | + * <p>村一覧はまだ読み込まれない。 | |
75 | + * | |
76 | + * @return 国リスト | |
77 | + */ | |
78 | + private static List<Land> buildLandList(){ | |
79 | + List<LandDef> landDefList = CoreData.getLandDefList(); | |
80 | + List<Land> newList = new ArrayList<>(landDefList.size()); | |
70 | 81 | |
71 | - Object[] path = {ROOT, land}; | |
72 | - TreePath treePath = new TreePath(path); | |
73 | - TreeModelEvent event = new TreeModelEvent(this, | |
74 | - treePath, | |
75 | - childIndices, | |
76 | - children ); | |
77 | - fireTreeStructureChanged(event); | |
82 | + landDefList.stream().map(landDef -> | |
83 | + new Land(landDef) | |
84 | + ).forEachOrdered(land -> { | |
85 | + newList.add(land); | |
86 | + }); | |
78 | 87 | |
79 | - return; | |
88 | + return Collections.unmodifiableList(newList); | |
80 | 89 | } |
81 | 90 | |
82 | 91 | /** |
83 | - * 国一覧を読み込む。 | |
92 | + * 与えられた国の全ての村を指定されたinterval間隔で格納するために、 | |
93 | + * 範囲セクションのリストを生成する。 | |
94 | + * | |
95 | + * @param land 国 | |
96 | + * @param interval 範囲セクション間の村ID間隔 | |
97 | + * @return 範囲セクションのリスト | |
98 | + * @throws java.lang.IllegalArgumentException intervalが正でない | |
84 | 99 | */ |
85 | - // TODO static にできない? | |
86 | - public void loadLandList(){ | |
87 | - if(this.isLandListLoaded) return; | |
100 | + private static List<VillageSection> getSectionList(Land land, | |
101 | + int interval ) | |
102 | + throws IllegalArgumentException{ | |
103 | + if(interval <= 0){ | |
104 | + throw new IllegalArgumentException(); | |
105 | + } | |
88 | 106 | |
89 | - this.landList.clear(); | |
107 | + String pfx = land.getLandDef().getLandPrefix(); | |
108 | + List<Village> span = new ArrayList<>(interval); | |
90 | 109 | |
91 | - List<LandDef> landDefList = CoreData.getLandDefList(); | |
92 | - landDefList.stream().map((landDef) -> | |
93 | - new Land(landDef) | |
94 | - ).forEachOrdered((land) -> { | |
95 | - this.landList.add(land); | |
96 | - }); | |
110 | + List<VillageSection> result = new ArrayList<>(2500 / interval); | |
97 | 111 | |
98 | - this.isLandListLoaded = true; | |
112 | + boolean loop1st = true; | |
113 | + int rangeStart = -1; | |
114 | + int rangeEnd = -1; | |
99 | 115 | |
100 | - fireLandListChanged(); | |
116 | + for(Village village : land.getVillageList()){ | |
117 | + int vid = village.getVillageIDNum(); | |
101 | 118 | |
102 | - return; | |
119 | + if(loop1st){ | |
120 | + rangeStart = vid / interval * interval; | |
121 | + rangeEnd = rangeStart + interval - 1; | |
122 | + loop1st = false; | |
123 | + } | |
124 | + | |
125 | + if(rangeEnd < vid){ | |
126 | + VillageSection section = new VillageSection( | |
127 | + pfx, rangeStart, rangeEnd, span); | |
128 | + span.clear(); | |
129 | + result.add(section); | |
130 | + | |
131 | + rangeStart = vid / interval * interval; | |
132 | + rangeEnd = rangeStart + interval - 1; | |
133 | + } | |
134 | + | |
135 | + span.add(village); | |
136 | + } | |
137 | + | |
138 | + if( ! span.isEmpty()){ | |
139 | + VillageSection section = new VillageSection( | |
140 | + pfx, rangeStart, rangeEnd, span); | |
141 | + span.clear(); | |
142 | + result.add(section); | |
143 | + } | |
144 | + | |
145 | + return result; | |
103 | 146 | } |
104 | 147 | |
148 | + | |
105 | 149 | /** |
106 | - * ツリー内容が更新された事をリスナーに通知する。 | |
150 | + * 国リストを得る。 | |
151 | + * | |
152 | + * @return 国のリスト | |
107 | 153 | */ |
108 | - private void fireLandListChanged(){ | |
109 | - int size = this.landList.size(); | |
110 | - int[] childIndices = new int[size]; | |
111 | - for(int ct = 0; ct < size; ct++){ | |
112 | - int index = ct; | |
113 | - childIndices[ct] = index; | |
114 | - } | |
154 | + public List<Land> getLandList(){ | |
155 | + return this.landList; | |
156 | + } | |
115 | 157 | |
116 | - Object[] children = this.landList.toArray(); | |
158 | + /** | |
159 | + * 指定した国の村一覧でツリーリストを更新し、 | |
160 | + * 更新イベントをリスナに投げる。 | |
161 | + * | |
162 | + * <p>2020-04現在、もはや村一覧が増減することはない。 | |
163 | + * | |
164 | + * @param land 国 | |
165 | + */ | |
166 | + public void updateVillageList(Land land){ | |
167 | + List<VillageSection> sectionList = | |
168 | + getSectionList(land, SECTION_INTERVAL); | |
169 | + this.sectionMap.put(land, sectionList); | |
170 | + | |
171 | + int[] childIndices = new int[sectionList.size()]; | |
172 | + for(int ct = 0; ct < childIndices.length; ct++){ | |
173 | + childIndices[ct] = ct; | |
174 | + } | |
175 | + Object[] children = sectionList.toArray(); | |
117 | 176 | |
118 | 177 | TreePath treePath = new TreePath(ROOT); |
178 | + treePath = treePath.pathByAddingChild(land); | |
179 | + | |
119 | 180 | TreeModelEvent event = new TreeModelEvent(this, |
120 | 181 | treePath, |
121 | 182 | childIndices, |
@@ -127,7 +188,9 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
127 | 188 | |
128 | 189 | /** |
129 | 190 | * ツリーの並び順を設定する。 |
130 | - * 場合によってはTreeModelEventが発生する。 | |
191 | + * | |
192 | + * <p>場合によってはTreeModelEventが発生する。 | |
193 | + * | |
131 | 194 | * @param ascending trueなら昇順 |
132 | 195 | */ |
133 | 196 | public void setAscending(boolean ascending){ |
@@ -141,26 +204,29 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
141 | 204 | |
142 | 205 | /** |
143 | 206 | * {@inheritDoc} |
144 | - * @param l {@inheritDoc} | |
207 | + * | |
208 | + * @param lst {@inheritDoc} | |
145 | 209 | */ |
146 | 210 | @Override |
147 | - public void addTreeModelListener(TreeModelListener l){ | |
148 | - this.listeners.add(TreeModelListener.class, l); | |
211 | + public void addTreeModelListener(TreeModelListener lst){ | |
212 | + this.listeners.add(TreeModelListener.class, lst); | |
149 | 213 | return; |
150 | 214 | } |
151 | 215 | |
152 | 216 | /** |
153 | 217 | * {@inheritDoc} |
154 | - * @param l {@inheritDoc} | |
218 | + * | |
219 | + * @param lst {@inheritDoc} | |
155 | 220 | */ |
156 | 221 | @Override |
157 | - public void removeTreeModelListener(TreeModelListener l){ | |
158 | - this.listeners.remove(TreeModelListener.class, l); | |
222 | + public void removeTreeModelListener(TreeModelListener lst){ | |
223 | + this.listeners.remove(TreeModelListener.class, lst); | |
159 | 224 | return; |
160 | 225 | } |
161 | 226 | |
162 | 227 | /** |
163 | 228 | * 登録中のリスナーのリストを得る。 |
229 | + * | |
164 | 230 | * @return リスナーのリスト |
165 | 231 | */ |
166 | 232 | private TreeModelListener[] getTreeModelListeners(){ |
@@ -169,6 +235,7 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
169 | 235 | |
170 | 236 | /** |
171 | 237 | * 全リスナーにイベントを送出する。 |
238 | + * | |
172 | 239 | * @param event ツリーイベント |
173 | 240 | */ |
174 | 241 | protected void fireTreeStructureChanged(TreeModelEvent event){ |
@@ -179,15 +246,31 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
179 | 246 | } |
180 | 247 | |
181 | 248 | /** |
182 | - * 国リストを得る。 | |
183 | - * @return 国のリスト | |
249 | + * ツリー内容の国一覧が更新された事をリスナーに通知する。 | |
184 | 250 | */ |
185 | - public List<Land> getLandList(){ | |
186 | - return this.unmodList; | |
251 | + private void fireLandListChanged(){ | |
252 | + int size = getLandList().size(); | |
253 | + int[] childIndices = new int[size]; | |
254 | + for(int ct = 0; ct < size; ct++){ | |
255 | + int index = ct; | |
256 | + childIndices[ct] = index; | |
257 | + } | |
258 | + | |
259 | + Object[] children = getLandList().toArray(); | |
260 | + | |
261 | + TreePath treePath = new TreePath(ROOT); | |
262 | + TreeModelEvent event = new TreeModelEvent(this, | |
263 | + treePath, | |
264 | + childIndices, | |
265 | + children ); | |
266 | + fireTreeStructureChanged(event); | |
267 | + | |
268 | + return; | |
187 | 269 | } |
188 | 270 | |
189 | 271 | /** |
190 | 272 | * {@inheritDoc} |
273 | + * | |
191 | 274 | * @param parent {@inheritDoc} |
192 | 275 | * @param index {@inheritDoc} |
193 | 276 | * @return {@inheritDoc} |
@@ -197,58 +280,63 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
197 | 280 | if(index < 0) return null; |
198 | 281 | if(index >= getChildCount(parent)) return null; |
199 | 282 | |
200 | - if(parent == ROOT){ | |
283 | + Object result = null; | |
284 | + | |
285 | + if(isRoot(parent)){ | |
201 | 286 | List<Land> list = getLandList(); |
202 | 287 | int landIndex = index; |
203 | 288 | if( ! this.ascending) landIndex = list.size() - index - 1; |
204 | 289 | Land land = list.get(landIndex); |
205 | - return land; | |
206 | - } | |
207 | - if(parent instanceof Land){ | |
290 | + result = land; | |
291 | + }else if(parent instanceof Land){ | |
208 | 292 | Land land = (Land) parent; |
209 | 293 | List<VillageSection> sectionList = this.sectionMap.get(land); |
210 | 294 | int sectIndex = index; |
211 | 295 | if( ! this.ascending) sectIndex = sectionList.size() - index - 1; |
212 | 296 | VillageSection section = sectionList.get(sectIndex); |
213 | - return section; | |
214 | - } | |
215 | - if(parent instanceof VillageSection){ | |
297 | + result = section; | |
298 | + }else if(parent instanceof VillageSection){ | |
216 | 299 | VillageSection section = (VillageSection) parent; |
217 | 300 | int vilIndex = index; |
218 | 301 | if( ! this.ascending){ |
219 | 302 | vilIndex = section.getVillageCount() - index - 1; |
220 | 303 | } |
221 | 304 | Village village = section.getVillage(vilIndex); |
222 | - return village; | |
305 | + result = village; | |
223 | 306 | } |
224 | - return null; | |
307 | + | |
308 | + return result; | |
225 | 309 | } |
226 | 310 | |
227 | 311 | /** |
228 | 312 | * {@inheritDoc} |
313 | + * | |
229 | 314 | * @param parent {@inheritDoc} |
230 | 315 | * @return {@inheritDoc} |
231 | 316 | */ |
232 | 317 | @Override |
233 | 318 | public int getChildCount(Object parent){ |
234 | - if(parent == ROOT){ | |
235 | - return getLandList().size(); | |
236 | - } | |
237 | - if(parent instanceof Land){ | |
319 | + int result = 0; | |
320 | + | |
321 | + if(isRoot(parent)){ | |
322 | + result = getLandList().size(); | |
323 | + }else if(parent instanceof Land){ | |
238 | 324 | Land land = (Land) parent; |
239 | 325 | List<VillageSection> sectionList = this.sectionMap.get(land); |
240 | - if(sectionList == null) return 0; | |
241 | - return sectionList.size(); | |
242 | - } | |
243 | - if(parent instanceof VillageSection){ | |
326 | + if(sectionList != null){ | |
327 | + result = sectionList.size(); | |
328 | + } | |
329 | + }else if(parent instanceof VillageSection){ | |
244 | 330 | VillageSection section = (VillageSection) parent; |
245 | - return section.getVillageCount(); | |
331 | + result = section.getVillageCount(); | |
246 | 332 | } |
247 | - return 0; | |
333 | + | |
334 | + return result; | |
248 | 335 | } |
249 | 336 | |
250 | 337 | /** |
251 | 338 | * {@inheritDoc} |
339 | + * | |
252 | 340 | * @param parent {@inheritDoc} |
253 | 341 | * @param child {@inheritDoc} |
254 | 342 | * @return {@inheritDoc} |
@@ -256,32 +344,35 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
256 | 344 | @Override |
257 | 345 | public int getIndexOfChild(Object parent, Object child){ |
258 | 346 | if(child == null) return -1; |
259 | - if(parent == ROOT){ | |
347 | + | |
348 | + int result = -1; | |
349 | + | |
350 | + if(isRoot(parent)){ | |
260 | 351 | List<Land> list = getLandList(); |
261 | 352 | int index = list.indexOf(child); |
262 | 353 | if( ! this.ascending) index = list.size() - index - 1; |
263 | - return index; | |
264 | - } | |
265 | - if(parent instanceof Land){ | |
354 | + result = index; | |
355 | + }else if(parent instanceof Land){ | |
266 | 356 | Land land = (Land) parent; |
267 | 357 | List<VillageSection> sectionList = this.sectionMap.get(land); |
268 | 358 | int index = sectionList.indexOf(child); |
269 | 359 | if( ! this.ascending) index = sectionList.size() - index - 1; |
270 | - return index; | |
271 | - } | |
272 | - if(parent instanceof VillageSection){ | |
360 | + result = index; | |
361 | + }else if(parent instanceof VillageSection){ | |
273 | 362 | VillageSection section = (VillageSection) parent; |
274 | 363 | int index = section.getIndexOfVillage(child); |
275 | 364 | if( ! this.ascending){ |
276 | 365 | index = section.getVillageCount() - index - 1; |
277 | 366 | } |
278 | - return index; | |
367 | + result = index; | |
279 | 368 | } |
280 | - return -1; | |
369 | + | |
370 | + return result; | |
281 | 371 | } |
282 | 372 | |
283 | 373 | /** |
284 | 374 | * {@inheritDoc} |
375 | + * | |
285 | 376 | * @return {@inheritDoc} |
286 | 377 | */ |
287 | 378 | @Override |
@@ -291,21 +382,24 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
291 | 382 | |
292 | 383 | /** |
293 | 384 | * {@inheritDoc} |
385 | + * | |
294 | 386 | * @param node {@inheritDoc} |
295 | 387 | * @return {@inheritDoc} |
296 | 388 | */ |
297 | 389 | @Override |
298 | 390 | public boolean isLeaf(Object node){ |
299 | - if(node == ROOT) return false; | |
300 | - if(node instanceof Land) return false; | |
301 | - if(node instanceof VillageSection) return false; | |
302 | 391 | if(node instanceof Village) return true; |
392 | + if(node instanceof VillageSection) return false; | |
393 | + if(node instanceof Land) return false; | |
394 | + if(isRoot(node)) return false; | |
303 | 395 | return true; |
304 | 396 | } |
305 | 397 | |
306 | 398 | /** |
307 | 399 | * {@inheritDoc} |
308 | - * ※ たぶん使わないので必ず失敗させている。 | |
400 | + * | |
401 | + * <p>※ たぶん使わないので必ず失敗させている。 | |
402 | + * | |
309 | 403 | * @param path {@inheritDoc} |
310 | 404 | * @param newValue {@inheritDoc} |
311 | 405 | */ |
@@ -314,121 +408,109 @@ public class LandsTreeModel implements TreeModel{ // ComboBoxModelも付ける | ||
314 | 408 | throw new UnsupportedOperationException("Not supported yet."); |
315 | 409 | } |
316 | 410 | |
411 | + | |
317 | 412 | /** |
318 | 413 | * 村IDで範囲指定した、村のセクション集合。国-村間の中間ツリー。 |
414 | + * | |
319 | 415 | * @see javax.swing.tree.TreeModel |
320 | 416 | */ |
321 | 417 | private static final class VillageSection{ |
322 | 418 | |
323 | - private final int startID; | |
324 | - private final int endID; | |
325 | - private final String prefix; | |
419 | + private static final String FORM_NODE = | |
420 | + "{0}{1,number,#} ~ {0}{2,number,#}"; | |
421 | + private static final String FORM_NODE_G = | |
422 | + "{0}{1,number,#000} ~ {0}{2,number,#000}"; | |
423 | + | |
424 | + | |
425 | + private final int startId; | |
426 | + private final int endId; | |
427 | + | |
428 | + private final String text; | |
326 | 429 | |
327 | - private final List<Village> villageList = new LinkedList<>(); | |
430 | + private final List<Village> villageList; | |
328 | 431 | |
329 | 432 | |
330 | 433 | /** |
331 | 434 | * セクション集合を生成する。 |
332 | - * @param land 国 | |
333 | - * @param startID 開始村ID | |
334 | - * @param endID 終了村ID | |
435 | + * | |
436 | + * @param prefix 国名プレフィクス | |
437 | + * @param startId 区間開始村ID | |
438 | + * @param endId 区間終了村ID | |
439 | + * @param spanList 村の区間リスト | |
335 | 440 | * @throws java.lang.IndexOutOfBoundsException IDの範囲指定が変 |
336 | 441 | */ |
337 | - private VillageSection(Land land, int startID, int endID) | |
442 | + VillageSection( | |
443 | + String prefix, int startId, int endId, List<Village> spanList) | |
338 | 444 | throws IndexOutOfBoundsException{ |
339 | 445 | super(); |
340 | 446 | |
341 | - if(startID < 0 || startID > endID){ | |
447 | + if(startId < 0 || startId > endId){ | |
342 | 448 | throw new IndexOutOfBoundsException(); |
343 | 449 | } |
344 | 450 | |
345 | - this.startID = startID; | |
346 | - this.endID = endID; | |
347 | - this.prefix = land.getLandDef().getLandPrefix(); | |
451 | + this.startId = startId; | |
452 | + this.endId = endId; | |
348 | 453 | |
349 | - for(Village village : land.getVillageList()){ | |
350 | - int id = village.getVillageIDNum(); | |
351 | - if(startID <= id && id <= endID){ | |
352 | - this.villageList.add(village); | |
353 | - } | |
354 | - } | |
355 | - | |
356 | - return; | |
357 | - } | |
358 | - | |
359 | - | |
360 | - /** | |
361 | - * 与えられた国の全ての村を、指定されたinterval間隔でセクション化する。 | |
362 | - * @param land 国 | |
363 | - * @param interval セクションの間隔 | |
364 | - * @return セクションのリスト | |
365 | - * @throws java.lang.IllegalArgumentException intervalが正でない | |
366 | - */ | |
367 | - private static List<VillageSection> getSectionList(Land land, | |
368 | - int interval ) | |
369 | - throws IllegalArgumentException{ | |
370 | - if(interval <= 0){ | |
371 | - throw new IllegalArgumentException(); | |
372 | - } | |
373 | - | |
374 | - List<Village> villageList = land.getVillageList(); | |
375 | - Village village1st = villageList.get(0); | |
376 | - Village villageLast = villageList.get(villageList.size() - 1); | |
454 | + String format; | |
455 | + if("G".equals(prefix)) format = FORM_NODE_G; | |
456 | + else format = FORM_NODE; | |
457 | + this.text = MessageFormat.format( | |
458 | + format, prefix, this.startId, this.endId); | |
377 | 459 | |
378 | - int startID = village1st.getVillageIDNum(); | |
379 | - int endID = villageLast.getVillageIDNum(); | |
460 | + List<Village> newList = new ArrayList<>(spanList); | |
461 | + this.villageList = Collections.unmodifiableList(newList); | |
380 | 462 | |
381 | - List<VillageSection> result = new LinkedList<>(); | |
382 | - | |
383 | - int fixedStart = startID / interval * interval; | |
384 | - for(int ct = fixedStart; ct <= endID; ct += interval){ | |
385 | - VillageSection section = | |
386 | - new VillageSection(land, ct, ct + interval - 1); | |
387 | - result.add(section); | |
388 | - } | |
463 | + assert this.endId - this.startId + 1 >= this.villageList.size(); | |
389 | 464 | |
390 | - return Collections.unmodifiableList(result); | |
465 | + return; | |
391 | 466 | } |
392 | 467 | |
468 | + | |
393 | 469 | /** |
394 | - * セクションに含まれる村の総数を返す。 | |
470 | + * セクション内に含まれる村の総数を返す。 | |
471 | + * | |
472 | + * <p>ほとんどの場合はintervalと同じ数。 | |
473 | + * | |
395 | 474 | * @return 村の総数 |
396 | 475 | */ |
397 | - private int getVillageCount(){ | |
476 | + int getVillageCount(){ | |
398 | 477 | return this.villageList.size(); |
399 | 478 | } |
400 | 479 | |
401 | 480 | /** |
402 | - * セクションに含まれるindex番目の村を返す。 | |
481 | + * セクション内に含まれるindex番目の村を返す。 | |
482 | + * | |
403 | 483 | * @param index インデックス |
404 | 484 | * @return index番目の村 |
405 | 485 | */ |
406 | - private Village getVillage(int index){ | |
486 | + Village getVillage(int index){ | |
407 | 487 | return this.villageList.get(index); |
408 | 488 | } |
409 | 489 | |
410 | 490 | /** |
411 | - * セクションにおける、指定された子(村)のインデックス位置を返す。 | |
491 | + * セクション内における、指定された子(村)のインデックス位置を返す。 | |
492 | + * | |
412 | 493 | * @param child 子 |
413 | 494 | * @return インデックス位置 |
414 | 495 | */ |
415 | - private int getIndexOfVillage(Object child){ | |
496 | + int getIndexOfVillage(Object child){ | |
416 | 497 | return this.villageList.indexOf(child); |
417 | 498 | } |
418 | 499 | |
419 | 500 | /** |
420 | 501 | * セクションの文字列表記。 |
421 | - * JTree描画に反映される。 | |
502 | + * | |
503 | + * <p>JTree描画に反映される。 | |
504 | + * | |
505 | + * <p>例:「G800 ~ G899」 | |
506 | + * | |
422 | 507 | * @return 文字列表記 |
423 | 508 | */ |
424 | 509 | @Override |
425 | 510 | public String toString(){ |
426 | - StringBuilder result = new StringBuilder(); | |
427 | - result.append(this.prefix).append(this.startID); | |
428 | - result.append(" ~ "); | |
429 | - result.append(this.prefix).append(this.endID); | |
430 | - return result.toString(); | |
511 | + return this.text; | |
431 | 512 | } |
513 | + | |
432 | 514 | } |
433 | 515 | |
434 | 516 | } |
@@ -7,136 +7,202 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.jindolf.log; |
9 | 9 | |
10 | +import io.github.olyutorskii.quetexj.HeightKeeper; | |
11 | +import io.github.olyutorskii.quetexj.MaxTracker; | |
12 | +import io.github.olyutorskii.quetexj.MvcFacade; | |
13 | +import io.github.olyutorskii.quetexj.SwingLogHandler; | |
10 | 14 | import java.awt.Container; |
11 | -import java.awt.Frame; | |
12 | -import java.awt.GridBagConstraints; | |
13 | -import java.awt.GridBagLayout; | |
14 | -import java.awt.Insets; | |
15 | -import java.awt.event.ActionEvent; | |
16 | -import java.awt.event.ActionListener; | |
15 | +import java.awt.Dialog; | |
17 | 16 | import java.util.logging.Handler; |
17 | +import javax.swing.Action; | |
18 | +import javax.swing.BorderFactory; | |
19 | +import javax.swing.BoundedRangeModel; | |
20 | +import javax.swing.Box; | |
21 | +import javax.swing.BoxLayout; | |
18 | 22 | import javax.swing.JButton; |
23 | +import javax.swing.JCheckBox; | |
19 | 24 | import javax.swing.JDialog; |
20 | -import javax.swing.JSeparator; | |
25 | +import javax.swing.JPopupMenu; | |
26 | +import javax.swing.JScrollBar; | |
27 | +import javax.swing.JScrollPane; | |
28 | +import javax.swing.JTextArea; | |
29 | +import javax.swing.JToggleButton; | |
30 | +import javax.swing.border.Border; | |
31 | +import javax.swing.text.Document; | |
32 | +import jp.sfjp.jindolf.dxchg.TextPopup; | |
33 | +import jp.sfjp.jindolf.util.Monodizer; | |
21 | 34 | |
22 | 35 | /** |
23 | 36 | * ログ表示ウィンドウ。 |
24 | 37 | */ |
25 | 38 | @SuppressWarnings("serial") |
26 | -public class LogFrame extends JDialog { | |
39 | +public final class LogFrame extends JDialog { | |
27 | 40 | |
28 | - private static final String CMD_CLOSELOG = "CMD_CLOSE_LOG"; | |
29 | - private static final String CMD_CLEARLOG = "CMD_CLEAR_LOG"; | |
41 | + private static final int HEIGHT_LIMIT = 5000; | |
42 | + private static final int HEIGHT_NEW = 4000; | |
30 | 43 | |
44 | + private static final int AROUND_TEXT = 3; | |
45 | + private static final int AROUND_BUTTON = 5; | |
31 | 46 | |
32 | - private final LogPanel logPanel = new LogPanel(); | |
33 | - private final JButton clearButton = new JButton("クリア"); | |
34 | - private final JButton closeButton = new JButton("閉じる"); | |
47 | + | |
48 | + private final MvcFacade facade; | |
49 | + | |
50 | + private final JScrollPane scrollPane; | |
51 | + private final JButton clearButton; | |
52 | + private final JButton closeButton; | |
53 | + private final JCheckBox trackButton; | |
54 | + | |
55 | + private final Handler handler; | |
35 | 56 | |
36 | 57 | |
37 | 58 | /** |
38 | 59 | * コンストラクタ。 |
39 | - * @param owner フレームオーナー | |
40 | 60 | */ |
41 | - public LogFrame(Frame owner){ | |
42 | - super(owner); | |
61 | + public LogFrame(){ | |
62 | + super((Dialog)null); | |
63 | + // We need unowned dialog | |
43 | 64 | |
44 | - design(); | |
65 | + this.facade = new MvcFacade(); | |
66 | + | |
67 | + this.scrollPane = buildScrollPane(this.facade); | |
45 | 68 | |
46 | - this.clearButton.setActionCommand(CMD_CLEARLOG); | |
47 | - this.closeButton.setActionCommand(CMD_CLOSELOG); | |
69 | + this.clearButton = new JButton(); | |
70 | + this.closeButton = new JButton(); | |
71 | + this.trackButton = new JCheckBox(); | |
48 | 72 | |
49 | - ActionListener actionListener = new ActionWatcher(); | |
50 | - this.clearButton.addActionListener(actionListener); | |
51 | - this.closeButton.addActionListener(actionListener); | |
73 | + setupButtons(); | |
74 | + | |
75 | + MaxTracker tracker = this.facade.getMaxTracker(); | |
76 | + HeightKeeper keeper = this.facade.getHeightKeeper(); | |
77 | + | |
78 | + tracker.setTrackingMode(true); | |
79 | + keeper.setConditions(HEIGHT_LIMIT, HEIGHT_NEW); | |
80 | + | |
81 | + Handler logHandler = null; | |
82 | + if(LogUtils.hasLoggingPermission()){ | |
83 | + Document document = this.facade.getDocument(); | |
84 | + logHandler = new SwingLogHandler(document); | |
85 | + } | |
86 | + this.handler = logHandler; | |
52 | 87 | |
53 | 88 | setResizable(true); |
54 | 89 | setLocationByPlatform(true); |
55 | 90 | setModal(false); |
56 | 91 | |
92 | + design(); | |
93 | + | |
57 | 94 | return; |
58 | 95 | } |
59 | 96 | |
97 | + | |
60 | 98 | /** |
61 | - * デザインを行う。 | |
99 | + * ログ用スクロール領域を生成する。 | |
100 | + * | |
101 | + * @param facadeArg ファサード | |
102 | + * @return スクロール領域 | |
62 | 103 | */ |
63 | - private void design(){ | |
64 | - Container content = getContentPane(); | |
104 | + private static JScrollPane buildScrollPane(MvcFacade facadeArg){ | |
105 | + JScrollPane scrollPane = new JScrollPane(); | |
65 | 106 | |
66 | - GridBagLayout layout = new GridBagLayout(); | |
67 | - GridBagConstraints constraints = new GridBagConstraints(); | |
68 | - content.setLayout(layout); | |
107 | + JScrollBar vbar = scrollPane.getVerticalScrollBar(); | |
108 | + BoundedRangeModel rangeModel = | |
109 | + facadeArg.getVerticalBoundedRangeModel(); | |
110 | + vbar.setModel(rangeModel); | |
69 | 111 | |
70 | - constraints.weightx = 1.0; | |
71 | - constraints.weighty = 1.0; | |
72 | - constraints.fill = GridBagConstraints.BOTH; | |
73 | - constraints.gridwidth = GridBagConstraints.REMAINDER; | |
112 | + JTextArea textArea = buildTextArea(facadeArg); | |
113 | + scrollPane.setViewportView(textArea); | |
74 | 114 | |
75 | - content.add(this.logPanel, constraints); | |
115 | + return scrollPane; | |
116 | + } | |
76 | 117 | |
77 | - constraints.weighty = 0.0; | |
78 | - constraints.fill = GridBagConstraints.HORIZONTAL; | |
79 | - constraints.insets = new Insets(5, 5, 5, 5); | |
118 | + /** | |
119 | + * ログ用テキストエリアを生成する。 | |
120 | + * | |
121 | + * @param facadeArg ファサード | |
122 | + * @return テキストエリア | |
123 | + */ | |
124 | + private static JTextArea buildTextArea(MvcFacade facadeArg){ | |
125 | + JTextArea textArea = facadeArg.getTextArea(); | |
80 | 126 | |
81 | - content.add(new JSeparator(), constraints); | |
127 | + textArea.setEditable(false); | |
128 | + textArea.setLineWrap(true); | |
129 | + Monodizer.monodize(textArea); | |
82 | 130 | |
83 | - constraints.anchor = GridBagConstraints.WEST; | |
84 | - constraints.fill = GridBagConstraints.NONE; | |
85 | - constraints.gridwidth = 1; | |
86 | - content.add(this.clearButton, constraints); | |
131 | + Border border = BorderFactory.createEmptyBorder( | |
132 | + AROUND_TEXT, | |
133 | + AROUND_TEXT, | |
134 | + AROUND_TEXT, | |
135 | + AROUND_TEXT | |
136 | + ); | |
137 | + textArea.setBorder(border); | |
87 | 138 | |
88 | - constraints.weightx = 0.0; | |
89 | - constraints.anchor = GridBagConstraints.EAST; | |
90 | - content.add(this.closeButton, constraints); | |
139 | + JPopupMenu popup = new TextPopup(); | |
140 | + textArea.setComponentPopupMenu(popup); | |
91 | 141 | |
92 | - return; | |
142 | + return textArea; | |
93 | 143 | } |
94 | 144 | |
95 | - /** | |
96 | - * ロギングハンドラを返す。 | |
97 | - * @return ロギングハンドラ | |
98 | - */ | |
99 | - public Handler getHandler(){ | |
100 | - return this.logPanel.getHandler(); | |
101 | - } | |
102 | 145 | |
103 | 146 | /** |
104 | - * ログ内容をクリアする。 | |
147 | + * ボタンの各種設定。 | |
105 | 148 | */ |
106 | - public void clearLog(){ | |
107 | - this.logPanel.clearLog(); | |
149 | + private void setupButtons(){ | |
150 | + Action clearAction = this.facade.getClearAction(); | |
151 | + this.clearButton.setAction(clearAction); | |
152 | + this.clearButton.setText("クリア"); | |
153 | + | |
154 | + this.closeButton.addActionListener(event -> { | |
155 | + if(event.getSource() == this.closeButton){ | |
156 | + setVisible(false); | |
157 | + } | |
158 | + }); | |
159 | + this.closeButton.setText("閉じる"); | |
160 | + | |
161 | + JToggleButton.ToggleButtonModel toggleModel; | |
162 | + toggleModel = this.facade.getTrackSwitchButtonModel(); | |
163 | + this.trackButton.setModel(toggleModel); | |
164 | + this.trackButton.setText("末尾に追従"); | |
165 | + | |
108 | 166 | return; |
109 | 167 | } |
110 | 168 | |
111 | - | |
112 | 169 | /** |
113 | - * ボタン操作を監視する。 | |
170 | + * レイアウトデザインを行う。 | |
114 | 171 | */ |
115 | - private final class ActionWatcher implements ActionListener{ | |
116 | - | |
117 | - /** | |
118 | - * コンストラクタ。 | |
119 | - */ | |
120 | - ActionWatcher(){ | |
121 | - super(); | |
122 | - return; | |
123 | - } | |
172 | + private void design(){ | |
173 | + Box buttonPanel = Box.createHorizontalBox(); | |
174 | + | |
175 | + buttonPanel.add(this.clearButton); | |
176 | + buttonPanel.add(Box.createHorizontalStrut(AROUND_BUTTON)); | |
177 | + buttonPanel.add(this.trackButton); | |
178 | + buttonPanel.add(Box.createHorizontalGlue()); | |
179 | + buttonPanel.add(this.closeButton); | |
180 | + | |
181 | + Border border = BorderFactory.createEmptyBorder( | |
182 | + AROUND_BUTTON, | |
183 | + AROUND_BUTTON, | |
184 | + AROUND_BUTTON, | |
185 | + AROUND_BUTTON | |
186 | + ); | |
187 | + buttonPanel.setBorder(border); | |
124 | 188 | |
125 | - /** | |
126 | - * {@inheritDoc} | |
127 | - * ボタン押下イベント処理。 | |
128 | - * @param event {@inheritDoc} | |
129 | - */ | |
130 | - @Override | |
131 | - public void actionPerformed(ActionEvent event){ | |
132 | - String cmd = event.getActionCommand(); | |
189 | + Container content = getContentPane(); | |
190 | + BoxLayout layout = new BoxLayout(content, BoxLayout.Y_AXIS); | |
191 | + content.setLayout(layout); | |
133 | 192 | |
134 | - if (CMD_CLEARLOG.equals(cmd)) clearLog(); | |
135 | - else if(CMD_CLOSELOG.equals(cmd)) setVisible(false); | |
193 | + content.add(this.scrollPane); | |
194 | + content.add(buttonPanel); | |
136 | 195 | |
137 | - return; | |
138 | - } | |
196 | + return; | |
197 | + } | |
139 | 198 | |
199 | + /** | |
200 | + * ロギングハンドラを返す。 | |
201 | + * | |
202 | + * @return ロギングハンドラ | |
203 | + */ | |
204 | + public Handler getHandler(){ | |
205 | + return this.handler; | |
140 | 206 | } |
141 | 207 | |
142 | 208 | } |
@@ -1,231 +0,0 @@ | ||
1 | -/* | |
2 | - * Log panel | |
3 | - * | |
4 | - * License : The MIT License | |
5 | - * Copyright(c) 2012 olyutorskii | |
6 | - */ | |
7 | - | |
8 | -package jp.sfjp.jindolf.log; | |
9 | - | |
10 | -import java.awt.Adjustable; | |
11 | -import java.awt.EventQueue; | |
12 | -import java.util.logging.Handler; | |
13 | -import javax.swing.BorderFactory; | |
14 | -import javax.swing.JPopupMenu; | |
15 | -import javax.swing.JScrollPane; | |
16 | -import javax.swing.JTextArea; | |
17 | -import javax.swing.border.Border; | |
18 | -import javax.swing.event.AncestorEvent; | |
19 | -import javax.swing.event.AncestorListener; | |
20 | -import javax.swing.event.DocumentEvent; | |
21 | -import javax.swing.event.DocumentListener; | |
22 | -import javax.swing.text.BadLocationException; | |
23 | -import javax.swing.text.Document; | |
24 | -import javax.swing.text.PlainDocument; | |
25 | -import jp.sfjp.jindolf.dxchg.TextPopup; | |
26 | -import jp.sfjp.jindolf.util.Monodizer; | |
27 | - | |
28 | -/** | |
29 | - * スクロールバー付きログ表示パネル。 | |
30 | - * 垂直スクロールバーは自動的に最下部へトラックする。 | |
31 | - */ | |
32 | -@SuppressWarnings("serial") | |
33 | -public class LogPanel extends JScrollPane { | |
34 | - | |
35 | - private static final Document DOC_EMPTY = new PlainDocument(); | |
36 | - | |
37 | - | |
38 | - private final Document document = new PlainDocument(); | |
39 | - private final Handler handler; | |
40 | - | |
41 | - private final JTextArea textarea = new JTextArea(); | |
42 | - | |
43 | - | |
44 | - /** | |
45 | - * コンストラクタ。 | |
46 | - */ | |
47 | - public LogPanel(){ | |
48 | - super(); | |
49 | - | |
50 | - if(LogUtils.hasLoggingPermission()){ | |
51 | - this.handler = new SwingDocHandler(this.document); | |
52 | - }else{ | |
53 | - this.handler = null; | |
54 | - } | |
55 | - | |
56 | - this.textarea.setDocument(DOC_EMPTY); | |
57 | - this.textarea.setEditable(false); | |
58 | - this.textarea.setLineWrap(true); | |
59 | - Monodizer.monodize(this.textarea); | |
60 | - | |
61 | - Border border = BorderFactory.createEmptyBorder(3, 3, 3, 3); | |
62 | - this.textarea.setBorder(border); | |
63 | - | |
64 | - JPopupMenu popup = new TextPopup(); | |
65 | - this.textarea.setComponentPopupMenu(popup); | |
66 | - | |
67 | - setViewportView(this.textarea); | |
68 | - | |
69 | - DocumentListener docListener = new DocWatcher(); | |
70 | - this.document.addDocumentListener(docListener); | |
71 | - | |
72 | - AncestorListener ancestorListener = new AncestorWatcher(); | |
73 | - addAncestorListener(ancestorListener); | |
74 | - | |
75 | - return; | |
76 | - } | |
77 | - | |
78 | - /** | |
79 | - * ロギングハンドラを返す。 | |
80 | - * @return ロギングハンドラ | |
81 | - */ | |
82 | - public Handler getHandler(){ | |
83 | - return this.handler; | |
84 | - } | |
85 | - | |
86 | - /** | |
87 | - * 垂直スクロールバーをドキュメント下端に設定し、 | |
88 | - * ログの最新部を表示する。 | |
89 | - * 不可視状態なら何もしない。 | |
90 | - */ | |
91 | - private void showLastPos(){ | |
92 | - if(this.textarea.getDocument() != this.document) return; | |
93 | - | |
94 | - final Adjustable yPos = getVerticalScrollBar(); | |
95 | - EventQueue.invokeLater(new Runnable(){ | |
96 | - @Override | |
97 | - public void run(){ | |
98 | - yPos.setValue(Integer.MAX_VALUE); | |
99 | - return; | |
100 | - } | |
101 | - }); | |
102 | - | |
103 | - return; | |
104 | - } | |
105 | - | |
106 | - /** | |
107 | - * モデルとビューを連携させる。 | |
108 | - * スクロール位置は末端に。 | |
109 | - */ | |
110 | - private void attachModel(){ | |
111 | - if(this.textarea.getDocument() != this.document){ | |
112 | - this.textarea.setDocument(this.document); | |
113 | - } | |
114 | - showLastPos(); | |
115 | - return; | |
116 | - } | |
117 | - | |
118 | - /** | |
119 | - * モデルとビューを切り離す。 | |
120 | - */ | |
121 | - private void detachModel(){ | |
122 | - if(this.textarea.getDocument() == DOC_EMPTY) return; | |
123 | - this.textarea.setDocument(DOC_EMPTY); | |
124 | - return; | |
125 | - } | |
126 | - | |
127 | - /** | |
128 | - * ログ内容をクリアする。 | |
129 | - */ | |
130 | - public void clearLog(){ | |
131 | - try{ | |
132 | - int docLength = this.document.getLength(); | |
133 | - this.document.remove(0, docLength); | |
134 | - }catch(BadLocationException e){ | |
135 | - assert false; | |
136 | - } | |
137 | - return; | |
138 | - } | |
139 | - | |
140 | - | |
141 | - /** | |
142 | - * 画面更新が必要な状態か監視し、必要に応じてモデルとビューを切り離す。 | |
143 | - */ | |
144 | - private final class AncestorWatcher implements AncestorListener{ | |
145 | - | |
146 | - /** | |
147 | - * コンストラクタ。 | |
148 | - */ | |
149 | - AncestorWatcher(){ | |
150 | - super(); | |
151 | - return; | |
152 | - } | |
153 | - | |
154 | - /** | |
155 | - * {@inheritDoc} | |
156 | - * @param event {@inheritDoc} | |
157 | - */ | |
158 | - @Override | |
159 | - public void ancestorAdded(AncestorEvent event){ | |
160 | - attachModel(); | |
161 | - return; | |
162 | - } | |
163 | - | |
164 | - /** | |
165 | - * {@inheritDoc} | |
166 | - * @param event {@inheritDoc} | |
167 | - */ | |
168 | - @Override | |
169 | - public void ancestorRemoved(AncestorEvent event){ | |
170 | - detachModel(); | |
171 | - return; | |
172 | - } | |
173 | - | |
174 | - /** | |
175 | - * {@inheritDoc} | |
176 | - * @param event {@inheritDoc} | |
177 | - */ | |
178 | - @Override | |
179 | - public void ancestorMoved(AncestorEvent event){ | |
180 | - return; | |
181 | - } | |
182 | - | |
183 | - } | |
184 | - | |
185 | - | |
186 | - /** | |
187 | - * ドキュメント操作を監視し、スクロールバーを更新する。 | |
188 | - */ | |
189 | - private final class DocWatcher implements DocumentListener{ | |
190 | - | |
191 | - /** | |
192 | - * コンストラクタ。 | |
193 | - */ | |
194 | - DocWatcher(){ | |
195 | - super(); | |
196 | - return; | |
197 | - } | |
198 | - | |
199 | - /** | |
200 | - * {@inheritDoc} | |
201 | - * @param event {@inheritDoc} | |
202 | - */ | |
203 | - @Override | |
204 | - public void changedUpdate(DocumentEvent event){ | |
205 | - showLastPos(); | |
206 | - return; | |
207 | - } | |
208 | - | |
209 | - /** | |
210 | - * {@inheritDoc} | |
211 | - * @param event {@inheritDoc} | |
212 | - */ | |
213 | - @Override | |
214 | - public void insertUpdate(DocumentEvent event){ | |
215 | - showLastPos(); | |
216 | - return; | |
217 | - } | |
218 | - | |
219 | - /** | |
220 | - * {@inheritDoc} | |
221 | - * @param event {@inheritDoc} | |
222 | - */ | |
223 | - @Override | |
224 | - public void removeUpdate(DocumentEvent event){ | |
225 | - showLastPos(); | |
226 | - return; | |
227 | - } | |
228 | - | |
229 | - } | |
230 | - | |
231 | -} |
@@ -24,7 +24,7 @@ public final class LogUtils { | ||
24 | 24 | new LoggingPermission("control", null); |
25 | 25 | |
26 | 26 | private static final PrintStream STDERR = System.err; |
27 | - private static final String ERRMSG_LOGSECURITY = | |
27 | + private static final String ERRMSG_LOGPERM = | |
28 | 28 | "セキュリティ設定により、ログ設定を変更できませんでした"; |
29 | 29 | |
30 | 30 |
@@ -38,6 +38,7 @@ public final class LogUtils { | ||
38 | 38 | |
39 | 39 | /** |
40 | 40 | * ログ操作のアクセス権があるか否か判定する。 |
41 | + * | |
41 | 42 | * @return アクセス権があればtrue |
42 | 43 | */ |
43 | 44 | public static boolean hasLoggingPermission(){ |
@@ -48,6 +49,7 @@ public final class LogUtils { | ||
48 | 49 | |
49 | 50 | /** |
50 | 51 | * ログ操作のアクセス権があるか否か判定する。 |
52 | + * | |
51 | 53 | * @param manager セキュリティマネージャ |
52 | 54 | * @return アクセス権があればtrue |
53 | 55 | */ |
@@ -65,6 +67,7 @@ public final class LogUtils { | ||
65 | 67 | |
66 | 68 | /** |
67 | 69 | * ルートロガーを返す。 |
70 | + * | |
68 | 71 | * @return ルートロガー |
69 | 72 | */ |
70 | 73 | public static Logger getRootLogger(){ |
@@ -74,14 +77,16 @@ public final class LogUtils { | ||
74 | 77 | |
75 | 78 | /** |
76 | 79 | * ルートロガーの初期化を行う。 |
77 | - * ルートロガーの既存ハンドラを全解除し、 | |
80 | + * | |
81 | + * <p>ルートロガーの既存ハンドラを全解除し、 | |
78 | 82 | * {@link MomentaryHandler}ハンドラを登録する。 |
83 | + * | |
79 | 84 | * @param useConsoleLog trueなら |
80 | 85 | * {@link java.util.logging.ConsoleHandler}も追加する。 |
81 | 86 | */ |
82 | 87 | public static void initRootLogger(boolean useConsoleLog){ |
83 | 88 | if( ! hasLoggingPermission() ){ |
84 | - STDERR.println(ERRMSG_LOGSECURITY); | |
89 | + STDERR.println(ERRMSG_LOGPERM); | |
85 | 90 | return; |
86 | 91 | } |
87 | 92 |
@@ -105,10 +110,14 @@ public final class LogUtils { | ||
105 | 110 | |
106 | 111 | /** |
107 | 112 | * ルートロガーに新ハンドラを追加する。 |
108 | - * ルートロガー中の全{@link MomentaryHandler}型ハンドラに | |
113 | + * | |
114 | + * <p>ルートロガー中の全{@link MomentaryHandler}型ハンドラに | |
109 | 115 | * 蓄積されていたログは、新ハンドラに一気に転送される。 |
110 | - * {@link MomentaryHandler}型ハンドラはルートロガーから削除される。 | |
111 | - * ログ操作のパーミッションがない場合、何もしない。 | |
116 | + * | |
117 | + * <p>{@link MomentaryHandler}型ハンドラはルートロガーから削除される。 | |
118 | + * | |
119 | + * <p>ログ操作のパーミッションがない場合、何もしない。 | |
120 | + * | |
112 | 121 | * @param newHandler 新ハンドラ |
113 | 122 | */ |
114 | 123 | public static void switchHandler(Handler newHandler){ |
@@ -122,10 +131,10 @@ public final class LogUtils { | ||
122 | 131 | |
123 | 132 | logger.addHandler(newHandler); |
124 | 133 | |
125 | - for(MomentaryHandler momentaryHandler : momentaryHandlers){ | |
134 | + momentaryHandlers.forEach(momentaryHandler -> { | |
126 | 135 | momentaryHandler.transfer(newHandler); |
127 | 136 | momentaryHandler.close(); |
128 | - } | |
137 | + }); | |
129 | 138 | |
130 | 139 | return; |
131 | 140 | } |
@@ -18,11 +18,11 @@ import java.util.logging.Logger; | ||
18 | 18 | */ |
19 | 19 | public class LoggingDispatcher extends EventQueue{ |
20 | 20 | |
21 | + private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
22 | + | |
21 | 23 | private static final String FATALMSG = |
22 | 24 | "イベントディスパッチ中に異常が起きました。"; |
23 | 25 | |
24 | - private static final Logger LOGGER = Logger.getAnonymousLogger(); | |
25 | - | |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * コンストラクタ。 |
@@ -47,17 +47,20 @@ public class LoggingDispatcher extends EventQueue{ | ||
47 | 47 | |
48 | 48 | /** |
49 | 49 | * 異常系を匿名ロガーに出力する。 |
50 | - * @param e 例外 | |
50 | + * | |
51 | + * @param throwable 例外 | |
51 | 52 | */ |
52 | - private static void logThrowable(Throwable e){ | |
53 | - LOGGER.log(Level.SEVERE, FATALMSG, e); | |
53 | + private static void logThrowable(Throwable throwable){ | |
54 | + LOGGER.log(Level.SEVERE, FATALMSG, throwable); | |
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | 58 | |
58 | 59 | /** |
59 | 60 | * {@inheritDoc} |
60 | - * イベントディスパッチにより発生した例外を匿名ログ出力する。 | |
61 | + * | |
62 | + * <p>イベントディスパッチにより発生した例外を匿名ログ出力する。 | |
63 | + * | |
61 | 64 | * @param event {@inheritDoc} |
62 | 65 | */ |
63 | 66 | @Override |
@@ -70,11 +73,11 @@ public class LoggingDispatcher extends EventQueue{ | ||
70 | 73 | }catch(Exception e){ |
71 | 74 | logThrowable(e); |
72 | 75 | } |
73 | - // TODO Toolkit#beep()もするべきか | |
74 | - // TODO モーダルダイアログを出すべきか | |
75 | - // TODO 標準エラー出力抑止オプションを用意すべきか | |
76 | - // TODO セキュリティバイパス | |
77 | 76 | return; |
78 | 77 | } |
79 | 78 | |
79 | + // TODO モーダルダイアログを出すべきか | |
80 | + // TODO 標準エラー出力抑止オプションを用意すべきか | |
81 | + // TODO セキュリティバイパス | |
82 | + | |
80 | 83 | } |
@@ -7,24 +7,28 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.jindolf.log; |
9 | 9 | |
10 | +import java.util.Arrays; | |
10 | 11 | import java.util.Collections; |
11 | 12 | import java.util.LinkedList; |
12 | 13 | import java.util.List; |
14 | +import java.util.Objects; | |
13 | 15 | import java.util.logging.Handler; |
14 | 16 | import java.util.logging.Level; |
15 | 17 | import java.util.logging.LogRecord; |
16 | 18 | import java.util.logging.Logger; |
19 | +import java.util.stream.Collectors; | |
17 | 20 | |
18 | 21 | /** |
19 | 22 | * なにもしない一時的なロギングハンドラ。 |
20 | - * なにがロギングされたのかあとから一括して取得することができる。 | |
23 | + * | |
24 | + * <p>なにがロギングされたのかあとから一括して取得することができる。 | |
21 | 25 | * |
22 | 26 | * <p>知らないうちにメモリを圧迫しないよう注意。 |
23 | 27 | */ |
24 | 28 | public class MomentaryHandler extends Handler{ |
25 | 29 | |
26 | 30 | private final List<LogRecord> logList = |
27 | - Collections.synchronizedList(new LinkedList<LogRecord>()); | |
31 | + Collections.synchronizedList(new LinkedList<>()); | |
28 | 32 | private final List<LogRecord> unmodList = |
29 | 33 | Collections.unmodifiableList(this.logList); |
30 | 34 |
@@ -40,36 +44,39 @@ public class MomentaryHandler extends Handler{ | ||
40 | 44 | |
41 | 45 | /** |
42 | 46 | * ロガーに含まれる{@link MomentaryHandler}型ハンドラのリストを返す。 |
47 | + * | |
43 | 48 | * @param logger ロガー |
44 | 49 | * @return {@link MomentaryHandler}型ハンドラのリスト |
45 | 50 | */ |
46 | 51 | public static List<MomentaryHandler> |
47 | 52 | getMomentaryHandlers(Logger logger){ |
48 | - List<MomentaryHandler> result = new LinkedList<>(); | |
53 | + List<MomentaryHandler> result; | |
49 | 54 | |
50 | - for(Handler handler : logger.getHandlers()){ | |
51 | - if( ! (handler instanceof MomentaryHandler) ) continue; | |
52 | - MomentaryHandler momentaryHandler = (MomentaryHandler) handler; | |
53 | - result.add(momentaryHandler); | |
54 | - } | |
55 | + result = Arrays.stream(logger.getHandlers()) | |
56 | + .filter(handler -> handler instanceof MomentaryHandler) | |
57 | + .map(handler -> (MomentaryHandler) handler) | |
58 | + .collect(Collectors.toList()); | |
55 | 59 | |
56 | 60 | return result; |
57 | 61 | } |
58 | 62 | |
59 | 63 | /** |
60 | 64 | * ロガーに含まれる{@link MomentaryHandler}型ハンドラを全て削除する。 |
65 | + * | |
61 | 66 | * @param logger ロガー |
62 | 67 | */ |
63 | 68 | public static void removeMomentaryHandlers(Logger logger){ |
64 | - for(MomentaryHandler handler : getMomentaryHandlers(logger)){ | |
69 | + getMomentaryHandlers(logger).forEach(handler -> { | |
65 | 70 | logger.removeHandler(handler); |
66 | - } | |
71 | + }); | |
67 | 72 | return; |
68 | 73 | } |
69 | 74 | |
70 | 75 | /** |
71 | 76 | * 蓄積されたログレコードのリストを返す。 |
72 | - * 古いログが先頭に来る。 | |
77 | + * | |
78 | + * <p>古いログが先頭に来る。 | |
79 | + * | |
73 | 80 | * @return 刻一刻と成長するログレコードのリスト。変更不可。 |
74 | 81 | */ |
75 | 82 | public List<LogRecord> getRecordList(){ |
@@ -78,7 +85,9 @@ public class MomentaryHandler extends Handler{ | ||
78 | 85 | |
79 | 86 | /** |
80 | 87 | * {@inheritDoc} |
81 | - * ログを内部に溜め込む。 | |
88 | + * | |
89 | + * <p>ログを内部に溜め込む。 | |
90 | + * | |
82 | 91 | * @param record {@inheritDoc} |
83 | 92 | */ |
84 | 93 | @Override |
@@ -89,6 +98,7 @@ public class MomentaryHandler extends Handler{ | ||
89 | 98 | return; |
90 | 99 | } |
91 | 100 | |
101 | + // recording caller method | |
92 | 102 | record.getSourceMethodName(); |
93 | 103 | |
94 | 104 | this.logList.add(record); |
@@ -98,7 +108,8 @@ public class MomentaryHandler extends Handler{ | ||
98 | 108 | |
99 | 109 | /** |
100 | 110 | * {@inheritDoc} |
101 | - * (何もしない)。 | |
111 | + * | |
112 | + * <p>(何もしない)。 | |
102 | 113 | */ |
103 | 114 | @Override |
104 | 115 | public void flush(){ |
@@ -107,7 +118,8 @@ public class MomentaryHandler extends Handler{ | ||
107 | 118 | |
108 | 119 | /** |
109 | 120 | * {@inheritDoc} |
110 | - * 以降のログ出力を無視する。 | |
121 | + * | |
122 | + * <p>以降のログ出力を無視する。 | |
111 | 123 | */ |
112 | 124 | @Override |
113 | 125 | public void close(){ |
@@ -119,19 +131,21 @@ public class MomentaryHandler extends Handler{ | ||
119 | 131 | /** |
120 | 132 | * 自分自身をクローズし、 |
121 | 133 | * 蓄積したログを他のハンドラへまとめて出力する。 |
122 | - * 最後に蓄積されたログを解放する。 | |
134 | + * | |
135 | + * <p>最後に蓄積されたログを解放する。 | |
136 | + * | |
123 | 137 | * @param handler 他のハンドラ |
124 | 138 | * @throws NullPointerException 引数がnull |
125 | 139 | */ |
126 | 140 | public void transfer(Handler handler) throws NullPointerException { |
127 | - if(handler == null) throw new NullPointerException(); | |
141 | + Objects.nonNull(handler); | |
128 | 142 | if(handler == this) return; |
129 | 143 | |
130 | 144 | close(); |
131 | 145 | |
132 | - for(LogRecord record : this.logList){ | |
146 | + this.logList.forEach(record -> { | |
133 | 147 | handler.publish(record); |
134 | - } | |
148 | + }); | |
135 | 149 | |
136 | 150 | handler.flush(); |
137 | 151 | this.logList.clear(); |
@@ -1,140 +0,0 @@ | ||
1 | -/* | |
2 | - * Logging handler for Swing text component | |
3 | - * | |
4 | - * License : The MIT License | |
5 | - * Copyright(c) 2011 olyutorskii | |
6 | - */ | |
7 | - | |
8 | -package jp.sfjp.jindolf.log; | |
9 | - | |
10 | -import java.awt.EventQueue; | |
11 | -import java.util.logging.Formatter; | |
12 | -import java.util.logging.Handler; | |
13 | -import java.util.logging.Level; | |
14 | -import java.util.logging.LogRecord; | |
15 | -import java.util.logging.SimpleFormatter; | |
16 | -import javax.swing.text.AttributeSet; | |
17 | -import javax.swing.text.BadLocationException; | |
18 | -import javax.swing.text.Document; | |
19 | - | |
20 | -/** | |
21 | - * Swingテキストコンポーネント用データモデル | |
22 | - * {@link javax.swing.text.Document} | |
23 | - * に出力する{@link java.util.logging.Handler}。 | |
24 | - * | |
25 | - * <p>スレッド間競合はEDTで解決される。 | |
26 | - * | |
27 | - * <p>一定の文字数を超えないよう、古い記録は消去される。 | |
28 | - */ | |
29 | -public class SwingDocHandler extends Handler{ | |
30 | - | |
31 | - private static final int DOCLIMIT = 100 * 1000; // 単位は文字 | |
32 | - private static final float CHOPRATIO = 0.9f; | |
33 | - private static final int CHOPPEDLEN = (int) (DOCLIMIT * CHOPRATIO); | |
34 | - | |
35 | - static{ | |
36 | - assert DOCLIMIT > CHOPPEDLEN; | |
37 | - } | |
38 | - | |
39 | - | |
40 | - private final Document document; | |
41 | - | |
42 | - | |
43 | - /** | |
44 | - * ログハンドラの生成。 | |
45 | - * @param document ドキュメントモデル | |
46 | - */ | |
47 | - public SwingDocHandler(Document document){ | |
48 | - super(); | |
49 | - | |
50 | - this.document = document; | |
51 | - | |
52 | - Formatter formatter = new SimpleFormatter(); | |
53 | - setFormatter(formatter); | |
54 | - | |
55 | - return; | |
56 | - } | |
57 | - | |
58 | - /** | |
59 | - * ドキュメント末尾に文字列を追加する。 | |
60 | - * | |
61 | - * <p>EDTから呼ばなければならない。 | |
62 | - * | |
63 | - * @param logMessage 文字列 | |
64 | - */ | |
65 | - private void appendLog(String logMessage){ | |
66 | - try{ | |
67 | - this.document.insertString(this.document.getLength(), | |
68 | - logMessage, | |
69 | - (AttributeSet) null ); | |
70 | - }catch(BadLocationException e){ | |
71 | - assert false; | |
72 | - } | |
73 | - return; | |
74 | - } | |
75 | - | |
76 | - /** | |
77 | - * ドキュメント先頭部をチョップして最大長に納める。 | |
78 | - * | |
79 | - * <p>EDTから呼ばなければならない。 | |
80 | - */ | |
81 | - private void chopHead(){ | |
82 | - int docLength = this.document.getLength(); | |
83 | - if(docLength <= DOCLIMIT) return; | |
84 | - | |
85 | - int offset = docLength - CHOPPEDLEN; | |
86 | - try{ | |
87 | - this.document.remove(0, offset); | |
88 | - }catch(BadLocationException e){ | |
89 | - assert false; | |
90 | - } | |
91 | - | |
92 | - return; | |
93 | - } | |
94 | - | |
95 | - /** | |
96 | - * {@inheritDoc} | |
97 | - * @param record {@inheritDoc} | |
98 | - */ | |
99 | - @Override | |
100 | - public void publish(LogRecord record){ | |
101 | - if( ! isLoggable(record) ){ | |
102 | - return; | |
103 | - } | |
104 | - | |
105 | - Formatter formatter = getFormatter(); | |
106 | - final String message = formatter.format(record); | |
107 | - | |
108 | - EventQueue.invokeLater(new Runnable(){ | |
109 | - @Override | |
110 | - public void run(){ | |
111 | - appendLog(message); | |
112 | - chopHead(); | |
113 | - return; | |
114 | - } | |
115 | - }); | |
116 | - | |
117 | - return; | |
118 | - } | |
119 | - | |
120 | - /** | |
121 | - * {@inheritDoc} | |
122 | - * (何もしない)。 | |
123 | - */ | |
124 | - @Override | |
125 | - public void flush(){ | |
126 | - return; | |
127 | - } | |
128 | - | |
129 | - /** | |
130 | - * {@inheritDoc} | |
131 | - * ログ受け入れを締め切る。 | |
132 | - */ | |
133 | - @Override | |
134 | - public void close(){ | |
135 | - setLevel(Level.OFF); | |
136 | - flush(); | |
137 | - return; | |
138 | - } | |
139 | - | |
140 | -} |
@@ -10,8 +10,8 @@ package jp.sfjp.jindolf.summary; | ||
10 | 10 | import java.awt.Color; |
11 | 11 | import java.awt.Component; |
12 | 12 | import java.awt.Container; |
13 | +import java.awt.Dialog; | |
13 | 14 | import java.awt.Dimension; |
14 | -import java.awt.Frame; | |
15 | 15 | import java.awt.GridBagConstraints; |
16 | 16 | import java.awt.GridBagLayout; |
17 | 17 | import java.awt.Image; |
@@ -57,7 +57,7 @@ import jp.sourceforge.jindolf.corelib.TalkType; | ||
57 | 57 | * その日ごとの集計。 |
58 | 58 | */ |
59 | 59 | @SuppressWarnings("serial") |
60 | -public class DaySummary extends JDialog | |
60 | +public final class DaySummary extends JDialog | |
61 | 61 | implements WindowListener, ActionListener, ItemListener{ |
62 | 62 | |
63 | 63 | private static final NumberFormat AVERAGE_FORM; |
@@ -92,11 +92,13 @@ public class DaySummary extends JDialog | ||
92 | 92 | |
93 | 93 | /** |
94 | 94 | * コンストラクタ。 |
95 | - * 集計結果を表示するモーダルダイアログを生成する。 | |
96 | - * @param owner オーナー | |
95 | + * | |
96 | + * <p>集計結果を表示するモーダルダイアログを生成する。 | |
97 | 97 | */ |
98 | - public DaySummary(Frame owner){ | |
99 | - super(owner); | |
98 | + public DaySummary(){ | |
99 | + super((Dialog)null); | |
100 | + // We need unowned dialog | |
101 | + | |
100 | 102 | setModal(true); |
101 | 103 | |
102 | 104 | GUIUtils.modifyWindowAttributes(this, true, false, true); |
@@ -154,6 +156,7 @@ public class DaySummary extends JDialog | ||
154 | 156 | |
155 | 157 | /** |
156 | 158 | * 初期のデータモデルを生成する。 |
159 | + * | |
157 | 160 | * @return データモデル |
158 | 161 | */ |
159 | 162 | private static DefaultTableModel createInitModel(){ |
@@ -180,6 +183,7 @@ public class DaySummary extends JDialog | ||
180 | 183 | |
181 | 184 | /** |
182 | 185 | * 行を追加する。 |
186 | + * | |
183 | 187 | * @param avatar アバター |
184 | 188 | * @param talkCount 発言回数 |
185 | 189 | * @param totalChars 発言文字総数 |
@@ -256,6 +260,7 @@ public class DaySummary extends JDialog | ||
256 | 260 | |
257 | 261 | /** |
258 | 262 | * 与えられたPeriodで集計を更新する。 |
263 | + * | |
259 | 264 | * @param newPeriod 日 |
260 | 265 | */ |
261 | 266 | public void summaryPeriod(Period newPeriod){ |
@@ -322,6 +327,7 @@ public class DaySummary extends JDialog | ||
322 | 327 | |
323 | 328 | /** |
324 | 329 | * {@inheritDoc} |
330 | + * | |
325 | 331 | * @param event {@inheritDoc} |
326 | 332 | */ |
327 | 333 | @Override |
@@ -331,6 +337,7 @@ public class DaySummary extends JDialog | ||
331 | 337 | |
332 | 338 | /** |
333 | 339 | * {@inheritDoc} |
340 | + * | |
334 | 341 | * @param event {@inheritDoc} |
335 | 342 | */ |
336 | 343 | @Override |
@@ -340,6 +347,7 @@ public class DaySummary extends JDialog | ||
340 | 347 | |
341 | 348 | /** |
342 | 349 | * {@inheritDoc} |
350 | + * | |
343 | 351 | * @param event {@inheritDoc} |
344 | 352 | */ |
345 | 353 | @Override |
@@ -349,6 +357,7 @@ public class DaySummary extends JDialog | ||
349 | 357 | |
350 | 358 | /** |
351 | 359 | * {@inheritDoc} |
360 | + * | |
352 | 361 | * @param event {@inheritDoc} |
353 | 362 | */ |
354 | 363 | @Override |
@@ -358,6 +367,7 @@ public class DaySummary extends JDialog | ||
358 | 367 | |
359 | 368 | /** |
360 | 369 | * {@inheritDoc} |
370 | + * | |
361 | 371 | * @param event {@inheritDoc} |
362 | 372 | */ |
363 | 373 | @Override |
@@ -367,7 +377,9 @@ public class DaySummary extends JDialog | ||
367 | 377 | |
368 | 378 | /** |
369 | 379 | * {@inheritDoc} |
370 | - * ダイアログのクローズボタン押下処理を行う。 | |
380 | + * | |
381 | + * <p>ダイアログのクローズボタン押下処理を行う。 | |
382 | + * | |
371 | 383 | * @param event ウィンドウ変化イベント {@inheritDoc} |
372 | 384 | */ |
373 | 385 | @Override |
@@ -378,6 +390,7 @@ public class DaySummary extends JDialog | ||
378 | 390 | |
379 | 391 | /** |
380 | 392 | * {@inheritDoc} |
393 | + * | |
381 | 394 | * @param event {@inheritDoc} |
382 | 395 | */ |
383 | 396 | @Override |
@@ -387,7 +400,9 @@ public class DaySummary extends JDialog | ||
387 | 400 | |
388 | 401 | /** |
389 | 402 | * {@inheritDoc} |
390 | - * クローズボタン押下処理。 | |
403 | + * | |
404 | + * <p>クローズボタン押下処理。 | |
405 | + * | |
391 | 406 | * @param event イベント {@inheritDoc} |
392 | 407 | */ |
393 | 408 | @Override |
@@ -399,7 +414,9 @@ public class DaySummary extends JDialog | ||
399 | 414 | |
400 | 415 | /** |
401 | 416 | * {@inheritDoc} |
402 | - * コンボボックス操作処理。 | |
417 | + * | |
418 | + * <p>コンボボックス操作処理。 | |
419 | + * | |
403 | 420 | * @param event イベント {@inheritDoc} |
404 | 421 | */ |
405 | 422 | @Override |
@@ -443,7 +460,9 @@ public class DaySummary extends JDialog | ||
443 | 460 | |
444 | 461 | /** |
445 | 462 | * {@inheritDoc} |
446 | - * セルに{@link Avatar}がきたら顔アイコンと名前を表示する。 | |
463 | + * | |
464 | + * <p>セルに{@link Avatar}がきたら顔アイコンと名前を表示する。 | |
465 | + * | |
447 | 466 | * @param value {@inheritDoc} |
448 | 467 | */ |
449 | 468 | @Override |
@@ -484,8 +503,10 @@ public class DaySummary extends JDialog | ||
484 | 503 | } |
485 | 504 | |
486 | 505 | /** |
487 | - * {@inheritDoc} | |
488 | - * 統計種別によってセル色を変える。 | |
506 | + * {@inheritDoc} | |
507 | + * | |
508 | + * <p>統計種別によってセル色を変える。 | |
509 | + * | |
489 | 510 | * @param table {@inheritDoc} |
490 | 511 | * @param value {@inheritDoc} |
491 | 512 | * @param isSelected {@inheritDoc} |
@@ -530,6 +551,7 @@ public class DaySummary extends JDialog | ||
530 | 551 | |
531 | 552 | return result; |
532 | 553 | } |
554 | + | |
533 | 555 | } |
534 | 556 | |
535 | 557 | } |
@@ -8,9 +8,9 @@ | ||
8 | 8 | package jp.sfjp.jindolf.summary; |
9 | 9 | |
10 | 10 | import java.awt.Container; |
11 | +import java.awt.Dialog; | |
11 | 12 | import java.awt.Dimension; |
12 | 13 | import java.awt.EventQueue; |
13 | -import java.awt.Frame; | |
14 | 14 | import java.awt.GridBagConstraints; |
15 | 15 | import java.awt.GridBagLayout; |
16 | 16 | import java.awt.Image; |
@@ -60,7 +60,7 @@ import jp.sourceforge.jindolf.corelib.Team; | ||
60 | 60 | * 決着のついた村のダイジェストを表示する。 |
61 | 61 | */ |
62 | 62 | @SuppressWarnings("serial") |
63 | -public class VillageDigest | |
63 | +public final class VillageDigest | |
64 | 64 | extends JDialog |
65 | 65 | implements ActionListener, |
66 | 66 | ItemListener { |
@@ -109,10 +109,12 @@ public class VillageDigest | ||
109 | 109 | |
110 | 110 | /** |
111 | 111 | * コンストラクタ。 |
112 | - * @param owner 親フレーム | |
113 | 112 | */ |
114 | - public VillageDigest(Frame owner){ | |
115 | - super(owner); | |
113 | + @SuppressWarnings("LeakingThisInConstructor") | |
114 | + public VillageDigest(){ | |
115 | + super((Dialog)null); | |
116 | + // We need unowned dialog | |
117 | + | |
116 | 118 | setModal(true); |
117 | 119 | |
118 | 120 | GUIUtils.modifyWindowAttributes(this, true, false, true); |
@@ -177,6 +179,7 @@ public class VillageDigest | ||
177 | 179 | |
178 | 180 | /** |
179 | 181 | * キャプション付き項目をコンテナに追加。 |
182 | + * | |
180 | 183 | * @param container コンテナ |
181 | 184 | * @param caption 項目キャプション名 |
182 | 185 | * @param delimiter デリミタ文字 |
@@ -222,6 +225,7 @@ public class VillageDigest | ||
222 | 225 | |
223 | 226 | /** |
224 | 227 | * キャプション付き項目をコンテナに追加。 |
228 | + * | |
225 | 229 | * @param container コンテナ |
226 | 230 | * @param caption 項目キャプション名 |
227 | 231 | * @param item 項目アイテム |
@@ -235,6 +239,7 @@ public class VillageDigest | ||
235 | 239 | |
236 | 240 | /** |
237 | 241 | * レイアウトの最後に詰め物をする。 |
242 | + * | |
238 | 243 | * @param container コンテナ |
239 | 244 | */ |
240 | 245 | private static void addFatPad(Container container){ |
@@ -257,6 +262,7 @@ public class VillageDigest | ||
257 | 262 | |
258 | 263 | /** |
259 | 264 | * GridBagLayoutでレイアウトする空コンポーネントを生成する。 |
265 | + * | |
260 | 266 | * @return 空コンポーネント |
261 | 267 | */ |
262 | 268 | private static JComponent createGridBagComponent(){ |
@@ -268,6 +274,7 @@ public class VillageDigest | ||
268 | 274 | |
269 | 275 | /** |
270 | 276 | * 村サマリ画面の生成。 |
277 | + * | |
271 | 278 | * @return 村サマリ画面 |
272 | 279 | */ |
273 | 280 | private JComponent buildSummaryPanel(){ |
@@ -281,6 +288,7 @@ public class VillageDigest | ||
281 | 288 | |
282 | 289 | /** |
283 | 290 | * プレイヤーサマリ画面の生成。 |
291 | + * | |
284 | 292 | * @return プレイヤーサマリ画面 |
285 | 293 | */ |
286 | 294 | private JComponent buildPlayerPanel(){ |
@@ -323,6 +331,7 @@ public class VillageDigest | ||
323 | 331 | |
324 | 332 | /** |
325 | 333 | * キャスト表生成画面を生成する。 |
334 | + * | |
326 | 335 | * @return キャスト表生成画面 |
327 | 336 | */ |
328 | 337 | private JComponent buildCastPanel(){ |
@@ -354,6 +363,7 @@ public class VillageDigest | ||
354 | 363 | |
355 | 364 | /** |
356 | 365 | * 投票Box生成画面を生成する。 |
366 | + * | |
357 | 367 | * @return 投票Box生成画面 |
358 | 368 | */ |
359 | 369 | private JComponent buildVotePanel(){ |
@@ -376,6 +386,7 @@ public class VillageDigest | ||
376 | 386 | |
377 | 387 | /** |
378 | 388 | * 村詳細Wiki生成画面を生成する。 |
389 | + * | |
379 | 390 | * @return 村詳細Wiki生成画面 |
380 | 391 | */ |
381 | 392 | private JComponent buildVillageWikiPanel(){ |
@@ -398,6 +409,7 @@ public class VillageDigest | ||
398 | 409 | |
399 | 410 | /** |
400 | 411 | * Wikiテキスト領域GUIの生成。 |
412 | + * | |
401 | 413 | * @return Wikiテキスト領域GUI |
402 | 414 | */ |
403 | 415 | private JComponent buildClipText(){ |
@@ -439,6 +451,7 @@ public class VillageDigest | ||
439 | 451 | |
440 | 452 | /** |
441 | 453 | * テンプレート生成画面を生成する。 |
454 | + * | |
442 | 455 | * @return テンプレート生成画面 |
443 | 456 | */ |
444 | 457 | private JComponent buildClipboardPanel(){ |
@@ -480,6 +493,7 @@ public class VillageDigest | ||
480 | 493 | |
481 | 494 | /** |
482 | 495 | * 画面レイアウトを行う。 |
496 | + * | |
483 | 497 | * @param container コンテナ |
484 | 498 | */ |
485 | 499 | private void design(Container container){ |
@@ -533,6 +547,7 @@ public class VillageDigest | ||
533 | 547 | |
534 | 548 | /** |
535 | 549 | * 村を設定する。 |
550 | + * | |
536 | 551 | * @param village 村 |
537 | 552 | */ |
538 | 553 | public void setVillage(Village village){ |
@@ -646,6 +661,7 @@ public class VillageDigest | ||
646 | 661 | |
647 | 662 | /** |
648 | 663 | * アクションイベントの振り分け。 |
664 | + * | |
649 | 665 | * @param event アクションイベント |
650 | 666 | */ |
651 | 667 | @Override |
@@ -713,7 +729,9 @@ public class VillageDigest | ||
713 | 729 | |
714 | 730 | /** |
715 | 731 | * Wikiテキストをテキストボックスに出力する。 |
716 | - * スクロール位置は一番上に。 | |
732 | + * | |
733 | + * <p>スクロール位置は一番上に。 | |
734 | + * | |
717 | 735 | * @param wikiText Wikiテキスト |
718 | 736 | */ |
719 | 737 | private void putWikiText(CharSequence wikiText){ |
@@ -741,6 +759,7 @@ public class VillageDigest | ||
741 | 759 | |
742 | 760 | /** |
743 | 761 | * プレイヤーの選択操作。 |
762 | + * | |
744 | 763 | * @param avatar 選択されたAvatar |
745 | 764 | */ |
746 | 765 | private void selectPlayer(Avatar avatar){ |
@@ -805,6 +824,7 @@ public class VillageDigest | ||
805 | 824 | |
806 | 825 | /** |
807 | 826 | * 顔アイコンセットの選択操作。 |
827 | + * | |
808 | 828 | * @param iconSet 顔アイコンセット |
809 | 829 | */ |
810 | 830 | private void selectIconSet(FaceIconSet iconSet){ |
@@ -817,6 +837,7 @@ public class VillageDigest | ||
817 | 837 | |
818 | 838 | /** |
819 | 839 | * コンボボックス操作の受信。 |
840 | + * | |
820 | 841 | * @param event コンボボックス操作イベント |
821 | 842 | */ |
822 | 843 | @Override |
@@ -8,7 +8,7 @@ | ||
8 | 8 | package jp.sfjp.jindolf.view; |
9 | 9 | |
10 | 10 | import java.awt.Container; |
11 | -import java.awt.Frame; | |
11 | +import java.awt.Dialog; | |
12 | 12 | import java.awt.GridBagConstraints; |
13 | 13 | import java.awt.GridBagLayout; |
14 | 14 | import java.awt.Insets; |
@@ -43,7 +43,7 @@ import jp.sourceforge.jindolf.corelib.TalkType; | ||
43 | 43 | * 発言フィルタ GUI。 |
44 | 44 | */ |
45 | 45 | @SuppressWarnings("serial") |
46 | -public class FilterPanel extends JDialog | |
46 | +public final class FilterPanel extends JDialog | |
47 | 47 | implements ActionListener, TopicFilter{ |
48 | 48 | |
49 | 49 | private static final int COLS = 4; |
@@ -71,11 +71,12 @@ public class FilterPanel extends JDialog | ||
71 | 71 | |
72 | 72 | /** |
73 | 73 | * 発言フィルタを生成する。 |
74 | - * @param owner フレームオーナー | |
75 | 74 | */ |
76 | 75 | @SuppressWarnings("LeakingThisInConstructor") |
77 | - public FilterPanel(Frame owner){ | |
78 | - super(owner); | |
76 | + public FilterPanel(){ | |
77 | + super((Dialog)null); | |
78 | + // We need unowned dialog | |
79 | + | |
79 | 80 | setModal(false); |
80 | 81 | |
81 | 82 | GUIUtils.modifyWindowAttributes(this, true, false, true); |
@@ -109,6 +110,7 @@ public class FilterPanel extends JDialog | ||
109 | 110 | |
110 | 111 | /** |
111 | 112 | * レイアウトデザインを行う。 |
113 | + * | |
112 | 114 | * @param topicPanel システムイベント選択 |
113 | 115 | * @param avatarPanel キャラ一覧 |
114 | 116 | * @param buttonPanel ボタン群 |
@@ -167,6 +169,7 @@ public class FilterPanel extends JDialog | ||
167 | 169 | |
168 | 170 | /** |
169 | 171 | * システムイベントチェックボックス群パネルを作成。 |
172 | + * | |
170 | 173 | * @return システムイベントチェックボックス群パネル |
171 | 174 | */ |
172 | 175 | private JComponent createTopicPanel(){ |
@@ -210,6 +213,7 @@ public class FilterPanel extends JDialog | ||
210 | 213 | |
211 | 214 | /** |
212 | 215 | * キャラ一覧チェックボックス群パネルを作成。 |
216 | + * | |
213 | 217 | * @return キャラ一覧チェックボックス群パネル |
214 | 218 | */ |
215 | 219 | private JComponent createAvatarPanel(){ |
@@ -248,6 +252,7 @@ public class FilterPanel extends JDialog | ||
248 | 252 | |
249 | 253 | /** |
250 | 254 | * ボタン群パネルを生成。 |
255 | + * | |
251 | 256 | * @return ボタン群パネル |
252 | 257 | */ |
253 | 258 | private JComponent createButtonPanel(){ |
@@ -276,6 +281,7 @@ public class FilterPanel extends JDialog | ||
276 | 281 | |
277 | 282 | /** |
278 | 283 | * 下段パネルを生成する。 |
284 | + * | |
279 | 285 | * @return 下段パネル |
280 | 286 | */ |
281 | 287 | private JComponent createBottomPanel(){ |
@@ -296,6 +302,7 @@ public class FilterPanel extends JDialog | ||
296 | 302 | |
297 | 303 | /** |
298 | 304 | * リスナを登録する。 |
305 | + * | |
299 | 306 | * @param listener リスナ |
300 | 307 | */ |
301 | 308 | public void addChangeListener(ChangeListener listener){ |
@@ -304,6 +311,7 @@ public class FilterPanel extends JDialog | ||
304 | 311 | |
305 | 312 | /** |
306 | 313 | * リスナを削除する。 |
314 | + * | |
307 | 315 | * @param listener リスナ |
308 | 316 | */ |
309 | 317 | public void removeChangeListener(ChangeListener listener){ |
@@ -312,6 +320,7 @@ public class FilterPanel extends JDialog | ||
312 | 320 | |
313 | 321 | /** |
314 | 322 | * 全リスナを取得する。 |
323 | + * | |
315 | 324 | * @return リスナの配列 |
316 | 325 | */ |
317 | 326 | public ChangeListener[] getChangeListeners(){ |
@@ -344,8 +353,10 @@ public class FilterPanel extends JDialog | ||
344 | 353 | } |
345 | 354 | |
346 | 355 | /** |
347 | - * チェックボックスまたはボタン操作時にリスナとして呼ばれる。 | |
348 | 356 | * {@inheritDoc} |
357 | + * | |
358 | + * <p>チェックボックスまたはボタン操作時にリスナとして呼ばれる。 | |
359 | + * | |
349 | 360 | * @param event イベント |
350 | 361 | */ |
351 | 362 | @Override |
@@ -407,6 +418,7 @@ public class FilterPanel extends JDialog | ||
407 | 418 | |
408 | 419 | /** |
409 | 420 | * {@inheritDoc} |
421 | + * | |
410 | 422 | * @param topic {@inheritDoc} |
411 | 423 | * @return {@inheritDoc} |
412 | 424 | */ |
@@ -462,6 +474,7 @@ public class FilterPanel extends JDialog | ||
462 | 474 | |
463 | 475 | /** |
464 | 476 | * {@inheritDoc} |
477 | + * | |
465 | 478 | * @return {@inheritDoc} |
466 | 479 | */ |
467 | 480 | @Override |
@@ -471,6 +484,7 @@ public class FilterPanel extends JDialog | ||
471 | 484 | |
472 | 485 | /** |
473 | 486 | * {@inheritDoc} |
487 | + * | |
474 | 488 | * @param context {@inheritDoc} |
475 | 489 | * @return {@inheritDoc} |
476 | 490 | */ |
@@ -520,6 +534,7 @@ public class FilterPanel extends JDialog | ||
520 | 534 | |
521 | 535 | /** |
522 | 536 | * {@inheritDoc} |
537 | + * | |
523 | 538 | * @return {@inheritDoc} |
524 | 539 | */ |
525 | 540 | @Override |
@@ -10,7 +10,7 @@ package jp.sfjp.jindolf.view; | ||
10 | 10 | import java.awt.BorderLayout; |
11 | 11 | import java.awt.Component; |
12 | 12 | import java.awt.Container; |
13 | -import java.awt.Frame; | |
13 | +import java.awt.Dialog; | |
14 | 14 | import java.awt.GridBagConstraints; |
15 | 15 | import java.awt.GridBagLayout; |
16 | 16 | import java.awt.GridLayout; |
@@ -64,7 +64,7 @@ import jp.sourceforge.jovsonz.JsValue; | ||
64 | 64 | * 検索パネルGUI。 |
65 | 65 | */ |
66 | 66 | @SuppressWarnings("serial") |
67 | -public class FindPanel extends JDialog | |
67 | +public final class FindPanel extends JDialog | |
68 | 68 | implements ActionListener, |
69 | 69 | ItemListener, |
70 | 70 | ChangeListener, |
@@ -76,6 +76,7 @@ public class FindPanel extends JDialog | ||
76 | 76 | private static final String LABEL_REENTER = "再入力"; |
77 | 77 | private static final String LABEL_IGNORE = "無視して検索をキャンセル"; |
78 | 78 | |
79 | + | |
79 | 80 | private final JComboBox<Object> findBox = new JComboBox<>(); |
80 | 81 | private final JButton searchButton = new JButton("検索"); |
81 | 82 | private final JButton clearButton = new JButton("クリア"); |
@@ -99,13 +100,15 @@ public class FindPanel extends JDialog | ||
99 | 100 | private boolean canceled = false; |
100 | 101 | private RegexPattern regexPattern = null; |
101 | 102 | |
103 | + | |
102 | 104 | /** |
103 | 105 | * 検索パネルを生成する。 |
104 | - * @param owner 親フレーム。 | |
105 | 106 | */ |
106 | 107 | @SuppressWarnings("LeakingThisInConstructor") |
107 | - public FindPanel(Frame owner){ | |
108 | - super(owner); | |
108 | + public FindPanel(){ | |
109 | + super((Dialog)null); | |
110 | + // We need unowned dialog | |
111 | + | |
109 | 112 | setModal(true); |
110 | 113 | |
111 | 114 | GUIUtils.modifyWindowAttributes(this, true, false, true); |
@@ -145,6 +148,7 @@ public class FindPanel extends JDialog | ||
145 | 148 | return; |
146 | 149 | } |
147 | 150 | |
151 | + | |
148 | 152 | /** |
149 | 153 | * デザイン・レイアウトを行う。 |
150 | 154 | */ |
@@ -225,7 +229,9 @@ public class FindPanel extends JDialog | ||
225 | 229 | |
226 | 230 | /** |
227 | 231 | * {@inheritDoc} |
228 | - * 検索ダイアログを表示・非表示する。 | |
232 | + * | |
233 | + * <p>検索ダイアログを表示・非表示する。 | |
234 | + * | |
229 | 235 | * @param show 表示フラグ。真なら表示。{@inheritDoc} |
230 | 236 | */ |
231 | 237 | @Override |
@@ -238,6 +244,7 @@ public class FindPanel extends JDialog | ||
238 | 244 | |
239 | 245 | /** |
240 | 246 | * ダイアログが閉じられた原因を判定する。 |
247 | + * | |
241 | 248 | * @return キャンセルもしくはクローズボタンでダイアログが閉じられたらtrue |
242 | 249 | */ |
243 | 250 | public boolean isCanceled(){ |
@@ -246,6 +253,7 @@ public class FindPanel extends JDialog | ||
246 | 253 | |
247 | 254 | /** |
248 | 255 | * 一括検索が指定されたか否か返す。 |
256 | + * | |
249 | 257 | * @return 一括検索が指定されたらtrue |
250 | 258 | */ |
251 | 259 | public boolean isBulkSearch(){ |
@@ -254,7 +262,8 @@ public class FindPanel extends JDialog | ||
254 | 262 | |
255 | 263 | /** |
256 | 264 | * キャンセルボタン押下処理。 |
257 | - * このモーダルダイアログを閉じる。 | |
265 | + * | |
266 | + * <p>このモーダルダイアログを閉じる。 | |
258 | 267 | */ |
259 | 268 | private void actionCancel(){ |
260 | 269 | this.canceled = true; |
@@ -265,7 +274,8 @@ public class FindPanel extends JDialog | ||
265 | 274 | |
266 | 275 | /** |
267 | 276 | * 検索ボタン押下処理。 |
268 | - * このモーダルダイアログを閉じる。 | |
277 | + * | |
278 | + * <p>このモーダルダイアログを閉じる。 | |
269 | 279 | */ |
270 | 280 | private void actionSubmit(){ |
271 | 281 | Object selected = this.findBox.getSelectedItem(); |
@@ -306,6 +316,7 @@ public class FindPanel extends JDialog | ||
306 | 316 | |
307 | 317 | /** |
308 | 318 | * 正規表現パターン異常系のダイアログ表示。 |
319 | + * | |
309 | 320 | * @param e 正規表現構文エラー |
310 | 321 | * @return 再入力が押されたらtrue。それ以外はfalse。 |
311 | 322 | */ |
@@ -356,6 +367,7 @@ public class FindPanel extends JDialog | ||
356 | 367 | |
357 | 368 | /** |
358 | 369 | * 現時点での検索パターンを得る。 |
370 | + * | |
359 | 371 | * @return 検索パターン |
360 | 372 | */ |
361 | 373 | public RegexPattern getRegexPattern(){ |
@@ -364,6 +376,7 @@ public class FindPanel extends JDialog | ||
364 | 376 | |
365 | 377 | /** |
366 | 378 | * 検索パターンを設定する。 |
379 | + * | |
367 | 380 | * @param pattern 検索パターン |
368 | 381 | */ |
369 | 382 | public final void setRegexPattern(RegexPattern pattern){ |
@@ -388,7 +401,9 @@ public class FindPanel extends JDialog | ||
388 | 401 | |
389 | 402 | /** |
390 | 403 | * {@inheritDoc} |
391 | - * ボタン操作時にリスナとして呼ばれる。 | |
404 | + * | |
405 | + * <p>ボタン操作時にリスナとして呼ばれる。 | |
406 | + * | |
392 | 407 | * @param event イベント {@inheritDoc} |
393 | 408 | */ |
394 | 409 | @Override |
@@ -407,7 +422,9 @@ public class FindPanel extends JDialog | ||
407 | 422 | |
408 | 423 | /** |
409 | 424 | * {@inheritDoc} |
410 | - * コンボボックスのアイテム選択リスナ。 | |
425 | + * | |
426 | + * <p>コンボボックスのアイテム選択リスナ。 | |
427 | + * | |
411 | 428 | * @param event アイテム選択イベント {@inheritDoc} |
412 | 429 | */ |
413 | 430 | @Override |
@@ -426,7 +443,9 @@ public class FindPanel extends JDialog | ||
426 | 443 | |
427 | 444 | /** |
428 | 445 | * {@inheritDoc} |
429 | - * チェックボックス操作のリスナ。 | |
446 | + * | |
447 | + * <p>チェックボックス操作のリスナ。 | |
448 | + * | |
430 | 449 | * @param event チェックボックス操作イベント {@inheritDoc} |
431 | 450 | */ |
432 | 451 | @Override |
@@ -448,7 +467,9 @@ public class FindPanel extends JDialog | ||
448 | 467 | |
449 | 468 | /** |
450 | 469 | * {@inheritDoc} |
451 | - * コンボボックスのUI変更通知を受け取るリスナ。 | |
470 | + * | |
471 | + * <p>コンボボックスのUI変更通知を受け取るリスナ。 | |
472 | + * | |
452 | 473 | * @param event UI差し替えイベント {@inheritDoc} |
453 | 474 | */ |
454 | 475 | @Override |
@@ -464,7 +485,9 @@ public class FindPanel extends JDialog | ||
464 | 485 | |
465 | 486 | /** |
466 | 487 | * コンボボックスエディタを修飾する。 |
467 | - * マージン修飾と等幅フォントをいじる。 | |
488 | + * | |
489 | + * <p>マージン修飾と等幅フォントをいじる。 | |
490 | + * | |
468 | 491 | * @param editor エディタ |
469 | 492 | */ |
470 | 493 | private void modifyComboBoxEditor(ComboBoxEditor editor){ |
@@ -485,6 +508,7 @@ public class FindPanel extends JDialog | ||
485 | 508 | |
486 | 509 | /** |
487 | 510 | * JSON形式の検索履歴情報を返す。 |
511 | + * | |
488 | 512 | * @return JSON形式の検索履歴情報 |
489 | 513 | */ |
490 | 514 | public JsObject getJson(){ |
@@ -506,6 +530,7 @@ public class FindPanel extends JDialog | ||
506 | 530 | |
507 | 531 | /** |
508 | 532 | * JSON形式の検索履歴を反映させる。 |
533 | + * | |
509 | 534 | * @param root JSON形式の検索履歴。nullが来たら何もしない |
510 | 535 | */ |
511 | 536 | public void putJson(JsObject root){ |
@@ -530,6 +555,7 @@ public class FindPanel extends JDialog | ||
530 | 555 | |
531 | 556 | /** |
532 | 557 | * 起動時の履歴設定と等価か判定する。 |
558 | + * | |
533 | 559 | * @param conf 比較対象 |
534 | 560 | * @return 等価ならtrue |
535 | 561 | */ |
@@ -555,6 +581,7 @@ public class FindPanel extends JDialog | ||
555 | 581 | |
556 | 582 | /** |
557 | 583 | * {@inheritDoc} |
584 | + * | |
558 | 585 | * @param list {@inheritDoc} |
559 | 586 | * @param value {@inheritDoc} |
560 | 587 | * @param index {@inheritDoc} |
@@ -647,6 +674,7 @@ public class FindPanel extends JDialog | ||
647 | 674 | |
648 | 675 | /** |
649 | 676 | * {@inheritDoc} |
677 | + * | |
650 | 678 | * @return {@inheritDoc} |
651 | 679 | */ |
652 | 680 | @Override |
@@ -656,6 +684,7 @@ public class FindPanel extends JDialog | ||
656 | 684 | |
657 | 685 | /** |
658 | 686 | * {@inheritDoc} |
687 | + * | |
659 | 688 | * @param item {@inheritDoc} |
660 | 689 | */ |
661 | 690 | @Override |
@@ -667,6 +696,7 @@ public class FindPanel extends JDialog | ||
667 | 696 | |
668 | 697 | /** |
669 | 698 | * {@inheritDoc} |
699 | + * | |
670 | 700 | * @param index {@inheritDoc} |
671 | 701 | * @return {@inheritDoc} |
672 | 702 | */ |
@@ -698,6 +728,7 @@ public class FindPanel extends JDialog | ||
698 | 728 | |
699 | 729 | /** |
700 | 730 | * {@inheritDoc} |
731 | + * | |
701 | 732 | * @return {@inheritDoc} |
702 | 733 | */ |
703 | 734 | @Override |
@@ -712,6 +743,7 @@ public class FindPanel extends JDialog | ||
712 | 743 | |
713 | 744 | /** |
714 | 745 | * {@inheritDoc} |
746 | + * | |
715 | 747 | * @param listener {@inheritDoc} |
716 | 748 | */ |
717 | 749 | @Override |
@@ -722,6 +754,7 @@ public class FindPanel extends JDialog | ||
722 | 754 | |
723 | 755 | /** |
724 | 756 | * {@inheritDoc} |
757 | + * | |
725 | 758 | * @param listener {@inheritDoc} |
726 | 759 | */ |
727 | 760 | @Override |
@@ -732,6 +765,7 @@ public class FindPanel extends JDialog | ||
732 | 765 | |
733 | 766 | /** |
734 | 767 | * 検索履歴ヒストリ追加。 |
768 | + * | |
735 | 769 | * @param regexPattern 検索履歴 |
736 | 770 | */ |
737 | 771 | public void addHistory(RegexPattern regexPattern){ |
@@ -755,6 +789,7 @@ public class FindPanel extends JDialog | ||
755 | 789 | |
756 | 790 | /** |
757 | 791 | * プリセットでない検索ヒストリリストを返す。 |
792 | + * | |
758 | 793 | * @return 検索ヒストリリスト |
759 | 794 | */ |
760 | 795 | public List<RegexPattern> getOriginalHistoryList(){ |
@@ -41,7 +41,7 @@ import jp.sfjp.jindolf.util.GUIUtils; | ||
41 | 41 | * ヘルプ画面。 |
42 | 42 | */ |
43 | 43 | @SuppressWarnings("serial") |
44 | -public class HelpFrame extends JFrame | |
44 | +public final class HelpFrame extends JFrame | |
45 | 45 | implements ActionListener, HyperlinkListener{ |
46 | 46 | |
47 | 47 | private static final String HELP_HTML = "resources/html/help.html"; |
@@ -172,7 +172,7 @@ public class HelpFrame extends JFrame | ||
172 | 172 | |
173 | 173 | if(configStore.useStoreFile()){ |
174 | 174 | info.append("設定格納ディレクトリ : ") |
175 | - .append(configStore.getConfigDir().getPath()); | |
175 | + .append(configStore.getConfigDir().toString()); | |
176 | 176 | }else{ |
177 | 177 | info.append("※ 設定格納ディレクトリは使っていません。"); |
178 | 178 | } |
@@ -8,10 +8,7 @@ | ||
8 | 8 | package jp.sfjp.jindolf.view; |
9 | 9 | |
10 | 10 | import java.awt.BorderLayout; |
11 | -import java.awt.EventQueue; | |
12 | 11 | import java.awt.Insets; |
13 | -import java.awt.event.ActionEvent; | |
14 | -import java.awt.event.ActionListener; | |
15 | 12 | import javax.swing.BorderFactory; |
16 | 13 | import javax.swing.Icon; |
17 | 14 | import javax.swing.JButton; |
@@ -22,7 +19,6 @@ import javax.swing.JToolBar; | ||
22 | 19 | import javax.swing.JTree; |
23 | 20 | import javax.swing.border.Border; |
24 | 21 | import javax.swing.event.TreeSelectionEvent; |
25 | -import javax.swing.event.TreeSelectionListener; | |
26 | 22 | import javax.swing.tree.TreeModel; |
27 | 23 | import javax.swing.tree.TreePath; |
28 | 24 | import javax.swing.tree.TreeSelectionModel; |
@@ -32,56 +28,93 @@ import jp.sfjp.jindolf.data.LandsTreeModel; | ||
32 | 28 | |
33 | 29 | /** |
34 | 30 | * 国一覧Tree周辺コンポーネント群。 |
31 | + * | |
32 | + * <p>昇順/降順トグルボタン、村一覧リロードボタン、 | |
33 | + * 人狼BBSサーバ国および村一覧ツリーから構成される。 | |
35 | 34 | */ |
36 | 35 | @SuppressWarnings("serial") |
37 | -public class LandsTree | |
38 | - extends JPanel | |
39 | - implements ActionListener, TreeSelectionListener{ | |
36 | +public class LandsTree extends JPanel{ | |
37 | + | |
38 | + private static final String TIP_ASCEND = | |
39 | + "押すと降順に"; | |
40 | + private static final String TIP_DESCEND = | |
41 | + "押すと昇順に"; | |
42 | + private static final String TIP_ORDER = | |
43 | + "選択中の国の村一覧を読み込み直す"; | |
44 | + | |
45 | + private static final String RES_DIR = "resources/image/"; | |
46 | + private static final String RES_ASCEND = RES_DIR + "tb_ascend.png"; | |
47 | + private static final String RES_DESCEND = RES_DIR + "tb_descend.png"; | |
48 | + private static final String RES_RELOAD = RES_DIR + "tb_reload.png"; | |
40 | 49 | |
41 | - private static final String TIP_ASCEND = "押すと降順に"; | |
42 | - private static final String TIP_DESCEND = "押すと昇順に"; | |
43 | - private static final String TIP_ORDER = "選択中の国の村一覧を読み込み直す"; | |
44 | 50 | private static final Icon ICON_ASCEND; |
45 | 51 | private static final Icon ICON_DESCEND; |
52 | + private static final Icon ICON_RELOAD; | |
46 | 53 | |
47 | 54 | static{ |
48 | - ICON_ASCEND = | |
49 | - ResourceManager.getButtonIcon("resources/image/tb_ascend.png"); | |
50 | - ICON_DESCEND = | |
51 | - ResourceManager.getButtonIcon("resources/image/tb_descend.png"); | |
55 | + ICON_ASCEND = ResourceManager.getButtonIcon(RES_ASCEND); | |
56 | + ICON_DESCEND = ResourceManager.getButtonIcon(RES_DESCEND); | |
57 | + ICON_RELOAD = ResourceManager.getButtonIcon(RES_RELOAD); | |
52 | 58 | } |
53 | 59 | |
54 | - private final JButton orderButton = new JButton(); | |
55 | - private final JButton reloadButton = new JButton(); | |
56 | - private final JTree treeView = new JTree(); | |
60 | + | |
61 | + private final JButton orderButton; | |
62 | + private final JButton reloadButton; | |
63 | + private final JTree treeView; | |
57 | 64 | |
58 | 65 | private boolean ascending = false; |
59 | 66 | |
67 | + | |
60 | 68 | /** |
61 | 69 | * コンストラクタ。 |
62 | 70 | */ |
63 | - @SuppressWarnings("LeakingThisInConstructor") | |
64 | 71 | public LandsTree(){ |
65 | 72 | super(); |
66 | 73 | |
74 | + this.orderButton = new JButton(); | |
75 | + this.reloadButton = new JButton(); | |
76 | + this.treeView = new JTree(); | |
77 | + | |
78 | + TreeSelectionModel selModel = this.treeView.getSelectionModel(); | |
79 | + selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); | |
80 | + | |
81 | + setupObserver(); | |
82 | + | |
83 | + decorateButtons(); | |
67 | 84 | design(); |
68 | 85 | |
86 | + return; | |
87 | + } | |
88 | + | |
89 | + | |
90 | + /** | |
91 | + * 各種監視Observerの登録。 | |
92 | + */ | |
93 | + private void setupObserver(){ | |
94 | + this.orderButton.addActionListener((ev) -> { | |
95 | + toggleTreeOrder(); | |
96 | + }); | |
97 | + | |
98 | + this.treeView.addTreeSelectionListener((ev) -> { | |
99 | + updateReloadButton(ev); | |
100 | + }); | |
101 | + | |
102 | + this.reloadButton.setActionCommand(ActionManager.CMD_VILLAGELIST); | |
103 | + | |
104 | + return; | |
105 | + } | |
106 | + | |
107 | + /** | |
108 | + * ボタン群を装飾する。 | |
109 | + */ | |
110 | + private void decorateButtons(){ | |
69 | 111 | this.orderButton.setIcon(ICON_DESCEND); |
70 | 112 | this.orderButton.setToolTipText(TIP_DESCEND); |
71 | 113 | this.orderButton.setMargin(new Insets(1, 1, 1, 1)); |
72 | - this.orderButton.setActionCommand(ActionManager.CMD_SWITCHORDER); | |
73 | - this.orderButton.addActionListener(this); | |
74 | 114 | |
75 | - Icon icon = ResourceManager | |
76 | - .getButtonIcon("resources/image/tb_reload.png"); | |
77 | - this.reloadButton.setIcon(icon); | |
115 | + this.reloadButton.setIcon(ICON_RELOAD); | |
78 | 116 | this.reloadButton.setToolTipText(TIP_ORDER); |
79 | 117 | this.reloadButton.setMargin(new Insets(1, 1, 1, 1)); |
80 | - this.reloadButton.setActionCommand(ActionManager.CMD_VILLAGELIST); | |
81 | - | |
82 | - TreeSelectionModel selModel = this.treeView.getSelectionModel(); | |
83 | - selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); | |
84 | - this.treeView.addTreeSelectionListener(this); | |
85 | 118 | |
86 | 119 | return; |
87 | 120 | } |
@@ -94,6 +127,7 @@ public class LandsTree | ||
94 | 127 | setLayout(layout); |
95 | 128 | |
96 | 129 | JToolBar toolBar = new JToolBar(); |
130 | + toolBar.setFloatable(false); | |
97 | 131 | toolBar.add(this.orderButton); |
98 | 132 | toolBar.add(this.reloadButton); |
99 | 133 |
@@ -107,6 +141,7 @@ public class LandsTree | ||
107 | 141 | |
108 | 142 | /** |
109 | 143 | * 国村選択ツリーコンポーネントを生成する。 |
144 | + * | |
110 | 145 | * @return 国村選択ツリーコンポーネント |
111 | 146 | */ |
112 | 147 | private JComponent createLandSelector(){ |
@@ -123,6 +158,7 @@ public class LandsTree | ||
123 | 158 | |
124 | 159 | /** |
125 | 160 | * リロードボタンを返す。 |
161 | + * | |
126 | 162 | * @return リロードボタン |
127 | 163 | */ |
128 | 164 | public JButton getReloadVillageListButton(){ |
@@ -131,6 +167,7 @@ public class LandsTree | ||
131 | 167 | |
132 | 168 | /** |
133 | 169 | * 国村選択ツリービューを返す。 |
170 | + * | |
134 | 171 | * @return 国村選択ツリービュー |
135 | 172 | */ |
136 | 173 | public JTree getTreeView(){ |
@@ -138,7 +175,10 @@ public class LandsTree | ||
138 | 175 | } |
139 | 176 | |
140 | 177 | /** |
141 | - * 指定した国を展開する。 | |
178 | + * 指定した国をツリー展開する。 | |
179 | + * | |
180 | + * <p>セクション一覧が国の下にツリー展開される。 | |
181 | + * | |
142 | 182 | * @param land 国 |
143 | 183 | */ |
144 | 184 | public void expandLand(Land land){ |
@@ -152,6 +192,7 @@ public class LandsTree | ||
152 | 192 | |
153 | 193 | /** |
154 | 194 | * 管理下のLandsTreeModelを返す。 |
195 | + * | |
155 | 196 | * @return LandsTreeModel |
156 | 197 | */ |
157 | 198 | private LandsTreeModel getLandsModel(){ |
@@ -164,74 +205,61 @@ public class LandsTree | ||
164 | 205 | |
165 | 206 | /** |
166 | 207 | * Tree表示順を反転させる。 |
208 | + * | |
209 | + * <p>昇順/降順ボタンも表示が切り替わる。 | |
210 | + * | |
211 | + * <p>選択中のツリー要素があれば選択は保持される。 | |
212 | + * | |
167 | 213 | * @return 反転後が昇順ならtrue |
168 | 214 | */ |
169 | 215 | private boolean toggleTreeOrder(){ |
170 | 216 | this.ascending = ! this.ascending; |
171 | 217 | |
218 | + String newTip; | |
219 | + Icon newIcon; | |
172 | 220 | if(this.ascending){ |
173 | - this.orderButton.setToolTipText(TIP_ASCEND); | |
174 | - this.orderButton.setIcon(ICON_ASCEND); | |
221 | + newTip = TIP_ASCEND; | |
222 | + newIcon = ICON_ASCEND; | |
175 | 223 | }else{ |
176 | - this.orderButton.setToolTipText(TIP_DESCEND); | |
177 | - this.orderButton.setIcon(ICON_DESCEND); | |
224 | + newTip = TIP_DESCEND; | |
225 | + newIcon = ICON_DESCEND; | |
178 | 226 | } |
227 | + this.orderButton.setToolTipText(newTip); | |
228 | + this.orderButton.setIcon(newIcon); | |
179 | 229 | |
180 | - final TreePath lastPath = this.treeView.getSelectionPath(); | |
230 | + TreePath lastPath = this.treeView.getSelectionPath(); | |
181 | 231 | |
182 | 232 | LandsTreeModel model = getLandsModel(); |
183 | 233 | if(model != null){ |
184 | 234 | model.setAscending(this.ascending); |
185 | 235 | } |
186 | 236 | |
187 | - EventQueue.invokeLater(new Runnable(){ | |
188 | - @Override | |
189 | - public void run(){ | |
190 | - if(lastPath != null){ | |
191 | - LandsTree.this.treeView.setSelectionPath(lastPath); | |
192 | - LandsTree.this.treeView.scrollPathToVisible(lastPath); | |
193 | - } | |
194 | - return; | |
195 | - } | |
196 | - }); | |
237 | + if(lastPath != null){ | |
238 | + this.treeView.setSelectionPath(lastPath); | |
239 | + this.treeView.scrollPathToVisible(lastPath); | |
240 | + } | |
197 | 241 | |
198 | 242 | return this.ascending; |
199 | 243 | } |
200 | 244 | |
201 | 245 | /** |
202 | - * {@inheritDoc} | |
203 | - * ボタン押下処理。 | |
204 | - * @param event ボタン押下イベント {@inheritDoc} | |
246 | + * ツリー選択状況によってリロードボタンの状態を変更する。 | |
247 | + * | |
248 | + * <p>国がツリー選択された状況でのみリロードボタンは有効になる。 | |
249 | + * その他の状況では無効に。 | |
250 | + * | |
251 | + * @param event ツリー選択状況 | |
205 | 252 | */ |
206 | - @Override | |
207 | - public void actionPerformed(ActionEvent event){ | |
208 | - String cmd = event.getActionCommand(); | |
209 | - if(ActionManager.CMD_SWITCHORDER.equals(cmd)){ | |
210 | - toggleTreeOrder(); | |
211 | - } | |
212 | - return; | |
213 | - } | |
253 | + private void updateReloadButton(TreeSelectionEvent event){ | |
254 | + boolean reloadEnable = false; | |
214 | 255 | |
215 | - /** | |
216 | - * {@inheritDoc} | |
217 | - * ツリーリストで何らかの要素(国、村)がクリックされたときの処理。 | |
218 | - * @param event イベント {@inheritDoc} | |
219 | - */ | |
220 | - @Override | |
221 | - public void valueChanged(TreeSelectionEvent event){ | |
222 | 256 | TreePath path = event.getNewLeadSelectionPath(); |
223 | - if(path == null){ | |
224 | - this.reloadButton.setEnabled(false); | |
225 | - return; | |
257 | + if(path != null){ | |
258 | + Object selObj = path.getLastPathComponent(); | |
259 | + if(selObj instanceof Land) reloadEnable = true; | |
226 | 260 | } |
227 | 261 | |
228 | - Object selObj = path.getLastPathComponent(); | |
229 | - | |
230 | - if( selObj instanceof Land ){ | |
231 | - this.reloadButton.setEnabled(true); | |
232 | - }else{ | |
233 | - this.reloadButton.setEnabled(false); | |
234 | - } | |
262 | + this.reloadButton.setEnabled(reloadEnable); | |
235 | 263 | |
236 | 264 | return; |
237 | 265 | } |
@@ -7,75 +7,74 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.jindolf.view; |
9 | 9 | |
10 | -import java.awt.Component; | |
11 | -import java.awt.HeadlessException; | |
12 | -import java.awt.event.ActionEvent; | |
13 | -import java.awt.event.ActionListener; | |
10 | +import java.nio.file.Path; | |
11 | +import java.text.MessageFormat; | |
14 | 12 | import javax.swing.ButtonGroup; |
15 | -import javax.swing.JButton; | |
16 | -import javax.swing.JDialog; | |
17 | 13 | import javax.swing.JOptionPane; |
18 | 14 | import javax.swing.JRadioButton; |
19 | 15 | import jp.sfjp.jindolf.config.FileUtils; |
20 | -import jp.sfjp.jindolf.config.InterVMLock; | |
21 | 16 | |
22 | 17 | /** |
23 | 18 | * ロックエラー用ダイアログ。 |
19 | + * | |
24 | 20 | * <ul> |
25 | - * <li>強制解除 | |
21 | + * <li>ロックの強制解除を試行 | |
26 | 22 | * <li>リトライ |
27 | - * <li>設定ディレクトリを無視 | |
23 | + * <li>設定ディレクトリを無視して続行 | |
28 | 24 | * <li>起動中止 |
29 | 25 | * </ul> |
30 | - * の選択を利用者に求める。 | |
26 | + * | |
27 | + * <p>の選択を利用者に求める。 | |
31 | 28 | */ |
32 | 29 | @SuppressWarnings("serial") |
33 | -public class LockErrorPane extends JOptionPane implements ActionListener{ | |
34 | - | |
35 | - private final InterVMLock lock; | |
30 | +public final class LockErrorPane extends JOptionPane{ | |
36 | 31 | |
37 | - private final JRadioButton continueButton = | |
38 | - new JRadioButton("設定ディレクトリを使わずに起動を続行"); | |
39 | - private final JRadioButton retryButton = | |
40 | - new JRadioButton("再度ロック取得を試す"); | |
41 | - private final JRadioButton forceButton = | |
42 | - new JRadioButton( | |
32 | + private static final String FORM_MAIN = | |
43 | 33 | "<html>" |
44 | - + "ロックを強制解除<br>" | |
34 | + + "設定ディレクトリのロックファイル<br/>" | |
35 | + + "<center>[ {0} ]</center>" | |
36 | + + "<br/>" | |
37 | + + "のロックに失敗しました。<br/>" | |
38 | + + "考えられる原因としては、<br/>" | |
39 | + + "<ul>" | |
40 | + + "<li>前回起動したJindolfの終了が正しく行われなかった" | |
41 | + + "<li>今どこかで他のJindolfが動いている" | |
42 | + + "</ul>" | |
43 | + + "などが考えられます。<br/>" | |
44 | + + "<hr/>" | |
45 | + + "</html>"; | |
46 | + | |
47 | + private static final String LABEL_CONTINUE = | |
48 | + "設定ディレクトリを使わずに起動を続行"; | |
49 | + private static final String LABEL_RETRY = | |
50 | + "再度ロック取得を試す"; | |
51 | + private static final String LABEL_FORCE = | |
52 | + "<html>" | |
53 | + + "ロックを強制解除<br/>" | |
45 | 54 | + " (※他のJindolfと設定ファイル書き込みが衝突するかも…)" |
46 | - + "</html>"); | |
55 | + + "</html>"; | |
56 | + | |
57 | + private static final String LABEL_OK = "OK"; | |
58 | + private static final String LABEL_ABORT = "起動中止"; | |
59 | + private static final String[] OPTIONS = {LABEL_OK, LABEL_ABORT}; | |
47 | 60 | |
48 | - private final JButton okButton = new JButton("OK"); | |
49 | - private final JButton abortButton = new JButton("起動中止"); | |
50 | 61 | |
51 | - private boolean aborted = false; | |
62 | + private final JRadioButton continueButton; | |
63 | + private final JRadioButton retryButton; | |
64 | + private final JRadioButton forceButton; | |
65 | + | |
52 | 66 | |
53 | 67 | /** |
54 | 68 | * コンストラクタ。 |
55 | - * @param lock 失敗したロック | |
69 | + * | |
70 | + * @param lockFile ロックに失敗したファイル | |
56 | 71 | */ |
57 | - @SuppressWarnings("LeakingThisInConstructor") | |
58 | - public LockErrorPane(InterVMLock lock){ | |
72 | + public LockErrorPane(Path lockFile){ | |
59 | 73 | super(); |
60 | 74 | |
61 | - this.lock = lock; | |
62 | - | |
63 | - String htmlMessage = | |
64 | - "<html>" | |
65 | - + "設定ディレクトリのロックファイル<br>" | |
66 | - + "<center>[ " | |
67 | - + FileUtils.getHtmledFileName(this.lock.getLockFile()) | |
68 | - + " ]</center>" | |
69 | - + "<br>" | |
70 | - + "のロックに失敗しました。<br>" | |
71 | - + "考えられる原因としては、<br>" | |
72 | - + "<ul>" | |
73 | - + "<li>前回起動したJindolfの終了が正しく行われなかった" | |
74 | - + "<li>今どこかで他のJindolfが動いている" | |
75 | - + "</ul>" | |
76 | - + "などが考えられます。<br>" | |
77 | - + "<hr>" | |
78 | - + "</html>"; | |
75 | + this.continueButton = new JRadioButton(LABEL_CONTINUE); | |
76 | + this.retryButton = new JRadioButton(LABEL_RETRY); | |
77 | + this.forceButton = new JRadioButton(LABEL_FORCE); | |
79 | 78 | |
80 | 79 | ButtonGroup bgrp = new ButtonGroup(); |
81 | 80 | bgrp.add(this.continueButton); |
@@ -83,30 +82,40 @@ public class LockErrorPane extends JOptionPane implements ActionListener{ | ||
83 | 82 | bgrp.add(this.forceButton); |
84 | 83 | this.continueButton.setSelected(true); |
85 | 84 | |
85 | + String lockName = FileUtils.getHtmledFileName(lockFile); | |
86 | + String htmlMessage = MessageFormat.format(FORM_MAIN, lockName); | |
87 | + | |
86 | 88 | Object[] msg = { |
87 | 89 | htmlMessage, |
88 | 90 | this.continueButton, |
89 | 91 | this.retryButton, |
90 | 92 | this.forceButton, |
91 | 93 | }; |
92 | - setMessage(msg); | |
93 | - | |
94 | - Object[] opts = { | |
95 | - this.okButton, | |
96 | - this.abortButton, | |
97 | - }; | |
98 | - setOptions(opts); | |
99 | 94 | |
95 | + setMessage(msg); | |
96 | + setOptions(OPTIONS); | |
100 | 97 | setMessageType(JOptionPane.ERROR_MESSAGE); |
101 | 98 | |
102 | - this.okButton .addActionListener(this); | |
103 | - this.abortButton.addActionListener(this); | |
104 | - | |
105 | 99 | return; |
106 | 100 | } |
107 | 101 | |
102 | + | |
103 | + /** | |
104 | + * 「起動中止」が選択されたか判定する。 | |
105 | + * | |
106 | + * @param value ダイアログ結果 | |
107 | + * @return 「起動中止」が押されていたならtrue | |
108 | + * @see JOptionPane#getValue() | |
109 | + */ | |
110 | + public static boolean isAborted(Object value){ | |
111 | + boolean flag = LABEL_ABORT.equals(value); | |
112 | + return flag; | |
113 | + } | |
114 | + | |
115 | + | |
108 | 116 | /** |
109 | 117 | * 「設定ディレクトリを無視して続行」が選択されたか判定する。 |
118 | + * | |
110 | 119 | * @return 「無視して続行」が選択されていればtrue |
111 | 120 | */ |
112 | 121 | public boolean isRadioContinue(){ |
@@ -115,6 +124,7 @@ public class LockErrorPane extends JOptionPane implements ActionListener{ | ||
115 | 124 | |
116 | 125 | /** |
117 | 126 | * 「リトライ」が選択されたか判定する。 |
127 | + * | |
118 | 128 | * @return 「リトライ」が選択されていればtrue |
119 | 129 | */ |
120 | 130 | public boolean isRadioRetry(){ |
@@ -123,58 +133,11 @@ public class LockErrorPane extends JOptionPane implements ActionListener{ | ||
123 | 133 | |
124 | 134 | /** |
125 | 135 | * 「強制解除」が選択されたか判定する。 |
136 | + * | |
126 | 137 | * @return 「強制解除」が選択されていればtrue |
127 | 138 | */ |
128 | 139 | public boolean isRadioForce(){ |
129 | 140 | return this.forceButton.isSelected(); |
130 | 141 | } |
131 | 142 | |
132 | - /** | |
133 | - * 「起動中止」が選択されたか判定する。 | |
134 | - * @return 「起動中止」が押されていたならtrue | |
135 | - */ | |
136 | - public boolean isAborted(){ | |
137 | - return this.aborted; | |
138 | - } | |
139 | - | |
140 | - /** | |
141 | - * {@inheritDoc} | |
142 | - * @param parentComponent {@inheritDoc} | |
143 | - * @param title {@inheritDoc} | |
144 | - * @return {@inheritDoc} | |
145 | - * @throws HeadlessException {@inheritDoc} | |
146 | - */ | |
147 | - @Override | |
148 | - public JDialog createDialog(Component parentComponent, | |
149 | - String title) | |
150 | - throws HeadlessException{ | |
151 | - final JDialog dialog = | |
152 | - super.createDialog(parentComponent, title); | |
153 | - | |
154 | - ActionListener listener = new ActionListener(){ | |
155 | - @Override | |
156 | - public void actionPerformed(ActionEvent event){ | |
157 | - dialog.setVisible(false); | |
158 | - return; | |
159 | - } | |
160 | - }; | |
161 | - | |
162 | - this.okButton .addActionListener(listener); | |
163 | - this.abortButton.addActionListener(listener); | |
164 | - | |
165 | - return dialog; | |
166 | - } | |
167 | - | |
168 | - /** | |
169 | - * ボタン押下を受信する。 | |
170 | - * @param event イベント | |
171 | - */ | |
172 | - @Override | |
173 | - public void actionPerformed(ActionEvent event){ | |
174 | - Object source = event.getSource(); | |
175 | - if(source == this.okButton) this.aborted = false; | |
176 | - else this.aborted = true; | |
177 | - return; | |
178 | - } | |
179 | - | |
180 | 143 | } |
@@ -8,7 +8,7 @@ | ||
8 | 8 | package jp.sfjp.jindolf.view; |
9 | 9 | |
10 | 10 | import java.awt.Container; |
11 | -import java.awt.Frame; | |
11 | +import java.awt.Dialog; | |
12 | 12 | import java.awt.GridBagConstraints; |
13 | 13 | import java.awt.GridBagLayout; |
14 | 14 | import java.awt.Insets; |
@@ -29,7 +29,7 @@ import jp.sfjp.jindolf.util.GUIUtils; | ||
29 | 29 | * オプション設定パネル。 |
30 | 30 | */ |
31 | 31 | @SuppressWarnings("serial") |
32 | -public class OptionPanel | |
32 | +public final class OptionPanel | |
33 | 33 | extends JDialog |
34 | 34 | implements ActionListener, WindowListener{ |
35 | 35 |
@@ -46,11 +46,12 @@ public class OptionPanel | ||
46 | 46 | |
47 | 47 | /** |
48 | 48 | * コンストラクタ。 |
49 | - * @param owner フレームオーナ | |
50 | 49 | */ |
51 | 50 | @SuppressWarnings("LeakingThisInConstructor") |
52 | - public OptionPanel(Frame owner){ | |
53 | - super(owner); | |
51 | + public OptionPanel(){ | |
52 | + super((Dialog)null); | |
53 | + // We need unowned dialog | |
54 | + | |
54 | 55 | setModal(true); |
55 | 56 | |
56 | 57 | GUIUtils.modifyWindowAttributes(this, true, false, true); |
@@ -76,6 +77,7 @@ public class OptionPanel | ||
76 | 77 | |
77 | 78 | /** |
78 | 79 | * レイアウトを行う。 |
80 | + * | |
79 | 81 | * @param content コンテナ |
80 | 82 | */ |
81 | 83 | private void design(Container content){ |
@@ -109,6 +111,7 @@ public class OptionPanel | ||
109 | 111 | |
110 | 112 | /** |
111 | 113 | * FontChooserを返す。 |
114 | + * | |
112 | 115 | * @return FontChooser |
113 | 116 | */ |
114 | 117 | public FontChooser getFontChooser(){ |
@@ -117,6 +120,7 @@ public class OptionPanel | ||
117 | 120 | |
118 | 121 | /** |
119 | 122 | * ProxyChooserを返す。 |
123 | + * | |
120 | 124 | * @return ProxyChooser |
121 | 125 | */ |
122 | 126 | public ProxyChooser getProxyChooser(){ |
@@ -125,6 +129,7 @@ public class OptionPanel | ||
125 | 129 | |
126 | 130 | /** |
127 | 131 | * DialogPrefPanelを返す。 |
132 | + * | |
128 | 133 | * @return DialogPrefPanel |
129 | 134 | */ |
130 | 135 | public DialogPrefPanel getDialogPrefPanel(){ |
@@ -133,7 +138,9 @@ public class OptionPanel | ||
133 | 138 | |
134 | 139 | /** |
135 | 140 | * ダイアログが閉じられた原因が「キャンセル」か否か判定する。 |
136 | - * ウィンドウクローズ操作は「キャンセル」扱い。 | |
141 | + * | |
142 | + * <p>ウィンドウクローズ操作は「キャンセル」扱い。 | |
143 | + * | |
137 | 144 | * @return 「キャンセル」ならtrue |
138 | 145 | */ |
139 | 146 | public boolean isCanceled(){ |
@@ -142,7 +149,8 @@ public class OptionPanel | ||
142 | 149 | |
143 | 150 | /** |
144 | 151 | * OKボタン押下処理。 |
145 | - * ダイアログを閉じる。 | |
152 | + * | |
153 | + * <p>ダイアログを閉じる。 | |
146 | 154 | */ |
147 | 155 | private void actionOk(){ |
148 | 156 | this.isCanceled = false; |
@@ -153,7 +161,8 @@ public class OptionPanel | ||
153 | 161 | |
154 | 162 | /** |
155 | 163 | * キャンセルボタン押下処理。 |
156 | - * ダイアログを閉じる。 | |
164 | + * | |
165 | + * <p>ダイアログを閉じる。 | |
157 | 166 | */ |
158 | 167 | private void actionCancel(){ |
159 | 168 | this.isCanceled = true; |
@@ -164,6 +173,7 @@ public class OptionPanel | ||
164 | 173 | |
165 | 174 | /** |
166 | 175 | * ボタン押下イベント受信。 |
176 | + * | |
167 | 177 | * @param event イベント |
168 | 178 | */ |
169 | 179 | @Override |
@@ -176,6 +186,7 @@ public class OptionPanel | ||
176 | 186 | |
177 | 187 | /** |
178 | 188 | * {@inheritDoc} |
189 | + * | |
179 | 190 | * @param event {@inheritDoc} |
180 | 191 | */ |
181 | 192 | @Override |
@@ -185,8 +196,11 @@ public class OptionPanel | ||
185 | 196 | |
186 | 197 | /** |
187 | 198 | * {@inheritDoc} |
188 | - * ダイアログを閉じる。 | |
189 | - * キャンセルボタン押下時と同じ。 | |
199 | + * | |
200 | + * <p>ダイアログを閉じる。 | |
201 | + * | |
202 | + * <p>キャンセルボタン押下時と同じ。 | |
203 | + * | |
190 | 204 | * @param event {@inheritDoc} |
191 | 205 | */ |
192 | 206 | @Override |
@@ -197,6 +211,7 @@ public class OptionPanel | ||
197 | 211 | |
198 | 212 | /** |
199 | 213 | * {@inheritDoc} |
214 | + * | |
200 | 215 | * @param event {@inheritDoc} |
201 | 216 | */ |
202 | 217 | @Override |
@@ -206,6 +221,7 @@ public class OptionPanel | ||
206 | 221 | |
207 | 222 | /** |
208 | 223 | * {@inheritDoc} |
224 | + * | |
209 | 225 | * @param event {@inheritDoc} |
210 | 226 | */ |
211 | 227 | @Override |
@@ -215,6 +231,7 @@ public class OptionPanel | ||
215 | 231 | |
216 | 232 | /** |
217 | 233 | * {@inheritDoc} |
234 | + * | |
218 | 235 | * @param event {@inheritDoc} |
219 | 236 | */ |
220 | 237 | @Override |
@@ -224,6 +241,7 @@ public class OptionPanel | ||
224 | 241 | |
225 | 242 | /** |
226 | 243 | * {@inheritDoc} |
244 | + * | |
227 | 245 | * @param event {@inheritDoc} |
228 | 246 | */ |
229 | 247 | @Override |
@@ -233,6 +251,7 @@ public class OptionPanel | ||
233 | 251 | |
234 | 252 | /** |
235 | 253 | * {@inheritDoc} |
254 | + * | |
236 | 255 | * @param event {@inheritDoc} |
237 | 256 | */ |
238 | 257 | @Override |
@@ -46,7 +46,7 @@ import jp.sfjp.jindolf.data.Village; | ||
46 | 46 | * プログレスバーとフッタメッセージの管理を行う。 |
47 | 47 | */ |
48 | 48 | @SuppressWarnings("serial") |
49 | -public class TopView extends JPanel{ | |
49 | +public final class TopView extends JPanel{ | |
50 | 50 | |
51 | 51 | private static final String INITCARD = "INITCARD"; |
52 | 52 | private static final String LANDCARD = "LANDINFO"; |
@@ -80,6 +80,7 @@ public class TopView extends JPanel{ | ||
80 | 80 | super(); |
81 | 81 | |
82 | 82 | this.cards = createCards(); |
83 | + | |
83 | 84 | JComponent split = createSplitPane(this.landsTreeView, this.cards); |
84 | 85 | JComponent statusBar = createStatusBar(); |
85 | 86 |
@@ -129,7 +130,7 @@ public class TopView extends JPanel{ | ||
129 | 130 | |
130 | 131 | StringBuilder warn = new StringBuilder(); |
131 | 132 | warn.append("※ たまにはWebブラウザでアクセスして、"); |
132 | - warn.append("<br></br>"); | |
133 | + warn.append("<br/>"); | |
133 | 134 | warn.append("運営の動向を確かめようね!"); |
134 | 135 | warn.insert(0, "<font 'size=+1'>").append("</font>"); |
135 | 136 | warn.insert(0, "<center>").append("</center>"); |
@@ -8,10 +8,10 @@ | ||
8 | 8 | package jp.sfjp.jindolf.view; |
9 | 9 | |
10 | 10 | import java.awt.EventQueue; |
11 | -import java.awt.Frame; | |
12 | 11 | import java.awt.Window; |
13 | 12 | import java.util.LinkedList; |
14 | 13 | import java.util.List; |
14 | +import javax.swing.JOptionPane; | |
15 | 15 | import javax.swing.SwingUtilities; |
16 | 16 | import javax.swing.UIManager; |
17 | 17 | import javax.swing.UnsupportedLookAndFeelException; |
@@ -22,6 +22,32 @@ import jp.sfjp.jindolf.summary.VillageDigest; | ||
22 | 22 | |
23 | 23 | /** |
24 | 24 | * ウィンドウ群の管理を行う。 |
25 | + * | |
26 | + * <p>原則として閉じても再利用されるウィンドウを管理対象とする。 | |
27 | + * | |
28 | + * <p>管理対象ウィンドウは | |
29 | + * | |
30 | + * <ul> | |
31 | + * <li>アプリのトップウィンドウ | |
32 | + * <li>検索ウィンドウ | |
33 | + * <li>フィルタウィンドウ | |
34 | + * <li>発言集計ウィンドウ | |
35 | + * <li>村プレイ記録のダイジェストウィンドウ | |
36 | + * <li>オプション設定ウィンドウ | |
37 | + * <li>ヘルプウィンドウ | |
38 | + * <li>ログウィンドウ | |
39 | + * </ul> | |
40 | + * | |
41 | + * <p>である。 | |
42 | + * | |
43 | + * <p>トップウィンドウとヘルプウィンドウは{@link javax.swing.JFrame}、 | |
44 | + * その他は{@link javax.swing.JDialog}である。 | |
45 | + * | |
46 | + * <p>非モーダルダイアログは、他のウィンドウの下側にも回れるのが望ましい。 | |
47 | + * | |
48 | + * <p>各ウィンドウは、他のウィンドウの下に完全に隠れても | |
49 | + * Windowsタスクバーなどを介して前面に引っ張り出す操作手段を | |
50 | + * 提供することが望ましい。 | |
25 | 51 | */ |
26 | 52 | public class WindowManager { |
27 | 53 |
@@ -40,8 +66,8 @@ public class WindowManager { | ||
40 | 66 | private static final String TITLE_HELP = |
41 | 67 | getFrameTitle("ヘルプ"); |
42 | 68 | |
43 | - private static final Frame NULLPARENT = null; | |
44 | 69 | |
70 | + private final TopFrame topFrame; | |
45 | 71 | |
46 | 72 | private FilterPanel filterPanel; |
47 | 73 | private LogFrame logFrame; |
@@ -50,9 +76,8 @@ public class WindowManager { | ||
50 | 76 | private VillageDigest villageDigest; |
51 | 77 | private DaySummary daySummary; |
52 | 78 | private HelpFrame helpFrame; |
53 | - private TopFrame topFrame; | |
54 | 79 | |
55 | - private final List<Window> windowSet = new LinkedList<>(); | |
80 | + private final List<Window> windowSet; | |
56 | 81 | |
57 | 82 | |
58 | 83 | /** |
@@ -60,6 +85,15 @@ public class WindowManager { | ||
60 | 85 | */ |
61 | 86 | public WindowManager(){ |
62 | 87 | super(); |
88 | + | |
89 | + this.topFrame = new TopFrame(); | |
90 | + this.topFrame.setVisible(false); | |
91 | + | |
92 | + JOptionPane.setRootFrame(this.topFrame); | |
93 | + | |
94 | + this.windowSet = new LinkedList<>(); | |
95 | + this.windowSet.add(this.topFrame); | |
96 | + | |
63 | 97 | return; |
64 | 98 | } |
65 | 99 |
@@ -84,7 +118,7 @@ public class WindowManager { | ||
84 | 118 | protected FilterPanel createFilterPanel(){ |
85 | 119 | FilterPanel result; |
86 | 120 | |
87 | - result = new FilterPanel(NULLPARENT); | |
121 | + result = new FilterPanel(); | |
88 | 122 | result.setTitle(TITLE_FILTER); |
89 | 123 | result.pack(); |
90 | 124 | result.setVisible(false); |
@@ -114,7 +148,7 @@ public class WindowManager { | ||
114 | 148 | protected LogFrame createLogFrame(){ |
115 | 149 | LogFrame result; |
116 | 150 | |
117 | - result = new LogFrame(NULLPARENT); | |
151 | + result = new LogFrame(); | |
118 | 152 | result.setTitle(TITLE_LOGGER); |
119 | 153 | result.pack(); |
120 | 154 | result.setSize(600, 500); |
@@ -146,7 +180,7 @@ public class WindowManager { | ||
146 | 180 | protected OptionPanel createOptionPanel(){ |
147 | 181 | OptionPanel result; |
148 | 182 | |
149 | - result = new OptionPanel(NULLPARENT); | |
183 | + result = new OptionPanel(); | |
150 | 184 | result.setTitle(TITLE_OPTION); |
151 | 185 | result.pack(); |
152 | 186 | result.setSize(450, 500); |
@@ -177,7 +211,7 @@ public class WindowManager { | ||
177 | 211 | protected FindPanel createFindPanel(){ |
178 | 212 | FindPanel result; |
179 | 213 | |
180 | - result = new FindPanel(NULLPARENT); | |
214 | + result = new FindPanel(); | |
181 | 215 | result.setTitle(TITLE_FIND); |
182 | 216 | result.pack(); |
183 | 217 | result.setVisible(false); |
@@ -207,7 +241,7 @@ public class WindowManager { | ||
207 | 241 | protected VillageDigest createVillageDigest(){ |
208 | 242 | VillageDigest result; |
209 | 243 | |
210 | - result = new VillageDigest(NULLPARENT); | |
244 | + result = new VillageDigest(); | |
211 | 245 | result.setTitle(TITLE_DIGEST); |
212 | 246 | result.pack(); |
213 | 247 | result.setSize(600, 550); |
@@ -238,7 +272,7 @@ public class WindowManager { | ||
238 | 272 | protected DaySummary createDaySummary(){ |
239 | 273 | DaySummary result; |
240 | 274 | |
241 | - result = new DaySummary(NULLPARENT); | |
275 | + result = new DaySummary(); | |
242 | 276 | result.setTitle(TITLE_DAYSUMMARY); |
243 | 277 | result.pack(); |
244 | 278 | result.setSize(400, 500); |
@@ -293,26 +327,11 @@ public class WindowManager { | ||
293 | 327 | } |
294 | 328 | |
295 | 329 | /** |
296 | - * トップフレームを生成する。 | |
297 | - * | |
298 | - * @return トップフレーム | |
299 | - */ | |
300 | - protected TopFrame createTopFrame(){ | |
301 | - TopFrame result = new TopFrame(); | |
302 | - result.setVisible(false); | |
303 | - this.windowSet.add(result); | |
304 | - return result; | |
305 | - } | |
306 | - | |
307 | - /** | |
308 | 330 | * トップフレームを返す。 |
309 | 331 | * |
310 | 332 | * @return トップフレーム |
311 | 333 | */ |
312 | 334 | public TopFrame getTopFrame(){ |
313 | - if(this.topFrame == null){ | |
314 | - this.topFrame = createTopFrame(); | |
315 | - } | |
316 | 335 | return this.topFrame; |
317 | 336 | } |
318 | 337 |
@@ -332,12 +351,12 @@ public class WindowManager { | ||
332 | 351 | |
333 | 352 | UIManager.setLookAndFeel(className); |
334 | 353 | |
335 | - this.windowSet.forEach((window) -> { | |
354 | + this.windowSet.forEach(window -> { | |
336 | 355 | SwingUtilities.updateComponentTreeUI(window); |
337 | 356 | }); |
338 | 357 | |
339 | - if(this.filterPanel != null) this.filterPanel.pack(); | |
340 | - if(this.findPanel != null) this.findPanel.pack(); | |
358 | + if(this.filterPanel != null) this.filterPanel.pack(); | |
359 | + if(this.findPanel != null) this.findPanel.pack(); | |
341 | 360 | |
342 | 361 | return; |
343 | 362 | } |
@@ -0,0 +1,6 @@ | ||
1 | +UTF-8 Japanese | |
2 | +このディレクトリは、Jindolfの各種設定が格納されるディレクトリです。 | |
3 | +Jindolfの詳細は http://jindolf.osdn.jp/ を参照してください。 | |
4 | +このディレクトリを「Jindolf」の名前で起動元JARファイルと同じ位置に | |
5 | +コピーすれば、そちらの設定が優先して使われます。 | |
6 | +「lock」の名前を持つファイルはロックファイルです。 |