9049 9050 private static final long serialVersionUID = 642321655757800191L; 9051 9052 /** 9053 * Though the class is abstract, this should be called by 9054 * all sub-classes. 9055 */ 9056 protected AccessibleAWTComponent() { 9057 } 9058 9059 /** 9060 * Number of PropertyChangeListener objects registered. It's used 9061 * to add/remove ComponentListener and FocusListener to track 9062 * target Component's state. 9063 */ 9064 private volatile transient int propertyListenersCount = 0; 9065 9066 protected ComponentListener accessibleAWTComponentHandler = null; 9067 protected FocusListener accessibleAWTFocusHandler = null; 9068 9069 /** 9070 * Fire PropertyChange listener, if one is registered, 9071 * when shown/hidden.. 9072 * @since 1.3 9073 */ 9074 protected class AccessibleAWTComponentHandler implements ComponentListener { 9075 public void componentHidden(ComponentEvent e) { 9076 if (accessibleContext != null) { 9077 accessibleContext.firePropertyChange( 9078 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9079 AccessibleState.VISIBLE, null); 9080 } 9081 } 9082 9083 public void componentShown(ComponentEvent e) { 9084 if (accessibleContext != null) { 9085 accessibleContext.firePropertyChange( 9086 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9087 null, AccessibleState.VISIBLE); 9088 } 9112 public void focusLost(FocusEvent event) { 9113 if (accessibleContext != null) { 9114 accessibleContext.firePropertyChange( 9115 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9116 AccessibleState.FOCUSED, null); 9117 } 9118 } 9119 } // inner class AccessibleAWTFocusHandler 9120 9121 9122 /** 9123 * Adds a <code>PropertyChangeListener</code> to the listener list. 9124 * 9125 * @param listener the property change listener to be added 9126 */ 9127 public void addPropertyChangeListener(PropertyChangeListener listener) { 9128 if (accessibleAWTComponentHandler == null) { 9129 accessibleAWTComponentHandler = new AccessibleAWTComponentHandler(); 9130 } 9131 if (accessibleAWTFocusHandler == null) { 9132 accessibleAWTFocusHandler = new AccessibleAWTFocusHandler(); 9133 } 9134 if (propertyListenersCount++ == 0) { 9135 Component.this.addComponentListener(accessibleAWTComponentHandler); 9136 Component.this.addFocusListener(accessibleAWTFocusHandler); 9137 } 9138 super.addPropertyChangeListener(listener); 9139 } 9140 9141 /** 9142 * Remove a PropertyChangeListener from the listener list. 9143 * This removes a PropertyChangeListener that was registered 9144 * for all properties. 9145 * 9146 * @param listener The PropertyChangeListener to be removed 9147 */ 9148 public void removePropertyChangeListener(PropertyChangeListener listener) { 9149 if (--propertyListenersCount == 0) { 9150 Component.this.removeComponentListener(accessibleAWTComponentHandler); 9151 Component.this.removeFocusListener(accessibleAWTFocusHandler); 9152 } 9153 super.removePropertyChangeListener(listener); 9154 } 9155 9156 // AccessibleContext methods 9157 // 9158 /** 9159 * Gets the accessible name of this object. This should almost never 9160 * return <code>java.awt.Component.getName()</code>, 9161 * as that generally isn't a localized name, 9162 * and doesn't have meaning for the user. If the 9163 * object is fundamentally a text object (e.g. a menu item), the 9164 * accessible name should be the text of the object (e.g. "save"). 9165 * If the object has a tooltip, the tooltip text may also be an 9166 * appropriate String to return. 9167 * 9168 * @return the localized name of the object -- can be 9169 * <code>null</code> if this 9170 * object does not have a name 9171 * @see javax.accessibility.AccessibleContext#setAccessibleName | 9049 9050 private static final long serialVersionUID = 642321655757800191L; 9051 9052 /** 9053 * Though the class is abstract, this should be called by 9054 * all sub-classes. 9055 */ 9056 protected AccessibleAWTComponent() { 9057 } 9058 9059 /** 9060 * Number of PropertyChangeListener objects registered. It's used 9061 * to add/remove ComponentListener and FocusListener to track 9062 * target Component's state. 9063 */ 9064 private volatile transient int propertyListenersCount = 0; 9065 9066 protected ComponentListener accessibleAWTComponentHandler = null; 9067 protected FocusListener accessibleAWTFocusHandler = null; 9068 9069 // accessibleAWTFocusHandler can be set either from 9070 // JComponent.AccessibleJComponent.addPropertyChangeListener or from this 9071 // object's addPropertyChangeListener the first time that method is called 9072 // if accessibleAWTFocusHandler is null at the time of the call. In the 9073 // former case Component.addFocusListener has already been called so it 9074 // should not be called again in this object's addPropertyChangeListener. 9075 // Also, removeFocusListener should only be called if this boolean is set. 9076 boolean focusHandlerSetFromComponent = false; 9077 9078 /** 9079 * Fire PropertyChange listener, if one is registered, 9080 * when shown/hidden.. 9081 * @since 1.3 9082 */ 9083 protected class AccessibleAWTComponentHandler implements ComponentListener { 9084 public void componentHidden(ComponentEvent e) { 9085 if (accessibleContext != null) { 9086 accessibleContext.firePropertyChange( 9087 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9088 AccessibleState.VISIBLE, null); 9089 } 9090 } 9091 9092 public void componentShown(ComponentEvent e) { 9093 if (accessibleContext != null) { 9094 accessibleContext.firePropertyChange( 9095 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9096 null, AccessibleState.VISIBLE); 9097 } 9121 public void focusLost(FocusEvent event) { 9122 if (accessibleContext != null) { 9123 accessibleContext.firePropertyChange( 9124 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 9125 AccessibleState.FOCUSED, null); 9126 } 9127 } 9128 } // inner class AccessibleAWTFocusHandler 9129 9130 9131 /** 9132 * Adds a <code>PropertyChangeListener</code> to the listener list. 9133 * 9134 * @param listener the property change listener to be added 9135 */ 9136 public void addPropertyChangeListener(PropertyChangeListener listener) { 9137 if (accessibleAWTComponentHandler == null) { 9138 accessibleAWTComponentHandler = new AccessibleAWTComponentHandler(); 9139 } 9140 if (accessibleAWTFocusHandler == null) { 9141 focusHandlerSetFromComponent = true; 9142 accessibleAWTFocusHandler = new AccessibleAWTFocusHandler(); 9143 } 9144 if (propertyListenersCount++ == 0) { 9145 Component.this.addComponentListener(accessibleAWTComponentHandler); 9146 if (focusHandlerSetFromComponent) { 9147 Component.this.addFocusListener(accessibleAWTFocusHandler); 9148 } 9149 } 9150 super.addPropertyChangeListener(listener); 9151 } 9152 9153 /** 9154 * Remove a PropertyChangeListener from the listener list. 9155 * This removes a PropertyChangeListener that was registered 9156 * for all properties. 9157 * 9158 * @param listener The PropertyChangeListener to be removed 9159 */ 9160 public void removePropertyChangeListener(PropertyChangeListener listener) { 9161 if (--propertyListenersCount == 0) { 9162 Component.this.removeComponentListener(accessibleAWTComponentHandler); 9163 if (focusHandlerSetFromComponent) { 9164 Component.this.removeFocusListener(accessibleAWTFocusHandler); 9165 } 9166 } 9167 super.removePropertyChangeListener(listener); 9168 } 9169 9170 // AccessibleContext methods 9171 // 9172 /** 9173 * Gets the accessible name of this object. This should almost never 9174 * return <code>java.awt.Component.getName()</code>, 9175 * as that generally isn't a localized name, 9176 * and doesn't have meaning for the user. If the 9177 * object is fundamentally a text object (e.g. a menu item), the 9178 * accessible name should be the text of the object (e.g. "save"). 9179 * If the object has a tooltip, the tooltip text may also be an 9180 * appropriate String to return. 9181 * 9182 * @return the localized name of the object -- can be 9183 * <code>null</code> if this 9184 * object does not have a name 9185 * @see javax.accessibility.AccessibleContext#setAccessibleName |