1 19 20 package org.netbeans.modules.j2ee.common.method.impl; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import javax.swing.JPanel ; 25 import javax.swing.SwingUtilities ; 26 import javax.swing.event.DocumentEvent ; 27 import javax.swing.event.DocumentListener ; 28 import org.netbeans.modules.j2ee.common.method.MethodModel; 29 30 36 public class FieldCustomizerPanel extends JPanel { 37 38 public static final String NAME = "name"; 39 public static final String RETURN_TYPE = "returnType"; 40 public static final String INTERFACES = "interfaces"; 41 42 52 public FieldCustomizerPanel(MethodModel.Variable element, String description, boolean localEnabled, boolean remoteEnabled, 53 boolean localGetter, boolean localSetter, boolean remoteGetter, boolean remoteSetter) { 54 initComponents(); 55 56 descriptionTextField.setText(description); 57 localGetterCheckBox.setEnabled(localEnabled); 58 localSetterCheckBox.setEnabled(localEnabled); 59 remoteGetterCheckBox.setEnabled(remoteEnabled); 60 remoteSetterCheckBox.setEnabled(remoteEnabled); 61 localGetterCheckBox.setSelected(localGetter && localEnabled); 62 localSetterCheckBox.setSelected(localSetter && localEnabled); 63 remoteGetterCheckBox.setSelected(remoteGetter && remoteEnabled); 64 remoteSetterCheckBox.setSelected(remoteSetter && remoteEnabled); 65 nameTextField.setText(element.getName()); 66 typeTextField.setText(element.getType()); 67 68 nameTextField.getDocument().addDocumentListener(new SimpleListener(NAME)); 69 typeTextField.getDocument().addDocumentListener(new SimpleListener(RETURN_TYPE)); 70 SimpleListener interfacesListener = new SimpleListener(INTERFACES); 71 localGetterCheckBox.addActionListener(interfacesListener); 72 localSetterCheckBox.addActionListener(interfacesListener); 73 remoteGetterCheckBox.addActionListener(interfacesListener); 74 remoteSetterCheckBox.addActionListener(interfacesListener); 75 } 76 77 public void addNotify() { 78 super.addNotify(); 79 80 int nameLength = nameTextField.getText().length(); 82 nameTextField.setCaretPosition(0); 83 nameTextField.moveCaretPosition(nameLength); 84 nameTextField.requestFocus(); 85 SwingUtilities.invokeLater(new Runnable () { 86 public void run() { 87 nameTextField.requestFocus(); 88 } 89 }); 90 } 91 92 97 private void initComponents() { 99 100 nameLabel = new javax.swing.JLabel (); 101 nameTextField = new javax.swing.JTextField (); 102 descriptionLabel = new javax.swing.JLabel (); 103 descriptionTextField = new javax.swing.JTextField (); 104 typeLabel = new javax.swing.JLabel (); 105 addToLocalLabel = new javax.swing.JLabel (); 106 localGetterCheckBox = new javax.swing.JCheckBox (); 107 localSetterCheckBox = new javax.swing.JCheckBox (); 108 addToRemoteLabel = new javax.swing.JLabel (); 109 remoteGetterCheckBox = new javax.swing.JCheckBox (); 110 remoteSetterCheckBox = new javax.swing.JCheckBox (); 111 typeTextField = new javax.swing.JTextField (); 112 errorTextField = new javax.swing.JTextField (); 113 114 setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6)); 115 116 nameLabel.setLabelFor(nameTextField); 117 org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Name_")); 119 nameTextField.setColumns(30); 120 121 descriptionLabel.setLabelFor(descriptionTextField); 122 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Description")); 124 typeLabel.setLabelFor(typeTextField); 125 org.openide.awt.Mnemonics.setLocalizedText(typeLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Type")); 127 org.openide.awt.Mnemonics.setLocalizedText(addToLocalLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "LBL_AddToLocalInterface")); 129 org.openide.awt.Mnemonics.setLocalizedText(localGetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Getter_Local")); 131 org.openide.awt.Mnemonics.setLocalizedText(localSetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Setter_Local")); 133 org.openide.awt.Mnemonics.setLocalizedText(addToRemoteLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "LBL_AddToRemoteInterface")); 135 org.openide.awt.Mnemonics.setLocalizedText(remoteGetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Getter_Remote")); 137 org.openide.awt.Mnemonics.setLocalizedText(remoteSetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Setter_Remote")); 139 errorTextField.setEditable(false); 140 errorTextField.setText(org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "FieldCustomizerPanel.errorTextField.text")); errorTextField.setBorder(null); 142 143 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 144 this.setLayout(layout); 145 layout.setHorizontalGroup( 146 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 147 .add(layout.createSequentialGroup() 148 .addContainerGap() 149 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 150 .add(errorTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE) 151 .add(layout.createSequentialGroup() 152 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 153 .add(layout.createSequentialGroup() 154 .add(42, 42, 42) 155 .add(typeLabel)) 156 .add(layout.createSequentialGroup() 157 .add(37, 37, 37) 158 .add(nameLabel)) 159 .add(descriptionLabel)) 160 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 161 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 162 .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE) 163 .add(descriptionTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE) 164 .add(typeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))) 165 .add(layout.createSequentialGroup() 166 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 167 .add(addToLocalLabel) 168 .add(addToRemoteLabel)) 169 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 170 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 171 .add(layout.createSequentialGroup() 172 .add(localGetterCheckBox) 173 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 174 .add(localSetterCheckBox)) 175 .add(layout.createSequentialGroup() 176 .add(remoteGetterCheckBox) 177 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 178 .add(remoteSetterCheckBox))) 179 .add(190, 190, 190))) 180 .addContainerGap()) 181 ); 182 layout.setVerticalGroup( 183 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 184 .add(layout.createSequentialGroup() 185 .addContainerGap() 186 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 187 .add(nameLabel) 188 .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 189 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 190 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 191 .add(descriptionLabel) 192 .add(descriptionTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 193 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 194 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 195 .add(typeLabel) 196 .add(typeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 197 .add(18, 18, 18) 198 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 199 .add(localGetterCheckBox) 200 .add(localSetterCheckBox) 201 .add(addToLocalLabel)) 202 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 203 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 204 .add(addToRemoteLabel) 205 .add(remoteGetterCheckBox) 206 .add(remoteSetterCheckBox)) 207 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 208 .add(errorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 209 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 210 ); 211 212 nameTextField.getAccessibleContext().setAccessibleDescription(null); 213 descriptionTextField.getAccessibleContext().setAccessibleDescription(null); 214 localGetterCheckBox.getAccessibleContext().setAccessibleName(null); 215 localGetterCheckBox.getAccessibleContext().setAccessibleDescription(null); 216 localSetterCheckBox.getAccessibleContext().setAccessibleName(null); 217 localSetterCheckBox.getAccessibleContext().setAccessibleDescription(null); 218 remoteGetterCheckBox.getAccessibleContext().setAccessibleName(null); 219 remoteGetterCheckBox.getAccessibleContext().setAccessibleDescription(null); 220 remoteSetterCheckBox.getAccessibleContext().setAccessibleName(null); 221 remoteSetterCheckBox.getAccessibleContext().setAccessibleDescription(null); 222 } 224 private javax.swing.JLabel addToLocalLabel; 226 private javax.swing.JLabel addToRemoteLabel; 227 private javax.swing.JLabel descriptionLabel; 228 private javax.swing.JTextField descriptionTextField; 229 private javax.swing.JTextField errorTextField; 230 private javax.swing.JCheckBox localGetterCheckBox; 231 private javax.swing.JCheckBox localSetterCheckBox; 232 private javax.swing.JLabel nameLabel; 233 private javax.swing.JTextField nameTextField; 234 private javax.swing.JCheckBox remoteGetterCheckBox; 235 private javax.swing.JCheckBox remoteSetterCheckBox; 236 private javax.swing.JLabel typeLabel; 237 private javax.swing.JTextField typeTextField; 238 240 public void setError(String message) { 241 errorTextField.setText(message); 242 } 243 244 public String getMethodName() { 245 return nameTextField.getText(); 246 } 247 248 public String getReturnType() { 249 return typeTextField.getText(); 250 } 251 252 public String getDescription() { 253 return descriptionTextField.getText(); 254 } 255 256 public boolean isLocalGetter() { 257 return localGetterCheckBox.isSelected(); 258 } 259 260 public boolean isLocalSetter() { 261 return localSetterCheckBox.isSelected(); 262 } 263 264 public boolean isRemoteGetter() { 265 return remoteGetterCheckBox.isSelected(); 266 } 267 268 public boolean isRemoteSetter() { 269 return remoteSetterCheckBox.isSelected(); 270 } 271 272 279 private class SimpleListener implements DocumentListener , ActionListener { 280 281 private final String propertyName; 282 283 public SimpleListener(String propertyName) { 284 this.propertyName = propertyName; 285 } 286 287 public void insertUpdate(DocumentEvent documentEvent) { fire(); } 288 289 public void removeUpdate(DocumentEvent documentEvent) { fire(); } 290 291 public void changedUpdate(DocumentEvent documentEvent) {} 292 293 public void actionPerformed(ActionEvent actionEvent) { fire(); } 294 295 private void fire() { 296 firePropertyChange(propertyName, null, null); 297 } 298 299 } 300 } 301 | Popular Tags |