Source code: com/virtuosotechnologies/asaph/maingui/MainGuiPrefsPane.java
1 /*
2 ================================================================================
3
4 FILE: MainGuiPrefsPane.java
5
6 PROJECT:
7
8 Asaph
9
10 CONTENTS:
11
12 This interface should be implemented to implement a prefs pane
13
14 PROGRAMMERS:
15
16 Daniel Azuma (DA) <dazuma@kagi.com>
17
18 COPYRIGHT:
19
20 Copyright (C) 2003 Daniel Azuma (dazuma@kagi.com)
21
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public
33 License along with this program; if not, write to
34 Free Software Foundation, Inc.
35 59 Temple Place, Suite 330
36 Boston, MA 02111-1307 USA
37
38 ================================================================================
39 */
40
41
42 package com.virtuosotechnologies.asaph.maingui;
43
44
45 import java.awt.Insets;
46 import java.awt.BorderLayout;
47 import java.awt.GridBagLayout;
48 import java.awt.GridBagConstraints;
49 import java.awt.event.ItemListener;
50 import java.awt.event.ItemEvent;
51 import javax.swing.JComponent;
52 import javax.swing.JPanel;
53 import javax.swing.JScrollPane;
54 import javax.swing.JCheckBox;
55 import javax.swing.BorderFactory;
56
57 import com.virtuosotechnologies.lib.swing.ScrollablePanel;
58
59
60 /**
61 * Prefs pane for the main gui
62 */
63 /*package*/ class MainGuiPrefsPane
64 implements PrefsPaneProvider
65 {
66 private static final String STR_MainGuiPrefs_DetailPrefsPanelLabel =
67 ResourceAccess.Strings.buildString("MainGuiPrefs_DetailPrefsPanelLabel");
68 private static final String STR_MainGuiPrefs_ShowCommentDetailCheck =
69 ResourceAccess.Strings.buildString("MainGuiPrefs_ShowCommentDetailCheck");
70 private static final String STR_MainGuiPrefs_ShowAuthorDetailCheck =
71 ResourceAccess.Strings.buildString("MainGuiPrefs_ShowAuthorDetailCheck");
72 private static final String STR_MainGuiPrefs_ShowCopyrightDetailCheck =
73 ResourceAccess.Strings.buildString("MainGuiPrefs_ShowCopyrightDetailCheck");
74 private static final String STR_MainGuiPrefs_ShowAltTitlesDetailCheck =
75 ResourceAccess.Strings.buildString("MainGuiPrefs_ShowAltTitlesDetailCheck");
76
77
78 private ListsImpl listsImpl_;
79
80
81 /**
82 * Constructor
83 */
84 /*package*/ MainGuiPrefsPane(
85 ListsImpl listsImpl)
86 {
87 listsImpl_ = listsImpl;
88 }
89
90
91 /**
92 * This method is called when the prefs window is opened. The provider
93 * should return a JComponent implementing the prefs pane, and ensure that it
94 * reflects the current settings.
95 *
96 * @param a JComponent to use as a dialog parent
97 * @return the JComponent to add to the prefs window
98 */
99 public JComponent createPane(
100 JComponent dialogParent)
101 {
102 JPanel mainPanel = new JPanel(new GridBagLayout());
103 mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
104 GridBagConstraints maingbc = new GridBagConstraints();
105 maingbc.gridx = 0;
106 maingbc.weightx = 1;
107 maingbc.weighty = 1;
108 maingbc.fill = GridBagConstraints.HORIZONTAL;
109 maingbc.anchor = GridBagConstraints.WEST;
110 maingbc.insets = new Insets(5, 5, 0, 5);
111
112 JPanel detailPrefsPanel = new JPanel(new GridBagLayout());
113 detailPrefsPanel.setBorder(BorderFactory.createCompoundBorder(
114 BorderFactory.createTitledBorder(
115 BorderFactory.createEtchedBorder(),
116 STR_MainGuiPrefs_DetailPrefsPanelLabel),
117 BorderFactory.createEmptyBorder(5, 5, 5, 5)));
118 mainPanel.add(detailPrefsPanel, maingbc);
119
120 GridBagConstraints gbc = new GridBagConstraints();
121 gbc.gridx = 0;
122 gbc.weightx = 1;
123 gbc.weighty = 1;
124 gbc.fill = GridBagConstraints.NONE;
125 gbc.anchor = GridBagConstraints.WEST;
126 JCheckBox checkBox;
127
128 checkBox = new JCheckBox(STR_MainGuiPrefs_ShowCommentDetailCheck,
129 listsImpl_.isShowingCommentDetail());
130 checkBox.addItemListener(
131 new ItemListener()
132 {
133 public void itemStateChanged(
134 ItemEvent ev)
135 {
136 if (ev.getStateChange() == ItemEvent.SELECTED)
137 {
138 listsImpl_.setShowingCommentDetail(true);
139 }
140 else if (ev.getStateChange() == ItemEvent.DESELECTED)
141 {
142 listsImpl_.setShowingCommentDetail(false);
143 }
144 }
145 });
146 detailPrefsPanel.add(checkBox, gbc);
147
148 checkBox = new JCheckBox(STR_MainGuiPrefs_ShowAuthorDetailCheck,
149 listsImpl_.isShowingAuthorDetail());
150 checkBox.addItemListener(
151 new ItemListener()
152 {
153 public void itemStateChanged(
154 ItemEvent ev)
155 {
156 if (ev.getStateChange() == ItemEvent.SELECTED)
157 {
158 listsImpl_.setShowingAuthorDetail(true);
159 }
160 else if (ev.getStateChange() == ItemEvent.DESELECTED)
161 {
162 listsImpl_.setShowingAuthorDetail(false);
163 }
164 }
165 });
166 detailPrefsPanel.add(checkBox, gbc);
167
168 checkBox = new JCheckBox(STR_MainGuiPrefs_ShowCopyrightDetailCheck,
169 listsImpl_.isShowingCopyrightDetail());
170 checkBox.addItemListener(
171 new ItemListener()
172 {
173 public void itemStateChanged(
174 ItemEvent ev)
175 {
176 if (ev.getStateChange() == ItemEvent.SELECTED)
177 {
178 listsImpl_.setShowingCopyrightDetail(true);
179 }
180 else if (ev.getStateChange() == ItemEvent.DESELECTED)
181 {
182 listsImpl_.setShowingCopyrightDetail(false);
183 }
184 }
185 });
186 detailPrefsPanel.add(checkBox, gbc);
187
188 checkBox = new JCheckBox(STR_MainGuiPrefs_ShowAltTitlesDetailCheck,
189 listsImpl_.isShowingAltTitlesDetail());
190 checkBox.addItemListener(
191 new ItemListener()
192 {
193 public void itemStateChanged(
194 ItemEvent ev)
195 {
196 if (ev.getStateChange() == ItemEvent.SELECTED)
197 {
198 listsImpl_.setShowingAltTitlesDetail(true);
199 }
200 else if (ev.getStateChange() == ItemEvent.DESELECTED)
201 {
202 listsImpl_.setShowingAltTitlesDetail(false);
203 }
204 }
205 });
206 detailPrefsPanel.add(checkBox, gbc);
207
208 ScrollablePanel viewport = new ScrollablePanel(new BorderLayout());
209 viewport.add(mainPanel, BorderLayout.NORTH);
210 JScrollPane scroller = new JScrollPane(viewport);
211 return scroller;
212 }
213
214
215 /**
216 * This method is called when the pane is brought into focus.
217 */
218 public void paneFocused()
219 {
220 }
221
222
223 /**
224 * This method is called when the pane is unfocused.
225 */
226 public void paneUnfocused()
227 {
228 }
229
230
231 /**
232 * This method is called when the prefs window is closed. The provider should
233 * generally respond by defuncting the pane.
234 */
235 public void paneDisposed()
236 {
237 }
238 }