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.dialog;
21  
22  import java.awt.BorderLayout;
23  import java.awt.Dimension;
24  import java.awt.GridLayout;
25  import java.awt.Toolkit;
26  import java.awt.event.ActionEvent;
27  import java.awt.event.ActionListener;
28  
29  import javax.swing.JButton;
30  import javax.swing.JDialog;
31  import javax.swing.JLabel;
32  import javax.swing.JPanel;
33  import javax.swing.border.TitledBorder;
34  
35  import org.apache.log4j.Logger;
36  
37  import ui.Messages;
38  import ui.panel.UserAddressBookPanel;
39  import base.user.User;
40  
41  @SuppressWarnings("serial") //$NON-NLS-1$
42  public class UserAddressBookDialog extends JDialog {
43  
44  	private static final transient Logger logger = Logger
45  			.getLogger(UserAddressBookDialog.class.getName());
46  
47  	private JPanel contentPanel;
48  
49  	private UserAddressBookPanel userAddressBookPanel;
50  
51  	private JPanel buttonPanel;
52  
53  	private JButton closeButton;
54  
55  	private final User user;
56  
57  	public UserAddressBookDialog(User user) {
58  		this.user = user;
59  		initialize();
60  	}
61  
62  	protected void initialize() {
63  		this.setResizable(false);
64  		this.setSize(550, 600);
65  		// Center the dialog
66  		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
67  		Dimension frameSize = this.getSize();
68  		if (frameSize.height > screenSize.height) {
69  			frameSize.height = screenSize.height;
70  		}
71  		if (frameSize.width > screenSize.width) {
72  			frameSize.width = screenSize.width;
73  		}
74  		this.setLocation((screenSize.width - frameSize.width) / 2,
75  				(screenSize.height - frameSize.height) / 2);
76  
77  		this.setContentPane(getContentPanel());
78  		this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
79  	}
80  
81  	/***
82  	 * @return Returns the contentPanel.
83  	 */
84  	protected JPanel getContentPanel() {
85  		if (contentPanel == null) {
86  			contentPanel = new JPanel();
87  			contentPanel.setLayout(new BorderLayout());
88  			contentPanel.add(getUserAddressBookPanel(), BorderLayout.CENTER);
89  			contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
90  		}
91  		return contentPanel;
92  	}
93  
94  	/***
95  	 * @return Returns the buttonPanel.
96  	 */
97  	protected JPanel getButtonPanel() {
98  		if (buttonPanel == null) {
99  			buttonPanel = new JPanel();
100 			buttonPanel.setBorder(new TitledBorder(Messages.getString("dialog.availableactions"))); //$NON-NLS-1$
101 			buttonPanel.setLayout(new GridLayout(1, 3));
102 			buttonPanel.add(new JLabel("")); //$NON-NLS-1$
103 			buttonPanel.add(getCloseButton());
104 			buttonPanel.add(new JLabel("")); //$NON-NLS-1$
105 
106 		}
107 		return buttonPanel;
108 	}
109 
110 	/***
111 	 * @return Returns the userAddressBookPanel.
112 	 */
113 	protected UserAddressBookPanel getUserAddressBookPanel() {
114 		if (userAddressBookPanel == null) {
115 			userAddressBookPanel = new UserAddressBookPanel(getUser());
116 		}
117 		return userAddressBookPanel;
118 	}
119 
120 	/***
121 	 * @return Returns the user.
122 	 */
123 	protected User getUser() {
124 		return user;
125 	}
126 
127 	/***
128 	 * @return Returns the closeButton.
129 	 */
130 	protected JButton getCloseButton() {
131 		if (closeButton == null) {
132 			closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$
133 			// closeButton.setIcon(new
134 			// ImageIcon(this.getClass().getResource("/icon/16x16/actions/window-close.png")));
135 			closeButton.addActionListener(new ActionListener() {
136 				public void actionPerformed(ActionEvent arg0) {
137 					logger.debug("actionPerformed closeButton"); //$NON-NLS-1$
138 					setVisible(false);
139 				}
140 			});
141 		}
142 		return closeButton;
143 	}
144 }