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.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 | ||
42 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
43 | 0 | public class LicenseDialog extends JDialog { |
44 | 0 | |
45 | 0 | private static final transient Logger logger = Logger |
46 | 0 | .getLogger(LicenseDialog.class.getName()); |
47 | 0 | |
48 | private JTextArea licenseTextArea; | |
49 | ||
50 | private JScrollPane licenseScrollPane; | |
51 | ||
52 | private JPanel buttonPanel; | |
53 | ||
54 | private JButton closeButton; | |
55 | 0 | |
56 | 0 | public LicenseDialog() { |
57 | 0 | initialize(); |
58 | 0 | } |
59 | 0 | |
60 | 0 | protected void initialize() { |
61 | 0 | this.setSize(new Dimension(650, 600)); |
62 | 0 | this.setLayout(new BorderLayout()); |
63 | 0 | this.add(getLicenseScrollPane(), BorderLayout.CENTER); |
64 | 0 | this.add(getButtonPanel(), BorderLayout.SOUTH); |
65 | 0 | this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); |
66 | 0 | } |
67 | 0 | |
68 | /** | |
69 | * @return Returns the buttonPanel. | |
70 | */ | |
71 | 0 | protected JPanel getButtonPanel() { |
72 | 0 | if (buttonPanel == null) { |
73 | 0 | buttonPanel = new JPanel(); |
74 | 0 | buttonPanel.setLayout(new FlowLayout()); |
75 | 0 | buttonPanel.add(getCloseButton()); |
76 | 0 | } |
77 | 0 | return buttonPanel; |
78 | 0 | } |
79 | ||
80 | /** | |
81 | * @return Returns the closeButton. | |
82 | */ | |
83 | 0 | protected JButton getCloseButton() { |
84 | 0 | if (closeButton == null) { |
85 | 0 | closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$ |
86 | 0 | closeButton.addActionListener(new ActionListener() { |
87 | 0 | public void actionPerformed(ActionEvent arg0) { |
88 | logger.debug("actionPerformed closeButton"); //$NON-NLS-1$ | |
89 | setVisible(false); | |
90 | } | |
91 | }); | |
92 | 0 | } |
93 | 0 | return closeButton; |
94 | 0 | } |
95 | ||
96 | /** | |
97 | * @return Returns the licenseScrollPane. | |
98 | */ | |
99 | 0 | protected JScrollPane getLicenseScrollPane() { |
100 | 0 | if (licenseScrollPane == null) { |
101 | 0 | licenseScrollPane = new JScrollPane(); |
102 | 0 | licenseScrollPane.setViewportView(getLicenseTextArea()); |
103 | 0 | licenseScrollPane |
104 | 0 | .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
105 | 0 | licenseScrollPane |
106 | 0 | .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
107 | 0 | } |
108 | 0 | return licenseScrollPane; |
109 | 0 | } |
110 | ||
111 | /** | |
112 | * @return Returns the licenseTextArea. | |
113 | */ | |
114 | 0 | protected JTextArea getLicenseTextArea() { |
115 | 0 | if (licenseTextArea == null) { |
116 | 0 | licenseTextArea = new JTextArea(); |
117 | 0 | licenseTextArea.setEditable(false); |
118 | 0 | licenseTextArea |
119 | 0 | .setText(openFile(ConfigurationManager.LICENSE_FILE)); |
120 | 0 | licenseTextArea.setCaretPosition(0); |
121 | 0 | licenseTextArea.setWrapStyleWord(true); |
122 | 0 | } |
123 | 0 | return licenseTextArea; |
124 | 0 | } |
125 | ||
126 | 0 | public static String openFile(String fileName) { |
127 | 0 | String result = ""; //$NON-NLS-1$ |
128 | 0 | try { |
129 | 0 | File file = new File(fileName); |
130 | 0 | if (!file.exists()) |
131 | 0 | return ""; //$NON-NLS-1$ |
132 | 0 | // Read the contents of the file into a byte[] object. |
133 | 0 | FileInputStream input_file = new FileInputStream(fileName); |
134 | 0 | byte[] file_data = new byte[(int) file.length()]; |
135 | 0 | input_file.read(file_data); |
136 | 0 | result = new String(file_data); |
137 | 0 | } catch (IOException ex) { |
138 | 0 | ex.printStackTrace(); |
139 | 0 | } |
140 | 0 | return result; |
141 | 0 | } |
142 | ||
143 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |