Coverage details for ui.dialog.TextFileDialog

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.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTextArea;
34  
35 import org.apache.log4j.Logger;
36  
37 import ui.Messages;
380 
39 @SuppressWarnings("serial") //$NON-NLS-1$
400public class TextFileDialog extends JDialog {
410 
420    private static final transient Logger logger = Logger
430            .getLogger(TextFileDialog.class.getName());
44  
45     private JTextArea textArea;
46  
47     private JScrollPane textAreaScrollPane;
48  
49     private JPanel buttonPanel;
50  
51     private JButton closeButton;
52  
530    private String text;
540 
550    public TextFileDialog(String text) {
560        this.text = text;
570        initialize();
580    }
590 
600    protected void initialize() {
610        this.setSize(550, 600);
620        this.setResizable(false);
630        // Center the dialog
640        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
650        Dimension frameSize = this.getSize();
660        if (frameSize.height > screenSize.height) {
670            frameSize.height = screenSize.height;
680        }
690        if (frameSize.width > screenSize.width) {
700            frameSize.width = screenSize.width;
710        }
720        this.setLocation((screenSize.width - frameSize.width) / 2,
730                (screenSize.height - frameSize.height) / 2);
740        this.setLayout(new BorderLayout());
750        this.add(getTextAreaScrollPane(), BorderLayout.CENTER);
760        this.add(getButtonPanel(), BorderLayout.SOUTH);
770        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
780    }
79  
80     /**
81      * @return Returns the buttonPanel.
820     */
830    protected JPanel getButtonPanel() {
840        if (buttonPanel == null) {
850            buttonPanel = new JPanel();
860            buttonPanel.setLayout(new FlowLayout());
870            buttonPanel.add(getCloseButton());
88         }
890        return buttonPanel;
90     }
91  
92     /**
93      * @return Returns the closeButton.
940     */
950    protected JButton getCloseButton() {
960        if (closeButton == null) {
970            closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$
980            closeButton.addActionListener(new ActionListener() {
99                 public void actionPerformed(ActionEvent arg0) {
100                     logger.debug("actionPerformed closeButton"); //$NON-NLS-1$
101                     setVisible(false);
102                 }
1030            });
104         }
1050        return closeButton;
106     }
107  
108     /**
109      * @return Returns the textAreaScrollPane.
1100     */
1110    protected JScrollPane getTextAreaScrollPane() {
1120        if (textAreaScrollPane == null) {
1130            textAreaScrollPane = new JScrollPane();
1140            textAreaScrollPane.setViewportView(getTextArea());
1150            textAreaScrollPane
1160                    .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
1170            textAreaScrollPane
1180                    .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
119         }
1200        return textAreaScrollPane;
121     }
122  
123     /**
124      * @return Returns the textArea.
1250     */
1260    protected JTextArea getTextArea() {
1270        if (textArea == null) {
1280            textArea = new JTextArea();
1290            textArea.setEditable(false);
1300            textArea.setText(text);
1310            textArea.setCaretPosition(0);
1320            textArea.setWrapStyleWord(true);
133         }
1340        return textArea;
135     }
136 }

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.