public static AccessibleStateSet getAccessibleStateSet(java.awt.Component c,
XAccessibleStateSet xAccessibleStateSet) {
try {
if (xAccessibleStateSet != null) {
AccessibleStateSet as = new AccessibleStateSet();
short[] unoStateTypes = xAccessibleStateSet.getStates();
for (int i=0; i<unoStateTypes.length; i++) {
if (unoStateTypes[i] > 0 &&
unoStateTypes[i] < stateTypeMap.length) {
as.add(stateTypeMap[unoStateTypes[i]]);
}
}
// Note: COLLAPSED does not exists in the UAA.
if (as.contains(AccessibleState.EXPANDABLE) &&
! as.contains(AccessibleState.EXPANDED)) {
as.add(AccessibleState.COLLAPSED);
}
// Sync office and Java FOCUSED state
boolean isFocusInSync;
if (c.isFocusOwner()) {
isFocusInSync = !as.add(AccessibleState.FOCUSED);
} else {
isFocusInSync = !as.remove(AccessibleState.FOCUSED);
}
// Sync office and Java ACTIVE state
boolean isActiveInSync;
if (c instanceof java.awt.Window && ((java.awt.Window) c).isActive()) {
isActiveInSync = !as.add(AccessibleState.ACTIVE);
} else {
isActiveInSync = !as.remove(AccessibleState.ACTIVE);
}
// Report out-of-sync messages
if (!Build.PRODUCT) {
if (!isFocusInSync) {
printOutOfSyncMessage(AccessibleState.FOCUSED, c, c.isFocusOwner());
}
if (!isActiveInSync) {
printOutOfSyncMessage(AccessibleState.ACTIVE, c, ((java.awt.Window) c).isActive());
}
if (as.contains(AccessibleState.ENABLED) != c.isEnabled()) {
printOutOfSyncMessage(AccessibleState.ENABLED, c, c.isEnabled());
}
if (as.contains(AccessibleState.FOCUSABLE) != c.isFocusable()) {
printOutOfSyncMessage(AccessibleState.FOCUSABLE, c, c.isFocusable());
}
if (as.contains(AccessibleState.SHOWING) != c.isShowing()) {
printOutOfSyncMessage(AccessibleState.SHOWING, c, c.isShowing());
}
if (as.contains(AccessibleState.VISIBLE) != c.isVisible()) {
printOutOfSyncMessage(AccessibleState.VISIBLE, c, c.isVisible());
}
// The following states are for toplevel windows only
if (! (c instanceof java.awt.Window)) {
if (as.contains(AccessibleState.ACTIVE)) {
printToplevelStateMessage(AccessibleState.ACTIVE, c);
}
if (as.contains(AccessibleState.ICONIFIED)) {
printToplevelStateMessage(AccessibleState.ICONIFIED, c);
}
if (as.contains(AccessibleState.MODAL)) {
printToplevelStateMessage(AccessibleState.MODAL, c);
}
}
}
return as;