KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import java.awt.Component JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.util.*;
26 import java.security.cert.Certificate JavaDoc;
27 import java.security.cert.X509Certificate JavaDoc;
28
29 import javax.swing.JList JavaDoc;
30
31 import org.openide.util.NbBundle;
32
33 /** Paints the list items in the ResultsListBox
34  * @author phrebejk
35  * @version
36  */

37 class ResultListCellRenderer extends javax.swing.JPanel JavaDoc
38     implements javax.swing.ListCellRenderer JavaDoc{
39
40     static final long serialVersionUID =-3181200208271061471L;
41
42     private static final String JavaDoc SPACE = " "; //NOI18N
43

44     private static final String JavaDoc BAD_DOWNLOAD = SPACE + getBundle("CTL_BAD_DOWNLOAD") + SPACE;
45     private static final String JavaDoc CORRUPTED = SPACE + getBundle("CTL_CORRUPTED") + SPACE;
46     private static final String JavaDoc NOT_SIGNED = SPACE + getBundle("CTL_NOT_SIGNED") + SPACE;
47     private static final String JavaDoc SIGNED = SPACE + getBundle("CTL_SIGNED") + SPACE;
48     private static final String JavaDoc TRUSTED = SPACE + getBundle("CTL_TRUSTED") + SPACE;
49
50     /** The one instalnce of the renderer in the system */
51     private static ResultListCellRenderer renderer = null;
52
53
54     public Component JavaDoc getListCellRendererComponent( JList JavaDoc list,
55             Object JavaDoc 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 JavaDoc sec = ""; // NOI18N
67
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 JavaDoc sb = new StringBuffer JavaDoc( 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 JavaDoc cert = (Certificate JavaDoc)it.next();
84                 if ( cert instanceof X509Certificate JavaDoc ) {
85                     sb.append( " " ).append( ((X509Certificate JavaDoc)cert).getSubjectDN().getName() ); //NOI18N
86
}
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 JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); // NOI18N
108
renderer.nameLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); // NOI18N
109
renderer.securityLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); // NOI18N
110
renderer.includeCheckBox.setBackground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); // NOI18N
111
renderer.includeCheckBox.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); // NOI18N
112
renderer.globalCheckBox.setBackground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionBackground")); // NOI18N
113
renderer.globalCheckBox.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.selectionForeground")); // NOI18N
114
}
115         else {
116             renderer.setBackground ((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.background")); // NOI18N
117
renderer.nameLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); // NOI18N
118
renderer.securityLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); // NOI18N
119
renderer.includeCheckBox.setBackground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.background")); // NOI18N
120
renderer.includeCheckBox.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); // NOI18N
121
renderer.globalCheckBox.setBackground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.background")); // NOI18N
122
renderer.globalCheckBox.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("List.Foreground")); // NOI18N
123
}
124
125         renderer.invalidate();
126
127         return renderer;
128
129     }
130
131
132     /** Creates new form ResultListCellRenderer */
133     public ResultListCellRenderer() {
134         initComponents ();
135         // don't use deriveFont() - see #49973 for details
136
nameLabel.setFont(ResultsPanel.doDeriveFont(nameLabel.getFont(), Font.BOLD));
137     }
138
139     /** This method is called from within the constructor to
140      * initialize the form.
141      * WARNING: Do NOT modify this code. The content of this method is
142      * always regenerated by the FormEditor.
143      */

144     private void initComponents() {//GEN-BEGIN:initComponents
145
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
146
147         includeCheckBox = new javax.swing.JCheckBox JavaDoc();
148         nameLabel = new javax.swing.JLabel JavaDoc();
149         securityLabel = new javax.swing.JLabel JavaDoc();
150         globalCheckBox = new javax.swing.JCheckBox JavaDoc();
151
152         setLayout(new java.awt.GridBagLayout JavaDoc());
153
154         setBackground(java.awt.Color.white);
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridheight = 2;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 0, 0);
158         add(includeCheckBox, gridBagConstraints);
159
160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 6, 0, 0);
167         add(nameLabel, gridBagConstraints);
168
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 6, 0, 0);
178         add(securityLabel, gridBagConstraints);
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 2;
182         gridBagConstraints.gridy = 0;
183         gridBagConstraints.gridheight = 2;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 0, 0);
185         add(globalCheckBox, gridBagConstraints);
186
187     }//GEN-END:initComponents
188

189
190     // Variables declaration - do not modify//GEN-BEGIN:variables
191
private javax.swing.JCheckBox JavaDoc globalCheckBox;
192     private javax.swing.JCheckBox JavaDoc includeCheckBox;
193     private javax.swing.JLabel JavaDoc nameLabel;
194     private javax.swing.JLabel JavaDoc securityLabel;
195     // End of variables declaration//GEN-END:variables
196

197     boolean isIncludeCheckBoxSelected(java.awt.event.MouseEvent JavaDoc evt) {
198         return (((includeCheckBox.getX()+includeCheckBox.getWidth()) >= evt.getX()) &&
199             (includeCheckBox.getX() <= evt.getX()));
200     }
201     
202     boolean isGlobalCheckBoxSelected(java.awt.event.MouseEvent JavaDoc evt) {
203         return (((globalCheckBox.getX()+globalCheckBox.getWidth()) >= evt.getX()) &&
204             (globalCheckBox.getX() <= evt.getX()));
205     }
206     
207     private static String JavaDoc getBundle( String JavaDoc key ) {
208         return NbBundle.getMessage( ResultListCellRenderer.class, key );
209     }
210 }
Popular Tags