KickJava   Java API By Example, From Geeks To Geeks.

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


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.Font JavaDoc;
23 import java.util.Collection JavaDoc;
24 import javax.swing.*;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.util.NbBundle;
28
29 /**
30  *
31  * @author
32  */

33 class CertificateDialog extends javax.swing.JPanel JavaDoc {
34
35     static final int CLOSE = 0;
36     static final int ACCEPT = 1;
37     static final int ALWAYS_ACCEPT = 2;
38     static final int NOT_ALWAYS_ACCEPT = 3;
39     static final int REJECT = 4;
40     /** Result of the dialog */
41     private static int result = CLOSE;
42
43     static final int SIGNED_MODULE = 0;
44     static final int TRUSTED_MODULE = 1;
45     /** Type of the dialog */
46     private static int type;
47
48     /** Creates new form CertificateDialog */
49     public CertificateDialog(Collection JavaDoc certs) {
50         initComponents();
51         certificateTextArea.setText( SignVerifier.formatCerts( certs ) );
52         certificateTextArea.setCaretPosition(0);
53 // setPreferredSize(new java.awt.Dimension(350,220));
54

55         getAccessibleContext().setAccessibleName(getBundle("CTL_Certificate_Title"));
56         getAccessibleContext().setAccessibleDescription(aboutTextArea.getText());
57     }
58
59     /** This method is called from within the constructor to
60      * initialize the form.
61      * WARNING: Do NOT modify this code. The content of this method is
62      * always regenerated by the Form Editor.
63      */

64     private void initComponents() {//GEN-BEGIN:initComponents
65
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
66
67         aboutTextArea = new javax.swing.JTextArea JavaDoc();
68         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
69         certificateTextArea = new javax.swing.JTextArea JavaDoc();
70
71         setLayout(new java.awt.GridBagLayout JavaDoc());
72
73         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(12, 12, 11, 11)));
74         aboutTextArea.setBackground(javax.swing.UIManager.getDefaults().getColor("TextField.inactiveBackground"));
75         aboutTextArea.setFont(new Font JavaDoc("Dialog", Font.PLAIN, aboutTextArea.getFont().getSize()));
76         aboutTextArea.setLineWrap(true);
77         aboutTextArea.setText(NbBundle.getBundle(CertificateDialog.class).getString(type == SIGNED_MODULE ? "CTL_Certificate_Signed_About" : "CTL_Certificate_Trusted_About"));
78         aboutTextArea.setWrapStyleWord(true);
79         aboutTextArea.setDisabledTextColor(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
80         aboutTextArea.setEnabled(false);
81         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
82         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
83         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
84         add(aboutTextArea, gridBagConstraints);
85
86         certificateTextArea.setDisabledTextColor(javax.swing.UIManager.getDefaults().getColor("TextField.foreground"));
87         certificateTextArea.setEnabled(false);
88         jScrollPane1.setViewportView(certificateTextArea);
89
90         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
91         gridBagConstraints.gridx = 0;
92         gridBagConstraints.gridy = 1;
93         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
94         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
95         gridBagConstraints.weightx = 1.0;
96         gridBagConstraints.weighty = 1.0;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
98         add(jScrollPane1, gridBagConstraints);
99
100     }//GEN-END:initComponents
101

102
103     // Variables declaration - do not modify//GEN-BEGIN:variables
104
private javax.swing.JTextArea JavaDoc aboutTextArea;
105     private javax.swing.JTextArea JavaDoc certificateTextArea;
106     private javax.swing.JScrollPane JavaDoc jScrollPane1;
107     // End of variables declaration//GEN-END:variables
108

109     private static DialogDescriptor createDialog(Collection JavaDoc certs) {
110
111         Object JavaDoc[] buttons;
112         final JButton closeButton = new JButton(getBundle( "CTL_Certificate_Close" ) );
113         final JButton acceptButton = new JButton(getBundle( "CTL_Certificate_Accept" ) );
114         final JButton alwaysButton = new JButton(getBundle( "CTL_Certificate_AlwaysAccept" ) );
115         final JButton notalwaysButton = new JButton(getBundle( "CTL_Certificate_NotAlwaysAccept" ) );
116         final JButton rejectButton = new JButton(getBundle( "CTL_Certificate_Reject" ) );
117
118         closeButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Certificate_Close"));
119         acceptButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Certificate_Accept"));
120         alwaysButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Certificate_AlwaysAccept"));
121         notalwaysButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Certificate_NotAlwaysAccept"));
122         rejectButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Certificate_Reject"));
123         //mnemonics
124
closeButton.setMnemonic(getBundle("ACS_Certificate_Close_mnc").charAt(0));
125         acceptButton.setMnemonic(getBundle("ACS_Certificate_Accept_mnc").charAt(0));
126         alwaysButton.setMnemonic(getBundle("ACS_Certificate_AlwaysAccept_mnc").charAt(0));
127         notalwaysButton.setMnemonic(getBundle("ACS_Certificate_NotAlwaysAccept_mnc").charAt(0));
128         rejectButton.setMnemonic(getBundle("ACS_Certificate_Reject_mnc").charAt(0));
129
130         if (type == SIGNED_MODULE)
131             buttons = new Object JavaDoc [] {
132                 acceptButton,
133                 alwaysButton,
134                 rejectButton,
135                 closeButton
136             };
137         else
138             buttons = new Object JavaDoc [] {
139                 notalwaysButton,
140                 closeButton
141             };
142         
143         DialogDescriptor dd;
144         dd = new DialogDescriptor(
145                  new CertificateDialog(certs),
146                  getBundle( "CTL_Certificate_Title" ),
147                  true, // Modal
148
buttons, // Option list
149
closeButton, // Default
150
DialogDescriptor.DEFAULT_ALIGN, // Align
151
null, //new HelpCtx (CertificateDialog.class), // Help
152
new java.awt.event.ActionListener JavaDoc() {
153                      public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
154                          if ( evt.getSource() == acceptButton )
155                              result = ACCEPT;
156                          else if ( evt.getSource() == alwaysButton )
157                              result = ALWAYS_ACCEPT;
158                          else if ( evt.getSource() == notalwaysButton )
159                              result = NOT_ALWAYS_ACCEPT;
160                          else if ( evt.getSource() == rejectButton )
161                              result = REJECT;
162                          else if ( evt.getSource() == closeButton )
163                              result = CLOSE;
164                      }
165                  });
166
167         dd.setClosingOptions( null );
168
169         return dd;
170     }
171     
172     static int showDialog(Collection JavaDoc certs, int type) {
173         if (type == SignVerifier.TRUSTED)
174             CertificateDialog.type = TRUSTED_MODULE;
175         else
176             CertificateDialog.type = SIGNED_MODULE;
177         DialogDescriptor dd = createDialog(certs);
178         java.awt.Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
179         dialog.setVisible(true);
180         dialog.dispose();
181         
182         return result;
183     }
184     
185     private static String JavaDoc getBundle( String JavaDoc key ) {
186         return NbBundle.getMessage( CertificateDialog.class, key );
187     }
188 }
189
Popular Tags