Search in sources :

Example 6 with Accessible

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());
    }
}
Also used : AccessibleContext(javax.accessibility.AccessibleContext) JProgressBar(javax.swing.JProgressBar) JSlider(javax.swing.JSlider) Accessible(javax.accessibility.Accessible)

Example 7 with Accessible

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 };
}
Also used : Rectangle(java.awt.Rectangle) JTextComponent(javax.swing.text.JTextComponent) Point(java.awt.Point) Point(java.awt.Point) Accessible(javax.accessibility.Accessible)

Example 8 with Accessible

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();
        });
    }
}
Also used : JComboBox(javax.swing.JComboBox) AccessibleContext(javax.accessibility.AccessibleContext) AccessibleSelection(javax.accessibility.AccessibleSelection) JFrame(javax.swing.JFrame) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) Accessible(javax.accessibility.Accessible)

Aggregations

Accessible (javax.accessibility.Accessible)8 JTextComponent (javax.swing.text.JTextComponent)3 AccessibleContext (javax.accessibility.AccessibleContext)2 JFrame (javax.swing.JFrame)2 Element (javax.swing.text.Element)2 ValuedTreeNode (com.android.tools.adtui.ValuedTreeNode)1 SunburstChart (com.android.tools.adtui.chart.SunburstChart)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 AccessibleSelection (javax.accessibility.AccessibleSelection)1 JComboBox (javax.swing.JComboBox)1 JProgressBar (javax.swing.JProgressBar)1 JSlider (javax.swing.JSlider)1 RootPaneContainer (javax.swing.RootPaneContainer)1 NimbusLookAndFeel (javax.swing.plaf.nimbus.NimbusLookAndFeel)1 Ignore (org.junit.Ignore)1