src/share/classes/javax/swing/JComponent.java

Print this page




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();


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();


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             // Due to JDK-7179482 the accessibleFocusHandler field in this class
3741             // is deprecated and need to use accessibleAWTFocusHandler in superclass.
3742             if (accessibleAWTFocusHandler == null) {
3743                 accessibleAWTFocusHandler = new AccessibleFocusHandler();
3744             }
3745             if (accessibleContainerHandler == null) {
3746                 accessibleContainerHandler = new AccessibleContainerHandler();
3747             }
3748             if (propertyListenersCount++ == 0) {
3749                 JComponent.this.addFocusListener(accessibleAWTFocusHandler);
3750                 JComponent.this.addContainerListener(accessibleContainerHandler);
3751             }
3752             super.addPropertyChangeListener(listener);
3753         }
3754 
3755         /**
3756          * Removes a PropertyChangeListener from the listener list.
3757          * This removes a PropertyChangeListener that was registered
3758          * for all properties.
3759          *
3760          * @param listener  the PropertyChangeListener to be removed
3761          */
3762         public void removePropertyChangeListener(PropertyChangeListener listener) {
3763             if (--propertyListenersCount == 0) {
3764                 // Due to JDK-7179482 the accessibleFocusHandler field in this class
3765                 // is deprecated and need to use accessibleAWTFocusHandler in superclass.
3766                 JComponent.this.removeFocusListener(accessibleAWTFocusHandler);
3767                 JComponent.this.removeContainerListener(accessibleContainerHandler);
3768             }
3769             super.removePropertyChangeListener(listener);
3770         }
3771 
3772 
3773 
3774         /**
3775          * Recursively search through the border hierarchy (if it exists)
3776          * for a TitledBorder with a non-null title.  This does a depth
3777          * first search on first the inside borders then the outside borders.
3778          * The assumption is that titles make really pretty inside borders
3779          * but not very pretty outside borders in compound border situations.
3780          * It's rather arbitrary, but hopefully decent UI programmers will
3781          * not create multiple titled borders for the same component.
3782          */
3783         protected String getBorderTitle(Border b) {
3784             String s;
3785             if (b instanceof TitledBorder) {
3786                 return ((TitledBorder) b).getTitle();