class. It provides an implementation of the
Java Accessibility API appropriate to menu user-interface elements.
Method from javax.swing.JMenu$AccessibleJMenu Detail: |
public void addAccessibleSelection(int i) {
if (i < 0 || i >= getItemCount()) {
return;
}
JMenuItem mi = getItem(i);
if (mi != null) {
if (mi instanceof JMenu) {
MenuElement me[] = buildMenuElementArray((JMenu) mi);
MenuSelectionManager.defaultManager().setSelectedPath(me);
} else {
MenuSelectionManager.defaultManager().setSelectedPath(null);
}
}
}
Selects the i th menu in the menu.
If that item is a submenu,
it will pop up in response. If a different item is already
popped up, this will force it to close. If this is a sub-menu
that is already popped up (selected), this method has no
effect. |
public void clearAccessibleSelection() {
// if this menu is selected, reset selection to only go
// to this menu; else do nothing
MenuElement old[] =
MenuSelectionManager.defaultManager().getSelectedPath();
if (old != null) {
for (int j = 0; j < old.length; j++) {
if (old[j] == JMenu.this) { // menu is in the selection!
MenuElement me[] = new MenuElement[j+1];
System.arraycopy(old, 0, me, 0, j);
me[j] = JMenu.this.getPopupMenu();
MenuSelectionManager.defaultManager().setSelectedPath(me);
}
}
}
}
Clears the selection in the object, so that nothing in the
object is selected. This will close any open sub-menu. |
public Accessible getAccessibleChild(int i) {
Component[] children = getMenuComponents();
int count = 0;
for (Component child : children) {
if (child instanceof Accessible) {
if (count == i) {
if (child instanceof JComponent) {
// FIXME: [[[WDW - probably should set this when
// the component is added to the menu. I tried
// to do this in most cases, but the separators
// added by addSeparator are hard to get to.]]]
AccessibleContext ac = child.getAccessibleContext();
ac.setAccessibleParent(JMenu.this);
}
return (Accessible) child;
} else {
count++;
}
}
}
return null;
}
Returns the nth Accessible child of the object. |
public int getAccessibleChildrenCount() {
Component[] children = getMenuComponents();
int count = 0;
for (Component child : children) {
if (child instanceof Accessible) {
count++;
}
}
return count;
}
Returns the number of accessible children in the object. If all
of the children of this object implement Accessible, than this
method should return the number of children of this object. |
public AccessibleRole getAccessibleRole() {
return AccessibleRole.MENU;
}
Get the role of this object. |
public AccessibleSelection getAccessibleSelection() {
return this;
}
Get the AccessibleSelection associated with this object. In the
implementation of the Java Accessibility API for this class,
return this object, which is responsible for implementing the
AccessibleSelection interface on behalf of itself. |
public Accessible getAccessibleSelection(int i) {
// if i is a sub-menu & popped, return it
if (i < 0 || i >= getItemCount()) {
return null;
}
MenuElement me[] =
MenuSelectionManager.defaultManager().getSelectedPath();
if (me != null) {
for (int j = 0; j < me.length; j++) {
if (me[j] == JMenu.this) { // this menu is selected
// so find the next JMenuItem in the MenuElement
// array, and return it!
while (++j < me.length) {
if (me[j] instanceof JMenuItem) {
return (Accessible) me[j];
}
}
}
}
}
return null;
}
Returns the currently selected sub-menu if one is selected,
otherwise null (there can only be one selection, and it can
only be a sub-menu, as otherwise menu items don't remain
selected). |
public int getAccessibleSelectionCount() {
MenuElement me[] =
MenuSelectionManager.defaultManager().getSelectedPath();
if (me != null) {
for (int i = 0; i < me.length; i++) {
if (me[i] == JMenu.this) { // this menu is selected
if (i+1 < me.length) {
return 1;
}
}
}
}
return 0;
}
Returns 1 if a sub-menu is currently selected in this menu. |
public boolean isAccessibleChildSelected(int i) {
// if i is a sub-menu and is pop-ed up, return true, else false
MenuElement me[] =
MenuSelectionManager.defaultManager().getSelectedPath();
if (me != null) {
JMenuItem mi = JMenu.this.getItem(i);
for (int j = 0; j < me.length; j++) {
if (me[j] == mi) {
return true;
}
}
}
return false;
}
Returns true if the current child of this object is selected
(that is, if this child is a popped-up submenu). |
public void removeAccessibleSelection(int i) {
if (i < 0 || i >= getItemCount()) {
return;
}
JMenuItem mi = getItem(i);
if (mi != null && mi instanceof JMenu) {
if (mi.isSelected()) {
MenuElement old[] =
MenuSelectionManager.defaultManager().getSelectedPath();
MenuElement me[] = new MenuElement[old.length-2];
for (int j = 0; j < old.length -2; j++) {
me[j] = old[j];
}
MenuSelectionManager.defaultManager().setSelectedPath(me);
}
}
}
Removes the nth item from the selection. In general, menus
can only have one item within them selected at a time
(e.g. one sub-menu popped open). |
public void selectAllAccessibleSelection() {
}
Normally causes every selected item in the object to be selected
if the object supports multiple selections. This method
makes no sense in a menu bar, and so does nothing. |