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 base.jdbs.ui.dialog;
22  
23  import java.awt.BorderLayout;
24  import java.awt.GridLayout;
25  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;
27  
28  import javax.swing.JButton;
29  import javax.swing.JDialog;
30  import javax.swing.JLabel;
31  import javax.swing.JPanel;
32  
33  import org.apache.log4j.Logger;
34  
35  import ui.command.CommandExecutor;
36  import ui.util.GeneralUtil;
37  import base.jdbs.Backup;
38  import base.jdbs.BackupFactory;
39  import base.jdbs.ui.command.BuildBackupArtifactCommand;
40  import base.jdbs.ui.panel.BackupPanel;
41  
42  /***
43   * @author skunk
44   * 
45   */
46  @SuppressWarnings("serial")
47  public class BackupDialog extends JDialog {
48  
49  	private static final transient Logger logger = Logger
50  			.getLogger(BackupDialog.class.getName());
51  
52  	private JPanel backupPanel;
53  
54  	private JPanel buttonPanel;
55  
56  	private JButton buildBackupArtifactButton;
57  
58  	private JButton closeButton;
59  
60  	private final Backup backup = BackupFactory.newDefaultBackup();
61  
62  	public BackupDialog() {
63  		initialize();
64  	}
65  
66  	protected void initialize() {
67  		this.setSize(800, 600);
68  		GeneralUtil.centerComponent(this);
69  		this.setLayout(new BorderLayout());
70  		this.add(this.getBackupPanel(), BorderLayout.CENTER);
71  		this.add(this.getButtonPanel(), BorderLayout.SOUTH);
72  	}
73  
74  	/***
75  	 * @return Returns the backupPanel.
76  	 */
77  	protected JPanel getBackupPanel() {
78  		if (this.backupPanel == null) {
79  			this.backupPanel = new BackupPanel(backup);
80  		}
81  		return backupPanel;
82  	}
83  
84  	/***
85  	 * @return Returns the buttonPanel.
86  	 */
87  	protected JPanel getButtonPanel() {
88  		if (this.buttonPanel == null) {
89  			this.buttonPanel = new JPanel();
90  			this.buttonPanel.setLayout(new GridLayout(1, 4));
91  			this.buttonPanel.add(new JLabel());
92  			this.buttonPanel.add(this.getBuildBackupArtifactButton());
93  			this.buttonPanel.add(this.getCloseButton());
94  			this.buttonPanel.add(new JLabel());
95  		}
96  		return buttonPanel;
97  	}
98  
99  	/***
100 	 * @return Returns the buildBackupArtifactButton.
101 	 */
102 	protected JButton getBuildBackupArtifactButton() {
103 		if (this.buildBackupArtifactButton == null) {
104 			this.buildBackupArtifactButton = new JButton("Build Artifact");
105 			this.buildBackupArtifactButton
106 					.addActionListener(new ActionListener() {
107 
108 						public void actionPerformed(ActionEvent arg0) {
109 							CommandExecutor.getInstance().executeCommand(
110 									new BuildBackupArtifactCommand(backup),
111 									false);
112 							setVisible(false);
113 						}
114 					});
115 		}
116 		return buildBackupArtifactButton;
117 	}
118 
119 	/***
120 	 * @return Returns the closeButton.
121 	 */
122 	protected JButton getCloseButton() {
123 		if (this.closeButton == null) {
124 			this.closeButton = new JButton("Close");
125 			this.closeButton.addActionListener(new ActionListener() {
126 
127 				public void actionPerformed(ActionEvent arg0) {
128 					setVisible(false);
129 				}
130 			});
131 		}
132 		return closeButton;
133 	}
134 
135 }