This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Implement AccessibleAWTList
- From: Jerry Quinn <jlquinn at optonline dot net>
- To: java-patches at gcc dot gnu dot org
- Date: Tue, 28 Dec 2004 18:19:27 -0500
- Subject: [gui] Implement AccessibleAWTList
2004-12-28 Jerry Quinn <jlquinn@optonline.net>
* java/awt/List.java: Implement AccessibleAWTList,
AccessibleAWTListChild.
Index: List.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/List.java,v
retrieving revision 1.17.2.2
diff -u -r1.17.2.2 List.java
--- List.java 16 Nov 2004 09:55:36 -0000 1.17.2.2
+++ List.java 28 Dec 2004 23:14:46 -0000
@@ -47,6 +47,11 @@
import java.util.Vector;
import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleState;
+import javax.accessibility.AccessibleStateSet;
/**
* Class that implements a listbox widget
@@ -106,6 +111,7 @@
// The list of ActionListeners for this object.
private ActionListener action_listeners;
+
/*************************************************************************/
/*
@@ -1076,4 +1082,185 @@
{
return (ItemListener[]) getListeners (ItemListener.class);
}
+
+ // Accessibility internal class
+ protected class AccessibleAWTList extends AccessibleAWTComponent
+ implements AccessibleSelection, ItemListener, ActionListener
+ {
+ protected class AccessibleAWTListChild extends AccessibleAWTComponent
+ implements Accessible
+ {
+ private int index;
+ private List parent;
+
+ public AccessibleAWTListChild(List parent, int indexInParent)
+ {
+ this.parent = parent;
+ index = indexInParent;
+ if (parent == null)
+ index = -1;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.Accessible#getAccessibleContext()
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return this;
+ }
+
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.LIST_ITEM;
+ }
+
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ AccessibleStateSet states = super.getAccessibleStateSet();
+ if (parent.isIndexSelected(index))
+ states.add(AccessibleState.SELECTED);
+ return states;
+ }
+
+ public int getAccessibleIndexInParent()
+ {
+ return index;
+ }
+
+ }
+
+ public AccessibleAWTList()
+ {
+ addItemListener(this);
+ addActionListener(this);
+ }
+
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.LIST;
+ }
+
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ AccessibleStateSet states = super.getAccessibleStateSet();
+ states.add(AccessibleState.SELECTABLE);
+ if (isMultipleMode())
+ states.add(AccessibleState.MULTISELECTABLE);
+ return states;
+ }
+
+ public int getAccessibleChildrenCount()
+ {
+ return getItemCount();
+ }
+
+ public Accessible getAccessibleChild(int i)
+ {
+ if (i >= getItemCount())
+ return null;
+ return new AccessibleAWTListChild(List.this, i);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.AccessibleSelection#getAccessibleSelectionCount()
+ */
+ public int getAccessibleSelectionCount()
+ {
+ return getSelectedIndexes().length;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.AccessibleSelection#getAccessibleSelection()
+ */
+ public AccessibleSelection getAccessibleSelection()
+ {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.AccessibleSelection#getAccessibleSelection(int)
+ */
+ public Accessible getAccessibleSelection(int i)
+ {
+ int[] items = getSelectedIndexes();
+ if (i >= items.length)
+ return null;
+ return new AccessibleAWTListChild(List.this, items[i]);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.accessibility.AccessibleSelection#isAccessibleChildSelected(int)
+ */
+ public boolean isAccessibleChildSelected(int i)
+ {
+ return isIndexSelected(i);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.AccessibleSelection#addAccessibleSelection(int)
+ */
+ public void addAccessibleSelection(int i)
+ {
+ select(i);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.accessibility.AccessibleSelection#removeAccessibleSelection(int)
+ */
+ public void removeAccessibleSelection(int i)
+ {
+ deselect(i);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.accessibility.AccessibleSelection#clearAccessibleSelection()
+ */
+ public void clearAccessibleSelection()
+ {
+ for (int i = 0; i < getItemCount(); i++)
+ deselect(i);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.accessibility.AccessibleSelection#selectAllAccessibleSelection()
+ */
+ public void selectAllAccessibleSelection()
+ {
+ if (isMultipleMode())
+ for (int i = 0; i < getItemCount(); i++)
+ select(i);
+ }
+
+ /* (non-Javadoc)
+ * @see
java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
+ */
+ public void itemStateChanged(ItemEvent event)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+
+ }
+
+ /**
+ * Gets the AccessibleContext associated with this <code>List</code>.
+ * The context is created, if necessary.
+ *
+ * @return the associated context
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ /* Create the context if this is the first request */
+ if (accessibleContext == null)
+ {
+ /* Create the context */
+ accessibleContext = new AccessibleAWTList();
+ }
+ return accessibleContext;
+ }
} // class List