| Line | Hits | Source |
|---|---|---|
| 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; | |
| 34 | 0 | |
| 35 | 0 | public class ShowTextFileDialogCommand extends Command { |
| 36 | 0 | |
| 37 | 0 | private static final transient Logger logger = Logger |
| 38 | 0 | .getLogger(ShowTextFileDialogCommand.class.getName()); |
| 39 | ||
| 40 | private String textFileDialogTitle; | |
| 41 | ||
| 42 | private String textFileContent; | |
| 43 | ||
| 44 | private String textFilePath; | |
| 45 | 0 | |
| 46 | 0 | public ShowTextFileDialogCommand(String textFileDialogTitle, |
| 47 | 0 | String textFilePath) { |
| 48 | 0 | this.textFileDialogTitle = textFileDialogTitle; |
| 49 | 0 | this.textFilePath = textFilePath; |
| 50 | 0 | } |
| 51 | ||
| 52 | /* | |
| 53 | * (non-Javadoc) | |
| 54 | * | |
| 55 | * @see ui.command.Command#prologo() | |
| 56 | */ | |
| 57 | @Override | |
| 58 | 0 | protected void prologo() { |
| 59 | 0 | InternetCafe.setStatusBarMessage(Messages.getString("command.showtextfiledialogcommand.displaying")+" " + textFileDialogTitle+"..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 60 | 0 | try { |
| 61 | 0 | textFileContent = openFile(textFilePath); |
| 62 | 0 | setStatus(EXECUTE_STATUS); |
| 63 | 0 | } catch (Exception ex) { |
| 64 | 0 | logger.error(ex.getMessage()); |
| 65 | 0 | ex.printStackTrace(); |
| 66 | 0 | setStatus(ERROR_STATUS); |
| 67 | 0 | } |
| 68 | 0 | } |
| 69 | ||
| 70 | /* | |
| 71 | * (non-Javadoc) | |
| 72 | * | |
| 73 | * @see ui.command.Command#execution() | |
| 74 | */ | |
| 75 | @Override | |
| 76 | 0 | protected void execution() throws Exception { |
| 77 | 0 | switch (getStatus()) { |
| 78 | 0 | case ABORT_STATUS: |
| 79 | 0 | break; |
| 80 | 0 | case VETOED_STATUS: |
| 81 | 0 | break; |
| 82 | 0 | case EXECUTE_STATUS: |
| 83 | 0 | TextFileDialog dialog = new TextFileDialog(textFileContent); |
| 84 | 0 | dialog.setModal(true); |
| 85 | 0 | dialog.setTitle(textFileDialogTitle); |
| 86 | 0 | // Center the dialog |
| 87 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 88 | 0 | Dimension frameSize = dialog.getSize(); |
| 89 | 0 | if (frameSize.height > screenSize.height) { |
| 90 | 0 | frameSize.height = screenSize.height; |
| 91 | 0 | } |
| 92 | 0 | if (frameSize.width > screenSize.width) { |
| 93 | 0 | frameSize.width = screenSize.width; |
| 94 | 0 | } |
| 95 | 0 | dialog.setLocation((screenSize.width - frameSize.width) / 2, |
| 96 | 0 | (screenSize.height - frameSize.height) / 2); |
| 97 | 0 | dialog.setVisible(true); |
| 98 | 0 | setStatus(SUCCESS_STATUS); |
| 99 | break; | |
| 100 | 0 | } |
| 101 | 0 | } |
| 102 | ||
| 103 | public static String openFile(String fileName) { | |
| 104 | 0 | String result = ""; //$NON-NLS-1$ |
| 105 | try { | |
| 106 | 0 | File file = new File(fileName); |
| 107 | 0 | if (!file.exists()) |
| 108 | 0 | return ""; //$NON-NLS-1$ |
| 109 | 0 | // Read the contents of the file into a byte[] object. |
| 110 | 0 | FileInputStream input_file = new FileInputStream(fileName); |
| 111 | 0 | byte[] file_data = new byte[(int) file.length()]; |
| 112 | 0 | input_file.read(file_data); |
| 113 | 0 | result = new String(file_data); |
| 114 | 0 | } catch (IOException ex) { |
| 115 | 0 | ex.printStackTrace(); |
| 116 | 0 | } |
| 117 | 0 | return result; |
| 118 | 0 | } |
| 119 | 0 | |
| 120 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |