Line | Hits | Source |
---|---|---|
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.panel; | |
22 | ||
23 | import java.awt.BorderLayout; | |
24 | import java.awt.Dimension; | |
25 | import java.awt.GridLayout; | |
26 | import java.awt.event.ActionEvent; | |
27 | import java.awt.event.ActionListener; | |
28 | import java.io.File; | |
29 | import java.util.Vector; | |
30 | ||
31 | import javax.swing.ImageIcon; | |
32 | import javax.swing.JButton; | |
33 | import javax.swing.JLabel; | |
34 | import javax.swing.JPanel; | |
35 | import javax.swing.JScrollPane; | |
36 | import javax.swing.JTable; | |
37 | import javax.swing.border.TitledBorder; | |
38 | import javax.swing.table.TableModel; | |
39 | ||
40 | import org.apache.log4j.Logger; | |
41 | ||
42 | import ui.table.TableSorter; | |
43 | import base.jdbs.Backup; | |
44 | import base.jdbs.ui.FileTableModel; | |
45 | import base.util.FileUtil; | |
46 | ||
47 | /** | |
48 | * @author skunk | |
49 | * | |
50 | */ | |
51 | 0 | @SuppressWarnings("serial") |
52 | 0 | public class TabledFilePanel extends JPanel { |
53 | 0 | |
54 | 0 | private static final transient Logger logger = Logger |
55 | .getLogger(TabledFilePanel.class.getName()); | |
56 | ||
57 | private JTable fileTable; | |
58 | ||
59 | private JScrollPane fileTableScrollPane; | |
60 | ||
61 | private TableSorter fileTableSorter; | |
62 | ||
63 | private TableModel fileTableModel; | |
64 | ||
65 | private JPanel statPanel; | |
66 | ||
67 | private JPanel buttonPanel; | |
68 | 0 | |
69 | private JButton addFileButton; | |
70 | 0 | |
71 | 0 | private JButton removeFileButton; |
72 | 0 | |
73 | 0 | private final Backup backup; |
74 | ||
75 | 0 | public TabledFilePanel(Backup backup) { |
76 | 0 | this.backup = backup; |
77 | 0 | initialize(); |
78 | 0 | } |
79 | 0 | |
80 | 0 | protected void initialize() { |
81 | 0 | this.setBorder(new TitledBorder("Backup Files")); |
82 | 0 | this.setLayout(new BorderLayout()); |
83 | 0 | this.add(this.getFileTableScrollPane(), BorderLayout.CENTER); |
84 | 0 | this.add(this.getButtonPanel(), BorderLayout.EAST); |
85 | 0 | this.add(this.getStatPanel(), BorderLayout.SOUTH); |
86 | 0 | } |
87 | 0 | |
88 | 0 | /** |
89 | 0 | * @return Returns the fileTable. |
90 | */ | |
91 | 0 | protected JTable getFileTable() { |
92 | 0 | if (fileTable == null) { |
93 | 0 | fileTable = new JTable(getFileTableSorter()); |
94 | 0 | fileTable |
95 | 0 | .setPreferredScrollableViewportSize(new Dimension(500, 70)); |
96 | // We need to place it here to avoid a ciclyc call... | |
97 | 0 | fileTableSorter.setTableHeader(fileTable.getTableHeader()); |
98 | // Set up tool tips for column headers. | |
99 | 0 | fileTable |
100 | .getTableHeader() | |
101 | .setToolTipText( | |
102 | 0 | "Click to specify sorting; Control-Click to specify secondary sorting."); |
103 | 0 | } |
104 | 0 | return fileTable; |
105 | 0 | } |
106 | ||
107 | /** | |
108 | * @return Returns the fileTableScrollPane. | |
109 | */ | |
110 | protected JScrollPane getFileTableScrollPane() { | |
111 | 0 | if (fileTableScrollPane == null) { |
112 | 0 | fileTableScrollPane = new JScrollPane(getFileTable()); |
113 | 0 | } |
114 | 0 | return fileTableScrollPane; |
115 | 0 | } |
116 | ||
117 | /** | |
118 | * @return Returns the fileTableSorter. | |
119 | */ | |
120 | protected TableSorter getFileTableSorter() { | |
121 | 0 | if (fileTableSorter == null) { |
122 | 0 | fileTableSorter = new TableSorter(getFileTableModel()); |
123 | 0 | } |
124 | 0 | return fileTableSorter; |
125 | 0 | } |
126 | ||
127 | /** | |
128 | * @return Returns the fileTableModel. | |
129 | */ | |
130 | protected TableModel getFileTableModel() { | |
131 | 0 | if (fileTableModel == null) { |
132 | 0 | fileTableModel = new FileTableModel(backup); |
133 | 0 | } |
134 | 0 | return fileTableModel; |
135 | 0 | } |
136 | 0 | |
137 | 0 | /** |
138 | 0 | * @return Returns the buttonPanel. |
139 | */ | |
140 | 0 | protected JPanel getButtonPanel() { |
141 | 0 | if (this.buttonPanel == null) { |
142 | 0 | this.buttonPanel = new JPanel(); |
143 | 0 | this.buttonPanel.setLayout(new GridLayout(4, 1)); |
144 | 0 | this.buttonPanel.add(new JLabel()); |
145 | 0 | this.buttonPanel.add(this.getAddFileButton()); |
146 | 0 | this.buttonPanel.add(this.getRemoveFileButton()); |
147 | 0 | this.buttonPanel.add(new JLabel()); |
148 | 0 | } |
149 | 0 | return buttonPanel; |
150 | 0 | } |
151 | ||
152 | 0 | /** |
153 | * @return Returns the addFileButton. | |
154 | */ | |
155 | protected JButton getAddFileButton() { | |
156 | 0 | if (this.addFileButton == null) { |
157 | 0 | this.addFileButton = new JButton(); |
158 | 0 | this.addFileButton |
159 | .setToolTipText("Adds one or more files to the the backup..."); | |
160 | 0 | this.addFileButton.setIcon(new ImageIcon(this.getClass() |
161 | .getResource("/icon/16x16/actions/list-add.png"))); | |
162 | ||
163 | 0 | this.addFileButton.addActionListener(new ActionListener() { |
164 | ||
165 | public void actionPerformed(ActionEvent arg0) { | |
166 | Vector<File> fileSelection = new Vector<File>(); | |
167 | javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); | |
168 | chooser | |
169 | .setDialogTitle("Select the files and the folders that must be backupped..."); | |
170 | chooser | |
171 | .setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES); | |
172 | chooser.setApproveButtonText("Select"); | |
173 | 0 | chooser.setMultiSelectionEnabled(true); |
174 | ||
175 | if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) { | |
176 | File[] tempFileSelection = chooser.getSelectedFiles(); | |
177 | for (int i = 0; i < tempFileSelection.length; i++) { | |
178 | File[] allFileAndFolder = FileUtil | |
179 | .allFileContent(tempFileSelection[i]); | |
180 | 0 | for (int k = 0; k < allFileAndFolder.length; k++) |
181 | 0 | fileSelection.add(allFileAndFolder[k]); |
182 | 0 | } |
183 | 0 | } |
184 | backup.addAllFile(fileSelection.toArray(new File[0])); | |
185 | } | |
186 | 0 | }); |
187 | } | |
188 | 0 | return addFileButton; |
189 | } | |
190 | ||
191 | /** | |
192 | * @return Returns the removeFileButton. | |
193 | 0 | */ |
194 | 0 | protected JButton getRemoveFileButton() { |
195 | 0 | if (this.removeFileButton == null) { |
196 | 0 | this.removeFileButton = new JButton(); |
197 | 0 | this.removeFileButton |
198 | .setToolTipText("Removes one or more files from the the backup..."); | |
199 | 0 | this.removeFileButton.setIcon(new ImageIcon(this.getClass() |
200 | .getResource("/icon/16x16/actions/list-remove.png"))); | |
201 | ||
202 | } | |
203 | 0 | return removeFileButton; |
204 | } | |
205 | ||
206 | /** | |
207 | * @return Returns the statPanel. | |
208 | */ | |
209 | protected JPanel getStatPanel() { | |
210 | 0 | if (this.statPanel == null) { |
211 | 0 | this.statPanel = new FileStatisticPanel(backup); |
212 | } | |
213 | 0 | return statPanel; |
214 | } | |
215 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |