1 19 20 23 24 package org.netbeans.modules.web.wizards; 25 26 import java.awt.Color ; 27 import java.awt.Dialog ; 28 import java.awt.Dimension ; 29 import java.awt.Insets ; 30 import java.awt.GridBagConstraints ; 31 import java.awt.GridBagLayout ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.ActionListener ; 34 import java.awt.event.FocusEvent ; 35 import java.awt.event.FocusListener ; 36 37 import javax.swing.BorderFactory ; 38 import javax.swing.JLabel ; 39 import javax.swing.JScrollPane ; 40 import javax.swing.JTextArea ; 41 import javax.swing.JTextField ; 42 43 import org.openide.DialogDisplayer; 44 import org.openide.DialogDescriptor; 45 import org.openide.NotifyDescriptor; 46 import org.openide.util.NbBundle; 47 48 public class TableRowDialog extends javax.swing.JPanel { 49 50 private final static boolean debug = false; 51 52 private Dialog dialog = null; 54 private DialogDescriptor editDialog = null; 55 private String errorMessage = null; 56 private boolean dialogOK = false; 57 58 private String name = ""; private String value = ""; private Editable editable; 62 private Condition condition; 63 private String title = ""; 65 private boolean repainting = false; 67 68 private static final long serialVersionUID = -855447534116444417L; 69 70 public TableRowDialog(String name, String value, Editable e, Condition c, 71 String title) { 72 if(debug) log("::CONSTRUCTOR"); 73 this.name = name; 74 this.value = value; 75 this.editable = e; 76 if(debug) log("\tEditable: " + e.toString()); 77 this.condition = c; 78 if(debug) log("\tCondition: " + c.toString()); 79 this.title = title; 80 initialize(); 81 } 82 83 public boolean getDialogOK() { 84 if(debug) { 85 log("::getDialogOK()"); log("\tdialogOK = " + String.valueOf(dialogOK)); } 88 return dialogOK; 89 } 90 91 public String getName() { 92 return name; 93 } 94 95 public String getValue() { 96 return value; 97 } 98 99 public void initialize() { 100 101 if(debug) System.out.println("in (new) TableRowDialog.initialize()"); this.setLayout(new GridBagLayout ()); 103 104 GridBagConstraints labelC = new GridBagConstraints (); 106 labelC.gridx = 0; 107 labelC.gridy = GridBagConstraints.RELATIVE; 108 labelC.anchor = GridBagConstraints.WEST; 109 labelC.fill = GridBagConstraints.HORIZONTAL; 110 labelC.insets = new Insets (4, 15, 4, 15); 111 112 GridBagConstraints firstC = new GridBagConstraints (); 114 firstC.gridx = 0; 115 firstC.gridy = GridBagConstraints.RELATIVE; 116 firstC.gridwidth = 1; 117 firstC.anchor = GridBagConstraints.WEST; 118 firstC.insets = new Insets (4, 15, 4, 0); 119 120 GridBagConstraints tfC = new GridBagConstraints (); 122 tfC.gridx = GridBagConstraints.RELATIVE; 123 tfC.gridy = 0; 124 tfC.gridwidth = 7; 125 tfC.fill = GridBagConstraints.HORIZONTAL; 126 tfC.insets = new Insets (4, 0, 4, 15); 127 128 GridBagConstraints taC = new GridBagConstraints (); 130 taC.gridx = 0; 131 taC.gridy = GridBagConstraints.RELATIVE; 132 taC.gridheight = 3; 133 taC.gridwidth = 8; 134 taC.fill = GridBagConstraints.BOTH; 135 taC.anchor = GridBagConstraints.WEST; 136 taC.insets = new Insets (0, 15, 4, 15); 137 138 JLabel nameLabel = new JLabel (); 139 nameLabel.setDisplayedMnemonic(NbBundle.getMessage(TableRowDialog.class, "LBL_paramname_mnemonic").charAt(0)); 140 nameLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TableRowDialog.class, "ACSD_paramname")); 141 142 String text = NbBundle.getMessage(TableRowDialog.class, 143 "LBL_paramname"); 144 text = text.concat(": "); 146 if(editable == Editable.BOTH) { 147 final JTextField nameText = new JTextField (25); 148 nameText.addFocusListener(new FocusListener () { 149 public void focusGained(FocusEvent evt) { 150 } 151 public void focusLost(FocusEvent evt) { 152 name = nameText.getText(); 153 } 154 }); 155 nameLabel.setLabelFor(nameText); 156 nameText.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TableRowDialog.class, "ACSD_paramname")); 157 nameText.setText(name); 158 nameText.setBackground(java.awt.Color.white); 159 nameText.setEditable(editable == Editable.BOTH); 160 161 this.add(nameLabel, firstC); 162 this.add(nameText, tfC); 163 } 164 else { 165 this.add(nameLabel, labelC); 166 text = text.concat(name); 167 } 168 nameLabel.setText(text); 169 170 JLabel valueLabel = new JLabel (); 171 valueLabel.setText(NbBundle.getMessage(TableRowDialog.class, "LBL_paramvalue").concat(":")); 172 valueLabel.setDisplayedMnemonic(NbBundle.getMessage(TableRowDialog.class, "LBL_paramvalue_mnemonic").charAt(0)); 173 valueLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TableRowDialog.class, "ACSD_paramvalue")); 174 firstC.gridy++; 175 this.add(valueLabel, labelC); 176 177 final JTextArea valueText = new JTextArea (); 178 valueText.addFocusListener(new FocusListener () { 179 public void focusGained(FocusEvent evt) { 180 } 181 public void focusLost(FocusEvent evt) { 182 value = valueText.getText(); 183 } 184 }); 185 valueLabel.setLabelFor(valueText); 186 valueText.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TableRowDialog.class, "ACSD_paramvalue")); 187 188 if(editable == Editable.NEITHER) { 189 valueText.setEditable(false); 190 valueText.setBackground(this.getBackground().darker()); 191 valueText.setForeground(Color.BLACK); 192 valueText.setBorder(BorderFactory.createLoweredBevelBorder()); 193 } 194 valueText.setText(value); 195 valueText.setLineWrap(true); 196 valueText.setWrapStyleWord(false); 197 198 JScrollPane scrollpane = new JScrollPane (valueText); 199 this.add(scrollpane, taC); 201 202 this.repaint(); 205 } 206 207 public void showDialog() { 208 209 if(editable == Editable.NEITHER) { 210 if(debug) log("Non-modal dialog, OK option only"); 211 NotifyDescriptor d = 212 new NotifyDescriptor(this, title, 213 NotifyDescriptor.DEFAULT_OPTION, 214 NotifyDescriptor.PLAIN_MESSAGE, 215 new Object [] { NotifyDescriptor.OK_OPTION }, 216 NotifyDescriptor.OK_OPTION); 217 DialogDisplayer.getDefault().notify(d); 218 } 219 else { 220 editDialog = new DialogDescriptor 221 (this, title, true, DialogDescriptor.OK_CANCEL_OPTION, 222 DialogDescriptor.CANCEL_OPTION, 223 new ActionListener () { 224 public void actionPerformed(ActionEvent e) { 225 evaluateInput(); 226 } 227 }); 228 229 dialog = DialogDisplayer.getDefault().createDialog(editDialog); 230 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TableRowDialog.class, "ACSD_initparam_edit")); 232 dialog.show(); 233 this.repaint(); 234 } 235 } 236 237 240 241 public void evaluateInput() { 242 243 if (debug) { 244 log("::evaluateInput()"); } 246 247 if (editDialog.getValue().equals(NotifyDescriptor.CANCEL_OPTION)) { 248 if(debug) log("\tGot cancel"); dialog.dispose(); 250 dialogOK = false; 251 return; 252 } 253 254 if(debug) log("\tGot OK"); if(editable == Editable.NEITHER) { 256 if(debug) log("\tNot editable"); dialog.dispose(); 258 dialogOK = false; 259 return; 260 } 261 if(debug) log("Name is " + name); 262 if(debug) log("Value is " + value); 263 264 errorMessage = null; 265 266 if(name.equals("")) 267 errorMessage = NbBundle.getMessage(TableRowDialog.class, 268 "MSG_no_name"); 269 270 else if(condition == Condition.VALUE && value.equals("")) 271 errorMessage = NbBundle.getMessage(TableRowDialog.class, 272 "MSG_no_value"); 273 274 if(debug) log("ErrorMessage: " + errorMessage); 275 276 if(errorMessage == null) { 277 dialog.dispose(); 278 dialogOK = true; 279 } 280 else { 281 editDialog.setValue(NotifyDescriptor.CLOSED_OPTION); 282 NotifyDescriptor nd = new NotifyDescriptor.Message 283 (errorMessage, NotifyDescriptor.ERROR_MESSAGE); 284 DialogDisplayer.getDefault().notify(nd); 285 } 286 } 287 288 289 public void repaint() { 291 super.repaint(); 292 if (dialog != null && !repainting) { 293 repainting = true; 294 dialog.repaint(); 295 repainting = false; 296 } 297 } 298 299 private void log(String s) { 300 System.out.println("TableRowDialog" + s); 301 } 302 303 static class Condition { 304 private String condition; 305 306 private Condition(String condition) { 307 this.condition = condition; 308 } 309 310 public String toString() { return condition; } 311 312 public static final Condition NONE = new Condition("none"); 313 public static final Condition VALUE = new Condition("value"); 314 } 315 316 } | Popular Tags |