Coverage details for base.jdbs.ui.panel.TabledFilePanel

LineHitsSource
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  */
510@SuppressWarnings("serial")
520public class TabledFilePanel extends JPanel {
530 
540    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;
680 
69     private JButton addFileButton;
700 
710    private JButton removeFileButton;
720 
730    private final Backup backup;
74  
750    public TabledFilePanel(Backup backup) {
760        this.backup = backup;
770        initialize();
780    }
790 
800    protected void initialize() {
810        this.setBorder(new TitledBorder("Backup Files"));
820        this.setLayout(new BorderLayout());
830        this.add(this.getFileTableScrollPane(), BorderLayout.CENTER);
840        this.add(this.getButtonPanel(), BorderLayout.EAST);
850        this.add(this.getStatPanel(), BorderLayout.SOUTH);
860    }
870 
880    /**
890     * @return Returns the fileTable.
90      */
910    protected JTable getFileTable() {
920        if (fileTable == null) {
930            fileTable = new JTable(getFileTableSorter());
940            fileTable
950                    .setPreferredScrollableViewportSize(new Dimension(500, 70));
96             // We need to place it here to avoid a ciclyc call...
970            fileTableSorter.setTableHeader(fileTable.getTableHeader());
98             // Set up tool tips for column headers.
990            fileTable
100                     .getTableHeader()
101                     .setToolTipText(
1020                            "Click to specify sorting; Control-Click to specify secondary sorting.");
1030        }
1040        return fileTable;
1050    }
106  
107     /**
108      * @return Returns the fileTableScrollPane.
109      */
110     protected JScrollPane getFileTableScrollPane() {
1110        if (fileTableScrollPane == null) {
1120            fileTableScrollPane = new JScrollPane(getFileTable());
1130        }
1140        return fileTableScrollPane;
1150    }
116  
117     /**
118      * @return Returns the fileTableSorter.
119      */
120     protected TableSorter getFileTableSorter() {
1210        if (fileTableSorter == null) {
1220            fileTableSorter = new TableSorter(getFileTableModel());
1230        }
1240        return fileTableSorter;
1250    }
126  
127     /**
128      * @return Returns the fileTableModel.
129      */
130     protected TableModel getFileTableModel() {
1310        if (fileTableModel == null) {
1320            fileTableModel = new FileTableModel(backup);
1330        }
1340        return fileTableModel;
1350    }
1360 
1370    /**
1380     * @return Returns the buttonPanel.
139      */
1400    protected JPanel getButtonPanel() {
1410        if (this.buttonPanel == null) {
1420            this.buttonPanel = new JPanel();
1430            this.buttonPanel.setLayout(new GridLayout(4, 1));
1440            this.buttonPanel.add(new JLabel());
1450            this.buttonPanel.add(this.getAddFileButton());
1460            this.buttonPanel.add(this.getRemoveFileButton());
1470            this.buttonPanel.add(new JLabel());
1480        }
1490        return buttonPanel;
1500    }
151  
1520    /**
153      * @return Returns the addFileButton.
154      */
155     protected JButton getAddFileButton() {
1560        if (this.addFileButton == null) {
1570            this.addFileButton = new JButton();
1580            this.addFileButton
159                     .setToolTipText("Adds one or more files to the the backup...");
1600            this.addFileButton.setIcon(new ImageIcon(this.getClass()
161                     .getResource("/icon/16x16/actions/list-add.png")));
162  
1630            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");
1730                    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]);
1800                            for (int k = 0; k < allFileAndFolder.length; k++)
1810                                fileSelection.add(allFileAndFolder[k]);
1820                        }
1830                    }
184                     backup.addAllFile(fileSelection.toArray(new File[0]));
185                 }
1860            });
187         }
1880        return addFileButton;
189     }
190  
191     /**
192      * @return Returns the removeFileButton.
1930     */
1940    protected JButton getRemoveFileButton() {
1950        if (this.removeFileButton == null) {
1960            this.removeFileButton = new JButton();
1970            this.removeFileButton
198                     .setToolTipText("Removes one or more files from the the backup...");
1990            this.removeFileButton.setIcon(new ImageIcon(this.getClass()
200                     .getResource("/icon/16x16/actions/list-remove.png")));
201  
202         }
2030        return removeFileButton;
204     }
205  
206     /**
207      * @return Returns the statPanel.
208      */
209     protected JPanel getStatPanel() {
2100        if (this.statPanel == null) {
2110            this.statPanel = new FileStatisticPanel(backup);
212         }
2130        return statPanel;
214     }
215 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.