1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.awt.Color ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.Insets ; 25 import java.awt.event.FocusEvent ; 26 import java.awt.event.FocusAdapter ; 27 import java.awt.event.ItemEvent ; 28 import java.awt.event.ItemListener ; 29 import java.awt.event.KeyEvent ; 30 import java.awt.event.KeyListener ; 31 32 import javax.swing.JCheckBox ; 33 import javax.swing.JLabel ; 34 import javax.swing.JTextField ; 35 import javax.swing.KeyStroke ; 36 import javax.swing.SwingUtilities ; 37 38 import org.openide.util.HelpCtx; 39 import org.openide.util.NbBundle; 40 41 45 46 class DeployDataPanel extends BaseWizardPanel implements ItemListener , 47 KeyListener { 48 49 private TargetEvaluator evaluator = null; 50 51 private ServletData deployData; 52 private FileType fileType; 53 private boolean edited = false; 54 55 private static final boolean debug = false; 56 57 public DeployDataPanel(TargetEvaluator e) { 58 59 evaluator = e; 60 fileType = evaluator.getFileType(); 61 deployData = (ServletData)(evaluator.getDeployData()); 62 setName(NbBundle.getMessage(DeployDataPanel.class, 63 "TITLE_ddpanel_".concat(fileType.toString()))); 64 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class, "ACSD_deployment")); 65 initComponents (); 66 fireChangeEvent(); 67 } 68 69 private void initComponents () { 70 71 if(debug) log("::initComponents()"); setPreferredSize(new java.awt.Dimension (450, 250)); 74 setLayout(new java.awt.GridBagLayout ()); 75 76 GridBagConstraints fullRowC = new GridBagConstraints (); 78 fullRowC.gridx = 0; 79 fullRowC.gridy = GridBagConstraints.RELATIVE; 80 fullRowC.gridwidth = 8; 81 fullRowC.anchor = GridBagConstraints.WEST; 82 fullRowC.fill = GridBagConstraints.HORIZONTAL; 83 fullRowC.insets = new Insets (4, 0, 4, 60); 84 85 GridBagConstraints firstC = new GridBagConstraints (); 87 firstC.gridx = 0; 88 firstC.gridy = GridBagConstraints.RELATIVE; 89 firstC.gridwidth = 1; 90 firstC.anchor = GridBagConstraints.WEST; 91 firstC.insets = new Insets (4, 20, 4, 0); 92 94 GridBagConstraints tfC = new GridBagConstraints (); 96 tfC.gridx = GridBagConstraints.RELATIVE; 97 tfC.gridy = 0; 98 tfC.gridwidth = 7; 99 tfC.fill = GridBagConstraints.HORIZONTAL; 100 tfC.insets = new Insets (4, 20, 4, 60); 101 102 GridBagConstraints stfC = new GridBagConstraints (); 104 stfC.gridx = GridBagConstraints.RELATIVE; 105 stfC.gridy = 0; 106 stfC.gridwidth = 5; 108 stfC.weightx = 1.0; 109 stfC.fill = GridBagConstraints.HORIZONTAL; 110 stfC.insets = new Insets (4, 20, 4, 0); 111 112 GridBagConstraints tablePanelC = new GridBagConstraints (); 114 tablePanelC.gridx = 0; 115 tablePanelC.gridy = GridBagConstraints.RELATIVE; 116 tablePanelC.gridwidth = 8; 117 tablePanelC.fill = GridBagConstraints.BOTH; 118 tablePanelC.weightx = 1.0; 119 tablePanelC.weighty = 1.0; 120 tablePanelC.insets = new Insets (4, 20, 4, 0); 121 122 jLinstruction = new JLabel (NbBundle.getMessage(DeployDataPanel.class, "LBL_dd_".concat(fileType.toString()))); 125 this.add(jLinstruction, fullRowC); 126 127 129 tfC.gridy++; 130 jCBservlet = new JCheckBox (NbBundle.getMessage(DeployDataPanel.class, "LBL_addtodd"), true); 133 jCBservlet.setMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_add_mnemonic").charAt (0)); 134 jCBservlet.addItemListener(this); 135 jCBservlet.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class, "ACSD_addtodd")); 137 this.add(jCBservlet, fullRowC); 138 139 tfC.gridy++; 141 jTFclassname = new JTextField (25); 142 jTFclassname.setEnabled(false); 143 jTFclassname.setBackground(this.getBackground()); 144 jLclassname = new JLabel (NbBundle.getMessage(DeployDataPanel.class, "LBL_ClassName")); 145 jLclassname.setLabelFor(jTFclassname); 146 jLclassname.setDisplayedMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_Class_Mnemonic").charAt(0)); 147 jTFclassname.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_ClassName")); 148 149 this.add(jLclassname, firstC); 150 this.add(jTFclassname, tfC); 151 152 tfC.gridy++; 154 jTFname = new JTextField (25); 155 jTFname.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_name_".concat(fileType.toString()))); 156 jTFname.addKeyListener (this); 157 jTFname.unregisterKeyboardAction 158 (KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 159 jTFname.addFocusListener(new FocusAdapter () { 160 public void focusGained(FocusEvent evt) { 161 if(debug) log("\tjTFname got focus"); jTFname.selectAll(); 163 } 164 }); 165 166 jLname = new JLabel (NbBundle.getMessage(DeployDataPanel.class, "LBL_name_".concat(fileType.toString()))); 167 jLname.setLabelFor(jTFname); 168 jLname.setDisplayedMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_name_".concat(fileType.toString()).concat("_mnem")).charAt(0)); 169 170 this.add(jLname, firstC); 171 this.add(jTFname, tfC); 172 173 if(fileType == FileType.SERVLET) { 175 tfC.gridy++; 176 jTFmapping = new JTextField (25); 177 jTFmapping.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_url_mapping")); 178 jTFmapping.addKeyListener (this); 179 jTFmapping.unregisterKeyboardAction 180 (KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 181 jTFmapping.addFocusListener(new FocusAdapter () { 182 public void focusGained(FocusEvent evt) { 183 if(debug) log("\tjTFmapping got focus"); jTFmapping.selectAll(); 185 } 186 public void focusLost(FocusEvent evt) { 187 if(debug) log("\tjTFmapping lost focus"); deployData.parseUrlMappingString(jTFmapping.getText().trim()); 189 fireChangeEvent(); 190 } 191 }); 192 193 jLmapping = new JLabel (NbBundle.getMessage(DeployDataPanel.class, "LBL_url_mapping")); 194 jLmapping.setLabelFor (jTFmapping); 195 jLmapping.setDisplayedMnemonic(NbBundle.getMessage (DeployDataPanel.class, "LBL_mapping_mnemonic").charAt (0)); 196 197 this.add(jLmapping, firstC); 198 this.add(jTFmapping, tfC); 199 } 200 201 if(fileType == FileType.SERVLET) { 203 paramPanel = new InitParamPanel(deployData, this); 204 this.add(paramPanel, tablePanelC); 205 } 206 else if(fileType == FileType.FILTER) { 207 mappingPanel = new MappingPanel(deployData, this); 208 this.add(mappingPanel, tablePanelC); 209 } 210 GridBagConstraints fillerC = new GridBagConstraints (); 212 fillerC.gridx = 0; 213 fillerC.gridy = GridBagConstraints.RELATIVE; 214 fillerC.weighty = 1.0; 215 fillerC.fill = GridBagConstraints.BOTH; 216 this.add(new javax.swing.JPanel (), fillerC); 217 } 218 219 void setData() { 220 if(debug) log("::setData()"); 222 deployData.setClassName(evaluator.getClassName()); 223 jTFclassname.setText(deployData.getClassName()); 224 225 if(!edited) { 226 if(debug) log("\tUser has not edited dd data yet"); 228 deployData.setName(evaluator.getFileName()); 229 if(fileType == FileType.SERVLET) { 230 if(debug) log("\tData type is servlet"); deployData.parseUrlMappingString("/" + evaluator.getFileName()); 233 } 234 } 235 236 jTFname.setText(deployData.getName()); 237 238 if(fileType == FileType.SERVLET) 239 jTFmapping.setText(deployData.getUrlMappingsAsString()); 240 else if(fileType == FileType.FILTER) 241 mappingPanel.setData(); 242 } 243 244 public void itemStateChanged (java.awt.event.ItemEvent itemEvent) { 245 if(itemEvent.getSource() == jCBservlet) { 246 boolean enabled = 247 (itemEvent.getStateChange() == ItemEvent.SELECTED); 248 enableInput(enabled); 249 deployData.setMakeEntry(enabled); 250 deployData.setAddToDD(enabled); 251 if(fileType == FileType.SERVLET) { 252 paramPanel.setEnabled(); 253 } 254 } 255 fireChangeEvent (); 256 } 257 258 private void enableInput(boolean enable) { 259 260 if(debug) log("::enableInput()"); 261 262 jTFname.setEnabled(enable); 263 jLinstruction.setEnabled(enable); 264 jLclassname.setEnabled(enable); 265 jLname.setEnabled(enable); 266 if(fileType == FileType.SERVLET) { 267 jTFmapping.setEnabled(enable); 268 jLmapping.setEnabled(enable); 269 paramPanel.setEnabled(enable); 270 } 271 else if (fileType == FileType.FILTER) { 272 mappingPanel.setEnabled(enable); 273 } 274 275 if(enable) { 276 jTFclassname.setDisabledTextColor(Color.black); 277 jTFclassname.repaint(); 278 jTFname.setBackground(Color.white); 279 if(fileType == FileType.SERVLET) 280 jTFmapping.setBackground(Color.white); 281 } 282 else { 283 jTFclassname.setDisabledTextColor 284 (jTFname.getDisabledTextColor()); 285 jTFclassname.repaint(); 286 jTFname.setBackground(this.getBackground()); 287 if(fileType == FileType.SERVLET) 288 jTFmapping.setBackground(this.getBackground()); 289 } 290 } 291 292 public void keyPressed (java.awt.event.KeyEvent keyEvent) { 293 } 294 295 public void keyReleased (java.awt.event.KeyEvent keyEvent) { 296 edited = true; 297 if(keyEvent.getSource() == jTFname) { 298 SwingUtilities.invokeLater(new Runnable () { 299 public void run() { 300 deployData.setName(jTFname.getText().trim()); 303 if(fileType == FileType.FILTER) 304 mappingPanel.setData(); 305 fireChangeEvent(); 306 } 307 }); 308 return; 309 } 310 else if(keyEvent.getSource() == jTFmapping) { 311 SwingUtilities.invokeLater(new Runnable () { 312 public void run() { 313 deployData.parseUrlMappingString(jTFmapping.getText().trim()); 316 fireChangeEvent(); 317 } 318 }); 319 return; 320 } 321 fireChangeEvent(); 322 } 323 324 public void keyTyped (java.awt.event.KeyEvent keyEvent) { 325 } 326 327 328 public void log(String s) { 329 System.out.println("DeployDataPanel" + s); } 331 332 333 public HelpCtx getHelp() { 334 return new HelpCtx(this.getClass().getName()+"."+evaluator.getFileType().toString()); } 336 337 private JCheckBox jCBservlet; 339 private JTextField jTFclassname; 340 private JTextField jTFname; 341 private JTextField jTFmapping; 342 private JLabel jLinstruction; 343 private JLabel jLclassname; 344 private JLabel jLname; 345 private JLabel jLmapping; 346 private InitParamPanel paramPanel; 347 private MappingPanel mappingPanel; 348 349 private static final long serialVersionUID = -2704206901170711687L; 350 351 } 352 | Popular Tags |