Coverage details for ui.command.information.ShowTextFileDialogCommand

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.command.information;
21  
22 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27  
28 import org.apache.log4j.Logger;
29  
30 import ui.Messages;
31 import ui.command.Command;
32 import ui.dialog.TextFileDialog;
33 import base.InternetCafe;
340 
350public class ShowTextFileDialogCommand extends Command {
360 
370    private static final transient Logger logger = Logger
380            .getLogger(ShowTextFileDialogCommand.class.getName());
39  
40     private String textFileDialogTitle;
41  
42     private String textFileContent;
43  
44     private String textFilePath;
450 
460    public ShowTextFileDialogCommand(String textFileDialogTitle,
470            String textFilePath) {
480        this.textFileDialogTitle = textFileDialogTitle;
490        this.textFilePath = textFilePath;
500    }
51  
52     /*
53      * (non-Javadoc)
54      *
55      * @see ui.command.Command#prologo()
56      */
57     @Override
580    protected void prologo() {
590        InternetCafe.setStatusBarMessage(Messages.getString("command.showtextfiledialogcommand.displaying")+" " + textFileDialogTitle+"..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
600        try {
610            textFileContent = openFile(textFilePath);
620            setStatus(EXECUTE_STATUS);
630        } catch (Exception ex) {
640            logger.error(ex.getMessage());
650            ex.printStackTrace();
660            setStatus(ERROR_STATUS);
670        }
680    }
69  
70     /*
71      * (non-Javadoc)
72      *
73      * @see ui.command.Command#execution()
74      */
75     @Override
760    protected void execution() throws Exception {
770        switch (getStatus()) {
780        case ABORT_STATUS:
790            break;
800        case VETOED_STATUS:
810            break;
820        case EXECUTE_STATUS:
830            TextFileDialog dialog = new TextFileDialog(textFileContent);
840            dialog.setModal(true);
850            dialog.setTitle(textFileDialogTitle);
860            // Center the dialog
870            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
880            Dimension frameSize = dialog.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            dialog.setLocation((screenSize.width - frameSize.width) / 2,
960                    (screenSize.height - frameSize.height) / 2);
970            dialog.setVisible(true);
980            setStatus(SUCCESS_STATUS);
99             break;
1000        }
1010    }
102  
103     public static String openFile(String fileName) {
1040        String result = ""; //$NON-NLS-1$
105         try {
1060            File file = new File(fileName);
1070            if (!file.exists())
1080                return ""; //$NON-NLS-1$
1090            // Read the contents of the file into a byte[] object.
1100            FileInputStream input_file = new FileInputStream(fileName);
1110            byte[] file_data = new byte[(int) file.length()];
1120            input_file.read(file_data);
1130            result = new String(file_data);
1140        } catch (IOException ex) {
1150            ex.printStackTrace();
1160        }
1170        return result;
1180    }
1190 
120 }

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.