1 19 20 package org.netbeans.modules.autoupdate.catalog; 21 22 import java.awt.Component ; 23 import java.awt.Font ; 24 import java.io.CharConversionException ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 import javax.swing.DefaultListCellRenderer ; 28 import javax.swing.JList ; 29 import javax.swing.text.html.HTMLEditorKit ; 30 import javax.swing.text.html.StyleSheet ; 31 import org.netbeans.Module; 32 import org.openide.awt.Mnemonics; 33 import org.openide.xml.XMLUtil; 34 35 39 public class ModulesAndDescription extends javax.swing.JPanel { 40 41 private static final Logger LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.catalog.ModulesAndDescription"); 43 44 public ModulesAndDescription (Module [] modules, String labelText) { 45 initComponents (); 46 47 Mnemonics.setLocalizedText (moduleListLabel, labelText); 48 moduleList.setListData (modules); 49 50 HTMLEditorKit htmlkit = new HTMLEditorKit (); 51 54 59 StyleSheet css = htmlkit.getStyleSheet (); 60 61 if (css.getStyleSheets() == null) { 62 StyleSheet css2 = new StyleSheet (); 63 Font f = moduleList.getFont (); 64 int size = moduleList.getFont ().getSize (); 65 css2.addRule(new StringBuffer ("body { font-size: ").append(size) .append("; font-family: ").append(f.getName()).append("; }").toString()); 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 83 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 85 86 modulesArea = new javax.swing.JScrollPane (); 87 moduleList = new javax.swing.JList (); 88 moduleListLabel = new javax.swing.JLabel (); 89 descriptionPane = new javax.swing.JScrollPane (); 90 description = new javax.swing.JEditorPane (); 91 descriptionLabel = new javax.swing.JLabel (); 92 93 setLayout(new java.awt.GridBagLayout ()); 94 95 moduleList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 96 moduleList.setCellRenderer(new ModuleCellRenderer()); 97 moduleList.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 98 public void valueChanged(javax.swing.event.ListSelectionEvent 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 (); 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 (); 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 (5, 0, 2, 0); 124 add(moduleListLabel, gridBagConstraints); 125 126 descriptionPane.setMinimumSize(new java.awt.Dimension (400, 80)); 127 descriptionPane.setPreferredSize(new java.awt.Dimension (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 (); 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 (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 (); 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 (5, 0, 2, 0); 153 add(descriptionLabel, gridBagConstraints); 154 155 } 157 private void moduleListValueChanged (javax.swing.event.ListSelectionEvent evt) { JList l = (JList ) evt.getSource (); 159 Module m = (Module) l.getSelectedValue (); 160 if (m != null) { 161 String text; 162 try { 163 text = "<b>" + XMLUtil.toElementContent(m.getDisplayName()) + "</b>"; String longDesc = (String ) m.getLocalizedAttribute("OpenIDE-Module-Long-Description"); if (longDesc != null) { 166 text += "<br>" + XMLUtil.toElementContent(longDesc); } 168 } catch (CharConversionException 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 } 179 180 private javax.swing.JEditorPane description; 182 private javax.swing.JLabel descriptionLabel; 183 private javax.swing.JScrollPane descriptionPane; 184 private javax.swing.JList moduleList; 185 private javax.swing.JLabel moduleListLabel; 186 private javax.swing.JScrollPane modulesArea; 187 189 private static final class ModuleCellRenderer extends DefaultListCellRenderer { 190 ModuleCellRenderer () {} 191 public Component getListCellRendererComponent (JList list, Object 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 |