1 29 30 package nextapp.echo2.app; 31 32 import java.util.EventListener ; 33 34 import nextapp.echo2.app.event.WindowPaneEvent; 35 import nextapp.echo2.app.event.WindowPaneListener; 36 37 44 public class WindowPane extends Component 45 implements FloatingPane, ModalSupport, PaneContainer { 46 47 public static final String INPUT_CLOSE = "input_close"; 48 49 public static final String PROPERTY_BACKGROUND_IMAGE = "backgroundImage"; 50 public static final String PROPERTY_BORDER = "border"; 51 public static final String PROPERTY_CLOSABLE = "closable"; 52 public static final String PROPERTY_CLOSE_ICON = "closeIcon"; 53 public static final String PROPERTY_CLOSE_ICON_INSETS = "closeIconInsets"; 54 public static final String PROPERTY_DEFAULT_CLOSE_OPERATION = "defaultCloseOperation"; 55 public static final String PROPERTY_HEIGHT = "height"; 56 public static final String PROPERTY_ICON = "icon"; 57 public static final String PROPERTY_ICON_INSETS = "iconInsets"; 58 public static final String PROPERTY_INSETS = "insets"; 59 public static final String PROPERTY_MAXIMUM_HEIGHT = "maximumHeight"; 60 public static final String PROPERTY_MAXIMUM_WIDTH = "maximumWidth"; 61 public static final String PROPERTY_MINIMUM_HEIGHT = "minimumHeight"; 62 public static final String PROPERTY_MINIMUM_WIDTH = "minimumWidth"; 63 public static final String PROPERTY_MOVABLE = "movable"; 64 public static final String PROPERTY_POSITION_X = "positionX"; 65 public static final String PROPERTY_POSITION_Y = "positionY"; 66 public static final String PROPERTY_RESIZABLE = "resizable"; 67 public static final String PROPERTY_TITLE = "title"; 68 public static final String PROPERTY_TITLE_BACKGROUND = "titleBackground"; 69 public static final String PROPERTY_TITLE_BACKGROUND_IMAGE = "titleBackgroundImage"; 70 public static final String PROPERTY_TITLE_BAR_INSETS = "titleBarInsets"; 71 public static final String PROPERTY_TITLE_FONT = "titleFont"; 72 public static final String PROPERTY_TITLE_FOREGROUND = "titleForeground"; 73 public static final String PROPERTY_TITLE_HEIGHT = "titleHeight"; 74 public static final String PROPERTY_TITLE_INSETS = "titleInsets"; 75 public static final String PROPERTY_WIDTH = "width"; 76 77 public static final String Z_INDEX_CHANGED_PROPERTY = "zIndex"; 78 79 84 public static final int DO_NOTHING_ON_CLOSE = 0; 85 86 91 public static final int HIDE_ON_CLOSE = 1; 92 93 98 public static final int DISPOSE_ON_CLOSE = 2; 99 100 private boolean modal = false; 101 private int zIndex = 0; 102 103 106 public WindowPane() { 107 this(null, null, null); 108 } 109 110 118 public WindowPane(String title, Extent width, Extent height) { 119 super(); 120 if (title != null) { 121 setTitle(title); 122 } 123 if (width != null) { 124 setWidth(width); 125 } 126 if (height != null) { 127 setHeight(height); 128 } 129 } 130 131 136 public void addWindowPaneListener(WindowPaneListener l) { 137 getEventListenerList().addListener(WindowPaneListener.class, l); 138 } 139 140 144 protected void fireWindowClosing() { 145 if (!hasEventListenerList()) { 146 return; 147 } 148 EventListener [] listeners = getEventListenerList().getListeners(WindowPaneListener.class); 149 if (listeners.length == 0) { 150 return; 151 } 152 WindowPaneEvent e = new WindowPaneEvent(this); 153 for (int i = 0; i < listeners.length; ++i) { 154 ((WindowPaneListener) listeners[i]).windowPaneClosing(e); 155 } 156 } 157 158 163 public FillImage getBackgroundImage() { 164 return (FillImage) getProperty(PROPERTY_BACKGROUND_IMAGE); 165 } 166 167 172 public FillImageBorder getBorder() { 173 return (FillImageBorder) getProperty(PROPERTY_BORDER); 174 } 175 176 181 public ImageReference getCloseIcon() { 182 return (ImageReference) getProperty(PROPERTY_CLOSE_ICON); 183 } 184 185 190 public Insets getCloseIconInsets() { 191 return (Insets) getProperty(PROPERTY_CLOSE_ICON_INSETS); 192 } 193 194 204 public int getDefaultCloseOperation() { 205 Integer defaultCloseOperationValue = (Integer ) getProperty(PROPERTY_DEFAULT_CLOSE_OPERATION); 206 return defaultCloseOperationValue == null ? 0 : defaultCloseOperationValue.intValue(); 207 } 208 209 214 public Extent getHeight() { 215 return (Extent) getProperty(PROPERTY_HEIGHT); 216 } 217 218 223 public ImageReference getIcon() { 224 return (ImageReference) getProperty(PROPERTY_ICON); 225 } 226 227 232 public Insets getIconInsets() { 233 return (Insets) getProperty(PROPERTY_CLOSE_ICON_INSETS); 234 } 235 236 243 public Insets getInsets() { 244 return (Insets) getProperty(PROPERTY_INSETS); 245 } 246 247 253 public Extent getMaximumHeight() { 254 return (Extent) getProperty(PROPERTY_MAXIMUM_HEIGHT); 255 } 256 257 263 public Extent getMaximumWidth() { 264 return (Extent) getProperty(PROPERTY_MAXIMUM_WIDTH); 265 } 266 267 273 public Extent getMinimumHeight() { 274 return (Extent) getProperty(PROPERTY_MINIMUM_HEIGHT); 275 } 276 277 283 public Extent getMinimumWidth() { 284 return (Extent) getProperty(PROPERTY_MINIMUM_WIDTH); 285 } 286 287 293 public Extent getPositionX() { 294 return (Extent) getProperty(PROPERTY_POSITION_X); 295 } 296 297 303 public Extent getPositionY() { 304 return (Extent) getProperty(PROPERTY_POSITION_Y); 305 } 306 307 312 public String getTitle() { 313 return (String ) getProperty(PROPERTY_TITLE); 314 } 315 316 321 public Color getTitleBackground() { 322 return (Color) getProperty(PROPERTY_TITLE_BACKGROUND); 323 } 324 325 330 public FillImage getTitleBackgroundImage() { 331 return (FillImage) getProperty(PROPERTY_TITLE_BACKGROUND_IMAGE); 332 } 333 334 341 public Insets getTitleBarInsets() { 342 return (Insets) getProperty(PROPERTY_TITLE_BAR_INSETS); 343 } 344 345 350 public Font getTitleFont() { 351 return (Font) getProperty(PROPERTY_TITLE_FONT); 352 } 353 354 359 public Color getTitleForeground() { 360 return (Color) getProperty(PROPERTY_TITLE_FOREGROUND); 361 } 362 363 368 public Extent getTitleHeight() { 369 return (Extent) getProperty(PROPERTY_TITLE_HEIGHT); 370 } 371 372 377 public Insets getTitleInsets() { 378 return (Insets) getProperty(PROPERTY_TITLE_INSETS); 379 } 380 381 386 public Extent getWidth() { 387 return (Extent) getProperty(PROPERTY_WIDTH); 388 } 389 390 397 public int getZIndex() { 398 return zIndex; 399 } 400 401 407 public boolean isClosable() { 408 Boolean value = (Boolean ) getProperty(PROPERTY_CLOSABLE); 409 return value == null ? true: value.booleanValue(); 410 } 411 412 415 public boolean isModal() { 416 return modal; 417 } 418 419 424 public boolean isMovable() { 425 Boolean value = (Boolean ) getProperty(PROPERTY_MOVABLE); 426 return value == null ? true : value.booleanValue(); 427 } 428 429 434 public boolean isResizable() { 435 Boolean value = (Boolean ) getProperty(PROPERTY_RESIZABLE); 436 return value == null ? true : value.booleanValue(); 437 } 438 439 444 public boolean isValidChild(Component component) { 445 return getComponentCount() == 0; 446 } 447 448 453 public boolean isValidParent(Component parent) { 454 return parent instanceof ContentPane; 455 } 456 457 460 public void processInput(String inputName, Object inputValue) { 461 if (INPUT_CLOSE.equals(inputName)) { 462 userClose(); 463 } else if (PROPERTY_POSITION_X.equals(inputName)) { 464 setPositionX((Extent) inputValue); 465 } else if (PROPERTY_POSITION_Y.equals(inputName)) { 466 setPositionY((Extent) inputValue); 467 } else if (PROPERTY_WIDTH.equals(inputName)) { 468 setWidth((Extent) inputValue); 469 } else if (PROPERTY_HEIGHT.equals(inputName)) { 470 setHeight((Extent) inputValue); 471 } else if (Z_INDEX_CHANGED_PROPERTY.equals(inputName)) { 472 setZIndex(((Integer ) inputValue).intValue()); 473 } 474 } 475 476 481 public void setBackgroundImage(FillImage newValue) { 482 setProperty(PROPERTY_BACKGROUND_IMAGE, newValue); 483 } 484 485 490 public void setBorder(FillImageBorder newValue) { 491 setProperty(PROPERTY_BORDER, newValue); 492 } 493 494 500 public void setClosable(boolean newValue) { 501 setProperty(PROPERTY_CLOSABLE, new Boolean (newValue)); 502 } 503 504 509 public void setCloseIcon(ImageReference newValue) { 510 setProperty(PROPERTY_CLOSE_ICON, newValue); 511 } 512 513 518 public void setCloseIconInsets(Insets newValue) { 519 setProperty(PROPERTY_CLOSE_ICON_INSETS, newValue); 520 } 521 522 533 public void setDefaultCloseOperation(int newValue) { 534 setProperty(PROPERTY_DEFAULT_CLOSE_OPERATION, new Integer (newValue)); 535 } 536 537 543 public void setHeight(Extent newValue) { 544 Extent.validate(newValue, Extent.PX); 545 setProperty(PROPERTY_HEIGHT, newValue); 546 } 547 548 553 public void setIcon(ImageReference newValue) { 554 setProperty(PROPERTY_ICON, newValue); 555 } 556 557 562 public void setIconInsets(Insets newValue) { 563 setProperty(PROPERTY_ICON_INSETS, newValue); 564 } 565 566 573 public void setInsets(Insets newValue) { 574 setProperty(PROPERTY_INSETS, newValue); 575 } 576 577 584 public void setMaximumHeight(Extent newValue) { 585 Extent.validate(newValue, Extent.PX); 586 setProperty(PROPERTY_MAXIMUM_HEIGHT, newValue); 587 } 588 589 596 public void setMaximumWidth(Extent newValue) { 597 Extent.validate(newValue, Extent.PX); 598 setProperty(PROPERTY_MAXIMUM_WIDTH, newValue); 599 } 600 601 608 public void setMinimumHeight(Extent newValue) { 609 Extent.validate(newValue, Extent.PX); 610 setProperty(PROPERTY_MINIMUM_HEIGHT, newValue); 611 } 612 613 620 public void setMinimumWidth(Extent newValue) { 621 Extent.validate(newValue, Extent.PX); 622 setProperty(PROPERTY_MINIMUM_WIDTH, newValue); 623 } 624 625 628 public void setModal(boolean newValue) { 629 boolean oldValue = modal; 630 modal = newValue; 631 firePropertyChange(MODAL_CHANGED_PROPERTY, new Boolean (oldValue), new Boolean (newValue)); 632 } 633 634 639 public void setMovable(boolean newValue) { 640 setProperty(PROPERTY_MOVABLE, new Boolean (newValue)); 641 } 642 643 650 public void setPositionX(Extent newValue) { 651 Extent.validate(newValue, Extent.PX); 652 setProperty(PROPERTY_POSITION_X, newValue); 653 } 654 655 662 public void setPositionY(Extent newValue) { 663 Extent.validate(newValue, Extent.PX); 664 setProperty(PROPERTY_POSITION_Y, newValue); 665 } 666 667 672 public void setResizable(boolean newValue) { 673 setProperty(PROPERTY_RESIZABLE, new Boolean (newValue)); 674 } 675 676 681 public void setTitle(String newValue) { 682 setProperty(PROPERTY_TITLE, newValue); 683 } 684 685 690 public void setTitleBackground(Color newValue) { 691 setProperty(PROPERTY_TITLE_BACKGROUND, newValue); 692 } 693 694 699 public void setTitleBackgroundImage(FillImage newValue) { 700 setProperty(PROPERTY_TITLE_BACKGROUND_IMAGE, newValue); 701 } 702 703 710 public void setTitleBarInsets(Insets newValue) { 711 setProperty(PROPERTY_TITLE_BAR_INSETS, newValue); 712 } 713 714 719 public void setTitleFont(Font newValue) { 720 setProperty(PROPERTY_TITLE_FONT, newValue); 721 } 722 723 728 public void setTitleForeground(Color newValue) { 729 setProperty(PROPERTY_TITLE_FOREGROUND, newValue); 730 } 731 732 738 public void setTitleHeight(Extent newValue) { 739 Extent.validate(newValue, Extent.PX); 740 setProperty(PROPERTY_TITLE_HEIGHT, newValue); 741 } 742 743 748 public void setTitleInsets(Insets newValue) { 749 setProperty(PROPERTY_TITLE_INSETS, newValue); 750 } 751 752 758 public void setWidth(Extent newValue) { 759 Extent.validate(newValue, Extent.PX); 760 setProperty(PROPERTY_WIDTH, newValue); 761 } 762 763 770 public void setZIndex(int newValue) { 771 int oldValue = zIndex; 772 zIndex = newValue; 773 firePropertyChange(Z_INDEX_CHANGED_PROPERTY, new Integer (oldValue), new Integer (newValue)); 774 } 775 776 781 public void removeWindowPaneListener(WindowPaneListener l) { 782 if (!hasEventListenerList()) { 783 return; 784 } 785 getEventListenerList().removeListener(WindowPaneListener.class, l); 786 } 787 788 791 public void userClose() { 792 fireWindowClosing(); 793 Integer defaultCloseOperationValue = (Integer ) getRenderProperty(PROPERTY_DEFAULT_CLOSE_OPERATION); 794 int defaultCloseOperation = defaultCloseOperationValue == null 795 ? DISPOSE_ON_CLOSE : defaultCloseOperationValue.intValue(); 796 switch (defaultCloseOperation) { 797 case DISPOSE_ON_CLOSE: 798 getParent().remove(this); 799 break; 800 case HIDE_ON_CLOSE: 801 setVisible(false); 802 break; 803 } 804 } 805 } 806 | Popular Tags |