1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.awt.*; 22 import java.util.*; 23 import java.beans.*; 24 25 import javax.swing.*; 26 import javax.swing.table.*; 27 28 import org.openide.util.*; 29 import java.net.URL ; 30 import java.net.MalformedURLException ; 31 32 33 39 public final class SAXGeneratorMethodPanel extends SAXGeneratorAbstractPanel { 40 41 42 private static final long serialVersionUID =-4925652670676144240L; 43 44 45 private TableModel tableModel; 46 private MethodsTable table; 47 48 50 static final int ELEMENT_COLUMN = 0; 51 static final int TYPE_COLUMN = 1; 52 static final int METHOD_COLUMN = 2; 53 static final int COLUMNS = 3; 54 55 private final String [] COLUMN_NAMES = new String [] { 56 Util.THIS.getString ("SAXGeneratorMethodPanel.table.column1"), 57 Util.THIS.getString ("SAXGeneratorMethodPanel.table.column2"), 58 Util.THIS.getString ("SAXGeneratorMethodPanel.table.column3"), 59 }; 60 61 62 63 private final ValidatingTextField.Validator METHOD_VALIDATOR = new ValidatingTextField.Validator() { 64 public boolean isValid(String text) { 65 boolean ret = Utilities.isJavaIdentifier("_" + text); setValid(ret); 67 return ret; 68 } 69 70 public String getReason() { 71 return Util.THIS.getString("MSG_method_err_1"); 72 } 73 }; 74 75 76 public SAXGeneratorMethodPanel() { 77 } 82 83 88 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 90 91 descTextArea = new javax.swing.JTextArea (); 92 tableScrollPane = new javax.swing.JScrollPane (); 93 94 setLayout(new java.awt.GridBagLayout ()); 95 96 setPreferredSize(new java.awt.Dimension (480, 350)); 97 setName(Util.THIS.getString ("SAXGeneratorMethodPanel.Form.name")); 98 descTextArea.setWrapStyleWord(true); 99 descTextArea.setLineWrap(true); 100 descTextArea.setEditable(false); 101 descTextArea.setForeground(new java.awt.Color (102, 102, 153)); 102 descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font")); 103 descTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/tools/generator/Bundle").getString("DESC_saxw_methods")); 104 descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground")); 105 descTextArea.setEnabled(false); 106 descTextArea.setOpaque(false); 107 gridBagConstraints = new java.awt.GridBagConstraints (); 108 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 109 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 110 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 111 gridBagConstraints.weightx = 1.0; 112 add(descTextArea, gridBagConstraints); 113 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 116 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 117 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 118 gridBagConstraints.weightx = 1.0; 119 gridBagConstraints.weighty = 1.0; 120 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 121 add(tableScrollPane, gridBagConstraints); 122 123 } 125 private void initModels() { 126 tableModel = new MethodsTableModel(); 127 } 128 129 protected void initView() { 130 initModels(); 131 initComponents (); 132 133 table = new MethodsTable(); 134 table.setModel(tableModel); 135 tableScrollPane.setViewportView(table); 137 initAccessibility(); 138 } 139 140 protected void updateView() { 141 checkNames(); 142 } 143 144 protected void updateModel() { 145 } 147 148 private void checkNames() { 149 } 150 151 153 156 private class MethodsTable extends JTable { 157 158 159 private static final long serialVersionUID =-8352980237774025436L; 160 161 public MethodsTable() { 162 getTableHeader().setReorderingAllowed(false); 163 setRowHeight(Util.getTextCellHeight(this)); 164 } 165 166 170 public TableCellEditor getCellEditor(int row, int column) { 171 if (column == TYPE_COLUMN) { 172 ElementBindings.Entry entry = model.getElementBindings().getEntry(row); 173 final String element = entry.getElement(); 174 final JComboBox editor = 175 new JComboBox(entry.displayTypesFor(model.getElementDeclarations().getEntry(element))); 176 177 return new DefaultCellEditor(editor); 178 } else if (column == METHOD_COLUMN) { 179 ValidatingTextField input = new ValidatingTextField(); 180 input.setValidator(METHOD_VALIDATOR); 181 return new DefaultCellEditor(input); 182 } else { 183 return super.getCellEditor(row, column); 184 } 185 } 186 187 } 188 189 192 private class MethodsTableModel extends AbstractTableModel { 193 194 195 private static final long serialVersionUID =7287934953974099492L; 196 197 public String getColumnName(int col) { 198 return COLUMN_NAMES[col]; 199 } 200 201 public int getRowCount() { 202 if (model == null) return 0; 203 return model.getElementBindings().size(); 204 } 205 206 public int getColumnCount() { 207 return COLUMNS; 208 } 209 210 213 public Object getValueAt(int row, int column) { 214 ElementBindings.Entry entry = model.getElementBindings().getEntry(row); 215 switch (column) { 216 case ELEMENT_COLUMN: 217 return entry.getElement(); 218 case TYPE_COLUMN: 219 return entry.displayTypeFor(entry.getType()); 220 case METHOD_COLUMN: 221 return entry.getMethod(); 222 default: 223 return null; 224 } 225 } 226 227 public void setValueAt(Object value, int row, int col) { 228 229 ElementBindings.Entry entry = model.getElementBindings().getEntry(row); 230 switch (col) { 231 case TYPE_COLUMN: 232 entry.setType(entry.typeFor((String ) value)); 233 return; 234 case METHOD_COLUMN: 235 if (Utilities.isJavaIdentifier("_" + (String ) value) == false) { setValid(false); 238 return; 239 } else { 240 checkNames(); 241 } 242 entry.setMethod((String ) value); return; 244 } 245 } 246 247 public boolean isCellEditable(int row, int col) { 248 return col != ELEMENT_COLUMN; 249 } 250 } 251 252 254 255 256 257 258 private javax.swing.JTextArea descTextArea; 260 private javax.swing.JScrollPane tableScrollPane; 261 263 265 public void initAccessibility(){ 266 267 this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_SAXGeneratorMethodPanel")); 268 table.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_table")); 269 table.getAccessibleContext().setAccessibleName(Util.THIS.getString("ACSN_table")); 270 } 271 } 272 | Popular Tags |