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  
21  package ui.dialog;
22  
23  import java.awt.BorderLayout;
24  import java.awt.Dimension;
25  import java.awt.GridLayout;
26  import java.awt.Toolkit;
27  import java.awt.event.ActionEvent;
28  import java.awt.event.ActionListener;
29  
30  import javax.swing.JButton;
31  import javax.swing.JDialog;
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.command.CommandExecutor;
39  import ui.command.IO.SaveBackupCommand;
40  import ui.panel.BackupPanel;
41  
42  @SuppressWarnings("serial") //$NON-NLS-1$
43  public class BackupDialog extends JDialog {
44  
45  	private static final transient Logger logger = Logger
46  			.getLogger(BackupDialog.class.getName());
47  
48  	private BackupPanel backupPanel;
49  
50  	private JPanel buttonPanel;
51  
52  	private JButton saveButton;
53  
54  	private JButton closeButton;
55  
56  	public BackupDialog() {
57  		initialize();
58  	}
59  
60  	protected void initialize() {
61  		this.setResizable(false);
62  		this.setSize(300, 400);
63  		// Center the dialog
64  		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
65  		Dimension frameSize = this.getSize();
66  		if (frameSize.height > screenSize.height) {
67  			frameSize.height = screenSize.height;
68  		}
69  		if (frameSize.width > screenSize.width) {
70  			frameSize.width = screenSize.width;
71  		}
72  		this.setLocation((screenSize.width - frameSize.width) / 2,
73  				(screenSize.height - frameSize.height) / 2);
74  
75  		this.setLayout(new BorderLayout());
76  		this.add(getBackupPanel(), BorderLayout.CENTER);
77  		this.add(getButtonPanel(), BorderLayout.SOUTH);
78  	}
79  
80  	/***
81  	 * @return Returns the backupPanel.
82  	 */
83  	protected BackupPanel getBackupPanel() {
84  		if (backupPanel == null) {
85  			backupPanel = new BackupPanel();
86  		}
87  		return backupPanel;
88  	}
89  
90  	/***
91  	 * @return Returns the buttonPanel.
92  	 */
93  	protected JPanel getButtonPanel() {
94  		if (buttonPanel == null) {
95  			buttonPanel = new JPanel();
96  			buttonPanel.setBorder(new TitledBorder(Messages.getString("dialog.availableactions"))); //$NON-NLS-1$
97  			buttonPanel.setLayout(new GridLayout(1, 2));
98  			buttonPanel.add(getSaveButton());
99  			buttonPanel.add(getCloseButton());
100 		}
101 		return buttonPanel;
102 	}
103 
104 	/***
105 	 * @return Returns the closeButton.
106 	 */
107 	protected JButton getCloseButton() {
108 		if (closeButton == null) {
109 			closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$
110 			closeButton.addActionListener(new ActionListener() {
111 				public void actionPerformed(ActionEvent arg0) {
112 					logger.debug("actionPerformed closeButton"); //$NON-NLS-1$
113 					setVisible(false);
114 				}
115 			});
116 		}
117 		return closeButton;
118 	}
119 
120 	/***
121 	 * @return Returns the saveButton.
122 	 */
123 	protected JButton getSaveButton() {
124 		if (saveButton == null) {
125 			saveButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
126 			saveButton.addActionListener(new ActionListener() {
127 				public void actionPerformed(ActionEvent arg0) {
128 					logger.debug("actionPerformed saveButton"); //$NON-NLS-1$
129 					CommandExecutor.getInstance().executeCommand(
130 							new SaveBackupCommand(getBackupPanel()), false);
131 					setVisible(false);
132 				}
133 			});
134 		}
135 		return saveButton;
136 	}
137 }