View Javadoc

1   /*
2    * XMLCV - Gestion de CV sous forme XML
3    * 
4    * Copyright (C) 2004-2005, Damien Raude-Morvan
5    * 
6    * This file is part of XMLCV.
7    *
8    * XMLCV is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * XMLCV is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   *
18   * You should have received a copy of the GNU General Public License
19   * along with XMLCV; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   * 
22   * Contacts :
23   * - Sébastien Mathy <smathy@tuxfamily.org>
24   * - Emmanuel Berre <eberre@tuxfamily.org>
25   * - Damien Raude-Morvan <drazzib@drazzib.com>
26   */
27  package org.xmlcv.gui.tabs;
28  
29  import javax.swing.JTextField;
30  import javax.swing.SpringLayout;
31  import javax.swing.event.DocumentEvent;
32  
33  import org.xmlcv.gui.listeners.AbstractTextFieldDocumentListener;
34  import org.xmlcv.model.CvDocumentBean.Cv;
35  import org.xmlcv.util.I18n;
36  import org.xmlcv.util.SpringUtilities;
37  
38  /***
39   * 
40   * @version $Revision: 114 $
41   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
42   */
43  public class TabIdentity extends AbstractTab {
44  
45  	private SpringLayout springLayout;
46  
47  	private JTextField birthDateField;
48  
49  	JTextField zipCodeField;
50  
51  	JTextField phoneField;
52  
53  	//private MaskFormatter dateFormater;
54  
55  	JTextField cityField;
56  
57  	JTextField addressField;
58  
59  	JTextField firstNameField;
60  
61  	JTextField lastNameField;
62  
63  	JTextField mobilePhoneField;
64  
65  	public TabIdentity(Cv cv) {
66  
67  		assert cv != null;
68  
69  		this.springLayout = new SpringLayout();
70  		this.setLayout(this.springLayout);
71  
72  		//this.createFormaters();
73  
74  		this.createFields();
75  
76  		this.attachModel(cv);
77  
78  		// Lay out the panel.
79  		SpringUtilities.makeCompactGrid(this, // parent
80  				this.getComponentCount() / 2, 2, // rows, cols
81  				6, 6, // initX, initY
82  				6, 6); // xPad, yPad
83  
84  		this.setVisible(true);
85  
86  	}
87  
88  	/***
89  	 * @param cv
90  	 * 
91  	 */
92  	private void attachModel(final Cv cv) {
93  		this.lastNameField.setText(cv.getIdentite().getNom());
94  		this.lastNameField.getDocument().addDocumentListener(
95  				new AbstractTextFieldDocumentListener(this.lastNameField) {
96  
97  					public void recallUpdateGlobal(DocumentEvent arg0) {
98  						cv.getIdentite().setNom(this.getValue());
99  					}
100 				});
101 
102 		this.firstNameField.setText(cv.getIdentite().getPrenom());
103 		this.firstNameField.getDocument().addDocumentListener(
104 				new AbstractTextFieldDocumentListener(this.firstNameField) {
105 
106 					public void recallUpdateGlobal(DocumentEvent arg0) {
107 						cv.getIdentite().setPrenom(this.getValue());
108 					}
109 				});
110 
111 		this.addressField.setText(cv.getIdentite().getAdresse().getVoie());
112 		this.addressField.getDocument().addDocumentListener(
113 				new AbstractTextFieldDocumentListener(this.addressField) {
114 
115 					public void recallUpdateGlobal(DocumentEvent arg0) {
116 						cv.getIdentite().getAdresse().setVoie(this.getValue());
117 					}
118 				});
119 
120 		this.cityField.setText(cv.getIdentite().getAdresse().getVille());
121 		this.cityField.getDocument().addDocumentListener(
122 				new AbstractTextFieldDocumentListener(this.cityField) {
123 
124 					public void recallUpdateGlobal(DocumentEvent arg0) {
125 						cv.getIdentite().getAdresse().setVille(this.getValue());
126 					}
127 				});
128 
129 		this.zipCodeField.setText(cv.getIdentite().getAdresse().getCp());
130 		this.zipCodeField.getDocument().addDocumentListener(
131 				new AbstractTextFieldDocumentListener(this.zipCodeField) {
132 
133 					public void recallUpdateGlobal(DocumentEvent arg0) {
134 						cv.getIdentite().getAdresse().setCp(this.getValue());
135 					}
136 				});
137 
138 		this.phoneField.setText(cv.getIdentite().getTel().getTelFixe());
139 		this.phoneField.getDocument().addDocumentListener(
140 				new AbstractTextFieldDocumentListener(this.phoneField) {
141 
142 					public void recallUpdateGlobal(DocumentEvent arg0) {
143 						cv.getIdentite().getTel().setTelFixe(this.getValue());
144 					}
145 				});
146 
147 		this.mobilePhoneField.setText(cv.getIdentite().getTel().getTelMobile());
148 		this.mobilePhoneField.getDocument().addDocumentListener(
149 				new AbstractTextFieldDocumentListener(this.mobilePhoneField) {
150 
151 					public void recallUpdateGlobal(DocumentEvent arg0) {
152 						cv.getIdentite().getTel().setTelMobile(this.getValue());
153 					}
154 				});
155 	}
156 
157 	/*private void createFormaters() {
158 		try {
159 			// TODO Maybe externalize formatter's configuration.
160 			this.dateFormater = new MaskFormatter("##/##/####"); //$NON-NLS-1$
161 			this.dateFormater.setPlaceholderCharacter('_');
162 		} catch (ParseException e) {
163 			// FIXME e.printStackTrace();
164 		}
165 	}*/
166 
167 	private void createFields() {
168 		this.lastNameField = createField(I18n.getString("TabIdentity.LastName")); //$NON-NLS-1$
169 		this.firstNameField = createField(I18n
170 				.getString("TabIdentity.FirstName")); //$NON-NLS-1$
171 		this.birthDateField = createField(I18n
172 				.getString("TabIdentity.Birthdate")); //$NON-NLS-1$
173 		this.addressField = createField(I18n.getString("TabIdentity.Address")); //$NON-NLS-1$
174 		this.zipCodeField = createField(I18n
175 				.getString("TabIdentity.PostalCode")); //$NON-NLS-1$
176 		this.cityField = createField(I18n.getString("TabIdentity.City")); //$NON-NLS-1$
177 		this.phoneField = createField(I18n.getString("TabIdentity.Phone")); //$NON-NLS-1$
178 		this.mobilePhoneField = createField(I18n
179 				.getString("TabIdentity.MobilePhone")); //$NON-NLS-1$
180 	}
181 
182 }