1 19 20 package org.netbeans.modules.autoupdate; 21 22 23 import java.awt.Component ; 24 import java.awt.Font ; 25 import java.util.*; 26 import java.security.cert.Certificate ; 27 import java.security.cert.X509Certificate ; 28 29 import javax.swing.JList ; 30 31 import org.openide.util.NbBundle; 32 33 37 class ResultListCellRenderer extends javax.swing.JPanel 38 implements javax.swing.ListCellRenderer { 39 40 static final long serialVersionUID =-3181200208271061471L; 41 42 private static final String SPACE = " "; 44 private static final String BAD_DOWNLOAD = SPACE + getBundle("CTL_BAD_DOWNLOAD") + SPACE; 45 private static final String CORRUPTED = SPACE + getBundle("CTL_CORRUPTED") + SPACE; 46 private static final String NOT_SIGNED = SPACE + getBundle("CTL_NOT_SIGNED") + SPACE; 47 private static final String SIGNED = SPACE + getBundle("CTL_SIGNED") + SPACE; 48 private static final String TRUSTED = SPACE + getBundle("CTL_TRUSTED") + SPACE; 49 50 51 private static ResultListCellRenderer renderer = null; 52 53 54 public Component getListCellRendererComponent( JList list, 55 Object value, 56 int index, 57 boolean isSelected, 58 boolean cellHasFocus) { 59 if ( renderer == null ) { 60 renderer = new ResultListCellRenderer(); 61 } 62 63 renderer.includeCheckBox.setSelected(((ModuleUpdate)value).isInstallApproved()); 64 renderer.globalCheckBox.setSelected(((ModuleUpdate)value).isToInstallDir()); 65 66 String sec = ""; switch ( ((ModuleUpdate)value).getSecurity() ) { 68 case SignVerifier.BAD_DOWNLOAD: 69 sec = BAD_DOWNLOAD; 70 break; 71 case SignVerifier.CORRUPTED: 72 sec = CORRUPTED; 73 break; 74 case SignVerifier.NOT_SIGNED: 75 sec = NOT_SIGNED; 76 break; 77 case SignVerifier.SIGNED: 78 StringBuffer sb = new StringBuffer ( SIGNED ); 79 sb.append( SPACE + getBundle("CTL_By")); 80 Collection certs = ((ModuleUpdate)value).getCerts(); 81 Iterator it = certs.iterator(); 82 while ( it.hasNext() ) { 83 Certificate cert = (Certificate )it.next(); 84 if ( cert instanceof X509Certificate ) { 85 sb.append( " " ).append( ((X509Certificate )cert).getSubjectDN().getName() ); } 87 } 88 89 sec = sb.toString(); 90 break; 91 case SignVerifier.TRUSTED: 92 sec = TRUSTED; 93 break; 94 } 95 96 renderer.nameLabel.setText( ((ModuleUpdate)value).getName() + 97 " " + getBundle( "CTL_Version" ) + 98 ((ModuleUpdate)value).getRemoteModule().getSpecificationVersion()); 99 renderer.securityLabel.setText( sec ); 100 101 renderer.includeCheckBox.getAccessibleContext().setAccessibleDescription(renderer.nameLabel.getText()); 102 renderer.includeCheckBox.setMnemonic(getBundle("ACS_Include_Mnem").charAt(0)); 103 renderer.globalCheckBox.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Global1")+renderer.nameLabel.getText() + getBundle("ACS_Global2")); 104 renderer.globalCheckBox.setMnemonic(getBundle("ACS_Global_Mnem").charAt(0)); 105 106 if ( isSelected ) { 107 renderer.setBackground ((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); renderer.nameLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); renderer.securityLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); renderer.includeCheckBox.setBackground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); renderer.includeCheckBox.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); renderer.globalCheckBox.setBackground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); renderer.globalCheckBox.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); } 115 else { 116 renderer.setBackground ((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.background")); renderer.nameLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); renderer.securityLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); renderer.includeCheckBox.setBackground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.background")); renderer.includeCheckBox.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); renderer.globalCheckBox.setBackground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.background")); renderer.globalCheckBox.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); } 124 125 renderer.invalidate(); 126 127 return renderer; 128 129 } 130 131 132 133 public ResultListCellRenderer() { 134 initComponents (); 135 nameLabel.setFont(ResultsPanel.doDeriveFont(nameLabel.getFont(), Font.BOLD)); 137 } 138 139 144 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 146 147 includeCheckBox = new javax.swing.JCheckBox (); 148 nameLabel = new javax.swing.JLabel (); 149 securityLabel = new javax.swing.JLabel (); 150 globalCheckBox = new javax.swing.JCheckBox (); 151 152 setLayout(new java.awt.GridBagLayout ()); 153 154 setBackground(java.awt.Color.white); 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridheight = 2; 157 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 0); 158 add(includeCheckBox, gridBagConstraints); 159 160 gridBagConstraints = new java.awt.GridBagConstraints (); 161 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 162 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 163 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 164 gridBagConstraints.weightx = 1.0; 165 gridBagConstraints.weighty = 1.0; 166 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 167 add(nameLabel, gridBagConstraints); 168 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 1; 171 gridBagConstraints.gridy = 1; 172 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 173 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 174 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 175 gridBagConstraints.weightx = 1.0; 176 gridBagConstraints.weighty = 1.0; 177 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 178 add(securityLabel, gridBagConstraints); 179 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 2; 182 gridBagConstraints.gridy = 0; 183 gridBagConstraints.gridheight = 2; 184 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 0); 185 add(globalCheckBox, gridBagConstraints); 186 187 } 189 190 private javax.swing.JCheckBox globalCheckBox; 192 private javax.swing.JCheckBox includeCheckBox; 193 private javax.swing.JLabel nameLabel; 194 private javax.swing.JLabel securityLabel; 195 197 boolean isIncludeCheckBoxSelected(java.awt.event.MouseEvent evt) { 198 return (((includeCheckBox.getX()+includeCheckBox.getWidth()) >= evt.getX()) && 199 (includeCheckBox.getX() <= evt.getX())); 200 } 201 202 boolean isGlobalCheckBoxSelected(java.awt.event.MouseEvent evt) { 203 return (((globalCheckBox.getX()+globalCheckBox.getWidth()) >= evt.getX()) && 204 (globalCheckBox.getX() <= evt.getX())); 205 } 206 207 private static String getBundle( String key ) { 208 return NbBundle.getMessage( ResultListCellRenderer.class, key ); 209 } 210 } | Popular Tags |