OSDN Git Service

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