3661 @SuppressWarnings("serial") // Same-version serialization only 3662 public abstract class AccessibleJComponent extends AccessibleAWTContainer 3663 implements AccessibleExtendedComponent 3664 { 3665 /** 3666 * Though the class is abstract, this should be called by 3667 * all sub-classes. 3668 */ 3669 protected AccessibleJComponent() { 3670 super(); 3671 } 3672 3673 /** 3674 * Number of PropertyChangeListener objects registered. It's used 3675 * to add/remove ContainerListener and FocusListener to track 3676 * target JComponent's state 3677 */ 3678 private volatile transient int propertyListenersCount = 0; 3679 3680 /** 3681 * This field duplicates the one in java.awt.Component.AccessibleAWTComponent, 3682 * so it has been deprecated. 3683 */ 3684 @Deprecated 3685 protected FocusListener accessibleFocusHandler = null; 3686 3687 /** 3688 * Fire PropertyChange listener, if one is registered, 3689 * when children added/removed. 3690 */ 3691 protected class AccessibleContainerHandler 3692 implements ContainerListener { 3693 public void componentAdded(ContainerEvent e) { 3694 Component c = e.getChild(); 3695 if (c != null && c instanceof Accessible) { 3696 AccessibleJComponent.this.firePropertyChange( 3697 AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, 3698 null, c.getAccessibleContext()); 3699 } 3700 } 3701 public void componentRemoved(ContainerEvent e) { 3702 Component c = e.getChild(); 3703 if (c != null && c instanceof Accessible) { 3704 AccessibleJComponent.this.firePropertyChange( 3705 AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, 3706 c.getAccessibleContext(), null); 3707 } 3708 } 3709 } 3710 3711 /** 3712 * Fire PropertyChange listener, if one is registered, 3713 * when focus events happen 3714 * @since 1.3 3715 */ 3716 protected class AccessibleFocusHandler implements FocusListener { 3717 public void focusGained(FocusEvent event) { 3718 if (accessibleContext != null) { 3719 accessibleContext.firePropertyChange( 3720 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 3721 null, AccessibleState.FOCUSED); 3722 } 3723 } 3724 public void focusLost(FocusEvent event) { 3725 if (accessibleContext != null) { 3726 accessibleContext.firePropertyChange( 3727 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 3728 AccessibleState.FOCUSED, null); 3729 } 3730 } 3731 } // inner class AccessibleFocusHandler 3732 3733 3734 /** 3735 * Adds a PropertyChangeListener to the listener list. 3736 * 3737 * @param listener the PropertyChangeListener to be added 3738 */ 3739 public void addPropertyChangeListener(PropertyChangeListener listener) { 3740 if (accessibleFocusHandler == null) { 3741 accessibleFocusHandler = new AccessibleFocusHandler(); 3742 } 3743 if (accessibleContainerHandler == null) { 3744 accessibleContainerHandler = new AccessibleContainerHandler(); 3745 } 3746 if (propertyListenersCount++ == 0) { 3747 JComponent.this.addFocusListener(accessibleFocusHandler); 3748 JComponent.this.addContainerListener(accessibleContainerHandler); 3749 } 3750 super.addPropertyChangeListener(listener); 3751 } 3752 3753 /** 3754 * Removes a PropertyChangeListener from the listener list. 3755 * This removes a PropertyChangeListener that was registered 3756 * for all properties. 3757 * 3758 * @param listener the PropertyChangeListener to be removed 3759 */ 3760 public void removePropertyChangeListener(PropertyChangeListener listener) { 3761 if (--propertyListenersCount == 0) { 3762 JComponent.this.removeFocusListener(accessibleFocusHandler); 3763 JComponent.this.removeContainerListener(accessibleContainerHandler); 3764 } 3765 super.removePropertyChangeListener(listener); 3766 } 3767 3768 3769 3770 /** 3771 * Recursively search through the border hierarchy (if it exists) 3772 * for a TitledBorder with a non-null title. This does a depth 3773 * first search on first the inside borders then the outside borders. 3774 * The assumption is that titles make really pretty inside borders 3775 * but not very pretty outside borders in compound border situations. 3776 * It's rather arbitrary, but hopefully decent UI programmers will 3777 * not create multiple titled borders for the same component. 3778 */ 3779 protected String getBorderTitle(Border b) { 3780 String s; 3781 if (b instanceof TitledBorder) { 3782 return ((TitledBorder) b).getTitle(); | 3661 @SuppressWarnings("serial") // Same-version serialization only 3662 public abstract class AccessibleJComponent extends AccessibleAWTContainer 3663 implements AccessibleExtendedComponent 3664 { 3665 /** 3666 * Though the class is abstract, this should be called by 3667 * all sub-classes. 3668 */ 3669 protected AccessibleJComponent() { 3670 super(); 3671 } 3672 3673 /** 3674 * Number of PropertyChangeListener objects registered. It's used 3675 * to add/remove ContainerListener and FocusListener to track 3676 * target JComponent's state 3677 */ 3678 private volatile transient int propertyListenersCount = 0; 3679 3680 /** 3681 * This field duplicates the function of the accessibleAWTFocusHandler field 3682 * in java.awt.Component.AccessibleAWTComponent, so it has been deprecated. 3683 */ 3684 @Deprecated 3685 protected FocusListener accessibleFocusHandler = null; 3686 3687 /** 3688 * Fire PropertyChange listener, if one is registered, 3689 * when children added/removed. 3690 */ 3691 protected class AccessibleContainerHandler 3692 implements ContainerListener { 3693 public void componentAdded(ContainerEvent e) { 3694 Component c = e.getChild(); 3695 if (c != null && c instanceof Accessible) { 3696 AccessibleJComponent.this.firePropertyChange( 3697 AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, 3698 null, c.getAccessibleContext()); 3699 } 3700 } 3701 public void componentRemoved(ContainerEvent e) { 3702 Component c = e.getChild(); 3703 if (c != null && c instanceof Accessible) { 3704 AccessibleJComponent.this.firePropertyChange( 3705 AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, 3706 c.getAccessibleContext(), null); 3707 } 3708 } 3709 } 3710 3711 3712 /** 3713 * Adds a PropertyChangeListener to the listener list. 3714 * 3715 * @param listener the PropertyChangeListener to be added 3716 */ 3717 public void addPropertyChangeListener(PropertyChangeListener listener) { 3718 if (accessibleContainerHandler == null) { 3719 accessibleContainerHandler = new AccessibleContainerHandler(); 3720 } 3721 if (propertyListenersCount++ == 0) { 3722 JComponent.this.addContainerListener(accessibleContainerHandler); 3723 } 3724 super.addPropertyChangeListener(listener); 3725 } 3726 3727 /** 3728 * Removes a PropertyChangeListener from the listener list. 3729 * This removes a PropertyChangeListener that was registered 3730 * for all properties. 3731 * 3732 * @param listener the PropertyChangeListener to be removed 3733 */ 3734 public void removePropertyChangeListener(PropertyChangeListener listener) { 3735 if (--propertyListenersCount == 0) { 3736 JComponent.this.removeContainerListener(accessibleContainerHandler); 3737 } 3738 super.removePropertyChangeListener(listener); 3739 } 3740 3741 3742 3743 /** 3744 * Recursively search through the border hierarchy (if it exists) 3745 * for a TitledBorder with a non-null title. This does a depth 3746 * first search on first the inside borders then the outside borders. 3747 * The assumption is that titles make really pretty inside borders 3748 * but not very pretty outside borders in compound border situations. 3749 * It's rather arbitrary, but hopefully decent UI programmers will 3750 * not create multiple titled borders for the same component. 3751 */ 3752 protected String getBorderTitle(Border b) { 3753 String s; 3754 if (b instanceof TitledBorder) { 3755 return ((TitledBorder) b).getTitle(); |