OSDN Git Service

Maven3対応。
[jindolf/Jindolf.git] / src / main / java / jp / sourceforge / jindolf / DialogPrefPanel.java
1 /*
2  * dialog preference panel
3  *
4  * License : The MIT License
5  * Copyright(c) 2009 olyutorskii
6  */
7
8 package jp.sourceforge.jindolf;
9
10 import java.awt.Container;
11 import java.awt.GridBagConstraints;
12 import java.awt.GridBagLayout;
13 import java.awt.Insets;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16 import java.awt.event.ItemEvent;
17 import java.awt.event.ItemListener;
18 import javax.swing.BorderFactory;
19 import javax.swing.JButton;
20 import javax.swing.JCheckBox;
21 import javax.swing.JComponent;
22 import javax.swing.JPanel;
23 import javax.swing.border.Border;
24
25 /**
26  * 発言表示の各種設定パネル。
27  */
28 @SuppressWarnings("serial")
29 public class DialogPrefPanel
30         extends JPanel
31         implements ActionListener,
32                    ItemListener {
33
34     private final JCheckBox useBodyImage = new JCheckBox("デカキャラモード");
35     private final JCheckBox useMonoImage =
36             new JCheckBox("墓石を遺影に置き換える");
37     private final JCheckBox isSimpleMode =
38             new JCheckBox("シンプル表示モード");
39     private final JCheckBox alignBaloon =
40             new JCheckBox("フキダシ幅を揃える");
41     private final JButton resetDefault = new JButton("出荷時に戻す");
42
43     /**
44      * コンストラクタ。
45      */
46     public DialogPrefPanel(){
47         this.resetDefault.addActionListener(this);
48         this.isSimpleMode.addItemListener(this);
49
50         design(this);
51         modifyGUIState();
52
53         return;
54     }
55
56     /**
57      * レイアウトを行う。
58      * @param content コンテナ
59      */
60     private void design(Container content){
61         GridBagLayout layout = new GridBagLayout();
62         GridBagConstraints constraints = new GridBagConstraints();
63
64         content.setLayout(layout);
65
66         constraints.insets = new Insets(2, 2, 2, 2);
67
68         constraints.weightx = 0.0;
69         constraints.gridwidth = GridBagConstraints.REMAINDER;
70         constraints.fill = GridBagConstraints.NONE;
71         constraints.anchor = GridBagConstraints.NORTHWEST;
72
73         content.add(this.isSimpleMode, constraints);
74         content.add(this.alignBaloon, constraints);
75         content.add(buildIconPanel(), constraints);
76
77         constraints.weightx = 1.0;
78         constraints.weighty = 1.0;
79         constraints.fill = GridBagConstraints.NONE;
80         constraints.anchor = GridBagConstraints.SOUTHEAST;
81         content.add(this.resetDefault, constraints);
82
83         return;
84     }
85
86     /**
87      * アイコン設定パネルを生成する。
88      * @return アイコン設定パネル
89      */
90     private JComponent buildIconPanel(){
91         JPanel result = new JPanel();
92
93         GridBagLayout layout = new GridBagLayout();
94         GridBagConstraints constraints = new GridBagConstraints();
95         result.setLayout(layout);
96
97         constraints.insets = new Insets(1, 1, 1, 1);
98
99         constraints.weightx = 0.0;
100         constraints.gridwidth = GridBagConstraints.REMAINDER;
101         constraints.fill = GridBagConstraints.NONE;
102         constraints.anchor = GridBagConstraints.NORTHWEST;
103
104         result.add(this.useBodyImage, constraints);
105         result.add(this.useMonoImage, constraints);
106
107         Border border = BorderFactory.createTitledBorder("アイコン表示");
108         result.setBorder(border);
109
110         return result;
111     }
112
113     /**
114      * GUI間の一貫性を維持する。
115      */
116     private void modifyGUIState(){
117         if(this.isSimpleMode.isSelected()){
118             this.useBodyImage.setEnabled(false);
119             this.useMonoImage.setEnabled(false);
120             this.alignBaloon .setEnabled(false);
121         }else{
122             this.useBodyImage.setEnabled(true);
123             this.useMonoImage.setEnabled(true);
124             this.alignBaloon .setEnabled(true);
125         }
126
127         return;
128     }
129
130     /**
131      * デカキャラモードを使うか否か画面の状態を返す。
132      * @return デカキャラモードを使うならtrue
133      */
134     public boolean useBodyImage(){
135         return this.useBodyImage.isSelected();
136     }
137
138     /**
139      * 遺影モードを使うか否か画面の状態を返す。
140      * @return 遺影モードを使うならtrue
141      */
142     public boolean useMonoImage(){
143         return this.useMonoImage.isSelected();
144     }
145
146     /**
147      * シンプル表示モードか否か画面の状態を返す。
148      * @return シンプル表示モードならtrue
149      */
150     public boolean isSimpleMode(){
151         return this.isSimpleMode.isSelected();
152     }
153
154     /**
155      * フキダシ幅を揃えるか否か画面の状態を返す。
156      * @return フキダシ幅を揃えるならtrue
157      */
158     public boolean alignBaloon(){
159         return this.alignBaloon.isSelected();
160     }
161
162     /**
163      * デカキャラモードの設定を行う。
164      * @param setting 有効にするならtrue
165      */
166     public void setBodyImageSetting(boolean setting){
167         this.useBodyImage.setSelected(setting);
168         return;
169     }
170
171     /**
172      * 遺影モードの設定を行う。
173      * @param setting 有効にするならtrue
174      */
175     public void setMonoImageSetting(boolean setting){
176         this.useMonoImage.setSelected(setting);
177         return;
178     }
179
180     /**
181      * シンプル表示モードの設定を行う。
182      * @param setting 有効にするならtrue
183      */
184     public void setSimpleModeSetting(boolean setting){
185         this.isSimpleMode.setSelected(setting);
186         modifyGUIState();
187         return;
188     }
189
190     /**
191      * フキダシ幅揃えの設定を行う。
192      * @param setting 有効にするならtrue
193      */
194     public void setAlignBaloonSetting(boolean setting){
195         this.alignBaloon.setSelected(setting);
196         return;
197     }
198
199     /**
200      * 発言表示設定を設定する。
201      * @param pref 表示設定
202      */
203     public void setDialogPref(DialogPref pref){
204         setBodyImageSetting(pref.useBodyImage());
205         setMonoImageSetting(pref.useMonoImage());
206         setSimpleModeSetting(pref.isSimpleMode());
207         setAlignBaloonSetting(pref.alignBaloonWidth());
208         modifyGUIState();
209         return;
210     }
211
212     /**
213      * 発言表示設定を返す。
214      * @return 表示設定
215      */
216     public DialogPref getDialogPref(){
217         DialogPref result = new DialogPref();
218         result.setBodyImageSetting(useBodyImage());
219         result.setMonoImageSetting(useMonoImage());
220         result.setSimpleMode(isSimpleMode());
221         result.setAlignBalooonWidthSetting(alignBaloon());
222         return result;
223     }
224
225     /**
226      * デフォルトボタン押下処理。
227      * @param event ボタン押下イベント
228      */
229     public void actionPerformed(ActionEvent event){
230         Object source = event.getSource();
231         if(source != this.resetDefault) return;
232         this.useBodyImage.setSelected(false);
233         this.useMonoImage.setSelected(false);
234         this.isSimpleMode.setSelected(false);
235         this.alignBaloon.setSelected(false);
236         modifyGUIState();
237         return;
238     }
239
240     /**
241      * チェックボックス操作の受信。
242      * @param event チェックボックス操作イベント
243      */
244     public void itemStateChanged(ItemEvent event){
245         modifyGUIState();
246         return;
247     }
248
249 }