Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.73
diff -u -r1.73 JComponent.java
--- javax/swing/JComponent.java 19 Oct 2005 16:17:34 -0000 1.73
+++ javax/swing/JComponent.java 2 Nov 2005 09:23:15 -0000
@@ -84,6 +84,8 @@
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleStateSet;
import javax.swing.border.Border;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.EventListenerList;
@@ -161,9 +163,14 @@
protected ContainerListener accessibleContainerHandler;
protected FocusListener accessibleFocusHandler;
+ /**
+ * Manages the property change listeners;
+ */
+ private SwingPropertyChangeSupport changeSupport;
+
protected AccessibleJComponent()
{
- // TODO: Implement this properly.
+ changeSupport = new SwingPropertyChangeSupport(this);
}
/**
@@ -173,16 +180,58 @@
*/
public void addPropertyChangeListener(PropertyChangeListener listener)
{
- // TODO: Why is this overridden?
- super.addPropertyChangeListener(listener);
+ changeSupport.addPropertyChangeListener(listener);
}
+ /**
+ * Removes a propery change listener from the list of registered listeners.
+ *
+ * @param listener the listener to remove
+ */
public void removePropertyChangeListener(PropertyChangeListener listener)
{
- // TODO: Implement this properly.
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Returns the number of accessible children of this object.
+ *
+ * @return the number of accessible children of this object
+ */
+ public int getAccessibleChildrenCount()
+ {
+ int count = 0;
+ Component[] children = getComponents();
+ for (int i = 0; i < children.length; ++i)
+ {
+ if (children[i] instanceof Accessible)
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * Returns the accessible child component at index i
.
+ *
+ * @param i the index of the accessible child to return
+ *
+ * @return the accessible child component at index i
+ */
+ public Accessible getAccessibleChild(int i)
+ {
+ int index = 0;
+ Component[] children = getComponents();
+ Accessible found = null;
+ for (int j = 0; index != i; j++)
+ {
+ if (children[j] instanceof Accessible)
+ index++;
+ if (index == i)
+ found = (Accessible) children[index];
+ }
+ // TODO: Figure out what to do when i is not a valid index.
+ return found;
}
- public int getAccessibleChildrenCount() { return 0; }
- public Accessible getAccessibleChild(int value0) { return null; }
/**
* Returns the accessible state set of this component.
@@ -196,13 +245,115 @@
return super.getAccessibleStateSet();
}
- public String getAccessibleName() { return null; }
- public String getAccessibleDescription() { return null; }
- public AccessibleRole getAccessibleRole() { return null; }
- protected String getBorderTitle(Border value0) { return null; }
- public String getToolTipText() { return null; }
- public String getTitledBorderText() { return null; }
- public AccessibleKeyBinding getAccessibleKeyBinding() { return null; }
+ /**
+ * Returns the localized name for this object. Generally this should
+ * almost never return address@hidden Component#getName()} since that is not
+ * a localized name. If the object is some kind of text component (like
+ * a menu item), then the value of the object may be returned. Also, if
+ * the object has a tooltip, the value of the tooltip may also be
+ * appropriate.
+ *
+ * @return the localized name for this object or null
if this
+ * object has no name
+ */
+ public String getAccessibleName()
+ {
+ // TODO: Figure out what exactly to return here. It's possible that this
+ // method simply should return null.
+ return null;
+ }
+
+ /**
+ * Returns the localized description of this object.
+ *
+ * @return the localized description of this object or null
+ * if this object has no description
+ */
+ public String getAccessibleDescription()
+ {
+ // TODO: Figure out what exactly to return here. It's possible that this
+ // method simply should return null.
+ return null;
+ }
+
+ /**
+ * Returns the accessible role of this component.
+ *
+ * @return the accessible role of this component
+ *
+ * @see AccessibleRole
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ // TODO: Check if this is correct.
+ return AccessibleRole.SWING_COMPONENT;
+ }
+
+ /**
+ * Recursivly searches a border hierarchy (starting at border) for
+ * a titled border and returns the title if one is found, null
+ * otherwise.
+ *
+ * @param border the border to start search from
+ *
+ * @return the border title of a possibly found titled border
+ */
+ protected String getBorderTitle(Border border)
+ {
+ String title = null;
+ if (border instanceof CompoundBorder)
+ {
+ CompoundBorder compound = (CompoundBorder) border;
+ Border inner = compound.getInsideBorder();
+ title = getBorderTitle(inner);
+ if (title == null)
+ {
+ Border outer = compound.getOutsideBorder();
+ title = getBorderTitle(outer);
+ }
+ }
+ else if (border instanceof TitledBorder)
+ {
+ TitledBorder titled = (TitledBorder) border;
+ title = titled.getTitle();
+ }
+ return title;
+ }
+
+ /**
+ * Returns the tooltip text for this accessible component.
+ *
+ * @return the tooltip text for this accessible component
+ */
+ public String getToolTipText()
+ {
+ return JComponent.this.getToolTipText();
+ }
+
+ /**
+ * Returns the title of the border of this accessible component if
+ * this component has a titled border, otherwise returns null
.
+ *
+ * @return the title of the border of this accessible component if
+ * this component has a titled border, otherwise returns
+ * null
+ */
+ public String getTitledBorderText()
+ {
+ return getBorderTitle(getBorder());
+ }
+
+ /**
+ * Returns the keybindings associated with this accessible component or
+ * null
if the component does not support key bindings.
+ *
+ * @return the keybindings associated with this accessible component
+ */
+ public AccessibleKeyBinding getAccessibleKeyBinding()
+ {
+ // TODO: Implement this properly.
+ return null;
+ }
}
/**