[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: AWT accessiblity improvements

Kaffe CVS cvs-commits at kaffe.org
Thu Dec 2 18:00:47 PST 2004


PatchSet 5515 
Date: 2004/12/03 01:56:19
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: AWT accessiblity improvements

2004-12-02  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/awt/Button.java,
        libraries/javalib/java/awt/Checkbox.java,
        libraries/javalib/java/awt/Choice.java,
        libraries/javalib/java/awt/Menu.java,
        libraries/javalib/java/awt/MenuItem.java,
        libraries/javalib/java/awt/PopupMenu.java,
        libraries/javalib/java/awt/TextArea.java,
        libraries/javalib/java/awt/TextComponent.java,
        libraries/javalib/java/awt/TextField.java:
        Resynced with GNU Classpath.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Menu.java (AccessibleAWTMenu
        getAccessibleContext): Implement.
        * java/awt/PopupMenu.java (AccessibleAWTPopupMenu
        getAccessibleContext): Implement.
        * java/awt/TextComponent.java (AccessibleAWTTextComponent
        getAccessibleContext): Implement.
        (TextComponent): Extends Accessible.
        (getIndexAtPoint, getCharacterBounds): New methods.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Button.java
        (AccessibleAWTButton.getAccessibleActionDescription): Explain the
        source of 'click'.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Checkbox.java: Remove stub comments.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Button.java
        (AccessibleAWTButton.getAccessibleActionDescription): Return
        'click'.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Checkbox.java (AccessibleAWTCheckBox): Remove todo
        comments.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Checkbox.java (itemStateChanged): Implement function.
        (getAccessibleContext): Add AccessibleAWTCheckBox to item listeners.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/TextArea.java (AccessibleAWTTextArea,
        getAccessibleContext): Implement.
        * java/awt/TextField.java (AccessibleAWTTextField,
        getAccessibleContext): Implement.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Checkbox.java (AccessibleAWTCheckBox): Implement.
        (getAccessibleContext): Implement.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/MenuItem.java (AccessibleAWTMenuItem): Implement.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/Choice.java (AccessibleAWTChoice): Implement.

        2004-11-23 Jerry Quinn <jlquinn at optonline.net>

        * java/awt/MenuItem.java (AccessibleAWTMenuItem): Implement.

Members: 
	ChangeLog:1.3061->1.3062 
	libraries/javalib/java/awt/Button.java:1.6->1.7 
	libraries/javalib/java/awt/Checkbox.java:1.2->1.3 
	libraries/javalib/java/awt/Choice.java:1.3->1.4 
	libraries/javalib/java/awt/Menu.java:1.11->1.12 
	libraries/javalib/java/awt/MenuItem.java:1.14->1.15 
	libraries/javalib/java/awt/PopupMenu.java:1.9->1.10 
	libraries/javalib/java/awt/TextArea.java:1.4->1.5 
	libraries/javalib/java/awt/TextComponent.java:1.2->1.3 
	libraries/javalib/java/awt/TextField.java:1.3->1.4 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3061 kaffe/ChangeLog:1.3062
--- kaffe/ChangeLog:1.3061	Fri Dec  3 00:56:16 2004
+++ kaffe/ChangeLog	Fri Dec  3 01:56:19 2004
@@ -1,5 +1,79 @@
 2004-12-02  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/awt/Button.java,
+	libraries/javalib/java/awt/Checkbox.java,
+	libraries/javalib/java/awt/Choice.java,
+	libraries/javalib/java/awt/Menu.java,
+	libraries/javalib/java/awt/MenuItem.java,
+	libraries/javalib/java/awt/PopupMenu.java,
+	libraries/javalib/java/awt/TextArea.java,
+	libraries/javalib/java/awt/TextComponent.java,
+	libraries/javalib/java/awt/TextField.java:
+	Resynced with GNU Classpath.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Menu.java (AccessibleAWTMenu
+        getAccessibleContext): Implement.
+        * java/awt/PopupMenu.java (AccessibleAWTPopupMenu
+        getAccessibleContext): Implement.
+        * java/awt/TextComponent.java (AccessibleAWTTextComponent
+        getAccessibleContext): Implement.
+        (TextComponent): Extends Accessible.
+        (getIndexAtPoint, getCharacterBounds): New methods.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Button.java
+        (AccessibleAWTButton.getAccessibleActionDescription): Explain the
+        source of 'click'.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Checkbox.java: Remove stub comments.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Button.java
+        (AccessibleAWTButton.getAccessibleActionDescription): Return
+        'click'.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Checkbox.java (AccessibleAWTCheckBox): Remove todo
+        comments.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Checkbox.java (itemStateChanged): Implement function.
+        (getAccessibleContext): Add AccessibleAWTCheckBox to item listeners.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/TextArea.java (AccessibleAWTTextArea,
+        getAccessibleContext): Implement.
+        * java/awt/TextField.java (AccessibleAWTTextField,
+        getAccessibleContext): Implement.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Checkbox.java (AccessibleAWTCheckBox): Implement.
+        (getAccessibleContext): Implement.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/MenuItem.java (AccessibleAWTMenuItem): Implement.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/Choice.java (AccessibleAWTChoice): Implement.
+
+	2004-11-23 Jerry Quinn <jlquinn at optonline.net>
+
+        * java/awt/MenuItem.java (AccessibleAWTMenuItem): Implement.
+
+2004-12-02  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/javax/swing/DefaultSingleSelectionModel.java,
 	libraries/javalib/javax/swing/JPasswordField.java,
 	libraries/javalib/javax/swing/tree/AbstractLayoutCache.java:
Index: kaffe/libraries/javalib/java/awt/Button.java
diff -u kaffe/libraries/javalib/java/awt/Button.java:1.6 kaffe/libraries/javalib/java/awt/Button.java:1.7
--- kaffe/libraries/javalib/java/awt/Button.java:1.6	Wed Nov 24 21:49:17 2004
+++ kaffe/libraries/javalib/java/awt/Button.java	Fri Dec  3 01:56:21 2004
@@ -1,5 +1,5 @@
 /* Button.java -- AWT button widget
-   Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -44,13 +44,21 @@
 import java.lang.reflect.Array;
 import java.util.EventListener;
 
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRelation;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleValue;
+
 /**
   * This class provides a button widget for the AWT. 
   *
   * @author Aaron M. Renn (arenn at urbanophile.com)
   * @author Tom Tromey <tromey at cygnus.com>
   */
-public class Button extends Component implements java.io.Serializable
+public class Button extends Component
+  implements java.io.Serializable, Accessible
 {
 
 /*
@@ -85,6 +93,101 @@
    * The number used to generate the name returned by getName.
    */
   private static transient long next_button_number;
+  
+  protected class AccessibleAWTButton extends AccessibleAWTComponent
+    implements AccessibleAction, AccessibleValue
+  {
+    protected AccessibleAWTButton() { }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
+     */
+    public int getAccessibleActionCount()
+    {
+      // Only 1 action possible
+      return 1;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
+     */
+    public String getAccessibleActionDescription(int i)
+    {
+      // JDK 1.4.2 returns the string "click" for action 0.  However, the API
+      // docs don't say what the string to be returned is, beyond being a
+      // description of the action.  So we return the same thing for
+      // compatibility with 1.4.2.
+      if (i == 0)
+        return "click";
+      return null;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
+     */
+    public boolean doAccessibleAction(int i)
+    {
+      if (i != 0)
+        return false;
+      processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
+      return true;
+    }
+    
+    public String getAccessibleName()
+    {
+      return label;
+    }
+    
+    public AccessibleAction getAccessibleAction()
+    {
+      return this;
+    }
+    
+    public AccessibleValue getAccessibleValue()
+    {
+      return this;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
+     */
+    public Number getCurrentAccessibleValue()
+    {
+      // Docs say return 1 if selected, but buttons can't be selected, right?
+      return new Integer(0);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
+     */
+    public boolean setCurrentAccessibleValue(Number number)
+    {
+      // Since there's no selection with buttons, we're ignoring this.
+      // TODO someone who knows shoulw check this.
+      return false;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
+     */
+    public Number getMinimumAccessibleValue()
+    {
+      return new Integer(0);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
+     */
+    public Number getMaximumAccessibleValue()
+    {
+      return new Integer(0);
+    }
+    
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.PUSH_BUTTON;
+    }
+  }
 
 /*************************************************************************/
 
@@ -324,6 +427,11 @@
 {
   return getName () + "," + getX () + "," + getY () + ","
     + getWidth () + "x" + getHeight () + ",label=" + getLabel ();
+}
+
+public AccessibleContext getAccessibleContext()
+{
+  return new AccessibleAWTButton();
 }
 
   /**
Index: kaffe/libraries/javalib/java/awt/Checkbox.java
diff -u kaffe/libraries/javalib/java/awt/Checkbox.java:1.2 kaffe/libraries/javalib/java/awt/Checkbox.java:1.3
--- kaffe/libraries/javalib/java/awt/Checkbox.java:1.2	Thu Jul 22 19:20:21 2004
+++ kaffe/libraries/javalib/java/awt/Checkbox.java	Fri Dec  3 01:56:21 2004
@@ -43,6 +43,13 @@
 import java.awt.peer.CheckboxPeer;
 import java.io.Serializable;
 
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleState;
+import javax.accessibility.AccessibleValue;
+
 /**
  * This class implements a component which has an on/off state.  Two
  * or more Checkboxes can be grouped by a CheckboxGroup.
@@ -50,7 +57,8 @@
  * @author Aaron M. Renn (arenn at urbanophile.com)
  * @author Tom Tromey <tromey at redhat.com>
  */
-public class Checkbox extends Component implements ItemSelectable, Serializable
+public class Checkbox extends Component
+  implements ItemSelectable, Accessible, Serializable
 {
 
 // FIXME: Need readObject/writeObject for this.
@@ -86,6 +94,96 @@
 // The list of listeners for this object.
 private transient ItemListener item_listeners;
 
+protected class AccessibleAWTCheckBox
+  extends AccessibleAWTComponent
+  implements ItemListener, AccessibleAction, AccessibleValue
+{
+  
+
+  /* (non-Javadoc)
+   * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
+   */
+  public void itemStateChanged(ItemEvent event)
+  {
+    firePropertyChange(ACCESSIBLE_STATE_PROPERTY,
+		       state ? null : AccessibleState.CHECKED,
+                       state ? AccessibleState.CHECKED : null);
+  }
+  
+  public AccessibleAction getAccessibleAction()
+  {
+    return this;
+  }
+  
+  public AccessibleValue getAccessibleValue()
+  {
+    return this;
+  }
+  
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
+   */
+  public int getAccessibleActionCount()
+  {
+    // 1.4.1 does this
+    return 0;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
+   */
+  public String getAccessibleActionDescription(int i)
+  {
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
+   */
+  public boolean doAccessibleAction(int i)
+  {
+    return false;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
+   */
+  public Number getCurrentAccessibleValue()
+  {
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
+   */
+  public boolean setCurrentAccessibleValue(Number number)
+  {
+    return false;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
+   */
+  public Number getMinimumAccessibleValue()
+  {
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
+   */
+  public Number getMaximumAccessibleValue()
+  {
+    return null;
+  }
+  
+  public AccessibleRole getAccessibleRole() 
+  {
+    return AccessibleRole.CHECK_BOX;
+  }
+  
+}
+
 /*************************************************************************/
 
 /*
@@ -390,6 +488,13 @@
 {
   return ("label=" + label + ",state=" + state + ",group=" + group
 	  + "," + super.paramString());
+}
+
+public AccessibleContext getAccessibleContext()
+{
+  AccessibleAWTCheckBox ac = new AccessibleAWTCheckBox();
+  addItemListener(ac);
+  return ac;
 }
 
 } // class Checkbox 
Index: kaffe/libraries/javalib/java/awt/Choice.java
diff -u kaffe/libraries/javalib/java/awt/Choice.java:1.3 kaffe/libraries/javalib/java/awt/Choice.java:1.4
--- kaffe/libraries/javalib/java/awt/Choice.java:1.3	Wed Oct 27 19:08:27 2004
+++ kaffe/libraries/javalib/java/awt/Choice.java	Fri Dec  3 01:56:21 2004
@@ -45,6 +45,10 @@
 import java.util.EventListener;
 import java.util.Vector;
 
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+
 /**
   * This class implements a drop down choice list.
   *
@@ -79,6 +83,53 @@
 // Listener chain
 private ItemListener item_listeners;
 
+  protected class AccessibleAWTChoice
+    extends Component.AccessibleAWTComponent
+    implements AccessibleAction
+  {
+    public AccessibleAction getAccessibleAction()
+    {
+      return this;
+    }
+
+    // FIXME: I think this is right, but should be checked by someone who
+    // knows better.
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.POPUP_MENU;
+    }
+	  
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
+     */
+    public int getAccessibleActionCount()
+    {
+      return pItems.size();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
+     */
+    public String getAccessibleActionDescription(int i)
+    {
+      return (String) pItems.get(i);
+    }
+	  
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
+     */
+    public boolean doAccessibleAction(int i)
+    {
+      if (i < 0 || i >= pItems.size())
+	return false;
+	    
+      Choice.this.processItemEvent(new ItemEvent(Choice.this,
+						 ItemEvent.ITEM_STATE_CHANGED,
+						 this, ItemEvent.SELECTED));
+      return true;
+    }
+  }
+
 /*************************************************************************/
 
 /*
@@ -511,5 +562,10 @@
   public ItemListener[] getItemListeners ()
   {
     return (ItemListener[]) getListeners (ItemListener.class);
+  }
+
+  public AccessibleContext getAccessibleContext()
+  {
+    return new AccessibleAWTChoice();
   }
 } // class Choice 
Index: kaffe/libraries/javalib/java/awt/Menu.java
diff -u kaffe/libraries/javalib/java/awt/Menu.java:1.11 kaffe/libraries/javalib/java/awt/Menu.java:1.12
--- kaffe/libraries/javalib/java/awt/Menu.java:1.11	Mon Oct  4 09:01:30 2004
+++ kaffe/libraries/javalib/java/awt/Menu.java	Fri Dec  3 01:56:21 2004
@@ -43,6 +43,9 @@
 import java.util.Enumeration;
 import java.util.Vector;
 
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+
 /**
   * This class represents a pull down or tear off menu in Java's AWT.
   *
@@ -432,7 +435,28 @@
 	  + super.paramString());
 }
 
-// Accessibility API not yet implemented.
-// public AccessibleContext getAccessibleContext()
+  /**
+   * Basic Accessibility class for Menu.  Details get provided in derived
+   * classes.
+   */
+  protected class AccessibleAWTMenu extends AccessibleAWTMenuItem
+  {
+    protected AccessibleAWTMenu()
+    {
+    }
+
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.MENU;
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see java.awt.MenuComponent#getAccessibleContext()
+   */
+  public AccessibleContext getAccessibleContext()
+  {
+    return new AccessibleAWTMenu();
+  }
 
 } // class Menu
Index: kaffe/libraries/javalib/java/awt/MenuItem.java
diff -u kaffe/libraries/javalib/java/awt/MenuItem.java:1.14 kaffe/libraries/javalib/java/awt/MenuItem.java:1.15
--- kaffe/libraries/javalib/java/awt/MenuItem.java:1.14	Mon Sep 27 17:41:07 2004
+++ kaffe/libraries/javalib/java/awt/MenuItem.java	Fri Dec  3 01:56:22 2004
@@ -45,13 +45,18 @@
 import java.lang.reflect.Array;
 import java.util.EventListener;
 
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleValue;
+
 /**
   * This class represents an item in a menu.
   *
   * @author Aaron M. Renn (arenn at urbanophile.com)
   */
 public class MenuItem extends MenuComponent
-  implements Serializable
+  implements Serializable, Accessible
 {
 
 /*
@@ -94,6 +99,110 @@
 
 // The list of action listeners for this menu item.
 private transient ActionListener action_listeners;
+
+  protected class AccessibleAWTMenuItem
+    extends MenuComponent.AccessibleAWTMenuComponent
+    implements AccessibleAction, AccessibleValue
+  {
+    /** Constructor */
+    public AccessibleAWTMenuItem()
+    {
+      super();
+    }
+
+
+
+    public String getAccessibleName()
+    {
+      return label;
+    }
+
+    public AccessibleAction getAccessibleAction()
+    {
+      return this;
+    }
+
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.MENU_ITEM;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
+     */
+    public int getAccessibleActionCount()
+    {
+      return 1;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
+     */
+    public String getAccessibleActionDescription(int i)
+    {
+      if (i == 0)
+       return label;
+      else
+       return null;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
+     */
+    public boolean doAccessibleAction(int i)
+    {
+      if (i != 0)
+       return false;
+      processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
+      return true;
+    }
+
+    public AccessibleValue getAccessibleValue()
+    {
+      return this;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
+     */
+    public Number getCurrentAccessibleValue()
+    {
+      return (enabled) ? new Integer(1) : new Integer(0);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
+     */
+    public boolean setCurrentAccessibleValue(Number number)
+    {
+      if (number.intValue() == 0)
+       {
+         setEnabled(false);
+         return false;
+       }
+
+      setEnabled(true);
+      return true;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
+     */
+    public Number getMinimumAccessibleValue()
+    {
+      return new Integer(0);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
+     */
+    public Number getMaximumAccessibleValue()
+    {
+      return new Integer(0);
+    }
+
+  }
+
 
 /*************************************************************************/
 
Index: kaffe/libraries/javalib/java/awt/PopupMenu.java
diff -u kaffe/libraries/javalib/java/awt/PopupMenu.java:1.9 kaffe/libraries/javalib/java/awt/PopupMenu.java:1.10
--- kaffe/libraries/javalib/java/awt/PopupMenu.java:1.9	Mon Oct  4 09:01:32 2004
+++ kaffe/libraries/javalib/java/awt/PopupMenu.java	Fri Dec  3 01:56:22 2004
@@ -40,6 +40,9 @@
 
 import java.awt.peer.PopupMenuPeer;
 
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+
 /**
   * This class implement an AWT popup menu widget
   *
@@ -134,6 +137,24 @@
       pmp.show (component, x, y);
     }
 }
+
+  protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu
+  {
+    protected AccessibleAWTPopupMenu()
+    {
+    }
+
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.POPUP_MENU;
+    }
+
+  }
+
+  public AccessibleContext getAccessibleContext()
+  {
+    return new AccessibleAWTPopupMenu();
+  }
 
 } // class PopupMenu
 
Index: kaffe/libraries/javalib/java/awt/TextArea.java
diff -u kaffe/libraries/javalib/java/awt/TextArea.java:1.4 kaffe/libraries/javalib/java/awt/TextArea.java:1.5
--- kaffe/libraries/javalib/java/awt/TextArea.java:1.4	Tue Oct 12 00:24:58 2004
+++ kaffe/libraries/javalib/java/awt/TextArea.java	Fri Dec  3 01:56:22 2004
@@ -44,6 +44,9 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleStateSet;
+
 
 /**
  * A TextArea is a text component capable of displaying multiple lines
@@ -596,5 +599,22 @@
   private static synchronized long getUniqueLong ()
   {
     return next_text_number++;
+  }
+
+  protected class AccessibleAWTTextArea extends AccessibleAWTTextComponent
+  {
+    protected AccessibleAWTTextArea()
+    {
+    }
+
+    public AccessibleStateSet getAccessibleStateSet()
+    {
+      return super.getAccessibleStateSet();
+    }
+  }
+
+  public AccessibleContext getAccessibleContext()
+  {
+    return new AccessibleAWTTextArea();
   }
 }
Index: kaffe/libraries/javalib/java/awt/TextComponent.java
diff -u kaffe/libraries/javalib/java/awt/TextComponent.java:1.2 kaffe/libraries/javalib/java/awt/TextComponent.java:1.3
--- kaffe/libraries/javalib/java/awt/TextComponent.java:1.2	Thu Jul 22 19:37:02 2004
+++ kaffe/libraries/javalib/java/awt/TextComponent.java	Fri Dec  3 01:56:22 2004
@@ -42,8 +42,16 @@
 import java.awt.event.TextListener;
 import java.awt.peer.TextComponentPeer;
 import java.io.Serializable;
+import java.text.BreakIterator;
 import java.util.EventListener;
 
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleState;
+import javax.accessibility.AccessibleStateSet;
+import javax.accessibility.AccessibleText;
+import javax.swing.text.AttributeSet;
+
 /**
   * This class provides common functionality for widgets than 
   * contain text.
@@ -51,7 +59,7 @@
   * @author Aaron M. Renn (arenn at urbanophile.com)
   */
 public class TextComponent extends Component
-  implements Serializable
+  implements Serializable, Accessible
 {
 
 /*
@@ -90,6 +98,219 @@
   */
 protected transient TextListener textListener;
 
+  protected class AccessibleAWTTextComponent
+    extends AccessibleAWTComponent
+    implements AccessibleText, TextListener
+  {
+    // Constructor
+    // Adds a listener for tracking caret changes
+    public AccessibleAWTTextComponent()
+    {
+      TextComponent.this.addTextListener(this);
+    }
+
+    public AccessibleRole getAccessibleRole()
+    {
+      return AccessibleRole.TEXT;
+    }
+
+    public AccessibleStateSet getAccessibleStateSet()
+    {
+      // TODO: Docs say PropertyChangeEvent will fire if this state changes.
+      // That means that the event has to fire when editable changes.
+      AccessibleStateSet ss = super.getAccessibleStateSet();
+      if (editable)
+        ss.add(AccessibleState.EDITABLE);
+      return ss;
+    }
+
+    public AccessibleText getAccessibleText()
+    {
+      return this;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getIndexAtPoint(java.awt.Point)
+     */
+    public int getIndexAtPoint(Point point)
+    {
+      return TextComponent.this.getIndexAtPoint(point);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getCharacterBounds(int)
+     */
+    public Rectangle getCharacterBounds(int index)
+    {
+      return TextComponent.this.getCharacterBounds(index);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getCharCount()
+     */
+    public int getCharCount()
+    {
+      return text.length();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getCaretPosition()
+     */
+    public int getCaretPosition()
+    {
+      return TextComponent.this.getCaretPosition();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getAtIndex(int, int)
+     */
+    public String getAtIndex(int part, int index)
+    {
+      if (index < 0 || index >= text.length())
+        return null;
+      BreakIterator it = null;
+      switch (part)
+      {
+       case CHARACTER:
+         return text.substring(index, index + 1);
+       case WORD:
+         it = BreakIterator.getWordInstance();
+         break;
+       case SENTENCE:
+         it = BreakIterator.getSentenceInstance();
+         break;
+       default:
+         return null;
+      }
+         it.setText(text);
+         int start = index;
+         if (!it.isBoundary(index))
+           start = it.preceding(index);
+         int end = it.following(index);
+         if (end == -1)
+           return text.substring(index);
+         else
+           return text.substring(index, end);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getAfterIndex(int, int)
+     */
+    public String getAfterIndex(int part, int index) {
+      if (index < 0 || index >= text.length())
+        return null;
+      BreakIterator it = null;
+      switch (part)
+      {
+       case CHARACTER:
+         return text.substring(index, index + 1);
+       case WORD:
+         it = BreakIterator.getWordInstance();
+         break;
+       case SENTENCE:
+         it = BreakIterator.getSentenceInstance();
+         break;
+       default:
+         return null;
+      }
+         it.setText(text);
+         int start = index;
+         if (!it.isBoundary(index))
+           start = it.following(index);
+         // Make sure there was a complete unit.  I.e. if index is in the middle
+         // of a word, return null if there is no word after the that one.
+         if (start == -1)
+           return null;
+         int end = it.following(start);
+         if (end == -1)
+           return text.substring(index);
+         else
+           return text.substring(index, end);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.accessibility.AccessibleText#getBeforeIndex(int, int)
+     */
+    public String getBeforeIndex(int part, int index)
+    {
+      if (index < 1 || index >= text.length())
+        return null;
+      BreakIterator it = null;
+      switch (part)
+      {
+       case CHARACTER:
+         return text.substring(index - 1, index);
+       case WORD:
+         it = BreakIterator.getWordInstance();
+         break;
+       case SENTENCE:
+         it = BreakIterator.getSentenceInstance();
+         break;
+       default:
+         return null;
+      }
+         it.setText(text);
+         int end = index;
+         if (!it.isBoundary(index))
+           end = it.preceding(index);
+         // Make sure there was a complete unit.  I.e. if index is in the middle
+         // of a word, return null if there is no word before that one.
+         if (end == -1)
+           return null;
+         int start = it.preceding(end);
+         if (start == -1)
+           return text.substring(0, end);
+         else
+           return text.substring(start, end);
+    }

*** Patch too long, truncated ***




More information about the kaffe mailing list