Coverage details for ui.panel.SessionSearchPanel

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 package ui.panel;
21  
22 import java.awt.BorderLayout;
23 import java.awt.GridLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.Date;
27  
28 import javax.swing.ImageIcon;
29 import javax.swing.JButton;
30 import javax.swing.JCheckBox;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JTextField;
34 import javax.swing.border.TitledBorder;
35  
36 import org.apache.log4j.Logger;
37  
38 import ui.Messages;
39 import ui.command.CommandExecutor;
40 import ui.command.information.SearchSessionCommand;
41 import ui.table.model.SessionTableModel;
42  
43 import com.toedter.calendar.JDateChooser;
44  
450@SuppressWarnings("serial") //$NON-NLS-1$
460public class SessionSearchPanel extends JPanel {
470 
480    private static final transient Logger logger = Logger
490            .getLogger(SessionSearchPanel.class.getName());
50  
51     private JPanel containedTextPanel;
52  
53     private JPanel datePanel;
54  
55     private JPanel buttonPanel;
56  
57     private JButton searchButton;
58  
59     private JButton stopButton;
60  
61     private JDateChooser dateChooser;
62  
63     private JTextField containedTextTextField;
64  
65     private JCheckBox sortByDateCheckBox;
66  
67     private JCheckBox sortByTextCheckBox;
680 
690    private final SessionTableModel sessionTableModel;
700 
710    public SessionSearchPanel(SessionTableModel sessionTableModel) {
720        this.sessionTableModel = sessionTableModel;
730        initialize();
740    }
75  
760    protected void initialize() {
770        this.setLayout(new GridLayout(1, 3));
780        TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.sessionsearchpanel.searchsession")); //$NON-NLS-1$
790        this.setBorder(titledBorder);
800        this.add(getContainedTextPanel(), null);
810        this.add(getDatePanel(), null);
820        this.add(getButtonPanel(), null);
830    }
84  
85     /**
86      * @return Returns the buttonPanel.
87      */
880    protected JPanel getButtonPanel() {
890        if (buttonPanel == null) {
900            buttonPanel = new JPanel();
910            TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions")); //$NON-NLS-1$
920            buttonPanel.setBorder(titledBorder);
930            buttonPanel.setLayout(new GridLayout(1, 2));
940            buttonPanel.add(getSearchButton());
950            buttonPanel.add(getStopButton());
96  
970        }
980        return this.buttonPanel;
99     }
100  
101     /**
102      * @return Returns the searchButton.
103      */
1040    protected JButton getSearchButton() {
1050        if (searchButton == null) {
1060            searchButton = new JButton(Messages.getString("button.search")); //$NON-NLS-1$
1070            searchButton.setIcon(new ImageIcon(this.getClass().getResource(
1080                    "/icon/22x22/actions/system-search.png"))); //$NON-NLS-1$
1090            searchButton.addActionListener(new ActionListener() {
110                 public void actionPerformed(ActionEvent arg0) {
111                     logger.debug("actionPerformed searchButton"); //$NON-NLS-1$
112                     if (getSortByTextCheckBox().isSelected()
113                             && getSortByDateCheckBox().isSelected()) {
114                         CommandExecutor.getInstance().executeCommand(
115                                 new SearchSessionCommand(sessionTableModel,
116                                         getContainedTextTextField().getText(),
117                                         getDateChooser().getDate()), false);
118                     } else if (getSortByTextCheckBox().isSelected()) {
119                         CommandExecutor.getInstance().executeCommand(
120                                 new SearchSessionCommand(sessionTableModel,
121                                         getContainedTextTextField().getText(),
122                                         null), false);
123                     } else if (getSortByDateCheckBox().isSelected()) {
124                         CommandExecutor.getInstance().executeCommand(
125                                 new SearchSessionCommand(sessionTableModel,
126                                         null, getDateChooser().getDate()),
127                                 false);
128                     } else
129                         JOptionPane
130                                 .showMessageDialog(
131                                         null,
132                                         Messages.getString("panel.sessionsearchpanel.message1")); //$NON-NLS-1$
133                 }
134             });
1350        }
1360        return searchButton;
137     }
138  
139     /**
140      * @return Returns the stopButton.
141      */
1420    protected JButton getStopButton() {
1430        if (stopButton == null) {
1440            stopButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$
1450            stopButton.setIcon(new ImageIcon(this.getClass().getResource(
1460                    "/icon/22x22/actions/view-refresh.png"))); //$NON-NLS-1$
1470 
1480            stopButton.addActionListener(new ActionListener() {
149                 public void actionPerformed(ActionEvent arg0) {
150                     logger.debug("actionPerformed stopButton"); //$NON-NLS-1$
151                     getContainedTextTextField().setText(""); //$NON-NLS-1$
152                     getDateChooser().setDate(new Date());
153                     getSortByDateCheckBox().setSelected(false);
154                     getSortByTextCheckBox().setSelected(false);
155                     sessionTableModel.setData(null);
156                     sessionTableModel.fireTableDataChanged();
157                 }
158             });
1590        }
1600        return stopButton;
161     }
162  
163     /**
164      * @return Returns the datePanel.
165      */
1660    protected JPanel getDatePanel() {
1670        if (datePanel == null) {
1680            datePanel = new JPanel();
1690            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.searchbydate")); //$NON-NLS-1$
1700            datePanel.setBorder(titledBorder);
1710            datePanel.setLayout(new BorderLayout());
1720            datePanel.add(getDateChooser(), BorderLayout.CENTER);
1730            datePanel.add(getSortByDateCheckBox(), BorderLayout.WEST);
1740        }
1750        return datePanel;
176     }
177  
178     /**
179      * @return Returns the containedTextPanel.
180      */
1810    protected JPanel getContainedTextPanel() {
1820        if (containedTextPanel == null) {
1830            containedTextPanel = new JPanel();
1840            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.searchbycontainedtext")); //$NON-NLS-1$
1850            containedTextPanel.setBorder(titledBorder);
1860            containedTextPanel.setLayout(new BorderLayout());
1870            containedTextPanel.add(getContainedTextTextField(),
1880                    BorderLayout.CENTER);
1890            containedTextPanel.add(getSortByTextCheckBox(), BorderLayout.WEST);
1900        }
1910        return containedTextPanel;
192     }
193  
194     /**
195      * @return Returns the dateChooser.
196      */
1970    protected JDateChooser getDateChooser() {
1980        if (dateChooser == null) {
1990            dateChooser = new JDateChooser();
2000            dateChooser.setDate(new Date());
2010        }
2020        return this.dateChooser;
203     }
204  
205     /**
206      * @return Returns the containedTextTextField.
207      */
2080    protected JTextField getContainedTextTextField() {
2090        if (containedTextTextField == null) {
2100            containedTextTextField = new JTextField();
2110        }
2120        return this.containedTextTextField;
213     }
214  
215     /**
216      * @return Returns the sortByDateCheckBox.
217      */
2180    protected JCheckBox getSortByDateCheckBox() {
2190        if (sortByDateCheckBox == null) {
2200            sortByDateCheckBox = new JCheckBox();
2210        }
2220        return sortByDateCheckBox;
223     }
224  
225     /**
226      * @return Returns the sortByTextCheckBox.
227      */
2280    protected JCheckBox getSortByTextCheckBox() {
2290        if (sortByTextCheckBox == null) {
2300            sortByTextCheckBox = new JCheckBox();
2310        }
2320        return sortByTextCheckBox;
233     }
234  
235 }

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.