src/macosx/classes/sun/lwawt/macosx/CAccessibility.java

Print this page




  54     static CAccessibility sAccessibility;
  55     static synchronized CAccessibility getAccessibility(final String[] roles) {
  56         if (sAccessibility != null) return sAccessibility;
  57         sAccessibility = new CAccessibility();
  58 
  59         if (roles != null) {
  60             ignoredRoles = new HashSet<String>(roles.length);
  61             for (final String role : roles) ignoredRoles.add(role);
  62         } else {
  63             ignoredRoles = new HashSet<String>();
  64         }
  65 
  66         return sAccessibility;
  67     }
  68 
  69     private CAccessibility() {
  70         KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", this);
  71     }
  72 
  73     public void propertyChange(final PropertyChangeEvent evt) {
  74         if (evt.getNewValue() == null) return;










  75         focusChanged();
  76     }


  77 
  78     private native void focusChanged();
  79 
  80     static <T> T invokeAndWait(final Callable<T> callable, final Component c) {
  81         try {
  82             return LWCToolkit.invokeAndWait(callable, c);
  83         } catch (final Exception e) { e.printStackTrace(); }
  84         return null;
  85     }
  86 
  87     static <T> T invokeAndWait(final Callable<T> callable, final Component c, final T defValue) {
  88         T value = null;
  89         try {
  90             value = LWCToolkit.invokeAndWait(callable, c);
  91         } catch (final Exception e) { e.printStackTrace(); }
  92 
  93         return value != null ? value : defValue;
  94     }
  95 
  96     static void invokeLater(final Runnable runnable, final Component c) {


 685 
 686     // Either gets the immediate children of a, or recursively gets all unignored children of a
 687     private static void _addChildren(final Accessible a, final int whichChildren, final boolean allowIgnored, final ArrayList<Object> childrenAndRoles) {
 688         if (a == null) return;
 689 
 690         final AccessibleContext ac = a.getAccessibleContext();
 691         if (ac == null) return;
 692 
 693         final int numChildren = ac.getAccessibleChildrenCount();
 694 
 695         // each child takes up two entries in the array: itself, and its role
 696         // so the array holds alternating Accessible and AccessibleRole objects
 697         for (int i = 0; i < numChildren; i++) {
 698             final Accessible child = ac.getAccessibleChild(i);
 699             if (child == null) continue;
 700 
 701             final AccessibleContext context = child.getAccessibleContext();
 702             if (context == null) continue;
 703 
 704             if (whichChildren == JAVA_AX_VISIBLE_CHILDREN) {
 705                 if (!context.getAccessibleComponent().isVisible()) continue;



 706             } else if (whichChildren == JAVA_AX_SELECTED_CHILDREN) {
 707                 if (!ac.getAccessibleSelection().isAccessibleChildSelected(i)) continue;



 708             }
 709 
 710             if (!allowIgnored) {
 711                 final AccessibleRole role = context.getAccessibleRole();
 712                 if (role != null && ignoredRoles != null && ignoredRoles.contains(roleKey(role))) {
 713                     // Get the child's unignored children.
 714                     _addChildren(child, whichChildren, false, childrenAndRoles);
 715                 } else {
 716                     childrenAndRoles.add(child);
 717                     childrenAndRoles.add(getAccessibleRole(child));
 718                 }
 719             } else {
 720                 childrenAndRoles.add(child);
 721                 childrenAndRoles.add(getAccessibleRole(child));
 722             }
 723 
 724             // If there is an index, and we are beyond it, time to finish up
 725             if ((whichChildren >= 0) && (childrenAndRoles.size() / 2) >= (whichChildren + 1)) {
 726                 return;
 727             }




  54     static CAccessibility sAccessibility;
  55     static synchronized CAccessibility getAccessibility(final String[] roles) {
  56         if (sAccessibility != null) return sAccessibility;
  57         sAccessibility = new CAccessibility();
  58 
  59         if (roles != null) {
  60             ignoredRoles = new HashSet<String>(roles.length);
  61             for (final String role : roles) ignoredRoles.add(role);
  62         } else {
  63             ignoredRoles = new HashSet<String>();
  64         }
  65 
  66         return sAccessibility;
  67     }
  68 
  69     private CAccessibility() {
  70         KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", this);
  71     }
  72 
  73     public void propertyChange(final PropertyChangeEvent evt) {
  74         Object newValue = evt.getNewValue();
  75         if (newValue == null) return;
  76         // Don't post focus on things that don't matter, i.e. alert, colorchooser,
  77         // desktoppane, dialog, directorypane, filechooser, filler, fontchoose,
  78         // frame, glasspane, layeredpane, optionpane, panel, rootpane, separator,
  79         // tooltip, viewport, window.
  80         // List taken from initializeRoles() in JavaComponentUtilities.m.
  81         if (newValue instanceof Accessible) {
  82             AccessibleContext nvAC = ((Accessible) newValue).getAccessibleContext();
  83             AccessibleRole nvRole = nvAC.getAccessibleRole();
  84             if (!ignoredRoles.contains(roleKey(nvRole))) {
  85                 focusChanged();
  86             }
  87         }
  88     }
  89 
  90     private native void focusChanged();
  91 
  92     static <T> T invokeAndWait(final Callable<T> callable, final Component c) {
  93         try {
  94             return LWCToolkit.invokeAndWait(callable, c);
  95         } catch (final Exception e) { e.printStackTrace(); }
  96         return null;
  97     }
  98 
  99     static <T> T invokeAndWait(final Callable<T> callable, final Component c, final T defValue) {
 100         T value = null;
 101         try {
 102             value = LWCToolkit.invokeAndWait(callable, c);
 103         } catch (final Exception e) { e.printStackTrace(); }
 104 
 105         return value != null ? value : defValue;
 106     }
 107 
 108     static void invokeLater(final Runnable runnable, final Component c) {


 697 
 698     // Either gets the immediate children of a, or recursively gets all unignored children of a
 699     private static void _addChildren(final Accessible a, final int whichChildren, final boolean allowIgnored, final ArrayList<Object> childrenAndRoles) {
 700         if (a == null) return;
 701 
 702         final AccessibleContext ac = a.getAccessibleContext();
 703         if (ac == null) return;
 704 
 705         final int numChildren = ac.getAccessibleChildrenCount();
 706 
 707         // each child takes up two entries in the array: itself, and its role
 708         // so the array holds alternating Accessible and AccessibleRole objects
 709         for (int i = 0; i < numChildren; i++) {
 710             final Accessible child = ac.getAccessibleChild(i);
 711             if (child == null) continue;
 712 
 713             final AccessibleContext context = child.getAccessibleContext();
 714             if (context == null) continue;
 715 
 716             if (whichChildren == JAVA_AX_VISIBLE_CHILDREN) {
 717                 AccessibleComponent acomp = context.getAccessibleComponent();
 718                 if (acomp == null || !acomp.isVisible()) {
 719                     continue;
 720                 }
 721             } else if (whichChildren == JAVA_AX_SELECTED_CHILDREN) {
 722                 AccessibleSelection sel = ac.getAccessibleSelection();
 723                 if (sel == null || !sel.isAccessibleChildSelected(i)) {
 724                     continue;
 725                 }
 726             }
 727 
 728             if (!allowIgnored) {
 729                 final AccessibleRole role = context.getAccessibleRole();
 730                 if (role != null && ignoredRoles != null && ignoredRoles.contains(roleKey(role))) {
 731                     // Get the child's unignored children.
 732                     _addChildren(child, whichChildren, false, childrenAndRoles);
 733                 } else {
 734                     childrenAndRoles.add(child);
 735                     childrenAndRoles.add(getAccessibleRole(child));
 736                 }
 737             } else {
 738                 childrenAndRoles.add(child);
 739                 childrenAndRoles.add(getAccessibleRole(child));
 740             }
 741 
 742             // If there is an index, and we are beyond it, time to finish up
 743             if ((whichChildren >= 0) && (childrenAndRoles.size() / 2) >= (whichChildren + 1)) {
 744                 return;
 745             }