View Javadoc

1   /********************************************************************************
2    * InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  package ui.panel;
21  
22  import java.awt.BorderLayout;
23  import java.awt.GridLayout;
24  
25  import javax.swing.JPanel;
26  import javax.swing.JTextField;
27  import javax.swing.border.TitledBorder;
28  
29  import ui.Messages;
30  import base.user.PhoneNumber;
31  
32  @SuppressWarnings("serial") //$NON-NLS-1$
33  public class PhoneNumberPanel extends JPanel {
34  
35  	private JPanel areaCodePanel;
36  
37  	private JTextField areaCodeTextField;
38  
39  	private JPanel exchangePanel;
40  
41  	private JTextField exchangeTextField;
42  
43  	private JPanel numberPanel;
44  
45  	private JTextField numberTextField;
46  
47  	private JPanel descriptionPanel;
48  
49  	private JTextField descriptionTextField;
50  
51  	public String getPhoneNumberAreaCode() {
52  		return this.getAreaCodeTextField().getText();
53  	}
54  
55  	public String getPhoneNumberExchange() {
56  		return this.getExchangeTextField().getText();
57  	}
58  
59  	public String getPhoneNumberNumber() {
60  		return this.getNumberTextField().getText();
61  	}
62  
63  	public String getPhoneNumberDescription() {
64  		return this.getDescriptionTextField().getText();
65  	}
66  
67  	private PhoneNumber phoneNumber;
68  
69  	/***
70  	 * @param phoneNumber
71  	 *            The PhoneNumber from which the displayed informations must be
72  	 *            retrieved.
73  	 */
74  	public PhoneNumberPanel(PhoneNumber phoneNumber) {
75  		this.phoneNumber = phoneNumber;
76  		initialize();
77  	}
78  
79  	protected void initialize() {
80  		this.setLayout(new GridLayout(4, 1));
81  		this.add(getAreaCodePanel());
82  		this.add(getExchangePanel());
83  		this.add(getNumberPanel());
84  		this.add(getDescriptionPanel());
85  	}
86  
87  	/***
88  	 * @return Returns the areaCodePanel.
89  	 */
90  	protected JPanel getAreaCodePanel() {
91  		if (areaCodePanel == null) {
92  			areaCodePanel = new JPanel();
93  			areaCodePanel.setBorder(new TitledBorder(Messages.getString("common.areacode"))); //$NON-NLS-1$
94  			areaCodePanel.setLayout(new BorderLayout());
95  			areaCodePanel.add(getAreaCodeTextField(), BorderLayout.CENTER);
96  		}
97  		return areaCodePanel;
98  	}
99  
100 	/***
101 	 * @return Returns the descriptionPanel.
102 	 */
103 	protected JPanel getDescriptionPanel() {
104 		if (descriptionPanel == null) {
105 			descriptionPanel = new JPanel();
106 			descriptionPanel.setBorder(new TitledBorder(Messages.getString("common.description"))); //$NON-NLS-1$
107 			descriptionPanel.setLayout(new BorderLayout());
108 			descriptionPanel
109 					.add(getDescriptionTextField(), BorderLayout.CENTER);
110 		}
111 		return descriptionPanel;
112 	}
113 
114 	/***
115 	 * @return Returns the exchangePanel.
116 	 */
117 	protected JPanel getExchangePanel() {
118 		if (exchangePanel == null) {
119 			exchangePanel = new JPanel();
120 			exchangePanel.setBorder(new TitledBorder(Messages.getString("common.exchange"))); //$NON-NLS-1$
121 			exchangePanel.setLayout(new BorderLayout());
122 			exchangePanel.add(getExchangeTextField(), BorderLayout.CENTER);
123 		}
124 		return exchangePanel;
125 	}
126 
127 	/***
128 	 * @return Returns the numberPanel.
129 	 */
130 	protected JPanel getNumberPanel() {
131 		if (numberPanel == null) {
132 			numberPanel = new JPanel();
133 			numberPanel.setBorder(new TitledBorder(Messages.getString("common.number"))); //$NON-NLS-1$
134 			numberPanel.setLayout(new BorderLayout());
135 			numberPanel.add(getNumberTextField(), BorderLayout.CENTER);
136 		}
137 		return numberPanel;
138 	}
139 
140 	/***
141 	 * @return Returns the areaCodeTextField.
142 	 */
143 	protected JTextField getAreaCodeTextField() {
144 		if (areaCodeTextField == null) {
145 			areaCodeTextField = new JTextField();
146 			areaCodeTextField.setText(phoneNumber != null ? "" //$NON-NLS-1$
147 					+ phoneNumber.getAreaCode() : Messages.getString("phonenumber.default.areacode")); //$NON-NLS-1$
148 		}
149 		return areaCodeTextField;
150 	}
151 
152 	/***
153 	 * @return Returns the descriptionTextField.
154 	 */
155 	protected JTextField getDescriptionTextField() {
156 		if (descriptionTextField == null) {
157 			descriptionTextField = new JTextField();
158 			descriptionTextField.setText(phoneNumber != null ? phoneNumber
159 					.getDescription() : ""); //$NON-NLS-1$
160 		}
161 		return descriptionTextField;
162 	}
163 
164 	/***
165 	 * @return Returns the exchangeTextField.
166 	 */
167 	protected JTextField getExchangeTextField() {
168 		if (exchangeTextField == null) {
169 			exchangeTextField = new JTextField();
170 			exchangeTextField.setText(phoneNumber != null ? phoneNumber
171 					.getExchange() : ""); //$NON-NLS-1$
172 		}
173 		return exchangeTextField;
174 	}
175 
176 	/***
177 	 * @return Returns the numberTextField.
178 	 */
179 	protected JTextField getNumberTextField() {
180 		if (numberTextField == null) {
181 			numberTextField = new JTextField();
182 			numberTextField.setText(phoneNumber != null ? phoneNumber
183 					.getNumber() : ""); //$NON-NLS-1$
184 		}
185 		return numberTextField;
186 	}
187 
188 }