use of javax.accessibility.Accessible in project jdk8u_jdk by JetBrains.
the class CAccessible method addNotificationListeners.
public void addNotificationListeners(Component c) {
if (c instanceof Accessible) {
AccessibleContext ac = ((Accessible) c).getAccessibleContext();
ac.addPropertyChangeListener(new AXChangeNotifier());
}
if (c instanceof JProgressBar) {
JProgressBar pb = (JProgressBar) c;
pb.addChangeListener(new AXProgressChangeNotifier());
} else if (c instanceof JSlider) {
JSlider slider = (JSlider) c;
slider.addChangeListener(new AXProgressChangeNotifier());
}
}
use of javax.accessibility.Accessible in project jdk8u_jdk by JetBrains.
the class CAccessibleText method getVisibleCharacterRange.
static int[] getVisibleCharacterRange(final Accessible a) {
final Accessible sa = CAccessible.getSwingAccessible(a);
if (!(sa instanceof JTextComponent))
return null;
final JTextComponent jc = (JTextComponent) sa;
final Rectangle rect = jc.getVisibleRect();
final Point topLeft = new Point(rect.x, rect.y);
final Point topRight = new Point(rect.x + rect.width, rect.y);
final Point bottomLeft = new Point(rect.x, rect.y + rect.height);
final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height);
int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight));
int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight));
if (start < 0)
start = 0;
if (end < 0)
end = 0;
return new int[] { start, end };
}
use of javax.accessibility.Accessible in project jdk8u_jdk by JetBrains.
the class Bug8154069 method main.
public static void main(String[] args) throws Exception {
try {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (Exception e) {
throw new RuntimeException(e);
}
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
String[] petStrings = { "Bird", "Cat" };
JComboBox<String> cb = new JComboBox<>(petStrings);
// select Cat
cb.setSelectedIndex(1);
frame.add(cb);
frame.pack();
try {
cb.setSelectedIndex(-1);
int i = cb.getSelectedIndex();
if (i != -1) {
throw new RuntimeException("getSelectedIndex is not -1");
}
Object o = cb.getSelectedItem();
if (o != null) {
throw new RuntimeException("getSelectedItem is not null");
}
AccessibleContext ac = cb.getAccessibleContext();
AccessibleSelection as = ac.getAccessibleSelection();
int count = as.getAccessibleSelectionCount();
if (count != 0) {
throw new RuntimeException("getAccessibleSelection count is not 0");
}
Accessible a = as.getAccessibleSelection(0);
if (a != null) {
throw new RuntimeException("getAccessibleSelection(0) is not null");
}
} catch (Exception e) {
exception = e;
}
});
if (exception != null) {
System.out.println("Test failed: " + exception.getMessage());
throw exception;
} else {
System.out.println("Test passed.");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
frame.dispose();
});
}
}
Aggregations