KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > LicenceDialog


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.autoupdate;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.Font JavaDoc;
24 import javax.swing.JButton JavaDoc;
25
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.NbBundle;
29
30 /** Panel and dialog for showing LicenceAgreement.
31  * @author Petr Hrebejk
32  */

33 class LicenceDialog extends javax.swing.JPanel JavaDoc {
34
35     /** Preferred size of this dialog */
36     private static final java.awt.Dimension JavaDoc preferredSize = new java.awt.Dimension JavaDoc ( 620, 475 );
37
38     /** The only Licence panel instance in system */
39     private static LicenceDialog licencePanel;
40     /** The dialog descriptor of licence dialog */
41     private static DialogDescriptor dialogDescriptor = null;
42     /** Is the licence accepted */
43     private static boolean accepted = false;
44     
45     static final long serialVersionUID =-4862117522808181670L;
46     /** Creates new form LicencePanel */
47     public LicenceDialog () {
48         initComponents ();
49         
50         getAccessibleContext ().setAccessibleName (getBundle ("CTL_Licence_Title"));
51         getAccessibleContext ().setAccessibleDescription (getBundle ("ACS_LicenceDialog"));
52         licenceTextArea.getAccessibleContext ().setAccessibleName (getBundle ("ACS_LicenceDialog_Licence"));
53         licenceTextArea.getAccessibleContext ().setAccessibleDescription (getBundle ("ACSD_LicenceDialog_Licence"));
54     }
55     
56     /** Overload getPreffered size to get a bit bigger dialog */
57     public java.awt.Dimension JavaDoc getPreferredSize () {
58         return preferredSize;
59     }
60     
61     /** This method is called from within the constructor to
62      * initialize the form.
63      * WARNING: Do NOT modify this code. The content of this method is
64      * always regenerated by the FormEditor.
65      */

66     private void initComponents() {//GEN-BEGIN:initComponents
67
jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
68         licenceTextArea = new javax.swing.JTextArea JavaDoc();
69
70         setLayout(new java.awt.BorderLayout JavaDoc());
71
72         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(8, 8, 8, 8)));
73         licenceTextArea.setEditable(false);
74         licenceTextArea.setFont(new Font JavaDoc("Monospaced", Font.PLAIN, licenceTextArea.getFont().getSize() + 1));
75         jScrollPane1.setViewportView(licenceTextArea);
76
77         add(jScrollPane1, java.awt.BorderLayout.CENTER);
78
79     }//GEN-END:initComponents
80

81     
82     // Variables declaration - do not modify//GEN-BEGIN:variables
83
private javax.swing.JScrollPane JavaDoc jScrollPane1;
84     private javax.swing.JTextArea JavaDoc licenceTextArea;
85     // End of variables declaration//GEN-END:variables
86

87     void setLicenceText ( String JavaDoc licenceText ) {
88         licenceTextArea.setText ( licenceText );
89         licenceTextArea.setCaretPosition (0);
90         licenceTextArea.revalidate ();
91     }
92     
93     static boolean acceptLicence ( String JavaDoc licenceText ) {
94         createDialog (licenceText).setVisible (true);
95         
96         return accepted;
97     }
98     
99     private static Dialog JavaDoc createDialog (String JavaDoc licenseText) {
100         licencePanel = new LicenceDialog ();
101         licencePanel.setLicenceText (licenseText);
102         
103         final JButton JavaDoc acceptButton = new JButton JavaDoc ( getBundle ( "CTL_Licence_Accept" ) );
104         acceptButton.setMnemonic (getBundle ( "ACS_Licence_Accept_mnc" ).charAt (0) );
105         final JButton JavaDoc declineButton = new JButton JavaDoc ( getBundle ( "CTL_Licence_Decline" ));
106         declineButton.setMnemonic (getBundle ( "ACS_Licence_Decline_mnc" ).charAt (0) );
107         
108         acceptButton.getAccessibleContext ().setAccessibleDescription (getBundle ("ACS_Licence_Accept"));
109         declineButton.getAccessibleContext ().setAccessibleDescription (getBundle ("ACS_Licence_Decline"));
110         
111         accepted = false;
112         
113         dialogDescriptor = new DialogDescriptor (
114                 licencePanel,
115                 getBundle ( "CTL_Licence_Title" ),
116                 true, // Modal
117
new Object JavaDoc[] { acceptButton, declineButton }, // Option list
118
acceptButton, // Default
119
DialogDescriptor.BOTTOM_ALIGN, // Align
120
null, // Help
121
new java.awt.event.ActionListener JavaDoc () {
122                     public void actionPerformed ( java.awt.event.ActionEvent JavaDoc evt ) {
123                         accepted = evt.getSource ().equals (acceptButton);
124                     }
125                 });
126                 
127                 dialogDescriptor.setClosingOptions (null);
128                 
129                 return DialogDisplayer.getDefault ().createDialog ( dialogDescriptor );
130     }
131     
132     private static String JavaDoc getBundle ( String JavaDoc key ) {
133         return NbBundle.getMessage ( LicenceDialog.class, key );
134     }
135 }
136
Popular Tags