1 19 20 package org.netbeans.modules.tasklist.suggestions; 21 22 import java.awt.Component ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 import java.util.ResourceBundle ; 30 import java.util.Vector ; 31 import javax.swing.AbstractListModel ; 32 import javax.swing.event.ListSelectionListener ; 33 import javax.swing.ListModel ; 34 import javax.swing.DefaultListModel ; 35 import javax.swing.JCheckBox ; 36 import javax.swing.JComboBox ; 37 import javax.swing.JList ; 38 import javax.swing.JTable ; 39 import javax.swing.JTextField ; 40 import javax.swing.ListCellRenderer ; 41 import javax.swing.ListSelectionModel ; 42 import javax.swing.UIManager ; 43 import javax.swing.border.Border ; 44 import javax.swing.border.EmptyBorder ; 45 import javax.swing.table.AbstractTableModel ; 46 import javax.swing.table.TableColumn ; 47 import javax.swing.table.TableColumnModel ; 48 import org.netbeans.modules.tasklist.client.SuggestionManager; 49 import org.openide.util.NbBundle; 50 import org.openide.awt.Mnemonics; 51 52 64 public final class TypesCustomizer extends javax.swing.JPanel 65 implements ListSelectionListener { 66 67 private static final long serialVersionUID = 1; 68 69 72 public TypesCustomizer() { 73 initComponents(); 74 initA11y(); 75 76 typesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 77 typesTable.setModel(new TypesCustomizer.SuggTypesTableModel()); 78 TableColumnModel cm = typesTable.getColumnModel(); 79 cm.getColumn(0).setPreferredWidth(50); 80 cm.getColumn(1).setPreferredWidth(50); 81 cm.getColumn(2).setPreferredWidth(300); 82 typesTable.getSelectionModel().addListSelectionListener(this); 83 typesTable.getSelectionModel().setSelectionInterval(0, 0); 84 } 85 86 92 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 94 95 activeLabel = new javax.swing.JLabel (); 96 typeDescLabel = new javax.swing.JLabel (); 97 jScrollPane1 = new javax.swing.JScrollPane (); 98 descTextArea = new javax.swing.JTextArea (); 99 jScrollPane3 = new javax.swing.JScrollPane (); 100 typesTable = new javax.swing.JTable (); 101 102 setLayout(new java.awt.GridBagLayout ()); 103 104 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (12, 12, 11, 11))); 105 activeLabel.setLabelFor(typesTable); 106 109 gridBagConstraints = new java.awt.GridBagConstraints (); 110 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 111 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 112 add(activeLabel, gridBagConstraints); 113 114 typeDescLabel.setLabelFor(descTextArea); 115 118 gridBagConstraints = new java.awt.GridBagConstraints (); 119 gridBagConstraints.gridx = 0; 120 gridBagConstraints.gridy = 3; 121 gridBagConstraints.insets = new java.awt.Insets (12, 0, 2, 0); 122 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 123 add(typeDescLabel, gridBagConstraints); 124 125 descTextArea.setEditable(false); 126 descTextArea.setLineWrap(true); 127 descTextArea.setWrapStyleWord(true); 128 descTextArea.setPreferredSize(new java.awt.Dimension (400, 100)); 129 jScrollPane1.setViewportView(descTextArea); 130 131 gridBagConstraints = new java.awt.GridBagConstraints (); 132 gridBagConstraints.gridx = 0; 133 gridBagConstraints.gridy = 4; 134 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 135 gridBagConstraints.weightx = 1.0; 136 gridBagConstraints.weighty = 1.0; 137 add(jScrollPane1, gridBagConstraints); 138 139 jScrollPane3.setViewportView(typesTable); 140 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 0; 143 gridBagConstraints.gridy = 1; 144 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 145 gridBagConstraints.weighty = 1.0; 146 add(jScrollPane3, gridBagConstraints); 147 148 } 150 151 152 private void initA11y() { 153 162 163 Mnemonics.setLocalizedText(activeLabel, 164 NbBundle.getMessage(TypesCustomizer.class, "ActiveTypes")); Mnemonics.setLocalizedText(typeDescLabel, 166 NbBundle.getMessage(TypesCustomizer.class, "TypeDesc")); 168 this.getAccessibleContext().setAccessibleDescription( 169 NbBundle.getMessage(TypesCustomizer.class, "ACSD_TypesCustomizer")); typesTable.getAccessibleContext().setAccessibleDescription( 171 NbBundle.getMessage(TypesCustomizer.class, "ACSD_Enabled")); descTextArea.getAccessibleContext().setAccessibleDescription( 173 NbBundle.getMessage(TypesCustomizer.class, "ACSD_TypeDesc")); } 175 176 177 private javax.swing.JTable typesTable; 179 private javax.swing.JScrollPane jScrollPane1; 180 private javax.swing.JTextArea descTextArea; 181 private javax.swing.JLabel activeLabel; 182 private javax.swing.JLabel typeDescLabel; 183 private javax.swing.JScrollPane jScrollPane3; 184 186 189 public void apply() { 190 SuggTypesTableModel model = (SuggTypesTableModel) typesTable.getModel(); 191 model.save(); 192 } 193 194 public void valueChanged(javax.swing.event.ListSelectionEvent event) { 195 int selected = typesTable.getSelectedRow(); 196 if (selected < 0) { 197 descTextArea.setText(""); 198 } else { 199 SuggTypesTableModel m = (SuggTypesTableModel) typesTable.getModel(); 200 descTextArea.setText(m.getType(selected).getDescription()); 201 } 202 } 203 204 207 private static class SuggTypesTableModel extends AbstractTableModel { 208 209 private static final long serialVersionUID = 1; 210 211 private static String [] columnNames; 212 213 static { 214 ResourceBundle rb = NbBundle.getBundle(SuggTypesTableModel.class); 215 columnNames = new String [] { 216 rb.getString("Active"), 217 rb.getString("Confirmation"), 218 rb.getString("Name") 219 }; 220 } 221 222 private SuggestionType[] types; 223 private boolean[] enabled; 224 private boolean[] confirm; 225 226 229 public SuggTypesTableModel() { 230 Collection cl = SuggestionTypes.getDefault().getAllTypes(); 231 Iterator it = cl.iterator(); 232 SuggestionManagerImpl manager = 233 (SuggestionManagerImpl) SuggestionManager.getDefault(); 234 ArrayList types = new ArrayList (); 235 while (it.hasNext()) { 236 types.add(it.next()); 237 } 238 239 240 this.types = (SuggestionType[]) types.toArray( 241 new SuggestionType[types.size()]); 242 this.enabled = new boolean[types.size()]; 243 this.confirm = new boolean[types.size()]; 244 for (int i = 0; i < types.size(); i++) { 245 SuggestionType type = (SuggestionType) types.get(i); 246 enabled[i] = manager.isEnabled(type.getName()); 247 confirm[i] = manager.isConfirm(type); 248 } 249 } 250 251 254 public void save() { 255 SuggestionManagerImpl manager = 256 (SuggestionManagerImpl) SuggestionManager.getDefault(); 257 for (int i = 0; i < types.length; i++) { 258 manager.setEnabled(types[i].getName(), enabled[i], true); 259 manager.setConfirm(types[i], confirm[i], 260 i != types.length - 1); 261 } 262 } 263 264 269 public SuggestionType getType(int index) { 270 return types[index]; 271 } 272 273 278 public boolean getConfirmation(int index) { 279 return confirm[index]; 280 } 281 282 287 public void setConfirmation(int index, boolean c) { 288 confirm[index] = c; 289 fireTableCellUpdated(index, 1); 290 } 291 292 public int getRowCount() { 293 return types.length; 294 } 295 296 public int getColumnCount() { 297 return 3; 298 } 299 300 public String getColumnName(int columnIndex) { 301 return columnNames[columnIndex]; 302 } 303 304 public Class getColumnClass(int columnIndex) { 305 if (columnIndex == 2) 306 return String .class; 307 else 308 return Boolean .class; 309 } 310 311 public boolean isCellEditable(int rowIndex, int columnIndex) { 312 return columnIndex != 2; 313 } 314 315 public Object getValueAt(int rowIndex, int columnIndex) { 316 switch (columnIndex) { 317 case 0: 318 return enabled[rowIndex] ? Boolean.TRUE : Boolean.FALSE; 319 case 1: 320 return confirm[rowIndex] ? Boolean.TRUE : Boolean.FALSE; 321 case 2: 322 return types[rowIndex].getLocalizedName(); 323 } 324 return null; 325 } 326 327 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 328 switch (columnIndex) { 329 case 0: 330 enabled[rowIndex] = ((Boolean ) aValue).booleanValue(); 331 fireTableCellUpdated(rowIndex, columnIndex); 332 break; 333 case 1: 334 confirm[rowIndex] = ((Boolean ) aValue).booleanValue(); 335 fireTableCellUpdated(rowIndex, columnIndex); 336 break; 337 } 338 } 339 } 340 } 341 | Popular Tags |