1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.awt.Font ; 23 import java.util.Collection ; 24 import javax.swing.*; 25 import org.openide.DialogDescriptor; 26 import org.openide.DialogDisplayer; 27 import org.openide.util.NbBundle; 28 29 33 class CertificateDialog extends javax.swing.JPanel { 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 41 private static int result = CLOSE; 42 43 static final int SIGNED_MODULE = 0; 44 static final int TRUSTED_MODULE = 1; 45 46 private static int type; 47 48 49 public CertificateDialog(Collection certs) { 50 initComponents(); 51 certificateTextArea.setText( SignVerifier.formatCerts( certs ) ); 52 certificateTextArea.setCaretPosition(0); 53 55 getAccessibleContext().setAccessibleName(getBundle("CTL_Certificate_Title")); 56 getAccessibleContext().setAccessibleDescription(aboutTextArea.getText()); 57 } 58 59 64 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 66 67 aboutTextArea = new javax.swing.JTextArea (); 68 jScrollPane1 = new javax.swing.JScrollPane (); 69 certificateTextArea = new javax.swing.JTextArea (); 70 71 setLayout(new java.awt.GridBagLayout ()); 72 73 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (12, 12, 11, 11))); 74 aboutTextArea.setBackground(javax.swing.UIManager.getDefaults().getColor("TextField.inactiveBackground")); 75 aboutTextArea.setFont(new Font ("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 (); 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 (); 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 (6, 0, 0, 0); 98 add(jScrollPane1, gridBagConstraints); 99 100 } 102 103 private javax.swing.JTextArea aboutTextArea; 105 private javax.swing.JTextArea certificateTextArea; 106 private javax.swing.JScrollPane jScrollPane1; 107 109 private static DialogDescriptor createDialog(Collection certs) { 110 111 Object [] 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 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 [] { 132 acceptButton, 133 alwaysButton, 134 rejectButton, 135 closeButton 136 }; 137 else 138 buttons = new Object [] { 139 notalwaysButton, 140 closeButton 141 }; 142 143 DialogDescriptor dd; 144 dd = new DialogDescriptor( 145 new CertificateDialog(certs), 146 getBundle( "CTL_Certificate_Title" ), 147 true, buttons, closeButton, DialogDescriptor.DEFAULT_ALIGN, null, new java.awt.event.ActionListener () { 153 public void actionPerformed( java.awt.event.ActionEvent 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 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 dialog = DialogDisplayer.getDefault().createDialog( dd ); 179 dialog.setVisible(true); 180 dialog.dispose(); 181 182 return result; 183 } 184 185 private static String getBundle( String key ) { 186 return NbBundle.getMessage( CertificateDialog.class, key ); 187 } 188 } 189 | Popular Tags |