Coverage details for ui.dialog.DocumentDialog

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.dialog;
21  
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
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.IO.SaveUserCommand;
41 import ui.command.IO.SaveUserDocumentCommand;
42 import ui.panel.DocumentPanel;
43 import base.user.Document;
44 import base.user.User;
45  
460@SuppressWarnings("serial") //$NON-NLS-1$
470public class DocumentDialog extends JDialog {
480 
490    private static final transient Logger logger = Logger
500            .getLogger(DocumentDialog.class.getName());
51  
52     private JPanel contentPanel;
53  
54     private DocumentPanel documentPanel;
55  
56     private JPanel buttonPanel;
57  
58     private JButton saveDocumentButton;
59  
60     private JButton clearDocumentDataButton;
610 
620    private final Document document;
63  
64     private final User user;
650 
660    private boolean createDocument = false;
670 
680    public DocumentDialog(User user, Document document) {
690        this.user = user;
700        this.document = document;
710        if (document == null)
720            createDocument = true;
730        initialize();
740    }
750 
760    public DocumentDialog(User user) {
770        this.user = user;
780        this.document = this.user.getDocument();
790        createDocument = true;
800        initialize();
810    }
82  
830    protected void initialize() {
840        this.setResizable(false);
850        this.setSize(550, 600);
860        // Center the dialog
870        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
880        Dimension frameSize = this.getSize();
890        if (frameSize.height > screenSize.height) {
900            frameSize.height = screenSize.height;
910        }
920        if (frameSize.width > screenSize.width) {
930            frameSize.width = screenSize.width;
940        }
950        this.setLocation((screenSize.width - frameSize.width) / 2,
960                (screenSize.height - frameSize.height) / 2);
970 
980        this.setContentPane(getContentPanel());
990        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
1000    }
101  
102     /**
103      * @return Returns the documentPanel.
104      */
1050    protected DocumentPanel getDocumentPanel() {
1060        if (documentPanel == null) {
1070            documentPanel = new DocumentPanel(document);
1080        }
1090        return documentPanel;
110     }
111  
112     /**
113      * @return Returns the document.
114      */
1150    public Document getDocument() {
1160        return document;
117     }
118  
119     /**
120      * @return Returns the contentPanel.
121      */
1220    protected JPanel getContentPanel() {
1230        if (contentPanel == null) {
1240            contentPanel = new JPanel();
1250            contentPanel.setLayout(new BorderLayout());
1260            contentPanel.add(getDocumentPanel(), BorderLayout.CENTER);
1270            contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
1280        }
1290        return contentPanel;
130     }
131  
132     /**
133      * @return Returns the buttonPanel.
134      */
1350    protected JPanel getButtonPanel() {
1360        if (buttonPanel == null) {
1370            buttonPanel = new JPanel();
1380            TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions")); //$NON-NLS-1$
1390            buttonPanel.setBorder(titledBorder);
1400            buttonPanel.setLayout(new GridLayout(1, 4));
1410            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1420            buttonPanel.add(getSaveDocumentButton());
1430            buttonPanel.add(getClearDocumentDataButton());
1440            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1450        }
1460        return buttonPanel;
147     }
148  
149     /**
150      * @return Returns the clearDocumentDataButton.
151      */
1520    protected JButton getClearDocumentDataButton() {
1530        if (clearDocumentDataButton == null) {
1540            clearDocumentDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$
1550            clearDocumentDataButton.setIcon(new ImageIcon(this.getClass()
1560                    .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
1570 
1580            clearDocumentDataButton.addActionListener(new ActionListener() {
159                 public void actionPerformed(ActionEvent arg0) {
160                     logger.debug("actionPerformed clearDocumentDataButton"); //$NON-NLS-1$
161                     getDocumentPanel().clearDocumentData();
162                 }
163             });
1640        }
1650        return clearDocumentDataButton;
166     }
167  
168     /**
169      * @return Returns the saveDocumentButton.
170      */
1710    protected JButton getSaveDocumentButton() {
1720        if (saveDocumentButton == null) {
1730            saveDocumentButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
1740            saveDocumentButton.setIcon(new ImageIcon(this.getClass()
1750                    .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
1760 
1770            saveDocumentButton.addActionListener(new ActionListener() {
178                 public void actionPerformed(ActionEvent arg0) {
179                     logger.debug("actionPerformed saveDocumentButton"); //$NON-NLS-1$
180                     SaveUserDocumentCommand saveUserDocumentCommand = new SaveUserDocumentCommand(
181                             getDocumentPanel(), document, createDocument);
182                     CommandExecutor.getInstance().executeCommand(
183                             saveUserDocumentCommand, true);
184                     if (saveUserDocumentCommand.getStatus() == SaveUserCommand.SUCCESS_STATUS)
185                         setVisible(false);
186                 }
187             });
188  
1890        }
1900        return saveDocumentButton;
191     }
192 }

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.