class. It provides an implementation of the
Java Accessibility API appropriate to button and menu item
user-interface elements.
Method from javax.swing.AbstractButton$AccessibleAbstractButton Detail: |
public boolean doAccessibleAction(int i) {
if (i == 0) {
doClick();
return true;
} else {
return false;
}
}
Perform the specified Action on the object |
public AccessibleAction getAccessibleAction() {
return this;
}
Get the AccessibleAction associated with this object. In the
implementation of the Java Accessibility API for this class,
return this object, which is responsible for implementing the
AccessibleAction interface on behalf of itself. |
public int getAccessibleActionCount() {
return 1;
}
Returns the number of Actions available in this object. The
default behavior of a button is to have one action - toggle
the button. |
public String getAccessibleActionDescription(int i) {
if (i == 0) {
return UIManager.getString("AbstractButton.clickText");
} else {
return null;
}
}
Return a description of the specified action of the object. |
AccessibleExtendedComponent getAccessibleExtendedComponent() {
return this;
}
Returns the AccessibleExtendedComponent |
public AccessibleIcon[] getAccessibleIcon() {
Icon defaultIcon = getIcon();
if (defaultIcon instanceof Accessible) {
AccessibleContext ac =
((Accessible)defaultIcon).getAccessibleContext();
if (ac != null && ac instanceof AccessibleIcon) {
return new AccessibleIcon[] { (AccessibleIcon)ac };
}
}
return null;
}
Get the AccessibleIcons associated with this object if one
or more exist. Otherwise return null. |
public AccessibleKeyBinding getAccessibleKeyBinding() {
int mnemonic = AbstractButton.this.getMnemonic();
if (mnemonic == 0) {
return null;
}
return new ButtonKeyBinding(mnemonic);
}
Returns key bindings associated with this object |
public String getAccessibleName() {
String name = accessibleName;
if (name == null) {
name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
}
if (name == null) {
name = AbstractButton.this.getText();
}
if (name == null) {
name = super.getAccessibleName();
}
return name;
}
Returns the accessible name of this object. |
public AccessibleRelationSet getAccessibleRelationSet() {
// Check where the AccessibleContext's relation
// set already contains a MEMBER_OF relation.
AccessibleRelationSet relationSet
= super.getAccessibleRelationSet();
if (!relationSet.contains(AccessibleRelation.MEMBER_OF)) {
// get the members of the button group if one exists
ButtonModel model = getModel();
if (model != null && model instanceof DefaultButtonModel) {
ButtonGroup group = ((DefaultButtonModel)model).getGroup();
if (group != null) {
// set the target of the MEMBER_OF relation to be
// the members of the button group.
int len = group.getButtonCount();
Object [] target = new Object[len];
Enumeration elem = group.getElements();
for (int i = 0; i < len; i++) {
if (elem.hasMoreElements()) {
target[i] = elem.nextElement();
}
}
AccessibleRelation relation =
new AccessibleRelation(AccessibleRelation.MEMBER_OF);
relation.setTarget(target);
relationSet.add(relation);
}
}
}
return relationSet;
}
Get the AccessibleRelationSet associated with this object if one
exists. Otherwise return null. |
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states = super.getAccessibleStateSet();
if (getModel().isArmed()) {
states.add(AccessibleState.ARMED);
}
if (isFocusOwner()) {
states.add(AccessibleState.FOCUSED);
}
if (getModel().isPressed()) {
states.add(AccessibleState.PRESSED);
}
if (isSelected()) {
states.add(AccessibleState.CHECKED);
}
return states;
}
Get the state set of this object. |
public AccessibleText getAccessibleText() {
View view = (View)AbstractButton.this.getClientProperty("html");
if (view != null) {
return this;
} else {
return null;
}
}
|
public AccessibleValue getAccessibleValue() {
return this;
}
Get the AccessibleValue associated with this object. In the
implementation of the Java Accessibility API for this class,
return this object, which is responsible for implementing the
AccessibleValue interface on behalf of itself. |
public String getAfterIndex(int part,
int index) {
if (index < 0 || index >= getCharCount()) {
return null;
}
switch (part) {
case AccessibleText.CHARACTER:
if (index+1 >= getCharCount()) {
return null;
}
try {
return getText(index+1, 1);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.WORD:
try {
String s = getText(0, getCharCount());
BreakIterator words = BreakIterator.getWordInstance(getLocale());
words.setText(s);
int start = words.following(index);
if (start == BreakIterator.DONE || start >= s.length()) {
return null;
}
int end = words.following(start);
if (end == BreakIterator.DONE || end >= s.length()) {
return null;
}
return s.substring(start, end);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.SENTENCE:
try {
String s = getText(0, getCharCount());
BreakIterator sentence =
BreakIterator.getSentenceInstance(getLocale());
sentence.setText(s);
int start = sentence.following(index);
if (start == BreakIterator.DONE || start > s.length()) {
return null;
}
int end = sentence.following(start);
if (end == BreakIterator.DONE || end > s.length()) {
return null;
}
return s.substring(start, end);
} catch (BadLocationException e) {
return null;
}
default:
return null;
}
}
Returns the String after a given index. |
public String getAtIndex(int part,
int index) {
if (index < 0 || index >= getCharCount()) {
return null;
}
switch (part) {
case AccessibleText.CHARACTER:
try {
return getText(index, 1);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.WORD:
try {
String s = getText(0, getCharCount());
BreakIterator words = BreakIterator.getWordInstance(getLocale());
words.setText(s);
int end = words.following(index);
return s.substring(words.previous(), end);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.SENTENCE:
try {
String s = getText(0, getCharCount());
BreakIterator sentence =
BreakIterator.getSentenceInstance(getLocale());
sentence.setText(s);
int end = sentence.following(index);
return s.substring(sentence.previous(), end);
} catch (BadLocationException e) {
return null;
}
default:
return null;
}
}
Returns the String at a given index. |
public String getBeforeIndex(int part,
int index) {
if (index < 0 || index > getCharCount()-1) {
return null;
}
switch (part) {
case AccessibleText.CHARACTER:
if (index == 0) {
return null;
}
try {
return getText(index-1, 1);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.WORD:
try {
String s = getText(0, getCharCount());
BreakIterator words = BreakIterator.getWordInstance(getLocale());
words.setText(s);
int end = words.following(index);
end = words.previous();
int start = words.previous();
if (start == BreakIterator.DONE) {
return null;
}
return s.substring(start, end);
} catch (BadLocationException e) {
return null;
}
case AccessibleText.SENTENCE:
try {
String s = getText(0, getCharCount());
BreakIterator sentence =
BreakIterator.getSentenceInstance(getLocale());
sentence.setText(s);
int end = sentence.following(index);
end = sentence.previous();
int start = sentence.previous();
if (start == BreakIterator.DONE) {
return null;
}
return s.substring(start, end);
} catch (BadLocationException e) {
return null;
}
default:
return null;
}
}
Returns the String before a given index. |
public int getCaretPosition() {
// There is no caret.
return -1;
}
Return the zero-based offset of the caret.
Note: That to the right of the caret will have the same index
value as the offset (the caret is between two characters). |
public int getCharCount() {
View view = (View) AbstractButton.this.getClientProperty("html");
if (view != null) {
Document d = view.getDocument();
if (d instanceof StyledDocument) {
StyledDocument doc = (StyledDocument)d;
return doc.getLength();
}
}
return accessibleContext.getAccessibleName().length();
}
Return the number of characters (valid indicies) |
public AttributeSet getCharacterAttribute(int i) {
View view = (View) AbstractButton.this.getClientProperty("html");
if (view != null) {
Document d = view.getDocument();
if (d instanceof StyledDocument) {
StyledDocument doc = (StyledDocument)d;
Element elem = doc.getCharacterElement(i);
if (elem != null) {
return elem.getAttributes();
}
}
}
return null;
}
Return the AttributeSet for a given character at a given index |
public Rectangle getCharacterBounds(int i) {
View view = (View) AbstractButton.this.getClientProperty("html");
if (view != null) {
Rectangle r = getTextRectangle();
if (r == null) {
return null;
}
Rectangle2D.Float shape =
new Rectangle2D.Float(r.x, r.y, r.width, r.height);
try {
Shape charShape =
view.modelToView(i, shape, Position.Bias.Forward);
return charShape.getBounds();
} catch (BadLocationException e) {
return null;
}
} else {
return null;
}
}
Determine the bounding box of the character at the given
index into the string. The bounds are returned in local
coordinates. If the index is invalid an empty rectangle is
returned.
Note: the AbstractButton must have a valid size (e.g. have
been added to a parent container whose ancestor container
is a valid top-level window) for this method to be able
to return a meaningful value. |
public Number getCurrentAccessibleValue() {
if (isSelected()) {
return Integer.valueOf(1);
} else {
return Integer.valueOf(0);
}
}
Get the value of this object as a Number. |
public int getIndexAtPoint(Point p) {
View view = (View) AbstractButton.this.getClientProperty("html");
if (view != null) {
Rectangle r = getTextRectangle();
if (r == null) {
return -1;
}
Rectangle2D.Float shape =
new Rectangle2D.Float(r.x, r.y, r.width, r.height);
Position.Bias bias[] = new Position.Bias[1];
return view.viewToModel(p.x, p.y, shape, bias);
} else {
return -1;
}
}
Given a point in local coordinates, return the zero-based index
of the character under that Point. If the point is invalid,
this method returns -1.
Note: the AbstractButton must have a valid size (e.g. have
been added to a parent container whose ancestor container
is a valid top-level window) for this method to be able
to return a meaningful value. |
public Number getMaximumAccessibleValue() {
return Integer.valueOf(1);
}
Get the maximum value of this object as a Number. |
public Number getMinimumAccessibleValue() {
return Integer.valueOf(0);
}
Get the minimum value of this object as a Number. |
public String getSelectedText() {
// Text cannot be selected.
return null;
}
Returns the portion of the text that is selected. |
public int getSelectionEnd() {
// Text cannot be selected.
return -1;
}
Returns the end offset within the selected text.
If there is no selection, but there is
a caret, the start and end offsets will be the same. |
public int getSelectionStart() {
// Text cannot be selected.
return -1;
}
Returns the start offset within the selected text.
If there is no selection, but there is
a caret, the start and end offsets will be the same. |
public String getTitledBorderText() {
return super.getTitledBorderText();
}
Returns the titled border text |
public String getToolTipText() {
return AbstractButton.this.getToolTipText();
}
Returns the tool tip text |
public boolean setCurrentAccessibleValue(Number n) {
// TIGER - 4422535
if (n == null) {
return false;
}
int i = n.intValue();
if (i == 0) {
setSelected(false);
} else {
setSelected(true);
}
return true;
}
Set the value of this object as a Number. |