View Javadoc
1   /******************************************************************************
2    * EditGroupDialog.java - Allow the user to edit a GroupOfPlayers
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.1  2010/12/31 05:45:42  dick
10   * Allow the user to define a new GroupOfPlayers.
11   */
12  
13  /* 
14   * This program is free software: you can redistribute it and/or modify
15   * it under the terms of the GNU General Public License as published by
16   * the Free Software Foundation, either version 3 of the License, or
17   * (at your option) any later version.
18   *
19   * This program is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   * GNU General Public License for more details.
23   *
24   * You should have received a copy of the GNU General Public License
25   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26   *
27   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
28   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
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  /** Allow the user to edit a GroupOfPlayers
50   * @author Dick Balaska
51   * @since 2010/12/30
52   * @version $Revision$ <br> $Date$
53   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/playerList/group/EditGroupDialog.java">cvs EditGroupDialog.java</a>
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  	 * @param owner
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  	 * This method initializes this
87  	 * 
88  	 * @return void
89  	 */
90  	private void initialize() {
91  		this.setSize(300, 200);
92  		this.setTitle("Define New Group");
93  		this.setContentPane(getJContentPane());
94  	}
95  
96  
97  	/** If we are editing an existing group, set it here.
98  	 * Otherwise, we are creating a new group.
99  	 * @param groupOfPlayers The GroupOfPlayers to edit.
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 	 * This method initializes jContentPane
112 	 * 
113 	 * @return javax.swing.JPanel
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 	 * This method initializes jTextFieldName	
181 	 * 	
182 	 * @return javax.swing.JTextField	
183 	 */
184 	private JTextField getJTextFieldName() {
185 		if (jTextFieldName == null) {
186 			jTextFieldName = new JTextField();
187 		}
188 		return jTextFieldName;
189 	}
190 
191 	/**
192 	 * This method initializes jTextFieldColor	
193 	 * 	
194 	 * @return javax.swing.JTextField	
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 	 * This method initializes jCheckBoxIgnore	
207 	 * 	
208 	 * @return javax.swing.JCheckBox	
209 	 */
210 	private JCheckBox getJCheckBoxIgnore() {
211 		if (jCheckBoxIgnore == null) {
212 			jCheckBoxIgnore = new JCheckBox();
213 		}
214 		return jCheckBoxIgnore;
215 	}
216 
217 	/**
218 	 * This method initializes jCheckBoxActive	
219 	 * 	
220 	 * @return javax.swing.JCheckBox	
221 	 */
222 	private JCheckBox getJCheckBoxActive() {
223 		if (jCheckBoxActive == null) {
224 			jCheckBoxActive = new JCheckBox();
225 		}
226 		return jCheckBoxActive;
227 	}
228 
229 	/**
230 	 * This method initializes jPanelButtons	
231 	 * 	
232 	 * @return javax.swing.JPanel	
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 	 * This method initializes jButtonOK	
252 	 * 	
253 	 * @return javax.swing.JButton	
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 	 * This method initializes jButtonCancel	
270 	 * 	
271 	 * @return javax.swing.JButton	
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 }