static void readTableElement(final AccessibleContext context) {
if (!(context instanceof AccessibleTable)) {
return;
}
final AccessibleTable table = (AccessibleTable) context;
// Evaluate number of columns and rows in the accessible table
final int tableColCount = table.getAccessibleColumnCount();
final int tableRowCount = table.getAccessibleRowCount();
String name = context.getAccessibleName();
if (name == null) {
name = "";
}
// Describe the table
final StringBuffer tableHeader = new StringBuffer();
tableHeader.append(name);
tableHeader.append(" table with ");
tableHeader.append(tableColCount);
tableHeader.append(" columns and ");
tableHeader.append(tableRowCount);
tableHeader.append(" rows");
Util.speak(tableHeader.toString());
// Get the column headers
final AccessibleContext[] tableColumnsNames =
table.getAccessibleColumnHeader();
if (tableColumnsNames != null) {
// Read cells, column by column
for (int i = 0; i < tableColumnsNames.length; i++) {
final AccessibleContext column = tableColumnsNames[i];
Util.speak("column " + (i + 1));
if (column == null) {
Util.speak("empty");
} else {
readChildElement(column);
}
// Read cells in the column
for (int row = 0; row < tableRowCount; row++) {
final AccessibleContext accessibleCell =
table.getAccessibleAt(row, i);
if (accessibleCell == null) {
Util.speak("empty");
} else {
readChildElement(accessibleCell);
}
}
}
} else {
// Read cells, row by row
Util.speak("table data");
for (int row = 0; row < tableRowCount; row++) {
for (int col = 0; col < tableColCount; col++) {
final AccessibleContext accessibleCell =
table.getAccessibleAt(row, col);
if (accessibleCell == null) {
Util.speak("empty");
} else {
readChildElement(accessibleCell);
}