1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
package com.buckosoft.fibs.BuckoFIBS.gui.playerList.group; |
43 | |
|
44 | |
import java.awt.BorderLayout; |
45 | |
import java.awt.GridBagConstraints; |
46 | |
import java.awt.GridBagLayout; |
47 | |
import java.awt.Insets; |
48 | |
import java.awt.event.ItemEvent; |
49 | |
import java.util.LinkedList; |
50 | |
|
51 | |
import javax.swing.JButton; |
52 | |
import javax.swing.JCheckBox; |
53 | |
import javax.swing.JLabel; |
54 | |
import javax.swing.JPanel; |
55 | |
import javax.swing.JScrollPane; |
56 | |
|
57 | |
import com.buckosoft.fibs.BuckoFIBS.GroupManager; |
58 | |
import com.buckosoft.fibs.BuckoFIBS.gui.MainDialog; |
59 | |
import com.buckosoft.fibs.domain.GroupOfPlayers; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 0 | public class GroupSelectPane extends JPanel { |
68 | |
private static final boolean DEBUG = false; |
69 | |
private static final long serialVersionUID = 1L; |
70 | 0 | private JPanel jPanelMainPane = null; |
71 | 0 | private JCheckBox jCheckBoxAll = null; |
72 | |
|
73 | |
|
74 | 0 | private JScrollPane scrollPane = null; |
75 | 0 | private GroupManager groupManager = null; |
76 | 0 | private MainDialog mainDialog = null; |
77 | |
|
78 | 0 | private LinkedList<CheckWithName> checkWithNameList = new LinkedList<CheckWithName>(); |
79 | |
|
80 | 0 | class CheckWithName { |
81 | |
int id; |
82 | |
JCheckBox checkBox; |
83 | |
JButton label; |
84 | |
String name; |
85 | |
GroupOfPlayers group; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public GroupSelectPane() { |
92 | 0 | super(); |
93 | 0 | initialize(); |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
private void initialize() { |
107 | 0 | System.out.println("GroupSelectPane:<init>"); |
108 | 0 | this.setLayout(new BorderLayout()); |
109 | 0 | this.setSize(300, 200); |
110 | 0 | this.add(getScrollPane()); |
111 | 0 | } |
112 | |
|
113 | |
private JScrollPane getScrollPane() { |
114 | 0 | if (scrollPane == null) { |
115 | 0 | scrollPane = new JScrollPane(); |
116 | 0 | scrollPane.setViewportView(getJPanelMainPane()); |
117 | |
} |
118 | 0 | return(scrollPane); |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private JPanel getJPanelMainPane() { |
127 | 0 | if (jPanelMainPane == null) { |
128 | 0 | jPanelMainPane = new JPanel(); |
129 | 0 | jPanelMainPane.setLayout(new GridBagLayout()); |
130 | |
} |
131 | 0 | return jPanelMainPane; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public void setGroupManager(GroupManager groupManager) { |
138 | 0 | this.groupManager = groupManager; |
139 | 0 | this.groupManager.setGroupSelectPane(this); |
140 | 0 | } |
141 | |
|
142 | |
public void setMainDialog(MainDialog mainDialog) { |
143 | 0 | this.mainDialog = mainDialog; |
144 | 0 | } |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
private JCheckBox getJCheckBoxAll() { |
151 | 0 | if (jCheckBoxAll == null) { |
152 | 0 | jCheckBoxAll = new JCheckBox(); |
153 | |
} |
154 | 0 | return jCheckBoxAll; |
155 | |
} |
156 | |
|
157 | |
public void repopulate() { |
158 | 0 | jPanelMainPane = null; |
159 | 0 | scrollPane.setViewportView(getJPanelMainPane()); |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
public void populatePane() { |
165 | 0 | this.groupManager.populatePane(); |
166 | 0 | } |
167 | |
|
168 | |
public void addGroup(GroupOfPlayers groupOfPlayers) { |
169 | 0 | GridBagConstraints gridBagConstraintsR = new GridBagConstraints(); |
170 | 0 | gridBagConstraintsR.insets = new Insets(0, 0, 0, 1); |
171 | 0 | gridBagConstraintsR.gridx = 1; |
172 | |
|
173 | 0 | gridBagConstraintsR.gridy = this.checkWithNameList.size(); |
174 | 0 | GridBagConstraints gridBagConstraintsL = new GridBagConstraints(); |
175 | 0 | gridBagConstraintsL.gridx = 0; |
176 | 0 | gridBagConstraintsL.gridy = this.checkWithNameList.size(); |
177 | 0 | gridBagConstraintsL.insets = new Insets(0, 1, 0, 0); |
178 | |
|
179 | 0 | String s = groupOfPlayers.getGroupName(); |
180 | |
JCheckBox cb; |
181 | 0 | if (s.equals("All")) |
182 | 0 | cb = getJCheckBoxAll(); |
183 | |
else { |
184 | 0 | cb = new JCheckBox(); |
185 | 0 | cb.setName(s); |
186 | |
} |
187 | 0 | cb.addItemListener(new java.awt.event.ItemListener() { |
188 | |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
189 | |
if (DEBUG) |
190 | |
System.out.println("Group toggled: "); |
191 | 0 | groupChecked(e); |
192 | 0 | } |
193 | |
}); |
194 | 0 | cb.getModel().setSelected(groupOfPlayers.isActive()); |
195 | 0 | jPanelMainPane.add(cb, gridBagConstraintsL); |
196 | 0 | JButton l = null; |
197 | 0 | if (s.equals("All")) { |
198 | 0 | JLabel jl = new JLabel(); |
199 | 0 | jl.setText(s); |
200 | 0 | jPanelMainPane.add(jl, gridBagConstraintsR); |
201 | 0 | } else { |
202 | 0 | l = new JButton(); |
203 | 0 | l.setBorder(null); |
204 | 0 | l.addActionListener(new java.awt.event.ActionListener() { |
205 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
206 | 0 | onEditGroup((JButton)e.getSource()); |
207 | 0 | } |
208 | |
}); |
209 | 0 | gridBagConstraintsR.fill = GridBagConstraints.HORIZONTAL; |
210 | 0 | if (groupOfPlayers.isIgnore()) |
211 | 0 | l.setText("!" + s); |
212 | |
else |
213 | 0 | l.setText(s); |
214 | 0 | jPanelMainPane.add(l, gridBagConstraintsR); |
215 | |
} |
216 | 0 | CheckWithName cwn = new CheckWithName(); |
217 | 0 | cwn.id = groupOfPlayers.getId(); |
218 | 0 | cwn.checkBox = cb; |
219 | 0 | cwn.name = s; |
220 | 0 | cwn.label = l; |
221 | 0 | cwn.group = groupOfPlayers; |
222 | 0 | checkWithNameList.add(cwn); |
223 | |
|
224 | 0 | } |
225 | |
|
226 | |
|
227 | |
|
228 | |
public void populateFinish() { |
229 | 0 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
230 | 0 | gridBagConstraints.gridwidth = 2; |
231 | 0 | gridBagConstraints.gridx = 0; |
232 | |
|
233 | 0 | gridBagConstraints.insets = new Insets(10, 0, 0, 0); |
234 | 0 | gridBagConstraints.anchor = GridBagConstraints.SOUTH; |
235 | 0 | JLabel l = new JLabel(); |
236 | 0 | l.setText("Add New Group..."); |
237 | 0 | l.addMouseListener(new java.awt.event.MouseAdapter() { |
238 | |
public void mouseClicked(java.awt.event.MouseEvent e) { |
239 | 0 | handleAddNewGroupButton(); |
240 | 0 | } |
241 | |
}); |
242 | 0 | jPanelMainPane.add(l, gridBagConstraints); |
243 | 0 | updateDisabledItems(); |
244 | 0 | } |
245 | |
public void savePaneToList() { |
246 | 0 | for (CheckWithName cwn : checkWithNameList) { |
247 | 0 | this.groupManager.updateGroupOfPlayers(cwn.id, cwn.name, cwn.checkBox.getModel().isSelected()); |
248 | 0 | } |
249 | 0 | } |
250 | |
|
251 | |
private void handleAddNewGroupButton() { |
252 | 0 | EditGroupDialog egd = new EditGroupDialog(mainDialog, this); |
253 | 0 | egd.setVisible(true); |
254 | 0 | } |
255 | |
|
256 | |
public void addNewGroupFromUser(GroupOfPlayers groupOfPlayers) { |
257 | 0 | this.groupManager.addNewGroupFromUser(groupOfPlayers); |
258 | 0 | } |
259 | |
|
260 | |
public void editGroupFromUser(GroupOfPlayers groupOfPlayers) { |
261 | 0 | this.groupManager.editGroupFromUser(groupOfPlayers); |
262 | 0 | } |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
private void groupChecked(ItemEvent e) { |
268 | 0 | updateDisabledItems(); |
269 | 0 | for (CheckWithName cwn : checkWithNameList) { |
270 | 0 | if (cwn.checkBox == e.getItem()) { |
271 | 0 | this.groupManager.updateGroupOfPlayers(cwn.id, cwn.name, cwn.checkBox.getModel().isSelected()); |
272 | |
} |
273 | 0 | } |
274 | 0 | } |
275 | |
|
276 | |
|
277 | |
|
278 | |
private void updateDisabledItems() { |
279 | 0 | boolean allMode = this.getJCheckBoxAll().getModel().isSelected(); |
280 | 0 | for (CheckWithName cwn : checkWithNameList) { |
281 | 0 | if (cwn.name.equals("All")) |
282 | 0 | continue; |
283 | 0 | if (!cwn.group.isIgnore()) { |
284 | 0 | cwn.checkBox.setEnabled(!allMode); |
285 | 0 | cwn.label.setEnabled(!allMode); |
286 | |
} |
287 | 0 | } |
288 | 0 | } |
289 | |
|
290 | |
private void onEditGroup(JButton e) { |
291 | 0 | for (CheckWithName cwn : checkWithNameList) { |
292 | 0 | if (cwn.name.equals("All")) |
293 | 0 | continue; |
294 | 0 | if (cwn.label == e) { |
295 | 0 | EditGroupDialog egd = new EditGroupDialog(mainDialog, this); |
296 | 0 | egd.setGroupOfPlayers(this.groupManager.getGroupOfPlayers(cwn.id)); |
297 | 0 | egd.setVisible(true); |
298 | 0 | return; |
299 | |
} |
300 | 0 | } |
301 | 0 | } |
302 | |
} |