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 | |
package com.buckosoft.fibs.BuckoFIBS.gui.playerList.group; |
32 | |
|
33 | |
import java.awt.Color; |
34 | |
import java.awt.GridBagConstraints; |
35 | |
import java.awt.GridBagLayout; |
36 | |
import java.awt.Insets; |
37 | |
|
38 | |
import javax.swing.JButton; |
39 | |
import javax.swing.JCheckBox; |
40 | |
import javax.swing.JDialog; |
41 | |
import javax.swing.JFrame; |
42 | |
import javax.swing.JLabel; |
43 | |
import javax.swing.JOptionPane; |
44 | |
import javax.swing.JPanel; |
45 | |
import javax.swing.JTextField; |
46 | |
|
47 | |
import com.buckosoft.fibs.domain.GroupOfPlayers; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class EditGroupDialog extends JDialog { |
56 | |
|
57 | |
private static final long serialVersionUID = 1L; |
58 | |
private GroupSelectPane groupSelectPane; |
59 | |
|
60 | 0 | private JPanel jContentPane = null; |
61 | 0 | private JLabel jLabel = null; |
62 | 0 | private JTextField jTextFieldName = null; |
63 | 0 | private JLabel jLabel1 = null; |
64 | 0 | private JTextField jTextFieldColor = null; |
65 | 0 | private JLabel jLabel2 = null; |
66 | 0 | private JCheckBox jCheckBoxIgnore = null; |
67 | 0 | private JLabel jLabel3 = null; |
68 | 0 | private JCheckBox jCheckBoxActive = null; |
69 | 0 | private JPanel jPanelButtons = null; |
70 | 0 | private JButton jButtonOK = null; |
71 | 0 | private JButton jButtonCancel = null; |
72 | |
|
73 | 0 | private GroupOfPlayers groupOfPlayers = null; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public EditGroupDialog(JFrame owner, GroupSelectPane groupSelectPane) { |
79 | 0 | super(owner, true); |
80 | 0 | this.groupSelectPane = groupSelectPane; |
81 | 0 | initialize(); |
82 | 0 | this.setLocationRelativeTo(owner); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
private void initialize() { |
91 | 0 | this.setSize(300, 200); |
92 | 0 | this.setTitle("Define New Group"); |
93 | 0 | this.setContentPane(getJContentPane()); |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public void setGroupOfPlayers(GroupOfPlayers groupOfPlayers) { |
102 | 0 | this.groupOfPlayers = groupOfPlayers; |
103 | 0 | this.setTitle("Edit Group"); |
104 | 0 | this.jTextFieldName.setText(groupOfPlayers.getGroupName()); |
105 | 0 | this.jCheckBoxIgnore.getModel().setSelected(groupOfPlayers.isIgnore()); |
106 | 0 | this.jCheckBoxActive.getModel().setSelected(groupOfPlayers.isActive()); |
107 | |
|
108 | 0 | } |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
private JPanel getJContentPane() { |
116 | 0 | if (jContentPane == null) { |
117 | 0 | GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
118 | 0 | gridBagConstraints8.gridx = 0; |
119 | 0 | gridBagConstraints8.gridwidth = 2; |
120 | 0 | gridBagConstraints8.anchor = GridBagConstraints.SOUTH; |
121 | 0 | gridBagConstraints8.weighty = 0.2; |
122 | 0 | gridBagConstraints8.insets = new Insets(0, 0, 5, 0); |
123 | 0 | gridBagConstraints8.gridy = 4; |
124 | 0 | GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
125 | 0 | gridBagConstraints7.gridx = 1; |
126 | 0 | gridBagConstraints7.anchor = GridBagConstraints.WEST; |
127 | 0 | gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL; |
128 | 0 | gridBagConstraints7.gridy = 3; |
129 | 0 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
130 | 0 | gridBagConstraints6.gridx = 0; |
131 | 0 | gridBagConstraints6.gridy = 3; |
132 | 0 | jLabel3 = new JLabel(); |
133 | 0 | jLabel3.setText("Active?"); |
134 | 0 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
135 | 0 | gridBagConstraints5.gridx = 1; |
136 | 0 | gridBagConstraints5.anchor = GridBagConstraints.WEST; |
137 | 0 | gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL; |
138 | 0 | gridBagConstraints5.gridy = 2; |
139 | 0 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
140 | 0 | gridBagConstraints4.gridx = 0; |
141 | 0 | gridBagConstraints4.gridy = 2; |
142 | 0 | jLabel2 = new JLabel(); |
143 | 0 | jLabel2.setText("Ignore?"); |
144 | 0 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
145 | 0 | gridBagConstraints3.fill = GridBagConstraints.BOTH; |
146 | 0 | gridBagConstraints3.gridy = 1; |
147 | 0 | gridBagConstraints3.weightx = 1.0; |
148 | 0 | gridBagConstraints3.gridx = 1; |
149 | 0 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
150 | 0 | gridBagConstraints2.gridx = 0; |
151 | 0 | gridBagConstraints2.gridy = 1; |
152 | 0 | jLabel1 = new JLabel(); |
153 | 0 | jLabel1.setText("Color:"); |
154 | 0 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
155 | 0 | gridBagConstraints1.fill = GridBagConstraints.BOTH; |
156 | 0 | gridBagConstraints1.gridy = 0; |
157 | 0 | gridBagConstraints1.weightx = 1.0; |
158 | 0 | gridBagConstraints1.gridx = 1; |
159 | 0 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
160 | 0 | gridBagConstraints.gridx = 0; |
161 | 0 | gridBagConstraints.gridy = 0; |
162 | 0 | jLabel = new JLabel(); |
163 | 0 | jLabel.setText("Name:"); |
164 | 0 | jContentPane = new JPanel(); |
165 | 0 | jContentPane.setLayout(new GridBagLayout()); |
166 | 0 | jContentPane.add(jLabel, gridBagConstraints); |
167 | 0 | jContentPane.add(getJTextFieldName(), gridBagConstraints1); |
168 | 0 | jContentPane.add(jLabel1, gridBagConstraints2); |
169 | 0 | jContentPane.add(getJTextFieldColor(), gridBagConstraints3); |
170 | 0 | jContentPane.add(jLabel2, gridBagConstraints4); |
171 | 0 | jContentPane.add(getJCheckBoxIgnore(), gridBagConstraints5); |
172 | 0 | jContentPane.add(jLabel3, gridBagConstraints6); |
173 | 0 | jContentPane.add(getJCheckBoxActive(), gridBagConstraints7); |
174 | 0 | jContentPane.add(getJPanelButtons(), gridBagConstraints8); |
175 | |
} |
176 | 0 | return jContentPane; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
private JTextField getJTextFieldName() { |
185 | 0 | if (jTextFieldName == null) { |
186 | 0 | jTextFieldName = new JTextField(); |
187 | |
} |
188 | 0 | return jTextFieldName; |
189 | |
} |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
private JTextField getJTextFieldColor() { |
197 | 0 | if (jTextFieldColor == null) { |
198 | 0 | jTextFieldColor = new JTextField(); |
199 | 0 | jTextFieldColor.setEditable(false); |
200 | 0 | jTextFieldColor.setText("Black"); |
201 | |
} |
202 | 0 | return jTextFieldColor; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
private JCheckBox getJCheckBoxIgnore() { |
211 | 0 | if (jCheckBoxIgnore == null) { |
212 | 0 | jCheckBoxIgnore = new JCheckBox(); |
213 | |
} |
214 | 0 | return jCheckBoxIgnore; |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
private JCheckBox getJCheckBoxActive() { |
223 | 0 | if (jCheckBoxActive == null) { |
224 | 0 | jCheckBoxActive = new JCheckBox(); |
225 | |
} |
226 | 0 | return jCheckBoxActive; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
private JPanel getJPanelButtons() { |
235 | 0 | if (jPanelButtons == null) { |
236 | 0 | GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); |
237 | 0 | gridBagConstraints10.insets = new Insets(0, 0, 0, 10); |
238 | 0 | gridBagConstraints10.anchor = GridBagConstraints.SOUTH; |
239 | 0 | GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
240 | 0 | gridBagConstraints9.insets = new Insets(0, 10, 0, 0); |
241 | 0 | gridBagConstraints9.anchor = GridBagConstraints.SOUTH; |
242 | 0 | jPanelButtons = new JPanel(); |
243 | 0 | jPanelButtons.setLayout(new GridBagLayout()); |
244 | 0 | jPanelButtons.add(getJButtonOK(), gridBagConstraints10); |
245 | 0 | jPanelButtons.add(getJButtonCancel(), gridBagConstraints9); |
246 | |
} |
247 | 0 | return jPanelButtons; |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
private JButton getJButtonOK() { |
256 | 0 | if (jButtonOK == null) { |
257 | 0 | jButtonOK = new JButton(); |
258 | 0 | jButtonOK.setText("OK"); |
259 | 0 | jButtonOK.addActionListener(new java.awt.event.ActionListener() { |
260 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
261 | 0 | onOK(); |
262 | 0 | } |
263 | |
}); |
264 | |
} |
265 | 0 | return jButtonOK; |
266 | |
} |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
private JButton getJButtonCancel() { |
274 | 0 | if (jButtonCancel == null) { |
275 | 0 | jButtonCancel = new JButton(); |
276 | 0 | jButtonCancel.setText("Cancel"); |
277 | 0 | jButtonCancel.addActionListener(new java.awt.event.ActionListener() { |
278 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
279 | 0 | onCancel(); |
280 | 0 | } |
281 | |
}); |
282 | |
} |
283 | 0 | return jButtonCancel; |
284 | |
} |
285 | |
|
286 | |
private void onOK() { |
287 | |
GroupOfPlayers gop; |
288 | 0 | if (this.groupOfPlayers != null) |
289 | 0 | gop = this.groupOfPlayers; |
290 | |
else |
291 | 0 | gop = new GroupOfPlayers(); |
292 | 0 | gop.setGroupName(jTextFieldName.getText()); |
293 | 0 | if (gop.getGroupName() == null || gop.getGroupName().length() == 0) { |
294 | 0 | JOptionPane.showMessageDialog(this, |
295 | |
"Group name must not be empty.", |
296 | |
"Error", |
297 | |
JOptionPane.ERROR_MESSAGE); |
298 | 0 | return; |
299 | |
} |
300 | 0 | gop.setActive(this.jCheckBoxActive.getModel().isSelected()); |
301 | 0 | gop.setIgnore(this.jCheckBoxIgnore.getModel().isSelected()); |
302 | 0 | gop.setColor(Color.black); |
303 | 0 | if (this.groupOfPlayers != null) |
304 | 0 | this.groupSelectPane.editGroupFromUser(gop); |
305 | |
else |
306 | 0 | this.groupSelectPane.addNewGroupFromUser(gop); |
307 | 0 | this.setVisible(false); |
308 | 0 | } |
309 | |
|
310 | |
private void onCancel() { |
311 | 0 | this.setVisible(false); |
312 | 0 | } |
313 | |
} |