提交 a8ae6f87 编写于 作者: P ptbrunet

7179482: Component.accessibleContext and JComponent.accessibleContext refactoring

Reviewed-by: art, anthony, alexsch
上级 5aea7122
/* /*
* Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -8994,7 +8994,10 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -8994,7 +8994,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
* to the individual objects which extend Component. * to the individual objects which extend Component.
*/ */
AccessibleContext accessibleContext = null; /**
* The {@code AccessibleContext} associated with this {@code Component}.
*/
protected AccessibleContext accessibleContext = null;
/** /**
* Gets the <code>AccessibleContext</code> associated * Gets the <code>AccessibleContext</code> associated
...@@ -9034,6 +9037,13 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9034,6 +9037,13 @@ public abstract class Component implements ImageObserver, MenuContainer,
protected AccessibleAWTComponent() { protected AccessibleAWTComponent() {
} }
/**
* Number of PropertyChangeListener objects registered. It's used
* to add/remove ComponentListener and FocusListener to track
* target Component's state.
*/
private volatile transient int propertyListenersCount = 0;
protected ComponentListener accessibleAWTComponentHandler = null; protected ComponentListener accessibleAWTComponentHandler = null;
protected FocusListener accessibleAWTFocusHandler = null; protected FocusListener accessibleAWTFocusHandler = null;
...@@ -9098,10 +9108,12 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9098,10 +9108,12 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void addPropertyChangeListener(PropertyChangeListener listener) { public void addPropertyChangeListener(PropertyChangeListener listener) {
if (accessibleAWTComponentHandler == null) { if (accessibleAWTComponentHandler == null) {
accessibleAWTComponentHandler = new AccessibleAWTComponentHandler(); accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
Component.this.addComponentListener(accessibleAWTComponentHandler);
} }
if (accessibleAWTFocusHandler == null) { if (accessibleAWTFocusHandler == null) {
accessibleAWTFocusHandler = new AccessibleAWTFocusHandler(); accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
}
if (propertyListenersCount++ == 0) {
Component.this.addComponentListener(accessibleAWTComponentHandler);
Component.this.addFocusListener(accessibleAWTFocusHandler); Component.this.addFocusListener(accessibleAWTFocusHandler);
} }
super.addPropertyChangeListener(listener); super.addPropertyChangeListener(listener);
...@@ -9115,13 +9127,9 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9115,13 +9127,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @param listener The PropertyChangeListener to be removed * @param listener The PropertyChangeListener to be removed
*/ */
public void removePropertyChangeListener(PropertyChangeListener listener) { public void removePropertyChangeListener(PropertyChangeListener listener) {
if (accessibleAWTComponentHandler != null) { if (--propertyListenersCount == 0) {
Component.this.removeComponentListener(accessibleAWTComponentHandler); Component.this.removeComponentListener(accessibleAWTComponentHandler);
accessibleAWTComponentHandler = null;
}
if (accessibleAWTFocusHandler != null) {
Component.this.removeFocusListener(accessibleAWTFocusHandler); Component.this.removeFocusListener(accessibleAWTFocusHandler);
accessibleAWTFocusHandler = null;
} }
super.removePropertyChangeListener(listener); super.removePropertyChangeListener(listener);
} }
......
/* /*
* Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -3824,6 +3824,12 @@ public class Container extends Component { ...@@ -3824,6 +3824,12 @@ public class Container extends Component {
return Container.this.getAccessibleAt(p); return Container.this.getAccessibleAt(p);
} }
/**
* Number of PropertyChangeListener objects registered. It's used
* to add/remove ContainerListener to track target Container's state.
*/
private volatile transient int propertyListenersCount = 0;
protected ContainerListener accessibleContainerHandler = null; protected ContainerListener accessibleContainerHandler = null;
/** /**
...@@ -3859,11 +3865,27 @@ public class Container extends Component { ...@@ -3859,11 +3865,27 @@ public class Container extends Component {
public void addPropertyChangeListener(PropertyChangeListener listener) { public void addPropertyChangeListener(PropertyChangeListener listener) {
if (accessibleContainerHandler == null) { if (accessibleContainerHandler == null) {
accessibleContainerHandler = new AccessibleContainerHandler(); accessibleContainerHandler = new AccessibleContainerHandler();
}
if (propertyListenersCount++ == 0) {
Container.this.addContainerListener(accessibleContainerHandler); Container.this.addContainerListener(accessibleContainerHandler);
} }
super.addPropertyChangeListener(listener); super.addPropertyChangeListener(listener);
} }
/**
* Remove a PropertyChangeListener from the listener list.
* This removes a PropertyChangeListener that was registered
* for all properties.
*
* @param listener the PropertyChangeListener to be removed
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
if (--propertyListenersCount == 0) {
Container.this.removeContainerListener(accessibleContainerHandler);
}
super.removePropertyChangeListener(listener);
}
} // inner class AccessibleAWTContainer } // inner class AccessibleAWTContainer
/** /**
......
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -3643,26 +3643,6 @@ public abstract class JComponent extends Container implements Serializable, ...@@ -3643,26 +3643,6 @@ public abstract class JComponent extends Container implements Serializable,
} }
} }
/**
* The <code>AccessibleContext</code> associated with this
* <code>JComponent</code>.
*/
protected AccessibleContext accessibleContext = null;
/**
* Returns the <code>AccessibleContext</code> associated with this
* <code>JComponent</code>. The method implemented by this base
* class returns null. Classes that extend <code>JComponent</code>
* should implement this method to return the
* <code>AccessibleContext</code> associated with the subclass.
*
* @return the <code>AccessibleContext</code> of this
* <code>JComponent</code>
*/
public AccessibleContext getAccessibleContext() {
return accessibleContext;
}
/** /**
* Inner class of JComponent used to provide default support for * Inner class of JComponent used to provide default support for
* accessibility. This class is not meant to be used directly by * accessibility. This class is not meant to be used directly by
...@@ -3689,7 +3669,18 @@ public abstract class JComponent extends Container implements Serializable, ...@@ -3689,7 +3669,18 @@ public abstract class JComponent extends Container implements Serializable,
super(); super();
} }
protected ContainerListener accessibleContainerHandler = null; /**
* Number of PropertyChangeListener objects registered. It's used
* to add/remove ContainerListener and FocusListener to track
* target JComponent's state
*/
private volatile transient int propertyListenersCount = 0;
/**
* This field duplicates the one in java.awt.Component.AccessibleAWTComponent,
* so it has been deprecated.
*/
@Deprecated
protected FocusListener accessibleFocusHandler = null; protected FocusListener accessibleFocusHandler = null;
/** /**
...@@ -3747,10 +3738,12 @@ public abstract class JComponent extends Container implements Serializable, ...@@ -3747,10 +3738,12 @@ public abstract class JComponent extends Container implements Serializable,
public void addPropertyChangeListener(PropertyChangeListener listener) { public void addPropertyChangeListener(PropertyChangeListener listener) {
if (accessibleFocusHandler == null) { if (accessibleFocusHandler == null) {
accessibleFocusHandler = new AccessibleFocusHandler(); accessibleFocusHandler = new AccessibleFocusHandler();
JComponent.this.addFocusListener(accessibleFocusHandler);
} }
if (accessibleContainerHandler == null) { if (accessibleContainerHandler == null) {
accessibleContainerHandler = new AccessibleContainerHandler(); accessibleContainerHandler = new AccessibleContainerHandler();
}
if (propertyListenersCount++ == 0) {
JComponent.this.addFocusListener(accessibleFocusHandler);
JComponent.this.addContainerListener(accessibleContainerHandler); JComponent.this.addContainerListener(accessibleContainerHandler);
} }
super.addPropertyChangeListener(listener); super.addPropertyChangeListener(listener);
...@@ -3764,9 +3757,9 @@ public abstract class JComponent extends Container implements Serializable, ...@@ -3764,9 +3757,9 @@ public abstract class JComponent extends Container implements Serializable,
* @param listener the PropertyChangeListener to be removed * @param listener the PropertyChangeListener to be removed
*/ */
public void removePropertyChangeListener(PropertyChangeListener listener) { public void removePropertyChangeListener(PropertyChangeListener listener) {
if (accessibleFocusHandler != null) { if (--propertyListenersCount == 0) {
JComponent.this.removeFocusListener(accessibleFocusHandler); JComponent.this.removeFocusListener(accessibleFocusHandler);
accessibleFocusHandler = null; JComponent.this.removeContainerListener(accessibleContainerHandler);
} }
super.removePropertyChangeListener(listener); super.removePropertyChangeListener(listener);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册