1 19 package org.netbeans.modules.editor.hints.options; 20 21 import java.awt.Component ; 22 import java.util.Arrays ; 23 import java.util.List ; 24 import javax.swing.DefaultCellEditor ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.JComboBox ; 27 import javax.swing.JLabel ; 28 import javax.swing.JList ; 29 import javax.swing.JTable ; 30 import javax.swing.ListCellRenderer ; 31 import javax.swing.table.AbstractTableModel ; 32 import javax.swing.table.TableCellRenderer ; 33 import javax.swing.table.TableColumn ; 34 import org.netbeans.spi.editor.hints.ProviderDescription; 35 import org.netbeans.spi.editor.hints.Severity; 36 import org.openide.awt.HtmlRenderer; 37 38 42 public class AdvancedPanelImpl extends javax.swing.JPanel { 43 44 private ModelImpl model; 45 46 47 public AdvancedPanelImpl(ModelImpl model) { 48 this.model = model; 49 initComponents(); 50 jTable1.setDefaultRenderer(Severity.class, new SeverityCellRenderer()); 51 JComboBox editor = new JComboBox (new Object [] { 52 Severity.ERROR, 53 Severity.WARNING, 54 Severity.VERIFIER, 55 Severity.HINT, 56 Severity.TODO, 57 Severity.DISABLED, 58 }); 59 editor.setRenderer(new SeverityComboRenderer()); 60 jTable1.setDefaultEditor(Severity.class, new DefaultCellEditor (editor)); 61 TableColumn c = jTable1.getColumnModel().getColumn(0); 62 c.setHeaderValue("XXXXXXXXX"); c.setHeaderRenderer(new HeaderTableCellRenderer()); 64 c.sizeWidthToFit(); 65 updateForCurrentProvider(); 66 eagerCombo.setSelectedIndex(2); 67 } 68 69 74 private void initComponents() { 76 77 jComboBox1 = new javax.swing.JComboBox (); 78 jCheckBox1 = new javax.swing.JCheckBox (); 79 jTable1 = new javax.swing.JTable (); 80 jLabel1 = new javax.swing.JLabel (); 81 eagerCombo = new javax.swing.JComboBox (); 82 83 jComboBox1.setModel(new ComboModelImpl()); 84 jComboBox1.setSelectedIndex(jComboBox1.getModel().getSize() > 0 ? 0 : (-1)); 85 jComboBox1.setRenderer(new RendererImpl()); 86 jComboBox1.addActionListener(new java.awt.event.ActionListener () { 87 public void actionPerformed(java.awt.event.ActionEvent evt) { 88 jComboBox1ActionPerformed(evt); 89 } 90 }); 91 92 jCheckBox1.setText("Enabled"); 93 jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 94 jCheckBox1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 95 jCheckBox1.addActionListener(new java.awt.event.ActionListener () { 96 public void actionPerformed(java.awt.event.ActionEvent evt) { 97 jCheckBox1ActionPerformed(evt); 98 } 99 }); 100 101 jTable1.setModel(new OptionsTableModel()); 102 jTable1.setRowSelectionAllowed(false); 103 jTable1.setShowHorizontalLines(false); 104 jTable1.setShowVerticalLines(false); 105 106 jLabel1.setText("Eagerness:"); 107 108 eagerCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "<html>On Project Open <i>requires restart</i>", "<html>On Demand", "<html>Lazy" })); 109 eagerCombo.addActionListener(new java.awt.event.ActionListener () { 110 public void actionPerformed(java.awt.event.ActionEvent evt) { 111 eagerComboActionPerformed(evt); 112 } 113 }); 114 115 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 116 this.setLayout(layout); 117 layout.setHorizontalGroup( 118 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 119 .add(layout.createSequentialGroup() 120 .addContainerGap() 121 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 122 .add(jTable1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE) 123 .add(jCheckBox1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE) 124 .add(layout.createSequentialGroup() 125 .add(jLabel1) 126 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 127 .add(eagerCombo, 0, 375, Short.MAX_VALUE)) 128 .add(jComboBox1, 0, 454, Short.MAX_VALUE)) 129 .addContainerGap()) 130 ); 131 layout.setVerticalGroup( 132 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 133 .add(layout.createSequentialGroup() 134 .addContainerGap() 135 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 136 .add(jLabel1) 137 .add(eagerCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 138 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 139 .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 140 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 141 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 142 .add(jTable1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 143 .add(jCheckBox1)) 144 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 145 ); 146 } 148 private void eagerComboActionPerformed(java.awt.event.ActionEvent evt) { 150 } 152 private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) { model.setProviderEnabled(getProviderDescription().getKey(), jCheckBox1.isSelected()); 154 155 int index = jComboBox1.getSelectedIndex(); 156 157 ((ComboModelImpl) jComboBox1.getModel()).fireContentsChanged(index, index); 158 } 160 private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { updateForCurrentProvider(); 162 } 164 165 public javax.swing.JComboBox eagerCombo; 167 public javax.swing.JCheckBox jCheckBox1; 168 public javax.swing.JComboBox jComboBox1; 169 public javax.swing.JLabel jLabel1; 170 public javax.swing.JTable jTable1; 171 173 private void updateForCurrentProvider() { 174 ProviderDescription desc = getProviderDescription(); 175 176 if (desc != null) { 177 jCheckBox1.setSelected(model.isProviderEnabled(desc.getKey())); 178 jCheckBox1.setEnabled(true); 179 } else { 180 jCheckBox1.setSelected(false); 181 jCheckBox1.setEnabled(false); 182 } 183 184 ((OptionsTableModel) jTable1.getModel()).fireTableDataChanged(); 185 } 186 187 private ProviderDescription getProviderDescription() { 188 return (ProviderDescription) jComboBox1.getSelectedItem(); 189 } 190 191 private final class ComboModelImpl extends DefaultComboBoxModel { 192 193 public int getSize() { 194 return model.getDescriptions().size(); 195 } 196 197 public Object getElementAt(int index) { 198 return model.getDescriptions().get(index); 199 } 200 201 public void fireContentsChanged(int start, int end) { 202 super.fireContentsChanged(this, start, end); 203 } 204 205 } 206 207 private static final class HeaderTableCellRenderer extends JLabel implements TableCellRenderer { 208 209 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 210 setText((String ) value); 211 return this; 212 } 213 214 } 215 216 private final class RendererImpl implements ListCellRenderer { 217 218 private ListCellRenderer delegateTo; 219 220 public RendererImpl() { 221 delegateTo = HtmlRenderer.createRenderer(); 222 } 223 224 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 225 String text; 226 227 if (value == null) { 228 text = "<none>"; 229 } else { 230 text = ((ProviderDescription) value).getDisplayName(); 231 232 if (!model.isProviderEnabled(((ProviderDescription) value).getKey())) { 233 text = "<html><s>" + text; 234 } 235 } 236 237 return delegateTo.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus); 238 } 239 } 240 241 private final class OptionsTableModel extends AbstractTableModel { 242 243 public int getRowCount() { 244 ProviderDescription desc = getProviderDescription(); 245 246 if (desc == null) 247 return 0; 248 249 return desc.getSupportedErrorKeys().size(); 250 } 251 252 public int getColumnCount() { 253 return 2; 254 } 255 256 public String getColumnName(int columnIndex) { 257 switch (columnIndex) { 258 case 0: 259 return "Severity"; 260 case 1: 261 return "Name"; 262 default: 263 throw new IllegalArgumentException ("columnIndex=" + columnIndex); 264 } 265 } 266 267 public Class getColumnClass(int columnIndex) { 268 switch (columnIndex) { 269 case 0: 270 return Severity.class; 271 case 1: 272 return String .class; 273 default: 274 throw new IllegalArgumentException ("columnIndex=" + columnIndex); 275 } 276 } 277 278 public boolean isCellEditable(int rowIndex, int columnIndex) { 279 switch (columnIndex) { 280 case 0: 281 return true; 282 case 1: 283 return false; 284 default: 285 throw new IllegalArgumentException ("columnIndex=" + columnIndex); 286 } 287 } 288 289 public Object getValueAt(int rowIndex, int columnIndex) { 290 ProviderDescription desc = getProviderDescription(); 291 292 switch (columnIndex) { 293 case 0: 294 return model.getErrorSeverity(desc.getKey(), (String ) desc.getSupportedErrorKeys().get(rowIndex)); 295 case 1: 296 return desc.getErrorDisplayName((String ) desc.getSupportedErrorKeys().get(rowIndex)); 297 default: 298 throw new IllegalArgumentException ("columnIndex=" + columnIndex); 299 } 300 } 301 302 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 303 ProviderDescription desc = getProviderDescription(); 304 305 switch (columnIndex) { 306 case 0: 307 model.setSeverity(desc.getKey(), (String ) desc.getSupportedErrorKeys().get(rowIndex), (Severity) aValue); 308 return ; 309 default: 310 throw new IllegalArgumentException ("columnIndex=" + columnIndex); 311 } 312 } 313 314 } 315 316 private static final class SeverityCellRenderer implements TableCellRenderer { 317 318 private TableCellRenderer delegateTo; 319 320 public SeverityCellRenderer() { 321 delegateTo = HtmlRenderer.createRenderer(); 322 } 323 324 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 325 return delegateTo.getTableCellRendererComponent(table, SEVERITIES.get(((Severity) value).ordinal()), isSelected, hasFocus, row, column); 326 } 327 } 328 329 private static final String [] SEVERITIES_ARRAY = new String [] { 330 "<html><font color=\"#808080\">disabled", 331 "<html><font color=\"#800000\">error", 332 "<html><font color=\"#808000\">warning", 333 "<html><font color=\"#000080\">verifier", 334 "<html><font color=\"#000080\">hint", 335 "<html><font color=\"#000080\">todo", 336 }; 337 338 static final List SEVERITIES = Arrays.asList(SEVERITIES_ARRAY); 339 340 } 341 | Popular Tags |