|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
LicensePane.java | 100% | 95.7% | 100% | 96.3% |
|
1 |
/*
|
|
2 |
* SimplyHTML, a word processor based on Java, HTML and CSS
|
|
3 |
* Copyright (C) 2002 Ulrich Hilger
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU General Public License
|
|
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 |
*/
|
|
19 |
|
|
20 |
import javax.swing.JPanel;
|
|
21 |
import javax.swing.JScrollPane;
|
|
22 |
import javax.swing.JTextArea;
|
|
23 |
import java.awt.Dimension;
|
|
24 |
import java.io.InputStream;
|
|
25 |
import java.io.Reader;
|
|
26 |
import java.io.BufferedReader;
|
|
27 |
import java.io.InputStreamReader;
|
|
28 |
import java.awt.BorderLayout;
|
|
29 |
import java.awt.Font;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* A panel for displaying license information of application SimplyHTML.
|
|
33 |
*
|
|
34 |
* @author Ulrich Hilger
|
|
35 |
* @author Light Development
|
|
36 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
37 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
38 |
* @author published under the terms and conditions of the
|
|
39 |
* GNU General Public License,
|
|
40 |
* for details see file gpl.txt in the distribution
|
|
41 |
* package of this software
|
|
42 |
*
|
|
43 |
* @version stage 11, April 27, 2003
|
|
44 |
*/
|
|
45 |
|
|
46 |
public class LicensePane extends JPanel { |
|
47 |
|
|
48 |
/* line separator character (sequence) */
|
|
49 |
private String lineSeparator = System.getProperty("line.separator"); |
|
50 |
|
|
51 |
/**
|
|
52 |
* construct a <code>LicensePane</code>
|
|
53 |
*/
|
|
54 | 2 |
public LicensePane(Dimension d, String licensePath) {
|
55 |
/* create a text area to show the license text in */
|
|
56 | 2 |
JTextArea licText = new JTextArea(getLicenseText(getClass().getResourceAsStream(licensePath)));
|
57 | 2 |
licText.setEditable(false);
|
58 | 2 |
licText.setFont(new Font("Courier", Font.PLAIN, 12)); |
59 |
|
|
60 |
/* create a scroll pane as the license text is long */
|
|
61 | 2 |
JScrollPane licPane = new JScrollPane();
|
62 | 2 |
licPane = new JScrollPane(licText);
|
63 | 2 |
licPane.setPreferredSize(d); |
64 | 2 |
licPane.setVerticalScrollBarPolicy( |
65 |
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
66 | 2 |
licPane.setHorizontalScrollBarPolicy( |
67 |
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
68 |
|
|
69 |
/* add the scroll pane to this panel */
|
|
70 | 2 |
setLayout(new BorderLayout());
|
71 | 2 |
add(licPane, BorderLayout.CENTER); |
72 | 2 |
licText.setCaretPosition(0); // go to top of text (for JRE versions earlier than 1.4)
|
73 |
} |
|
74 |
|
|
75 |
/**
|
|
76 |
* read and return the license text
|
|
77 |
*
|
|
78 |
* @return the license text
|
|
79 |
*/
|
|
80 | 2 |
private String getLicenseText(InputStream is) {
|
81 | 2 |
StringBuffer license = new StringBuffer();
|
82 | 2 |
try {
|
83 |
// InputStream is = getClass().getResourceAsStream(getLicense());
|
|
84 | 2 |
BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
85 | 2 |
String buf = r.readLine(); |
86 | 2 |
while(buf != null) { |
87 | 684 |
license.append(buf); |
88 | 684 |
license.append(lineSeparator); |
89 | 684 |
buf = r.readLine(); |
90 |
} |
|
91 | 2 |
r.close(); |
92 | 2 |
is.close(); |
93 |
} |
|
94 |
catch(Exception e) {
|
|
95 | 0 |
Util.errMsg(this, "The license text could not be opened.\n\nPlease consult file 'readme.txt' for installation guidelines\n\nSimplyHTML and all of its parts are distributed under\nthe terms and conditions of the GNU General Public License (GPL).\nYou may want to obtain a free and complete distribution package at\nhttp://www.lightdev.com", e); |
96 |
} |
|
97 | 2 |
return license.toString();
|
98 |
} |
|
99 |
} |
|