4 * License : The MIT License
5 * Copyright(c) 2012 olyutorskii
8 package jp.sfjp.jindolf.view;
10 import java.awt.Component;
11 import java.awt.Container;
12 import java.awt.Frame;
13 import java.awt.Window;
14 import java.util.LinkedList;
15 import java.util.List;
16 import javax.swing.JComponent;
17 import javax.swing.JMenu;
18 import javax.swing.JPopupMenu;
19 import jp.sfjp.jindolf.VerInfo;
20 import jp.sfjp.jindolf.editor.TalkPreview;
21 import jp.sfjp.jindolf.log.LogFrame;
22 import jp.sfjp.jindolf.summary.DaySummary;
23 import jp.sfjp.jindolf.summary.VillageDigest;
28 public class WindowManager {
30 private static final String TITLE_FILTER =
31 getFrameTitle("発言フィルタ");
32 private static final String TITLE_LOGGER =
33 getFrameTitle("ログ表示");
34 private static final String TITLE_EDITOR =
35 getFrameTitle("発言エディタ");
36 private static final String TITLE_OPTION =
37 getFrameTitle("オプション設定");
38 private static final String TITLE_FIND =
39 getFrameTitle("発言検索");
40 private static final String TITLE_ACCOUNT =
41 getFrameTitle("アカウント管理");
42 private static final String TITLE_DIGEST =
43 getFrameTitle("村のダイジェスト");
44 private static final String TITLE_DAYSUMMARY =
45 getFrameTitle("発言集計");
46 private static final String TITLE_HELP =
49 private static final Frame NULLPARENT = null;
52 private FilterPanel filterPanel;
53 private LogFrame logFrame;
54 private TalkPreview talkPreview;
55 private OptionPanel optionPanel;
56 private FindPanel findPanel;
57 private AccountPanel accountPanel;
58 private VillageDigest villageDigest;
59 private DaySummary daySummary;
60 private HelpFrame helpFrame;
61 private TopFrame topFrame;
63 private final List<Window> windowSet = new LinkedList<>();
69 public WindowManager(){
80 private static String getFrameTitle(String text){
81 String result = VerInfo.getFrameTitle(text);
90 protected FilterPanel createFilterPanel(){
93 result = new FilterPanel(NULLPARENT);
94 result.setTitle(TITLE_FILTER);
96 result.setVisible(false);
98 this.windowSet.add(result);
105 * @return 発言フィルタウィンドウ
107 public FilterPanel getFilterPanel(){
108 if(this.filterPanel == null){
109 this.filterPanel = createFilterPanel();
111 return this.filterPanel;
118 protected LogFrame createLogFrame(){
121 result = new LogFrame(NULLPARENT);
122 result.setTitle(TITLE_LOGGER);
124 result.setSize(600, 500);
125 result.setLocationByPlatform(true);
126 result.setVisible(false);
128 this.windowSet.add(result);
137 public LogFrame getLogFrame(){
138 if(this.logFrame == null){
139 this.logFrame = createLogFrame();
141 return this.logFrame;
146 * @return 発言エディタウィンドウ
148 protected TalkPreview createTalkPreview(){
151 result = new TalkPreview();
152 result.setTitle(TITLE_EDITOR);
154 result.setSize(700, 500);
155 result.setVisible(false);
157 this.windowSet.add(result);
164 * @return 発言エディタウィンドウ
166 public TalkPreview getTalkPreview(){
167 if(this.talkPreview == null){
168 this.talkPreview = createTalkPreview();
170 return this.talkPreview;
175 * @return オプション設定ウィンドウ
177 protected OptionPanel createOptionPanel(){
180 result = new OptionPanel(NULLPARENT);
181 result.setTitle(TITLE_OPTION);
183 result.setSize(450, 500);
184 result.setVisible(false);
186 this.windowSet.add(result);
193 * @return オプション設定ウィンドウ
195 public OptionPanel getOptionPanel(){
196 if(this.optionPanel == null){
197 this.optionPanel = createOptionPanel();
199 return this.optionPanel;
206 protected FindPanel createFindPanel(){
209 result = new FindPanel(NULLPARENT);
210 result.setTitle(TITLE_FIND);
212 result.setVisible(false);
214 this.windowSet.add(result);
223 public FindPanel getFindPanel(){
224 if(this.findPanel == null){
225 this.findPanel = createFindPanel();
227 return this.findPanel;
234 protected AccountPanel createAccountPanel(){
237 result = new AccountPanel(NULLPARENT);
238 result.setTitle(TITLE_ACCOUNT);
240 result.setVisible(false);
242 this.windowSet.add(result);
251 public AccountPanel getAccountPanel(){
252 if(this.accountPanel == null){
253 this.accountPanel = createAccountPanel();
255 return this.accountPanel;
260 * @return 村ダイジェストウィンドウ
262 protected VillageDigest createVillageDigest(){
263 VillageDigest result;
265 result = new VillageDigest(NULLPARENT);
266 result.setTitle(TITLE_DIGEST);
268 result.setSize(600, 550);
269 result.setVisible(false);
271 this.windowSet.add(result);
278 * @return 村ダイジェストウィンドウ
280 public VillageDigest getVillageDigest(){
281 if(this.villageDigest == null){
282 this.villageDigest = createVillageDigest();
284 return this.villageDigest;
291 protected DaySummary createDaySummary(){
294 result = new DaySummary(NULLPARENT);
295 result.setTitle(TITLE_DAYSUMMARY);
297 result.setSize(400, 500);
298 result.setVisible(false);
300 this.windowSet.add(result);
309 public DaySummary getDaySummary(){
310 if(this.daySummary == null){
311 this.daySummary = createDaySummary();
313 return this.daySummary;
320 protected HelpFrame createHelpFrame(){
323 result = new HelpFrame();
324 result.setTitle(TITLE_HELP);
326 result.setSize(450, 450);
327 result.setVisible(false);
329 this.windowSet.add(result);
338 public HelpFrame getHelpFrame(){
339 if(this.helpFrame == null){
340 this.helpFrame = createHelpFrame();
342 return this.helpFrame;
349 protected TopFrame createTopFrame(){
350 TopFrame result = new TopFrame();
351 result.setVisible(false);
352 this.windowSet.add(result);
360 public TopFrame getTopFrame(){
361 if(this.topFrame == null){
362 this.topFrame = createTopFrame();
364 return this.topFrame;
368 * 管理下にある全ウィンドウのLookAndFeelを更新する。
371 public void changeAllWindowUI(){
372 for(Window window : this.windowSet){
373 updateTreeUI(window);
376 if(this.filterPanel != null) this.filterPanel.pack();
377 if(this.findPanel != null) this.findPanel.pack();
378 if(this.accountPanel != null) this.accountPanel.pack();
384 * 再帰的に下層コンポーネントのLaFを更新する。
386 * <p>{@link javax.swing.SwingUtilities#updateComponentTreeUI(Component)}
387 * がポップアップメニューのLaF更新を正しく行わないSun製JREのバグ
391 * @param comp 開始コンポーネント
392 * @see <a href="http://bugs.sun.com/view_bug.do?bug_id=6299213">
396 public static void updateTreeUI(Component comp) {
397 updateTreeUI(comp, true);
402 * 再帰的に下層コンポーネントのLaFを更新する。
403 * @param comp 開始コンポーネント
404 * @param isRoot このコンポーネントが最上位か否か指定する。
405 * trueが指定された場合、LaF更新作業の後に再レイアウトを促す。
407 * ポップアップ以外の下層コンポーネントには
410 public static void updateTreeUI(Component comp, boolean isRoot) {
411 if(comp instanceof JComponent){
412 JComponent jcomp = (JComponent) comp;
415 JPopupMenu popup = jcomp.getComponentPopupMenu();
417 updateTreeUI(popup, true);
421 if(comp instanceof JMenu){
422 JMenu menu = (JMenu) comp;
423 for(Component child : menu.getMenuComponents()){
424 updateTreeUI(child, false);
426 }else if(comp instanceof Container){
427 Container cont = (Container) comp;
428 for(Component child : cont.getComponents()){
429 updateTreeUI(child, false);