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