Beispiel #1
0
    /*
     * Fires AccessibleActiveDescendant PropertyChangeEvent to notify listeners
     * on the popup menu invoker that a popup list item has been selected
     */
    private void fireActiveDescendant() {
      if (JPopupMenu.this instanceof BasicComboPopup) {
        // get the popup list
        JList popupList = ((BasicComboPopup) JPopupMenu.this).getList();
        if (popupList == null) {
          return;
        }

        // get the first selected item
        AccessibleContext ac = popupList.getAccessibleContext();
        AccessibleSelection selection = ac.getAccessibleSelection();
        if (selection == null) {
          return;
        }
        Accessible a = selection.getAccessibleSelection(0);
        if (a == null) {
          return;
        }
        AccessibleContext selectedItem = a.getAccessibleContext();

        // fire the event with the popup invoker as the source.
        if (selectedItem != null && invoker != null) {
          AccessibleContext invokerContext = invoker.getAccessibleContext();
          if (invokerContext != null) {
            // Check invokerContext because Component.getAccessibleContext
            // returns null. Classes that extend Component are responsible
            // for returning a non-null AccessibleContext.
            invokerContext.firePropertyChange(
                ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, null, selectedItem);
          }
        }
      }
    }
  void initAccessible() {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(
        new AccessibleAdapter() {
          @Override
          public void getName(AccessibleEvent e) {
            e.result = parse(text);
          }
        });

    accessible.addAccessibleControlListener(
        new AccessibleControlAdapter() {
          @Override
          public void getChildAtPoint(AccessibleControlEvent e) {
            e.childID = ACC.CHILDID_SELF;
          }

          @Override
          public void getLocation(AccessibleControlEvent e) {
            Rectangle rect = display.map(getParent(), null, getBounds());
            e.x = rect.x;
            e.y = rect.y;
            e.width = rect.width;
            e.height = rect.height;
          }

          @Override
          public void getChildCount(AccessibleControlEvent e) {
            e.detail = 0;
          }

          @Override
          public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_LINK;
          }

          @Override
          public void getState(AccessibleControlEvent e) {
            e.detail = ACC.STATE_FOCUSABLE;
            if (hasFocus()) e.detail |= ACC.STATE_FOCUSED;
          }

          @Override
          public void getDefaultAction(AccessibleControlEvent e) {
            e.result = SWT.getMessage("SWT_Press"); // $NON-NLS-1$
          }

          @Override
          public void getSelection(AccessibleControlEvent e) {
            if (hasFocus()) e.childID = ACC.CHILDID_SELF;
          }

          @Override
          public void getFocus(AccessibleControlEvent e) {
            if (hasFocus()) e.childID = ACC.CHILDID_SELF;
          }
        });
  }
Beispiel #3
0
  private void initAccessible() {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(
        new AccessibleAdapter() {
          public void getName(AccessibleEvent e) {
            e.result = getText();
          }

          public void getHelp(AccessibleEvent e) {
            e.result = getToolTipText();
          }

          public void getKeyboardShortcut(AccessibleEvent e) {
            char mnemonic = _findMnemonic(CLabel.this.text);
            if (mnemonic != '\0') {
              e.result = "Alt+" + mnemonic; // $NON-NLS-1$
            }
          }
        });

    accessible.addAccessibleControlListener(
        new AccessibleControlAdapter() {
          public void getChildAtPoint(AccessibleControlEvent e) {
            e.childID = ACC.CHILDID_SELF;
          }

          public void getLocation(AccessibleControlEvent e) {
            Rectangle rect = getDisplay().map(getParent(), null, getBounds());
            e.x = rect.x;
            e.y = rect.y;
            e.width = rect.width;
            e.height = rect.height;
          }

          public void getChildCount(AccessibleControlEvent e) {
            e.detail = 0;
          }

          public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_LABEL;
          }

          public void getState(AccessibleControlEvent e) {
            e.detail = ACC.STATE_READONLY;
          }
        });
  }
  public TableAccessibleDelegate(Accessible accessible) {
    tableAccessible = accessible;

    tableAccessible.addAccessibleControlListener(
        new AccessibleControlAdapter() {
          @Override
          public void getChildCount(AccessibleControlEvent e) {
            /* Return the number of row and column children.
             * If the CTable2 is being used as a list (i.e. if columns.length == 0) then add 1 column child.
             * If there is a column header (i.e. if columns.length > 0) then add 1 "column header" child.
             */
            e.detail = childColumnToIdMap.size() + childRowToIdMap.size();
            if (childColumnToIdMap.size() > 1) e.detail++;
          }

          @Override
          public void getChildren(AccessibleControlEvent e) {
            int childCount = childColumnToIdMap.size() + childRowToIdMap.size();
            if (childColumnToIdMap.size() > 1) childCount++;
            Accessible[] children = new Accessible[childCount];
            int childIndex = 0;

            Iterator iter = childRowToIdMap.values().iterator();
            while (iter.hasNext()) {
              AccessibleTableRow row = (AccessibleTableRow) iter.next();
              children[childIndex++] = row;
            }

            iter = childColumnToIdMap.values().iterator();
            while (iter.hasNext()) {
              AccessibleTableColumn col = (AccessibleTableColumn) iter.next();
              children[childIndex++] = col;
            }

            if (childColumnToIdMap.size() > 1) children[childIndex] = headerAccessible();

            e.children = children;
          }

          @Override
          public void getChildAtPoint(AccessibleControlEvent e) {
            NSPoint testPoint = new NSPoint();
            testPoint.x = e.x;
            Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor();
            testPoint.y = primaryMonitor.getBounds().height - e.y;

            Iterator iter = childRowToIdMap.values().iterator();

            while (iter.hasNext()) {
              AccessibleTableRow row = (AccessibleTableRow) iter.next();
              NSValue locationValue = new NSValue(row.getPositionAttribute(ACC.CHILDID_SELF).id);
              NSPoint location = locationValue.pointValue();

              NSValue sizeValue = new NSValue(row.getSizeAttribute(ACC.CHILDID_SELF));
              NSSize size = sizeValue.sizeValue();

              if (location.y < testPoint.y && testPoint.y < (location.y + size.height)) {
                AccessibleControlEvent e2 = new AccessibleControlEvent(e.getSource());
                e2.x = (int) testPoint.x;
                e2.y = (int) testPoint.y;
                row.getChildAtPoint(e);
                break;
              }
            }
          }

          @Override
          public void getState(AccessibleControlEvent e) {
            int state = ACC.STATE_NORMAL | ACC.STATE_FOCUSABLE | ACC.STATE_SELECTABLE;

            AccessibleTableEvent event = new AccessibleTableEvent(this);
            for (int i = 0; i < tableAccessible.accessibleTableListeners.size(); i++) {
              AccessibleTableListener listener = tableAccessible.accessibleTableListeners.get(i);
              listener.getSelectedRows(event);
            }

            if (event.selected != null) {
              int[] selected = event.selected;

              for (int i = 0; i < selected.length; i++) {
                if (selected[i] == tableAccessible.index) {
                  state |= ACC.STATE_SELECTED;
                  break;
                }
              }
            }

            NSNumber focusedObject =
                (NSNumber) tableAccessible.getFocusedAttribute(ACC.CHILDID_SELF);
            if (focusedObject.boolValue()) {
              state |= ACC.STATE_FOCUSED;
            }

            e.detail = state;
          }
        });

    tableAccessible.addAccessibleTableListener(
        new AccessibleTableAdapter() {
          @Override
          public void getColumnCount(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);

            for (int i = 0; i < tableAccessible.accessibleTableListeners.size(); i++) {
              AccessibleTableListener listener = tableAccessible.accessibleTableListeners.get(i);
              if (listener != this) listener.getColumnCount(event);
            }

            e.count = event.count;
          }

          @Override
          public void getColumn(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);
            getColumns(event);
            e.accessible = event.accessibles[e.column];
          }

          @Override
          public void getColumns(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);
            getColumnCount(event);

            // This happens if the table listeners just report back a column count but don't have
            // distinct objects for each of the column.
            // When that happens we need to make 'fake' accessibles that represent the rows.
            if (event.count != childColumnToIdMap.size()) {
              childColumnToIdMap.clear();
            }

            Accessible[] columns = new Accessible[event.count];

            for (int i = 0; i < event.count; i++) {
              columns[i] = childColumnToOs(i);
            }

            int columnCount = childColumnToIdMap.size() > 0 ? childColumnToIdMap.size() : 1;
            Accessible[] accessibles = new Accessible[columnCount];
            for (int i = 0; i < columnCount; i++) {
              accessibles[i] = (Accessible) childColumnToIdMap.get(Integer.valueOf(i));
            }
            e.accessibles = accessibles;
          }

          @Override
          public void getColumnHeader(AccessibleTableEvent e) {
            e.accessible = (childColumnToIdMap.size() > 1 ? headerAccessible() : null);
          }

          @Override
          public void getRowCount(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);

            for (int i = 0; i < tableAccessible.accessibleTableListeners.size(); i++) {
              AccessibleTableListener listener = tableAccessible.accessibleTableListeners.get(i);
              if (listener != this) listener.getRowCount(event);
            }

            e.count = event.count;
          }

          @Override
          public void getRow(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);
            getRows(event);
            e.accessible = event.accessibles[e.row];
          }

          @Override
          public void getRows(AccessibleTableEvent e) {
            AccessibleTableEvent event = new AccessibleTableEvent(this);
            getRowCount(event);

            // This happens if the table listeners just report back a column count but don't have
            // distinct objects for each of the column.
            // When that happens we need to make 'fake' accessibles that represent the rows.
            if (event.count != childRowToIdMap.size()) {
              childRowToIdMap.clear();
            }

            Accessible[] rows = new Accessible[event.count];

            for (int i = 0; i < event.count; i++) {
              rows[i] = childRowToOs(i);
            }

            int columnCount = childRowToIdMap.size() > 0 ? childRowToIdMap.size() : 1;
            Accessible[] accessibles = new Accessible[columnCount];
            for (int i = 0; i < columnCount; i++) {
              accessibles[i] = (Accessible) childRowToIdMap.get(Integer.valueOf(i));
            }
            e.accessibles = accessibles;
          }
        });
  }