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.panel;
22  
23  import java.awt.BorderLayout;
24  import java.awt.GridLayout;
25  import java.io.File;
26  import java.util.Date;
27  
28  import javax.swing.JPanel;
29  import javax.swing.JTextField;
30  import javax.swing.border.TitledBorder;
31  
32  import ui.Messages;
33  import base.ConfigurationManager;
34  import base.backup.BackupFactory;
35  
36  @SuppressWarnings("serial") //$NON-NLS-1$
37  public class DatabasePanel extends JPanel {
38  
39  	private JPanel databasePathPanel;
40  
41  	private JTextField databasePathTextField;
42  
43  	private JPanel databaseLastModifiedPanel;
44  
45  	private JTextField databaseLastModifiedTextField;
46  
47  	private JPanel databaseSizePanel;
48  
49  	private JTextField databaseSizeTextField;
50  
51  	public DatabasePanel() {
52  		initialize();
53  	}
54  
55  	protected void initialize() {
56  		this.setBorder(new TitledBorder(Messages.getString("panel.databasepanel.currentdatabasefile"))); //$NON-NLS-1$
57  		this.setLayout(new GridLayout(1, 3));
58  		this.add(getDatabasePathPanel());
59  		this.add(getDatabaseSizePanel());
60  		this.add(getDatabaseLastModifiedPanel());
61  	}
62  
63  	/***
64  	 * @return Returns the databasePathPanel.
65  	 */
66  	protected JPanel getDatabasePathPanel() {
67  		if (databasePathPanel == null) {
68  			databasePathPanel = new JPanel();
69  			TitledBorder titledBorder = new TitledBorder(Messages.getString("common.filepath")); //$NON-NLS-1$
70  			databasePathPanel.setBorder(titledBorder);
71  			databasePathPanel.setLayout(new BorderLayout());
72  			databasePathPanel.add(getDatabasePathTextField(),
73  					BorderLayout.CENTER);
74  		}
75  		return databasePathPanel;
76  	}
77  
78  	/***
79  	 * @return Returns the databasePathTextField.
80  	 */
81  	protected JTextField getDatabasePathTextField() {
82  		if (databasePathTextField == null) {
83  			databasePathTextField = new JTextField(ConfigurationManager
84  					.getInstance().getDataBasePath());
85  			databasePathTextField.setEditable(false);
86  		}
87  		return databasePathTextField;
88  	}
89  
90  	/***
91  	 * @return Returns the databaseSizePanel.
92  	 */
93  	protected JPanel getDatabaseSizePanel() {
94  		if (databaseSizePanel == null) {
95  			databaseSizePanel = new JPanel();
96  			databaseSizePanel.setBorder(new TitledBorder(Messages.getString("common.size")+" "+ Messages.getString("common.unit.kylobyte"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
97  			databaseSizePanel.setLayout(new BorderLayout());
98  			databaseSizePanel.add(getDatabaseSizeTextField(),
99  					BorderLayout.CENTER);
100 		}
101 		return databaseSizePanel;
102 	}
103 
104 	/***
105 	 * @return Returns the databaseSizeTextField.
106 	 */
107 	protected JTextField getDatabaseSizeTextField() {
108 		if (databaseSizeTextField == null) {
109 			databaseSizeTextField = new JTextField();
110 			databaseSizeTextField.setText("" //$NON-NLS-1$
111 					+ BackupFactory.fileSizeInKB(new File(ConfigurationManager
112 							.getInstance().getDataBasePath())));
113 			databaseSizeTextField.setEditable(false);
114 		}
115 		return databaseSizeTextField;
116 	}
117 
118 	/***
119 	 * @return Returns the databaseLastModifiedPanel.
120 	 */
121 	protected JPanel getDatabaseLastModifiedPanel() {
122 		if (databaseLastModifiedPanel == null) {
123 			databaseLastModifiedPanel = new JPanel();
124 			databaseLastModifiedPanel.setBorder(new TitledBorder(
125 					Messages.getString("common.lastmodified"))); //$NON-NLS-1$
126 			databaseLastModifiedPanel.setLayout(new BorderLayout());
127 			databaseLastModifiedPanel.add(getDatabaseLastModifiedTextField(),
128 					BorderLayout.CENTER);
129 		}
130 		return databaseLastModifiedPanel;
131 	}
132 
133 	/***
134 	 * @return Returns the databaseLastModifiedTextField.
135 	 */
136 	protected JTextField getDatabaseLastModifiedTextField() {
137 		if (databaseLastModifiedTextField == null) {
138 			databaseLastModifiedTextField = new JTextField();
139 			databaseLastModifiedTextField.setText(new Date(new File(
140 					ConfigurationManager.getInstance().getDataBasePath())
141 					.lastModified()).toString());
142 			databaseLastModifiedTextField.setEditable(false);
143 		}
144 		return databaseLastModifiedTextField;
145 	}
146 }