KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > catalog > ModulesAndDescription


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.catalog;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.io.CharConversionException JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import javax.swing.DefaultListCellRenderer JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.text.html.HTMLEditorKit JavaDoc;
30 import javax.swing.text.html.StyleSheet JavaDoc;
31 import org.netbeans.Module;
32 import org.openide.awt.Mnemonics;
33 import org.openide.xml.XMLUtil;
34
35 /**
36  *
37  * @author Jiri Rechtacek
38  */

39 public class ModulesAndDescription extends javax.swing.JPanel JavaDoc {
40     
41     private static final Logger JavaDoc LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.catalog.ModulesAndDescription"); // NOI18N
42

43     /** Creates new form ModuleListAndDescriptionPanel */
44     public ModulesAndDescription (Module [] modules, String JavaDoc labelText) {
45         initComponents ();
46         
47         Mnemonics.setLocalizedText (moduleListLabel, labelText);
48         moduleList.setListData (modules);
49         
50     HTMLEditorKit JavaDoc htmlkit = new HTMLEditorKit JavaDoc ();
51     // override the Swing default CSS to make the HTMLEditorKit use the
52
// same font as the rest of the UI.
53

54     // XXX the style sheet is shared by all HTMLEditorKits. We must
55
// detect if it has been tweaked by ourselves or someone else
56
// (code completion javadoc popup for example) and avoid doing the
57
// same thing again
58

59     StyleSheet JavaDoc css = htmlkit.getStyleSheet ();
60
61     if (css.getStyleSheets() == null) {
62         StyleSheet JavaDoc css2 = new StyleSheet JavaDoc();
63         Font JavaDoc f = moduleList.getFont ();
64         int size = moduleList.getFont ().getSize ();
65         css2.addRule(new StringBuffer JavaDoc("body { font-size: ").append(size) // NOI18N
66
.append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
67
css2.addStyleSheet(css);
68         htmlkit.setStyleSheet(css2);
69     }
70
71     this.description.setEditorKit (htmlkit);
72     if (modules.length > 0) {
73         moduleList.setSelectedIndex (0);
74     }
75     
76     }
77
78     /** This method is called from within the constructor to
79      * initialize the form.
80      * WARNING: Do NOT modify this code. The content of this method is
81      * always regenerated by the Form Editor.
82      */

83     private void initComponents() {//GEN-BEGIN:initComponents
84
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
85
86         modulesArea = new javax.swing.JScrollPane JavaDoc();
87         moduleList = new javax.swing.JList JavaDoc();
88         moduleListLabel = new javax.swing.JLabel JavaDoc();
89         descriptionPane = new javax.swing.JScrollPane JavaDoc();
90         description = new javax.swing.JEditorPane JavaDoc();
91         descriptionLabel = new javax.swing.JLabel JavaDoc();
92
93         setLayout(new java.awt.GridBagLayout JavaDoc());
94
95         moduleList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
96         moduleList.setCellRenderer(new ModuleCellRenderer());
97         moduleList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
98             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
99                 moduleListValueChanged(evt);
100             }
101         });
102
103         modulesArea.setViewportView(moduleList);
104         moduleList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ModulesAndDescription.class, "ACN_ModulesAndDescription_moduleList"));
105         moduleList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ModulesAndDescription.class, "ACD_ModulesAndDescription_moduleList"));
106
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 0;
109         gridBagConstraints.gridy = 1;
110         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
111         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
112         gridBagConstraints.weightx = 1.0;
113         gridBagConstraints.weighty = 0.7;
114         add(modulesArea, gridBagConstraints);
115
116         moduleListLabel.setLabelFor(moduleList);
117         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
118         gridBagConstraints.gridx = 0;
119         gridBagConstraints.gridy = 0;
120         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
122         gridBagConstraints.weightx = 1.0;
123         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 2, 0);
124         add(moduleListLabel, gridBagConstraints);
125
126         descriptionPane.setMinimumSize(new java.awt.Dimension JavaDoc(400, 80));
127         descriptionPane.setPreferredSize(new java.awt.Dimension JavaDoc(400, 80));
128         description.setEditable(false);
129         descriptionPane.setViewportView(description);
130         description.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ModulesAndDescription.class, "ACN_ModulesAndiDescription_description"));
131         description.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ModulesAndDescription.class, "ACD_ModulesAndiDescription_description"));
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 0;
135         gridBagConstraints.gridy = 3;
136         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
137         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
138         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
139         gridBagConstraints.weightx = 1.0;
140         gridBagConstraints.weighty = 0.7;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 3, 0);
142         add(descriptionPane, gridBagConstraints);
143
144         descriptionLabel.setLabelFor(description);
145         org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(ModulesAndDescription.class, "LBL_ModulesAndDescription"));
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridx = 0;
148         gridBagConstraints.gridy = 2;
149         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
151         gridBagConstraints.weightx = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 2, 0);
153         add(descriptionLabel, gridBagConstraints);
154
155     }//GEN-END:initComponents
156

157     private void moduleListValueChanged (javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_moduleListValueChanged
158
JList JavaDoc l = (JList JavaDoc) evt.getSource ();
159         Module m = (Module) l.getSelectedValue ();
160         if (m != null) {
161             String JavaDoc text;
162             try {
163                 text = "<b>" + XMLUtil.toElementContent(m.getDisplayName()) + "</b>"; // NOI18N
164
String JavaDoc longDesc = (String JavaDoc) m.getLocalizedAttribute("OpenIDE-Module-Long-Description"); // NOI18N
165
if (longDesc != null) {
166                     text += "<br>" + XMLUtil.toElementContent(longDesc); // NOI18N
167
}
168             } catch (CharConversionException JavaDoc e) {
169                 LOG.log(Level.WARNING, null, e);
170                 return;
171             }
172             description.setText(text);
173             description.setCaretPosition (0);
174         } else {
175             description.setText (null);
176         }
177     }//GEN-LAST:event_moduleListValueChanged
178

179     
180     // Variables declaration - do not modify//GEN-BEGIN:variables
181
private javax.swing.JEditorPane JavaDoc description;
182     private javax.swing.JLabel JavaDoc descriptionLabel;
183     private javax.swing.JScrollPane JavaDoc descriptionPane;
184     private javax.swing.JList JavaDoc moduleList;
185     private javax.swing.JLabel JavaDoc moduleListLabel;
186     private javax.swing.JScrollPane JavaDoc modulesArea;
187     // End of variables declaration//GEN-END:variables
188

189     private static final class ModuleCellRenderer extends DefaultListCellRenderer JavaDoc {
190         ModuleCellRenderer () {}
191         public Component JavaDoc getListCellRendererComponent (JList JavaDoc list, Object JavaDoc val, int idx, boolean sel, boolean focus) {
192             return super.getListCellRendererComponent (list, ((Module)val).getDisplayName (), idx, sel, focus);
193         }
194     }
195     
196 }
197
Popular Tags