1 29 30 package nextapp.echo2.app.button; 31 32 import java.util.EventListener ; 33 34 import nextapp.echo2.app.Alignment; 35 import nextapp.echo2.app.Border; 36 import nextapp.echo2.app.Color; 37 import nextapp.echo2.app.Component; 38 import nextapp.echo2.app.Extent; 39 import nextapp.echo2.app.FillImage; 40 import nextapp.echo2.app.Font; 41 import nextapp.echo2.app.ImageReference; 42 import nextapp.echo2.app.Insets; 43 import nextapp.echo2.app.event.ActionEvent; 44 import nextapp.echo2.app.event.ActionListener; 45 46 50 public abstract class AbstractButton extends Component { 51 52 public static final String ACTION_LISTENERS_CHANGED_PROPERTY = "actionListeners"; 53 public static final String INPUT_CLICK = "input_click"; 54 public static final String PROPERTY_BACKGROUND_IMAGE = "backgroundImage"; 55 public static final String PROPERTY_BORDER = "border"; 56 public static final String PROPERTY_DISABLED_BACKGROUND = "disabledBackground"; 57 public static final String PROPERTY_DISABLED_BACKGROUND_IMAGE = "disabledBackgroundImage"; 58 public static final String PROPERTY_DISABLED_BORDER = "disabledBorder"; 59 public static final String PROPERTY_DISABLED_FONT = "disabledFont"; 60 public static final String PROPERTY_DISABLED_FOREGROUND = "disabledForeground"; 61 public static final String PROPERTY_DISABLED_ICON = "disabledIcon"; 62 public static final String PROPERTY_HEIGHT = "height"; 63 public static final String PROPERTY_ICON = "icon"; 64 public static final String PROPERTY_ALIGNMENT = "alignment"; 65 public static final String PROPERTY_ICON_TEXT_MARGIN = "iconTextMargin"; 66 public static final String PROPERTY_INSETS = "insets"; 67 public static final String PROPERTY_LINE_WRAP = "lineWrap"; 68 public static final String PROPERTY_MODEL = "model"; 69 public static final String PROPERTY_PRESSED_BACKGROUND = "pressedBackground"; 70 public static final String PROPERTY_PRESSED_BACKGROUND_IMAGE = "pressedBackgroundImage"; 71 public static final String PROPERTY_PRESSED_BORDER = "pressedBorder"; 72 public static final String PROPERTY_PRESSED_ENABLED = "pressedEnabled"; 73 public static final String PROPERTY_PRESSED_FONT = "pressedFont"; 74 public static final String PROPERTY_PRESSED_FOREGROUND = "pressedForeground"; 75 public static final String PROPERTY_PRESSED_ICON = "pressedIcon"; 76 public static final String PROPERTY_ROLLOVER_BACKGROUND = "rolloverBackground"; 77 public static final String PROPERTY_ROLLOVER_BACKGROUND_IMAGE = "rolloverBackgroundImage"; 78 public static final String PROPERTY_ROLLOVER_BORDER = "rolloverBorder"; 79 public static final String PROPERTY_ROLLOVER_ENABLED = "rolloverEnabled"; 80 public static final String PROPERTY_ROLLOVER_FONT = "rolloverFont"; 81 public static final String PROPERTY_ROLLOVER_FOREGROUND = "rolloverForeground"; 82 public static final String PROPERTY_ROLLOVER_ICON = "rolloverIcon"; 83 public static final String PROPERTY_TEXT = "text"; 84 public static final String PROPERTY_TEXT_ALIGNMENT = "textAlignment"; 85 public static final String PROPERTY_TEXT_POSITION = "textPosition"; 86 public static final String PROPERTY_TOOL_TIP_TEXT = "toolTipText"; 87 public static final String PROPERTY_WIDTH = "width"; 88 89 93 private ActionListener actionForwarder = new ActionListener() { 94 95 98 public void actionPerformed(ActionEvent modelEvent) { 99 ActionEvent buttonEvent = new ActionEvent(AbstractButton.this, modelEvent.getActionCommand()); 100 fireActionPerformed(buttonEvent); 101 } 102 }; 103 104 110 public void addActionListener(ActionListener l) { 111 getEventListenerList().addListener(ActionListener.class, l); 112 firePropertyChange(ACTION_LISTENERS_CHANGED_PROPERTY, null, l); 115 } 116 117 120 public void doAction() { 121 getModel().doAction(); 122 } 123 124 129 public void fireActionPerformed(ActionEvent e) { 130 if (!hasEventListenerList()) { 131 return; 132 } 133 EventListener [] listeners = getEventListenerList().getListeners(ActionListener.class); 134 for (int index = 0; index < listeners.length; ++index) { 135 ((ActionListener) listeners[index]).actionPerformed(e); 136 } 137 } 138 139 145 public String getActionCommand() { 146 return getModel().getActionCommand(); 147 } 148 149 155 public Alignment getAlignment() { 156 return (Alignment) getProperty(PROPERTY_ALIGNMENT); 157 } 158 159 164 public FillImage getBackgroundImage() { 165 return (FillImage) getProperty(PROPERTY_BACKGROUND_IMAGE); 166 } 167 168 173 public Border getBorder() { 174 return (Border) getProperty(PROPERTY_BORDER); 175 } 176 177 182 public Color getDisabledBackground() { 183 return (Color) getProperty(PROPERTY_DISABLED_BACKGROUND); 184 } 185 186 191 public FillImage getDisabledBackgroundImage() { 192 return (FillImage) getProperty(PROPERTY_DISABLED_BACKGROUND_IMAGE); 193 } 194 195 201 public Border getDisabledBorder() { 202 return (Border) getProperty(PROPERTY_DISABLED_BORDER); 203 } 204 205 210 public Font getDisabledFont() { 211 return (Font) getProperty(PROPERTY_DISABLED_FONT); 212 } 213 214 219 public Color getDisabledForeground() { 220 return (Color) getProperty(PROPERTY_DISABLED_FOREGROUND); 221 } 222 223 229 public ImageReference getDisabledIcon() { 230 return (ImageReference) getProperty(PROPERTY_DISABLED_ICON); 231 } 232 233 240 public Extent getHeight() { 241 return (Extent) getProperty(PROPERTY_HEIGHT); 242 } 243 244 249 public ImageReference getIcon() { 250 return (ImageReference) getProperty(PROPERTY_ICON); 251 } 252 253 262 public Extent getIconTextMargin() { 263 return (Extent) getProperty(PROPERTY_ICON_TEXT_MARGIN); 264 } 265 266 271 public Insets getInsets() { 272 return (Insets) getProperty(PROPERTY_INSETS); 273 } 274 275 280 public ButtonModel getModel() { 281 return (ButtonModel) getProperty(PROPERTY_MODEL); 282 } 283 284 289 public Color getPressedBackground() { 290 return (Color) getProperty(PROPERTY_PRESSED_BACKGROUND); 291 } 292 293 298 public FillImage getPressedBackgroundImage() { 299 return (FillImage) getProperty(PROPERTY_PRESSED_BACKGROUND_IMAGE); 300 } 301 302 308 public Border getPressedBorder() { 309 return (Border) getProperty(PROPERTY_PRESSED_BORDER); 310 } 311 312 317 public Font getPressedFont() { 318 return (Font) getProperty(PROPERTY_PRESSED_FONT); 319 } 320 321 326 public Color getPressedForeground() { 327 return (Color) getProperty(PROPERTY_PRESSED_FOREGROUND); 328 } 329 330 336 public ImageReference getPressedIcon() { 337 return (ImageReference) getProperty(PROPERTY_PRESSED_ICON); 338 } 339 340 346 public Color getRolloverBackground() { 347 return (Color) getProperty(PROPERTY_ROLLOVER_BACKGROUND); 348 } 349 350 356 public FillImage getRolloverBackgroundImage() { 357 return (FillImage) getProperty(PROPERTY_ROLLOVER_BACKGROUND_IMAGE); 358 } 359 360 366 public Border getRolloverBorder() { 367 return (Border) getProperty(PROPERTY_ROLLOVER_BORDER); 368 } 369 370 376 public Font getRolloverFont() { 377 return (Font) getProperty(PROPERTY_ROLLOVER_FONT); 378 } 379 380 386 public Color getRolloverForeground() { 387 return (Color) getProperty(PROPERTY_ROLLOVER_FOREGROUND); 388 } 389 390 396 public ImageReference getRolloverIcon() { 397 return (ImageReference) getProperty(PROPERTY_ROLLOVER_ICON); 398 } 399 400 405 public String getText() { 406 return (String ) getProperty(PROPERTY_TEXT); 407 } 408 409 414 public Alignment getTextAlignment() { 415 return (Alignment) getProperty(PROPERTY_TEXT_ALIGNMENT); 416 } 417 418 423 public Alignment getTextPosition() { 424 return (Alignment) getProperty(PROPERTY_TEXT_POSITION); 425 } 426 427 433 public String getToolTipText() { 434 return (String ) getProperty(PROPERTY_TOOL_TIP_TEXT); 435 } 436 437 444 public Extent getWidth() { 445 return (Extent) getProperty(PROPERTY_WIDTH); 446 } 447 448 454 public boolean hasActionListeners() { 455 return hasEventListenerList() && getEventListenerList().getListenerCount(ActionListener.class) != 0; 456 } 457 458 464 public boolean isLineWrap() { 465 Boolean value = (Boolean ) getProperty(PROPERTY_LINE_WRAP); 466 return value == null ? true : value.booleanValue(); 467 } 468 469 475 public boolean isPressedEnabled() { 476 Boolean value = (Boolean ) getProperty(PROPERTY_PRESSED_ENABLED); 477 return value == null ? false : value.booleanValue(); 478 } 479 480 486 public boolean isRolloverEnabled() { 487 Boolean value = (Boolean ) getProperty(PROPERTY_ROLLOVER_ENABLED); 488 return value == null ? false : value.booleanValue(); 489 } 490 491 496 public boolean isValidChild(Component component) { 497 return false; 498 } 499 500 503 public void processInput(String name, Object value) { 504 super.processInput(name, value); 505 if (INPUT_CLICK.equals(name)) { 506 doAction(); 507 } 508 } 509 510 516 public void removeActionListener(ActionListener l) { 517 if (!hasEventListenerList()) { 518 return; 519 } 520 getEventListenerList().removeListener(ActionListener.class, l); 521 firePropertyChange(ACTION_LISTENERS_CHANGED_PROPERTY, l, null); 524 } 525 526 532 public void setActionCommand(String newValue) { 533 getModel().setActionCommand(newValue); 534 } 535 536 542 public void setAlignment(Alignment newValue) { 543 setProperty(PROPERTY_ALIGNMENT, newValue); 544 } 545 546 551 public void setBackgroundImage(FillImage newValue) { 552 setProperty(PROPERTY_BACKGROUND_IMAGE, newValue); 553 } 554 555 560 public void setBorder(Border newValue) { 561 setProperty(PROPERTY_BORDER, newValue); 562 } 563 564 569 public void setDisabledBackground(Color newValue) { 570 setProperty(PROPERTY_DISABLED_BACKGROUND, newValue); 571 } 572 573 578 public void setDisabledBackgroundImage(FillImage newValue) { 579 setProperty(PROPERTY_DISABLED_BACKGROUND_IMAGE, newValue); 580 } 581 582 587 public void setDisabledBorder(Border newValue) { 588 setProperty(PROPERTY_DISABLED_BORDER, newValue); 589 } 590 591 596 public void setDisabledFont(Font newValue) { 597 setProperty(PROPERTY_DISABLED_FONT, newValue); 598 } 599 600 605 public void setDisabledForeground(Color newValue) { 606 setProperty(PROPERTY_DISABLED_FOREGROUND, newValue); 607 } 608 609 615 public void setDisabledIcon(ImageReference newValue) { 616 setProperty(PROPERTY_DISABLED_ICON, newValue); 617 } 618 619 626 public void setHeight(Extent newValue) { 627 setProperty(PROPERTY_HEIGHT, newValue); 628 } 629 630 635 public void setIcon(ImageReference newValue) { 636 setProperty(PROPERTY_ICON, newValue); 637 } 638 639 648 public void setIconTextMargin(Extent newValue) { 649 setProperty(PROPERTY_ICON_TEXT_MARGIN, newValue); 650 } 651 652 657 public void setInsets(Insets newValue) { 658 setProperty(PROPERTY_INSETS, newValue); 659 } 660 661 667 public void setLineWrap(boolean newValue) { 668 setProperty(PROPERTY_LINE_WRAP, new Boolean (newValue)); 669 } 670 671 676 public void setModel(ButtonModel newValue) { 677 if (newValue == null) { 678 throw new IllegalArgumentException ("Model may not be null."); 679 } 680 681 ButtonModel oldValue = getModel(); 682 683 if (oldValue != null) { 684 oldValue.removeActionListener(actionForwarder); 685 } 686 687 newValue.addActionListener(actionForwarder); 688 689 setProperty(PROPERTY_MODEL, newValue); 690 } 691 692 697 public void setPressedBackground(Color newValue) { 698 setProperty(PROPERTY_PRESSED_BACKGROUND, newValue); 699 } 700 701 706 public void setPressedBackgroundImage(FillImage newValue) { 707 setProperty(PROPERTY_PRESSED_BACKGROUND_IMAGE, newValue); 708 } 709 710 715 public void setPressedBorder(Border newValue) { 716 setProperty(PROPERTY_PRESSED_BORDER, newValue); 717 } 718 719 726 public void setPressedEnabled(boolean newValue) { 727 setProperty(PROPERTY_PRESSED_ENABLED, new Boolean (newValue)); 728 } 729 730 735 public void setPressedFont(Font newValue) { 736 setProperty(PROPERTY_PRESSED_FONT, newValue); 737 } 738 739 744 public void setPressedForeground(Color newValue) { 745 setProperty(PROPERTY_PRESSED_FOREGROUND, newValue); 746 } 747 748 753 public void setPressedIcon(ImageReference newValue) { 754 setProperty(PROPERTY_PRESSED_ICON, newValue); 755 } 756 757 763 public void setRolloverBackground(Color newValue) { 764 setProperty(PROPERTY_ROLLOVER_BACKGROUND, newValue); 765 } 766 767 773 public void setRolloverBackgroundImage(FillImage newValue) { 774 setProperty(PROPERTY_ROLLOVER_BACKGROUND_IMAGE, newValue); 775 } 776 777 783 public void setRolloverBorder(Border newValue) { 784 setProperty(PROPERTY_ROLLOVER_BORDER, newValue); 785 } 786 787 794 public void setRolloverEnabled(boolean newValue) { 795 setProperty(PROPERTY_ROLLOVER_ENABLED, new Boolean (newValue)); 796 } 797 798 803 public void setRolloverFont(Font newValue) { 804 setProperty(PROPERTY_ROLLOVER_FONT, newValue); 805 } 806 807 813 public void setRolloverForeground(Color newValue) { 814 setProperty(PROPERTY_ROLLOVER_FOREGROUND, newValue); 815 } 816 817 823 public void setRolloverIcon(ImageReference newValue) { 824 setProperty(PROPERTY_ROLLOVER_ICON, newValue); 825 } 826 827 832 public void setText(String newValue) { 833 setProperty(PROPERTY_TEXT, newValue); 834 } 835 836 843 public void setTextAlignment(Alignment newValue) { 844 setProperty(PROPERTY_TEXT_ALIGNMENT, newValue); 845 } 846 847 854 public void setTextPosition(Alignment newValue) { 855 setProperty(PROPERTY_TEXT_POSITION, newValue); 856 } 857 858 864 public void setToolTipText(String newValue) { 865 setProperty(PROPERTY_TOOL_TIP_TEXT, newValue); 866 } 867 868 875 public void setWidth(Extent newValue) { 876 setProperty(PROPERTY_WIDTH, newValue); 877 } 878 } | Popular Tags |