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.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; | |
38 | 0 | |
39 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
40 | 0 | public class TextFileDialog extends JDialog { |
41 | 0 | |
42 | 0 | private static final transient Logger logger = Logger |
43 | 0 | .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 | ||
53 | 0 | private String text; |
54 | 0 | |
55 | 0 | public TextFileDialog(String text) { |
56 | 0 | this.text = text; |
57 | 0 | initialize(); |
58 | 0 | } |
59 | 0 | |
60 | 0 | protected void initialize() { |
61 | 0 | this.setSize(550, 600); |
62 | 0 | this.setResizable(false); |
63 | 0 | // Center the dialog |
64 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
65 | 0 | Dimension frameSize = this.getSize(); |
66 | 0 | if (frameSize.height > screenSize.height) { |
67 | 0 | frameSize.height = screenSize.height; |
68 | 0 | } |
69 | 0 | if (frameSize.width > screenSize.width) { |
70 | 0 | frameSize.width = screenSize.width; |
71 | 0 | } |
72 | 0 | this.setLocation((screenSize.width - frameSize.width) / 2, |
73 | 0 | (screenSize.height - frameSize.height) / 2); |
74 | 0 | this.setLayout(new BorderLayout()); |
75 | 0 | this.add(getTextAreaScrollPane(), BorderLayout.CENTER); |
76 | 0 | this.add(getButtonPanel(), BorderLayout.SOUTH); |
77 | 0 | this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); |
78 | 0 | } |
79 | ||
80 | /** | |
81 | * @return Returns the buttonPanel. | |
82 | 0 | */ |
83 | 0 | protected JPanel getButtonPanel() { |
84 | 0 | if (buttonPanel == null) { |
85 | 0 | buttonPanel = new JPanel(); |
86 | 0 | buttonPanel.setLayout(new FlowLayout()); |
87 | 0 | buttonPanel.add(getCloseButton()); |
88 | } | |
89 | 0 | return buttonPanel; |
90 | } | |
91 | ||
92 | /** | |
93 | * @return Returns the closeButton. | |
94 | 0 | */ |
95 | 0 | protected JButton getCloseButton() { |
96 | 0 | if (closeButton == null) { |
97 | 0 | closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$ |
98 | 0 | closeButton.addActionListener(new ActionListener() { |
99 | public void actionPerformed(ActionEvent arg0) { | |
100 | logger.debug("actionPerformed closeButton"); //$NON-NLS-1$ | |
101 | setVisible(false); | |
102 | } | |
103 | 0 | }); |
104 | } | |
105 | 0 | return closeButton; |
106 | } | |
107 | ||
108 | /** | |
109 | * @return Returns the textAreaScrollPane. | |
110 | 0 | */ |
111 | 0 | protected JScrollPane getTextAreaScrollPane() { |
112 | 0 | if (textAreaScrollPane == null) { |
113 | 0 | textAreaScrollPane = new JScrollPane(); |
114 | 0 | textAreaScrollPane.setViewportView(getTextArea()); |
115 | 0 | textAreaScrollPane |
116 | 0 | .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
117 | 0 | textAreaScrollPane |
118 | 0 | .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
119 | } | |
120 | 0 | return textAreaScrollPane; |
121 | } | |
122 | ||
123 | /** | |
124 | * @return Returns the textArea. | |
125 | 0 | */ |
126 | 0 | protected JTextArea getTextArea() { |
127 | 0 | if (textArea == null) { |
128 | 0 | textArea = new JTextArea(); |
129 | 0 | textArea.setEditable(false); |
130 | 0 | textArea.setText(text); |
131 | 0 | textArea.setCaretPosition(0); |
132 | 0 | textArea.setWrapStyleWord(true); |
133 | } | |
134 | 0 | return textArea; |
135 | } | |
136 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |