[cp-patches] FYI: AccessibleJTable fixes

David Gilbert david.gilbert at object-refinery.com
Tue Jun 6 04:21:03 UTC 2006


This patch fixes a few methods in AccessibleJTable:

2006-06-06  David Gilbert  <david.gilbert at object-refinery.com>

	* javax/swing/JTable.java
	(AccessibleJTableHeaderCell.header): New field,
	(AccessibleJTableHeaderCell.columnIndex): Likewise,
	(AccessibleJTableHeaderCell.AccessibleJTableHeaderCell()): Initialise,
	(AccessibleJTableHeaderCell.getColumnHeaderRenderer): New method,
	(AccessibleJTableHeaderCell.getAccessibleContext): Implemented,
	(AccessibleJTableHeaderCell.getAccessibleRole): Implemented,
	(AccessibleJTable.getAccessibleChild(int)): Overridden,
	(AccessibleJTable.getAccessibleAt): Reimplemented.

Regards,

Dave
-------------- next part --------------
Index: javax/swing/JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.114
diff -u -r1.114 JTable.java
--- javax/swing/JTable.java	2 Jun 2006 13:32:30 -0000	1.114
+++ javax/swing/JTable.java	6 Jun 2006 03:26:15 -0000
@@ -829,15 +829,52 @@
       implements Accessible, AccessibleComponent
     {
 
+      JTableHeader header;
+      
+      int columnIndex;
+      
+      /**
+       * 
+       * @param h  the table header.
+       * @param comp
+       * @param r
+       * @param c  the column index.
+       */
       private AccessibleJTableHeaderCell(JTableHeader h, Component comp, int r,
                                          int c)
       {
-        
+        header = h;
+        columnIndex = c;
       }
 
+      /**
+       * Returns the header renderer.
+       * 
+       * @return The header renderer.
+       */
+      Component getColumnHeaderRenderer()
+      {
+        TableColumn tc = header.getColumnModel().getColumn(columnIndex);
+        TableCellRenderer r = tc.getHeaderRenderer();
+        if (r == null)
+          r = header.getDefaultRenderer();
+        return r.getTableCellRendererComponent(header.getTable(), 
+            tc.getHeaderValue(), false, false, -1, columnIndex);
+      }
+      
+      /**
+       * Returns the accessible role for the table header cell.
+       * 
+       * @return The accessible role.
+       */
       public AccessibleRole getAccessibleRole()
       {
-        // TODO Auto-generated method stub
+        Component renderer = getColumnHeaderRenderer();
+        if (renderer instanceof Accessible)
+          {
+            Accessible ac = (Accessible) renderer;
+            return ac.getAccessibleContext().getAccessibleRole();
+          }
         return null;
       }
 
@@ -871,10 +908,14 @@
         return null;
       }
 
+      /**
+       * Returns the accessible context.
+       * 
+       * @return <code>this</code>.
+       */
       public AccessibleContext getAccessibleContext()
       {
-        // TODO Auto-generated method stub
-        return null;
+        return this;
       }
 
       public Color getBackground()
@@ -1585,6 +1626,20 @@
     }
 
     /**
+     * Returns the accessible child at the given index.
+     *
+     * @param index  the child index.
+     * 
+     * @return The accessible child.
+     */
+    public Accessible getAccessibleChild(int index)
+    {
+      int r = getAccessibleRow(index);
+      int c = getAccessibleColumn(index);
+      return getAccessibleAt(r, c);  
+    }
+    
+    /**
      * Returns the accessible child (table cell) at the specified row and
      * column.
      *
@@ -1596,7 +1651,12 @@
      */
     public Accessible getAccessibleAt(int r, int c)
     {
-      return getAccessibleChild(r * getAccessibleColumnCount() + c);
+      TableCellRenderer cellRenderer = getCellRenderer(r, c);
+      Component renderer = cellRenderer.getTableCellRendererComponent(
+          JTable.this, getValueAt(r, c), isCellSelected(r, c), false, r, c);
+      if (renderer instanceof Accessible)
+        return (Accessible) renderer;
+      return null;
     }
 
     /**


More information about the Classpath-patches mailing list