Index: java/awt/Menu.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/Menu.java,v retrieving revision 1.17 diff -u -r1.17 Menu.java --- java/awt/Menu.java 27 Sep 2004 15:11:46 -0000 1.17 +++ java/awt/Menu.java 23 Nov 2004 18:17:36 -0000 @@ -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: java/awt/PopupMenu.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/PopupMenu.java,v retrieving revision 1.13 diff -u -r1.13 PopupMenu.java --- java/awt/PopupMenu.java 27 Sep 2004 15:11:46 -0000 1.13 +++ java/awt/PopupMenu.java 23 Nov 2004 18:17:36 -0000 @@ -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 * @@ -135,5 +138,23 @@ } } + protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu + { + protected AccessibleAWTPopupMenu() + { + } + + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.POPUP_MENU; + } + + } + + public AccessibleContext getAccessibleContext() + { + return new AccessibleAWTPopupMenu(); + } + } // class PopupMenu Index: java/awt/TextComponent.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/TextComponent.java,v retrieving revision 1.15 diff -u -r1.15 TextComponent.java --- java/awt/TextComponent.java 26 Jun 2004 16:06:48 -0000 1.15 +++ java/awt/TextComponent.java 23 Nov 2004 18:17:36 -0000 @@ -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 (address@hidden) */ 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); + } + + /* (non-Javadoc) + * @see javax.accessibility.AccessibleText#getCharacterAttribute(int) + */ + public AttributeSet getCharacterAttribute(int index) + { + // FIXME: I suspect this really gets filled in by subclasses. + return null; + } + + /* (non-Javadoc) + * @see javax.accessibility.AccessibleText#getSelectionStart() + */ + public int getSelectionStart() { + // TODO Auto-generated method stub + return selectionStart; + } + + /* (non-Javadoc) + * @see javax.accessibility.AccessibleText#getSelectionEnd() + */ + public int getSelectionEnd() + { + return selectionEnd; + } + + /* (non-Javadoc) + * @see javax.accessibility.AccessibleText#getSelectedText() + */ + public String getSelectedText() + { + if (selectionEnd - selectionStart > 0) + return text.substring(selectionStart, selectionEnd); + else + return null; + } + + /* (non-Javadoc) + * @see java.awt.event.TextListener#textValueChanged(java.awt.event.TextEvent) + */ + public void textValueChanged(TextEvent event) + { + // TODO Auto-generated method stub + + } + + } + /*************************************************************************/ /* @@ -468,5 +689,30 @@ { return (TextListener[]) getListeners (TextListener.class); } + + /*******************************/ + // Provide AccessibleAWTTextComponent access to several peer functions that + // aren't publicly exposed. + private synchronized int + getIndexAtPoint(Point p) + { + TextComponentPeer tcp = (TextComponentPeer)getPeer(); + if (tcp != null) + return tcp.getIndexAtPoint(p.x, p.y); + return -1; + } + + private synchronized Rectangle + getCharacterBounds(int i) + { + TextComponentPeer tcp = (TextComponentPeer)getPeer(); + if (tcp != null) + return tcp.getCharacterBounds(i); + return null; + } + + + + } // class TextComponent