Coverage details for ui.dialog.LicenseDialog

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.FlowLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30  
31 import javax.swing.JButton;
32 import javax.swing.JDialog;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTextArea;
36  
37 import org.apache.log4j.Logger;
38  
39 import ui.Messages;
40 import base.ConfigurationManager;
41  
420@SuppressWarnings("serial") //$NON-NLS-1$
430public class LicenseDialog extends JDialog {
440 
450    private static final transient Logger logger = Logger
460            .getLogger(LicenseDialog.class.getName());
470 
48     private JTextArea licenseTextArea;
49  
50     private JScrollPane licenseScrollPane;
51  
52     private JPanel buttonPanel;
53  
54     private JButton closeButton;
550 
560    public LicenseDialog() {
570        initialize();
580    }
590 
600    protected void initialize() {
610        this.setSize(new Dimension(650, 600));
620        this.setLayout(new BorderLayout());
630        this.add(getLicenseScrollPane(), BorderLayout.CENTER);
640        this.add(getButtonPanel(), BorderLayout.SOUTH);
650        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
660    }
670 
68     /**
69      * @return Returns the buttonPanel.
70      */
710    protected JPanel getButtonPanel() {
720        if (buttonPanel == null) {
730            buttonPanel = new JPanel();
740            buttonPanel.setLayout(new FlowLayout());
750            buttonPanel.add(getCloseButton());
760        }
770        return buttonPanel;
780    }
79  
80     /**
81      * @return Returns the closeButton.
82      */
830    protected JButton getCloseButton() {
840        if (closeButton == null) {
850            closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$
860            closeButton.addActionListener(new ActionListener() {
870                public void actionPerformed(ActionEvent arg0) {
88                     logger.debug("actionPerformed closeButton"); //$NON-NLS-1$
89                     setVisible(false);
90                 }
91             });
920        }
930        return closeButton;
940    }
95  
96     /**
97      * @return Returns the licenseScrollPane.
98      */
990    protected JScrollPane getLicenseScrollPane() {
1000        if (licenseScrollPane == null) {
1010            licenseScrollPane = new JScrollPane();
1020            licenseScrollPane.setViewportView(getLicenseTextArea());
1030            licenseScrollPane
1040                    .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
1050            licenseScrollPane
1060                    .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
1070        }
1080        return licenseScrollPane;
1090    }
110  
111     /**
112      * @return Returns the licenseTextArea.
113      */
1140    protected JTextArea getLicenseTextArea() {
1150        if (licenseTextArea == null) {
1160            licenseTextArea = new JTextArea();
1170            licenseTextArea.setEditable(false);
1180            licenseTextArea
1190                    .setText(openFile(ConfigurationManager.LICENSE_FILE));
1200            licenseTextArea.setCaretPosition(0);
1210            licenseTextArea.setWrapStyleWord(true);
1220        }
1230        return licenseTextArea;
1240    }
125  
1260    public static String openFile(String fileName) {
1270        String result = ""; //$NON-NLS-1$
1280        try {
1290            File file = new File(fileName);
1300            if (!file.exists())
1310                return ""; //$NON-NLS-1$
1320            // Read the contents of the file into a byte[] object.
1330            FileInputStream input_file = new FileInputStream(fileName);
1340            byte[] file_data = new byte[(int) file.length()];
1350            input_file.read(file_data);
1360            result = new String(file_data);
1370        } catch (IOException ex) {
1380            ex.printStackTrace();
1390        }
1400        return result;
1410    }
142  
143 }

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.