Some more code has been added. A counter has been added to each of the three files. It is incremented when addPropertyChangeListener is called and decremented when removePropertyChangeListener is called. Only when the count is zero, i.e. the first add and last remove, do specific handlers (see below) get added/removed.
Component.java: This code has Component and Focus handlers. Container.java: This code has a Container handler. JComponent.java: This code has Container and Focus handlers. See http://cr.openjdk.java.net/~ptbrunet/7179482/webrev.01/ Pete -------- Original Message -------- Subject: <Swing Dev> Please review fix for 7179482 : Component.accessibleContext and JComponent.accessibleContext refactoring Date: Fri, 09 Nov 2012 15:27:33 -0600 From: Pete Brunet <peter.bru...@oracle.com> Reply-To: peter.bru...@oracle.com To: awt-dev <awt-dev@openjdk.java.net>, swing-...@openjdk.java.net Please review the following fix planned for JDK8. Part of the fix will go into 7u12 under 7177111. Problem: In the process of evaluating 7177111 the following problems were noticed: - Both Component and JComponent have field "accessibleContext". In Component it is package-private and accessed by other classes from java.awt, but in JComponent it is protected and therefore this field hides the same superclass field from any subclass. These two fields should be refactored to a single protected field in Component. - Container.AccessibleAWTContainer has an addPropertyChangeListener but not a removePropertyChangeListener. This method is needed so stale listeners can be removed when AT are no longer attached to a Java process. - The JComponent.AccessibleJComponent.accessibleFocusHandler field functionally duplicates its superclass field, Component.AccessibleAWTComponent.accessibleAWTFocusHandler. When this field is used properly there are no logical issues. However, the existence of this field could cause confusion for a developer trying to understand the code. The superclass field is sufficient. Solution: - Change java.awt.Component.accessibleContext from package-private to protected. This will allow use by subclasses and the removal of the duplicate field in javax.swing.JComponent. - Add java.awt.Container.AccessibleAWTContainer.removePropertyChangeListener so stale listeners can be removed when an Assistive Technology is no longer attached to a Java process. - Remove the protected field javax.swing.JComponent.accessibleContext. Instead the protected field java.awt.Component.accessibleContext, will be used. With the change subclasses would now use the protected field in the Component superclass. - Remove public method javax.swing.JComponent.getAccessibleContext. Instead it superclass public method java.awt.Component.getAccessibleContext method would be used. - javax.swing.JComponent.AccessibleJComponent.accessibleFocusHandler field will be deprecated. Developers should use the java.awt.Component.AccessibleAWTComponent.accessibleAWTFocusHandler field instead. Webrev: http://cr.openjdk.java.net/~ptbrunet/7179482/webrev.00/ Bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7179482 CCC: http://ccc.us.oracle.com/7179482