The accessible inner classes are now implemented. I am still running
various tests on it.

2005-19-19  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTreeUI.java
        (selectPath): Changed so DISCONTIGUOUS_TREE_SELECTION is the
        default.
        * javax/swing/JTree.java
        (AccessibleJTreeNode): Initialized all fields.
        (addAccessibleSelection): Implemented.
        (clearAccessibleSelection): Implemented.
        (doAccessibleAction): Implemented.
        (getAccessibleAction): Implemented.
        (getAccessibleActionCount): Implemented.
        (getAccessibleActionDescription): Implemented.
        (getAccesssibleChild): Remove mod variable, made global.
        (getAccessibleComponent): Changed to return this, since this
        class implements AccessibleComponent.
        (getAccessibleSelection): Likewise.
        (getAccessibleSelection): Implemented.
        (getAccessibleSelectionCount): Implemented.
        (getAccessibleStateSet): Remove mod variable, made global.
        (getCursor): Implemented.
        (isAccessibleChildSelected): Remove mod variable, made global.
        (removeAccessibleSelection): Implemented.
        (selectAllAccessibleSelection): Implemented.
        (setCursor): Implemented.
        (AccessibleJTree): Nothing to do.
        (getAccessibleAt): Implemented.
        (getAccessibleSelection): Implemented.
        (getAccessibleSelection): Implemented.
Index: javax/swing/JTree.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.40
diff -u -r1.40 JTree.java
--- javax/swing/JTree.java	16 Sep 2005 20:11:17 -0000	1.40
+++ javax/swing/JTree.java	19 Sep 2005 15:34:00 -0000
@@ -111,7 +111,11 @@
       private JTree tree;
       private TreePath tp;
       private Accessible acc;
-      private AccessibleStateSet states = new AccessibleStateSet();
+      private AccessibleStateSet states;
+      private Vector selectionList;
+      private Vector actionList;
+      private TreeModel mod;
+      private Cursor cursor;
       
       /**
        * Constructs an AccessibleJTreeNode
@@ -122,20 +126,54 @@
        */
       public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap)
       {
+        states = new AccessibleStateSet();
+        selectionList = new Vector();
+        actionList = new Vector();
+        mod = tree.getModel();
+        cursor = JTree.this.getCursor();
+                
         tree = t;
         tp = p;
         acc = ap;
+        
+        // Add all the children of this path that may already be
+        // selected to the selection list.
+        TreePath[] selected = tree.getSelectionPaths();
+        for (int i = 0; i < selected.length; i++)
+          {
+            TreePath sel = selected[i];
+            if ((sel.getParentPath()).equals(tp))
+              selectionList.add(sel);
+          }
+        
+        // Add all the actions available for a node to 
+        // the action list.
+        actionList.add("EXPAND");
+        actionList.add("COLLAPSE");
+        actionList.add("EDIT");
+        actionList.add("SELECT");
+        actionList.add("DESELECT");
       }      
       
       /**
        * Adds the specified selected item in the object to the object's
        * selection.
        * 
-       * @param i - the i-th element in the TreePath to add to the selection
+       * @param i - the i-th child of this node.
        */
       public void addAccessibleSelection(int i)
       {
-        // FIXME: not implemented properly.
+        if (mod != null)
+          {
+            Object child = mod.getChild(tp.getLastPathComponent(), i);
+            if (child != null)
+              {
+                if (!states.contains(AccessibleState.MULTISELECTABLE))
+                  clearAccessibleSelection();
+                selectionList.add(child);                  
+                tree.addSelectionPath(tp.pathByAddingChild(child));
+              }
+          }
       }
       
       /**
@@ -165,7 +203,7 @@
        */
       public void clearAccessibleSelection()
       {
-        // Nothing to do here.
+        selectionList.clear();
       }
       
       /**
@@ -189,8 +227,22 @@
        */
       public boolean doAccessibleAction(int i)
       {
-        // FIXME: Not implemented fully.
-        return false;
+        if (i >= actionList.size() || i < 0)
+          return false;
+        
+        if (actionList.get(i).equals("EXPAND"))
+          tree.expandPath(tp);
+        else if (actionList.get(i).equals("COLLAPSE"))
+          tree.collapsePath(tp);
+        else if (actionList.get(i).equals("SELECT"))
+          tree.addSelectionPath(tp);
+        else if (actionList.get(i).equals("DESELECT"))
+          tree.removeSelectionPath(tp);
+        else if (actionList.get(i).equals("EDIT"))
+          tree.startEditingAtPath(tp);
+        else
+          return false;
+        return true;
       }
       
       /**
@@ -200,8 +252,7 @@
        */
       public AccessibleAction getAccessibleAction()
       {
-        // FIXME: Not implemented fully.
-        return super.getAccessibleAction();
+        return this;
       }
       
       /**
@@ -211,8 +262,7 @@
        */
       public int getAccessibleActionCount()
       {
-        // FIXME: Not implemented fully.
-        return 0;
+        return actionList.size();
       }
       
       /**
@@ -223,6 +273,8 @@
        */
       public String getAccessibleActionDescription(int i)
       {
+        if (i < 0 || i >= actionList.size())
+          return (actionList.get(i)).toString();
         return super.getAccessibleDescription();
       }
       
@@ -249,7 +301,6 @@
        */
       public Accessible getAccessibleChild(int i)
       {
-        TreeModel mod = tree.getModel();
         if (mod != null)
           {
             Object child = mod.getChild(tp.getLastPathComponent(), i);
@@ -280,7 +331,7 @@
        */
       public AccessibleComponent getAccessibleComponent()
       {
-        return super.getAccessibleComponent();
+        return this;
       }
       
       /**
@@ -357,8 +408,7 @@
        */
       public AccessibleSelection getAccessibleSelection()
       {
-        // FIXME: Not implemented fully.
-        return super.getAccessibleSelection();
+        return this;
       }
       
       /**
@@ -369,10 +419,10 @@
        */
       public Accessible getAccessibleSelection(int i)
       {
-        // FIXME: Not implemented properly.
-        return new AccessibleJTreeNode(tree, tree.
-                                       getSelectionModel().
-                                       getSelectionPaths()[i], acc);
+        if (i > 0 && i < getAccessibleSelectionCount())
+            return new AccessibleJTreeNode(tree, 
+                  tp.pathByAddingChild(selectionList.get(i)), acc);
+        return null;
       }
       
       /**
@@ -382,7 +432,7 @@
        */
       public int getAccessibleSelectionCount()
       {
-        return AccessibleJTree.this.getAccessibleSelectionCount();
+        return selectionList.size();
       }
       
       /**
@@ -392,7 +442,6 @@
        */
       public AccessibleStateSet getAccessibleStateSet()
       {
-        TreeModel mod = tree.getModel();
         if (isVisible())
           states.add(AccessibleState.VISIBLE);
         if (tree.isCollapsed(tp))
@@ -469,8 +518,7 @@
        */
       public Cursor getCursor()
       {
-        // FIXME: Not implemented fully.
-        return null;
+        return cursor;
       }
       
       /**
@@ -568,9 +616,10 @@
        */
       public boolean isAccessibleChildSelected(int i)
       {
-        TreeModel mod = tree.getModel();
         Object child = mod.getChild(tp.getLastPathComponent(), i);
-        return tree.isPathSelected(tp.pathByAddingChild(child));
+        if (child != null)
+          return tree.isPathSelected(tp.pathByAddingChild(child));
+        return false;
       }
       
       /**
@@ -622,12 +671,20 @@
        */
       public void removeAccessibleSelection(int i)
       {
-        // FIXME: Not implemented properly.
-        TreePath[] elements = tree.getSelectionPaths();
-        Object[] newElements = new Object[i];
-        for (int j = 0; j < i; j++)
-          newElements[j] = elements[j];
-        tree.removeSelectionPath(new TreePath(newElements));
+        if (mod != null)
+          {
+            Object child = mod.getChild(tp.getLastPathComponent(), i);
+            if (child != null)
+              {
+                if (!states.contains(AccessibleState.MULTISELECTABLE))
+                  clearAccessibleSelection();
+                if (selectionList.contains(child))
+                  {
+                    selectionList.remove(child);                  
+                    tree.removeSelectionPath(tp.pathByAddingChild(child));
+                  }
+              }
+          }
       }
       
       /**
@@ -665,7 +722,24 @@
        */
       public void selectAllAccessibleSelection()
       {
-        // FIXME: Not implemented fully.
+        Object parent = tp.getLastPathComponent();
+        if (mod != null)
+          {
+            for (int i = 0; i < mod.getChildCount(parent); i++)
+              {
+                Object child = mod.getChild(parent, i);
+                if (child != null)
+                  {
+                    if (!states.contains(AccessibleState.MULTISELECTABLE))
+                      clearAccessibleSelection();
+                    if (selectionList.contains(child))
+                      {
+                        selectionList.add(child);
+                        tree.addSelectionPath(tp.pathByAddingChild(child));
+                      }
+                  }
+              }
+          }
       }
       
       /**
@@ -715,7 +789,7 @@
        */
       public void setCursor(Cursor c)
       {
-        // FIXME: Not implemented fully.
+        cursor = c;
       }
       
       /**
@@ -784,7 +858,7 @@
      */
     public AccessibleJTree()
     {
-      // FIXME: Not implemented fully.
+      // Nothing to do here.
     }
     
     /**
@@ -822,7 +896,9 @@
      */
     public Accessible getAccessibleAt(Point p)
     {
-      // FIXME: Not implemented fully.
+      TreePath tp = getClosestPathForLocation(p.x, p.y);
+      if (tp != null)
+        return new AccessibleJTreeNode(JTree.this, tp, null);
       return null;
     }
     
@@ -873,11 +949,14 @@
     /**
      * Get the AccessibleSelection associated with this object.
      * 
-     * @param the accessible selection of the tree
+     * @return the accessible selection of the tree
      */
     public AccessibleSelection getAccessibleSelection()
     {
-      // FIXME: Not implemented fully.
+      TreeModel mod = getModel();
+      if (mod != null)
+        return (new AccessibleJTreeNode(JTree.this, 
+                  new TreePath(mod.getRoot()), null)).getAccessibleSelection();
       return null;
     }
     
@@ -888,7 +967,10 @@
      */
     public Accessible getAccessibleSelection(int i)
     {
-      // FIXME: Not implemented fully.
+      TreeModel mod = getModel();
+      if (mod != null)
+        return (new AccessibleJTreeNode(JTree.this, 
+                  new TreePath(mod.getRoot()), null)).getAccessibleSelection(i);
       return null;
     }
     
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.78
diff -u -r1.78 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	14 Sep 2005 20:25:13 -0000	1.78
+++ javax/swing/plaf/basic/BasicTreeUI.java	19 Sep 2005 15:34:00 -0000
@@ -3519,22 +3519,24 @@
   {
     if (path != null)
       {
-        if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION)
+        if (tree.getSelectionModel().getSelectionMode() == 
+                          TreeSelectionModel.SINGLE_TREE_SELECTION)
           {
+            tree.getSelectionModel().clearSelection();
             tree.addSelectionPath(path);
             tree.setLeadSelectionPath(path);
           }
-        else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
+        else if (tree.getSelectionModel().getSelectionMode() == 
+                  TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
           {
             // TODO
           }
         else
           {
-            tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
-
-            tree.getSelectionModel().clearSelection();
             tree.addSelectionPath(path);
             tree.setLeadSelectionPath(path);
+            tree.getSelectionModel().setSelectionMode
+                      (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
           }
       }
   }
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to