1 /*
2 * LicenseDialog.java
3 *
4 * Copyright (c) 2003, Raben Systems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * Neither the name of Raben Systems, Inc. nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 package com.raben.telescope.comm;
35 import java.io.IOException;
36 import java.io.BufferedReader;
37 import java.io.InputStream;
38 import java.io.InputStreamReader;
39
40 /***
41 * Display license for user to read and ponder
42 * @author Vern Raben
43 * @version $Revision: 1.1.1.1 $ $Date: 2003/06/13 04:51:00 $
44 */
45 public class LicenseDialog extends javax.swing.JDialog {
46
47 /*** Creates new form LicenseDialog
48 * @param parent Reference to parent fr4ame
49 * @param modal Set to true if dialog is to be modal
50 */
51 public LicenseDialog(java.awt.Frame parent, boolean modal) {
52 super(parent, modal);
53 initComponents();
54 }
55
56 /*** This method is called from within the constructor to
57 * initialize the form.
58 * WARNING: Do NOT modify this code. The content of this method is
59 * always regenerated by the Form Editor.
60 */
61 private void initComponents() {//GEN-BEGIN:initComponents
62 jScrollPane1 = new javax.swing.JScrollPane();
63 licenseTextArea = new javax.swing.JTextArea();
64 jPanel2 = new javax.swing.JPanel();
65 acceptButton = new javax.swing.JButton();
66 declineButton = new javax.swing.JButton();
67
68 getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
69
70 setTitle("Binary License Agreement");
71 addWindowListener(new java.awt.event.WindowAdapter() {
72 public void windowClosing(java.awt.event.WindowEvent evt) {
73 closeDialog(evt);
74 }
75 });
76
77 licenseTextArea.setColumns(55);
78 licenseTextArea.setRows(15);
79 licenseTextArea.setText(getLicenseStr());
80 jScrollPane1.setViewportView(licenseTextArea);
81
82 getContentPane().add(jScrollPane1);
83
84 jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
85
86 acceptButton.setMnemonic('A');
87 acceptButton.setText("Accept");
88 acceptButton.addActionListener(new java.awt.event.ActionListener() {
89 public void actionPerformed(java.awt.event.ActionEvent evt) {
90 acceptButtonActionPerformed(evt);
91 }
92 });
93
94 jPanel2.add(acceptButton);
95
96 declineButton.setMnemonic('D');
97 declineButton.setText("Decline");
98 declineButton.addActionListener(new java.awt.event.ActionListener() {
99 public void actionPerformed(java.awt.event.ActionEvent evt) {
100 declineButtonActionPerformed(evt);
101 }
102 });
103
104 jPanel2.add(declineButton);
105
106 getContentPane().add(jPanel2);
107
108 pack();
109 }//GEN-END:initComponents
110 /***
111 * Handle event that occurs when user presses decline button
112 * @param evt Not used
113 */
114 private void declineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_declineButtonActionPerformed
115 accepted = false;
116 closeDialog(null);
117 }//GEN-LAST:event_declineButtonActionPerformed
118
119 /***
120 * Handle event that occurs when accept button pressed
121 * @param evt Not used
122 */
123 private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed
124 accepted = true;
125 closeDialog(null);
126 }//GEN-LAST:event_acceptButtonActionPerformed
127
128 /*** Closes the dialog
129 * @param evt Not used
130 */
131 private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
132 firePropertyChange(LICENSE_RESPONSE, null, String.valueOf(accepted));
133 setVisible(false);
134 dispose();
135 }//GEN-LAST:event_closeDialog
136
137 /***
138 * Called when LicenseDialog started as a standalone program
139 * @param args the command line arguments
140 */
141 public static void main(String args[]) {
142 new LicenseDialog(new javax.swing.JFrame(), true).show();
143 }
144
145 /***
146 * Get license string from text file
147 * @return String containing license text
148 */
149 public String getLicenseStr() {
150
151 StringBuffer buf = new StringBuffer();
152 BufferedReader br = null;
153 InputStream is = null;
154
155 try {
156 is = getClass().getResourceAsStream("/LICENSE.txt");
157 if (is != null) {
158 br = new BufferedReader(new InputStreamReader(is));
159
160 while (br.ready()) {
161 buf.append(br.readLine());
162 buf.append("\n");
163 }
164
165 }
166 } catch (IOException e) {
167 System.out.println("error reading license " + e);
168
169 } finally {
170 try {
171 if (br != null) {
172 br.close();
173 br = null;
174 }
175
176 if (is != null) {
177 is.close();
178 }
179 } catch (IOException e) {
180 // Ignore }
181 }
182 }
183
184 return buf.toString();
185 }
186
187 /***
188 * Check if license is accepted
189 * @return True if accepted
190 */
191 public boolean isAccepted() {
192 return accepted;
193 }
194
195 // Variables declaration - do not modify//GEN-BEGIN:variables
196 private javax.swing.JButton declineButton;
197 private javax.swing.JScrollPane jScrollPane1;
198 private javax.swing.JPanel jPanel2;
199 private javax.swing.JTextArea licenseTextArea;
200 private javax.swing.JButton acceptButton;
201 // End of variables declaration//GEN-END:variables
202
203 /*** Flag to indicate if license is accepted */
204 private boolean accepted = false;
205
206 /*** Define License Response key */
207 public static final String LICENSE_RESPONSE = "License Response";
208
209 }
This page was automatically generated by Maven