1 19 package org.openide; 20 21 import org.openide.util.HelpCtx; 22 import org.openide.util.NbBundle; 23 24 import java.awt.event.ActionListener ; 25 26 27 47 public class DialogDescriptor extends NotifyDescriptor implements HelpCtx.Provider { 48 50 51 public static final String PROP_OPTIONS_ALIGN = "optionsAlign"; 53 54 public static final String PROP_MODAL = "modal"; 56 57 public static final String PROP_LEAF = "leaf"; 59 60 public static final String PROP_HELP_CTX = "helpCtx"; 62 63 public static final String PROP_BUTTON_LISTENER = "buttonListener"; 65 66 public static final String PROP_CLOSING_OPTIONS = "closingOptions"; public static final int BOTTOM_ALIGN = 0; 68 69 71 public static final int RIGHT_ALIGN = 1; 72 73 74 public static final int DEFAULT_ALIGN = BOTTOM_ALIGN; 75 76 77 private static final Object [] DEFAULT_CLOSING_OPTIONS = new Object [] { YES_OPTION, NO_OPTION, CANCEL_OPTION, OK_OPTION }; 78 79 81 82 private boolean leaf = false; 83 84 85 private boolean modal; 86 87 89 private int optionsAlign; 90 91 92 private HelpCtx helpCtx; 93 94 96 private ActionListener buttonListener; 97 98 99 private Object [] closingOptions = DEFAULT_CLOSING_OPTIONS; 100 101 108 public DialogDescriptor(final Object innerPane, final String title) { 109 this(innerPane, title, true, OK_CANCEL_OPTION, OK_OPTION, DEFAULT_ALIGN, null, null); 110 } 111 112 123 public DialogDescriptor(final Object innerPane, final String title, final boolean isModal, final ActionListener bl) { 124 this(innerPane, title, isModal, OK_CANCEL_OPTION, OK_OPTION, DEFAULT_ALIGN, null, bl); 125 } 126 127 138 public DialogDescriptor( 139 final Object innerPane, final String title, final boolean isModal, final int optionType, 140 final Object initialValue, final ActionListener bl 141 ) { 142 this(innerPane, title, isModal, optionType, initialValue, DEFAULT_ALIGN, null, bl); 143 } 144 145 169 public DialogDescriptor( 170 final Object innerPane, final String title, final boolean modal, final Object [] options, 171 final Object initialValue, final int optionsAlign, final HelpCtx helpCtx, final ActionListener bl 172 ) { 173 super(innerPane, title, DEFAULT_OPTION, PLAIN_MESSAGE, options, initialValue); 174 this.modal = modal; 175 this.optionsAlign = optionsAlign; 176 this.helpCtx = (helpCtx == null) ? HelpCtx.DEFAULT_HELP : helpCtx; 177 this.buttonListener = bl; 178 179 if (bl == null) { 180 setClosingOptions(options); 181 } 182 } 183 184 210 public DialogDescriptor( 211 final Object innerPane, final String title, final boolean modal, final Object [] options, 212 final Object initialValue, final int optionsAlign, final HelpCtx helpCtx, final ActionListener bl, 213 final boolean leaf 214 ) { 215 super(innerPane, title, DEFAULT_OPTION, PLAIN_MESSAGE, options, initialValue); 216 this.modal = modal; 217 this.optionsAlign = optionsAlign; 218 this.helpCtx = (helpCtx == null) ? HelpCtx.DEFAULT_HELP : helpCtx; 219 this.buttonListener = bl; 220 this.leaf = leaf; 221 222 if (bl == null) { 223 setClosingOptions(options); 224 } 225 } 226 227 242 public DialogDescriptor( 243 final Object innerPane, final String title, final boolean isModal, final int optionType, 244 final Object initialValue, final int optionsAlign, final HelpCtx helpCtx, final ActionListener bl 245 ) { 246 super(innerPane, title, optionType, PLAIN_MESSAGE, null, initialValue); 247 this.modal = isModal; 248 this.optionsAlign = optionsAlign; 249 this.helpCtx = (helpCtx == null) ? HelpCtx.DEFAULT_HELP : helpCtx; 250 this.buttonListener = bl; 251 252 if (bl == null) { 253 setClosingOptions(null); 255 } 256 } 257 258 262 public int getOptionsAlign() { 263 getterCalled(); 264 265 return optionsAlign; 266 } 267 268 276 public void setOptionsAlign(final int optionsAlign) { 277 if ((optionsAlign != BOTTOM_ALIGN) && (optionsAlign != RIGHT_ALIGN)) { 278 throw new IllegalArgumentException ( 279 NbBundle.getBundle(DialogDescriptor.class).getString("EXC_OptionsAlign") 280 ); 281 } 282 283 if (this.optionsAlign == optionsAlign) { 284 return; 285 } 286 287 int oldValue = this.optionsAlign; 288 this.optionsAlign = optionsAlign; 289 firePropertyChange(PROP_OPTIONS_ALIGN, new Integer (oldValue), new Integer (optionsAlign)); 290 } 291 292 296 public boolean isModal() { 297 getterCalled(); 298 299 return modal; 300 } 301 302 308 public void setModal(final boolean modal) { 309 if (this.modal == modal) { 310 return; 311 } 312 313 boolean oldModal = this.modal; 314 this.modal = modal; 315 firePropertyChange(PROP_MODAL, Boolean.valueOf(oldModal), Boolean.valueOf(modal)); 316 } 317 318 323 public boolean isLeaf() { 324 getterCalled(); 325 326 return leaf; 327 } 328 329 336 public void setLeaf(final boolean leaf) { 337 if (this.leaf == leaf) { 338 return; 339 } 340 341 boolean oldLeaf = this.leaf; 342 this.leaf = leaf; 343 firePropertyChange(PROP_MODAL, Boolean.valueOf(oldLeaf), Boolean.valueOf(leaf)); 344 } 345 346 355 public void setClosingOptions(Object [] arr) { 356 Object [] old = closingOptions; 357 closingOptions = arr; 358 359 firePropertyChange(PROP_CLOSING_OPTIONS, old, arr); 360 } 361 362 365 public Object [] getClosingOptions() { 366 getterCalled(); 367 368 return closingOptions; 369 } 370 371 376 public HelpCtx getHelpCtx() { 377 getterCalled(); 378 379 return helpCtx; 380 } 381 382 402 public void setHelpCtx(final HelpCtx helpCtx) { 403 if ((this.helpCtx != null) && (this.helpCtx.equals(helpCtx))) { 404 return; 405 } 406 407 HelpCtx oldHelpCtx = this.helpCtx; 408 this.helpCtx = helpCtx; 409 firePropertyChange(PROP_HELP_CTX, oldHelpCtx, helpCtx); 410 } 411 412 416 public ActionListener getButtonListener() { 417 getterCalled(); 418 419 return buttonListener; 420 } 421 422 428 public void setButtonListener(final ActionListener l) { 429 if (this.buttonListener == l) { 430 return; 431 } 432 433 ActionListener oldButtonListener = this.buttonListener; 434 this.buttonListener = l; 435 firePropertyChange(PROP_BUTTON_LISTENER, oldButtonListener, l); 436 } 437 } 438 | Popular Tags |