OSDN Git Service

Merge branch 'release/v4.101.2'
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / view / WindowManager.java
1 /*
2  * window manager
3  *
4  * License : The MIT License
5  * Copyright(c) 2012 olyutorskii
6  */
7
8 package jp.sfjp.jindolf.view;
9
10 import java.awt.EventQueue;
11 import java.awt.Frame;
12 import java.awt.Window;
13 import java.util.LinkedList;
14 import java.util.List;
15 import javax.swing.SwingUtilities;
16 import javax.swing.UIManager;
17 import javax.swing.UnsupportedLookAndFeelException;
18 import jp.sfjp.jindolf.VerInfo;
19 import jp.sfjp.jindolf.log.LogFrame;
20 import jp.sfjp.jindolf.summary.DaySummary;
21 import jp.sfjp.jindolf.summary.VillageDigest;
22
23 /**
24  * ウィンドウ群の管理を行う。
25  */
26 public class WindowManager {
27
28     private static final String TITLE_FILTER =
29             getFrameTitle("発言フィルタ");
30     private static final String TITLE_LOGGER =
31             getFrameTitle("ログ表示");
32     private static final String TITLE_OPTION =
33             getFrameTitle("オプション設定");
34     private static final String TITLE_FIND =
35             getFrameTitle("発言検索");
36     private static final String TITLE_DIGEST =
37             getFrameTitle("村のダイジェスト");
38     private static final String TITLE_DAYSUMMARY =
39             getFrameTitle("発言集計");
40     private static final String TITLE_HELP =
41             getFrameTitle("ヘルプ");
42
43     private static final Frame NULLPARENT = null;
44
45
46     private FilterPanel filterPanel;
47     private LogFrame logFrame;
48     private OptionPanel optionPanel;
49     private FindPanel findPanel;
50     private VillageDigest villageDigest;
51     private DaySummary daySummary;
52     private HelpFrame helpFrame;
53     private TopFrame topFrame;
54
55     private final List<Window> windowSet = new LinkedList<>();
56
57
58     /**
59      * コンストラクタ。
60      */
61     public WindowManager(){
62         super();
63         return;
64     }
65
66
67     /**
68      * ウィンドウタイトルに前置詞をつける。
69      *
70      * @param text 元タイトル
71      * @return タイトル文字列
72      */
73     private static String getFrameTitle(String text){
74         String result = VerInfo.getFrameTitle(text);
75         return result;
76     }
77
78
79     /**
80      * 発言フィルタウィンドウを生成する。
81      *
82      * @return 発言フィルタウィンドウ
83      */
84     protected FilterPanel createFilterPanel(){
85         FilterPanel result;
86
87         result = new FilterPanel(NULLPARENT);
88         result.setTitle(TITLE_FILTER);
89         result.pack();
90         result.setVisible(false);
91
92         this.windowSet.add(result);
93
94         return result;
95     }
96
97     /**
98      * 発言フィルタウィンドウを返す。
99      *
100      * @return 発言フィルタウィンドウ
101      */
102     public FilterPanel getFilterPanel(){
103         if(this.filterPanel == null){
104             this.filterPanel = createFilterPanel();
105         }
106         return this.filterPanel;
107     }
108
109     /**
110      * ログウィンドウを生成する。
111      *
112      * @return ログウィンドウ
113      */
114     protected LogFrame createLogFrame(){
115         LogFrame result;
116
117         result = new LogFrame(NULLPARENT);
118         result.setTitle(TITLE_LOGGER);
119         result.pack();
120         result.setSize(600, 500);
121         result.setLocationByPlatform(true);
122         result.setVisible(false);
123
124         this.windowSet.add(result);
125
126         return result;
127     }
128
129     /**
130      * ログウィンドウを返す。
131      *
132      * @return ログウィンドウ
133      */
134     public LogFrame getLogFrame(){
135         if(this.logFrame == null){
136             this.logFrame = createLogFrame();
137         }
138         return this.logFrame;
139     }
140
141     /**
142      * オプション設定ウィンドウを生成する。
143      *
144      * @return オプション設定ウィンドウ
145      */
146     protected OptionPanel createOptionPanel(){
147         OptionPanel result;
148
149         result = new OptionPanel(NULLPARENT);
150         result.setTitle(TITLE_OPTION);
151         result.pack();
152         result.setSize(450, 500);
153         result.setVisible(false);
154
155         this.windowSet.add(result);
156
157         return result;
158     }
159
160     /**
161      * オプション設定ウィンドウを返す。
162      *
163      * @return オプション設定ウィンドウ
164      */
165     public OptionPanel getOptionPanel(){
166         if(this.optionPanel == null){
167             this.optionPanel = createOptionPanel();
168         }
169         return this.optionPanel;
170     }
171
172     /**
173      * 検索ウィンドウを生成する。
174      *
175      * @return 検索ウィンドウ
176      */
177     protected FindPanel createFindPanel(){
178         FindPanel result;
179
180         result = new FindPanel(NULLPARENT);
181         result.setTitle(TITLE_FIND);
182         result.pack();
183         result.setVisible(false);
184
185         this.windowSet.add(result);
186
187         return result;
188     }
189
190     /**
191      * 検索ウィンドウを返す。
192      *
193      * @return 検索ウィンドウ
194      */
195     public FindPanel getFindPanel(){
196         if(this.findPanel == null){
197             this.findPanel = createFindPanel();
198         }
199         return this.findPanel;
200     }
201
202     /**
203      * 村ダイジェストウィンドウを生成する。
204      *
205      * @return 村ダイジェストウィンドウ
206      */
207     protected VillageDigest createVillageDigest(){
208         VillageDigest result;
209
210         result = new VillageDigest(NULLPARENT);
211         result.setTitle(TITLE_DIGEST);
212         result.pack();
213         result.setSize(600, 550);
214         result.setVisible(false);
215
216         this.windowSet.add(result);
217
218         return result;
219     }
220
221     /**
222      * 村ダイジェストウィンドウを返す。
223      *
224      * @return 村ダイジェストウィンドウ
225      */
226     public VillageDigest getVillageDigest(){
227         if(this.villageDigest == null){
228             this.villageDigest = createVillageDigest();
229         }
230         return this.villageDigest;
231     }
232
233     /**
234      * 発言集計ウィンドウを生成する。
235      *
236      * @return 発言集計ウィンドウ
237      */
238     protected DaySummary createDaySummary(){
239         DaySummary result;
240
241         result = new DaySummary(NULLPARENT);
242         result.setTitle(TITLE_DAYSUMMARY);
243         result.pack();
244         result.setSize(400, 500);
245         result.setVisible(false);
246
247         this.windowSet.add(result);
248
249         return result;
250     }
251
252     /**
253      * 発言集計ウィンドウを返す。
254      *
255      * @return 発言集計ウィンドウ
256      */
257     public DaySummary getDaySummary(){
258         if(this.daySummary == null){
259             this.daySummary = createDaySummary();
260         }
261         return this.daySummary;
262     }
263
264     /**
265      * ヘルプウィンドウを生成する。
266      *
267      * @return ヘルプウィンドウ
268      */
269     protected HelpFrame createHelpFrame(){
270         HelpFrame result;
271
272         result = new HelpFrame();
273         result.setTitle(TITLE_HELP);
274         result.pack();
275         result.setSize(450, 450);
276         result.setVisible(false);
277
278         this.windowSet.add(result);
279
280         return result;
281     }
282
283     /**
284      * ヘルプウィンドウを返す。
285      *
286      * @return ヘルプウィンドウ
287      */
288     public HelpFrame getHelpFrame(){
289         if(this.helpFrame == null){
290             this.helpFrame = createHelpFrame();
291         }
292         return this.helpFrame;
293     }
294
295     /**
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      * トップフレームを返す。
309      *
310      * @return トップフレーム
311      */
312     public TopFrame getTopFrame(){
313         if(this.topFrame == null){
314             this.topFrame = createTopFrame();
315         }
316         return this.topFrame;
317     }
318
319     /**
320      * 管理下にある全ウィンドウのLookAndFeelを更新する。
321      *
322      * <p>必要に応じて再パッキングが行われる。
323      *
324      * @param className Look and Feel
325      * @throws java.lang.ReflectiveOperationException reflection error
326      * @throws javax.swing.UnsupportedLookAndFeelException Unsupported LAF
327      */
328     public void changeAllWindowUI(String className)
329             throws ReflectiveOperationException,
330                    UnsupportedLookAndFeelException {
331         assert EventQueue.isDispatchThread();
332
333         UIManager.setLookAndFeel(className);
334
335         this.windowSet.forEach((window) -> {
336             SwingUtilities.updateComponentTreeUI(window);
337         });
338
339         if(this.filterPanel  != null) this.filterPanel.pack();
340         if(this.findPanel    != null) this.findPanel.pack();
341
342         return;
343     }
344
345 }