Search in sources :

Example 6 with Accessible

use of org.eclipse.swt.accessibility.Accessible in project dbeaver by serge-rider.

the class Spreadsheet method hookAccessibility.

// //////////////////////////////////////////////////////////
// Accessibility support
private void hookAccessibility() {
    final Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new GridAccessibleListener());
    addCursorChangeListener(event -> accessible.selectionChanged());
}
Also used : Accessible(org.eclipse.swt.accessibility.Accessible)

Example 7 with Accessible

use of org.eclipse.swt.accessibility.Accessible in project translationstudio8 by heartsome.

the class Grid method initAccessible.

/**
     * Initialize accessibility.
     */
private void initAccessible() {
    final Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {

        public void getDescription(AccessibleEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                String descrption = "";
                for (int i = 0; i < columns.size(); i++) {
                    if (i != 0) {
                        descrption += ((GridColumn) columns.get(i)).getText() + " : ";
                        descrption += ((GridItem) items.get(childID)).getText(i) + " ";
                    }
                }
                e.result = descrption;
            }
        }

        public void getName(AccessibleEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // Name of the items
                e.result = ((GridItem) items.get(childID)).getText();
            } else if (childID >= items.size() && childID < items.size() + columns.size()) {
                // Name of the column headers
                e.result = ((GridColumn) columns.get(childID - items.size())).getText();
            } else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // Name of the column group headers
                e.result = ((GridColumnGroup) columnGroups[childID - items.size() - columns.size()]).getText();
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // Name of the toggle button for column group headers
                e.result = ACC_TOGGLE_BUTTON_NAME;
            }
        }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {

        public void getChildAtPoint(AccessibleControlEvent e) {
            Point location = toControl(e.x, e.y);
            e.childID = ACC.CHILDID_SELF;
            // Grid Items
            GridItem item = getItem(location);
            if (item != null) {
                for (int i = 0; i < getItems().length; i++) {
                    if (item.equals(getItem(i))) {
                        e.childID = i;
                        return;
                    }
                }
            } else {
                // Column Headers
                GridColumn column = overColumnHeader(location.x, location.y);
                if (column != null) {
                    for (int i = 0; i < getColumns().length; i++) {
                        if (column.equals(getColumn(i))) {
                            e.childID = getItems().length + i;
                            return;
                        }
                    }
                } else {
                    // Column Group headers
                    GridColumnGroup columnGroup = overColumnGroupHeader(location.x, location.y);
                    if (columnGroup != null) {
                        for (int i = 0; i < getColumnGroups().length; i++) {
                            if (columnGroup.equals(getColumnGroup(i))) {
                                Rectangle toggle = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
                                if (toggle.contains(location.x, location.y)) {
                                    // Toggle button for column group
                                    // header
                                    e.childID = getItems().length + getColumns().length + getColumnGroups().length + i;
                                } else {
                                    // Column Group header
                                    e.childID = getItems().length + getColumns().length + i;
                                }
                                return;
                            }
                        }
                    }
                }
            }
        }

        public void getChildCount(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                int length = items.size();
                if (isTree) {
                    // it is consider as children of Grid
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() != null) {
                            length--;
                        }
                    }
                }
                e.detail = length;
            }
        }

        public void getChildren(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                int length = items.size();
                if (isTree) {
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() != null) {
                            length--;
                        }
                    }
                    Object[] children = new Object[length];
                    int j = 0;
                    for (int i = 0; i < items.size(); i++) {
                        if (((GridItem) items.get(i)).getParentItem() == null) {
                            children[j] = new Integer(i);
                            j++;
                        }
                    }
                    e.children = children;
                } else {
                    Object[] children = new Object[length];
                    for (int i = 0; i < items.size(); i++) {
                        children[i] = new Integer(i);
                    }
                    e.children = children;
                }
            }
        }

        public void getDefaultAction(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                if (getItem(childID).hasChildren()) {
                    // Action of tree items
                    if (getItem(childID).isExpanded()) {
                        e.result = ACC_ITEM_ACTION_COLLAPSE;
                    } else {
                        e.result = ACC_ITEM_ACTION_EXPAND;
                    }
                } else {
                    // action of default items
                    e.result = ACC_ITEM_DEFAULT_ACTION;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // action of column and column group header
                e.result = ACC_COLUMN_DEFAULT_ACTION;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // action of toggle button of column group header
                e.result = SWT.getMessage("SWT_Press");
            }
        }

        public void getLocation(AccessibleControlEvent e) {
            // location of parent
            Rectangle location = getBounds();
            location.x = 0;
            location.y = 0;
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // location of items
                GridItem item = getItem(childID);
                if (item != null) {
                    Point p = getOrigin((GridColumn) columns.get(0), item);
                    location.y = p.y;
                    location.height = item.getHeight();
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size()) {
                // location of columns headers
                GridColumn column = getColumn(childID - items.size());
                if (column != null) {
                    location.x = getColumnHeaderXPosition(column);
                    if (column.getColumnGroup() == null) {
                        location.y = 0;
                    } else {
                        location.y = groupHeaderHeight;
                    }
                    location.height = headerHeight;
                    location.width = column.getWidth();
                }
            } else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // location of column group header
                GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size());
                if (columnGroup != null) {
                    location.y = 0;
                    location.height = groupHeaderHeight;
                    location.x = getColumnHeaderXPosition(columnGroup.getFirstVisibleColumn());
                    int width = 0;
                    for (int i = 0; i < columnGroup.getColumns().length; i++) {
                        if (columnGroup.getColumns()[i].isVisible()) {
                            width += columnGroup.getColumns()[i].getWidth();
                        }
                    }
                    location.width = width;
                }
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // location of toggle button of column group header
                GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size() - columnGroups.length);
                location = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
            }
            if (location != null) {
                Point pt = toDisplay(location.x, location.y);
                e.x = pt.x;
                e.y = pt.y;
                e.width = location.width;
                e.height = location.height;
            }
        }

        public void getRole(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // role of items
                if (isTree) {
                    e.detail = ACC.ROLE_TREEITEM;
                } else {
                    e.detail = ACC.ROLE_LISTITEM;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // role of columns headers and column group headers
                e.detail = ACC.ROLE_TABLECOLUMNHEADER;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // role of toggle button of column group headers
                e.detail = ACC.ROLE_PUSHBUTTON;
            } else if (childID == ACC.CHILDID_SELF) {
                // role of parent
                if (isTree) {
                    e.detail = ACC.ROLE_TREE;
                } else {
                    e.detail = ACC.ROLE_TABLE;
                }
            }
        }

        public void getSelection(AccessibleControlEvent e) {
            e.childID = ACC.CHILDID_NONE;
            if (selectedItems.size() == 1) {
                // Single selection
                e.childID = indexOf(((GridItem) selectedItems.get(0)));
            } else if (selectedItems.size() > 1) {
                // multiple selection
                e.childID = ACC.CHILDID_MULTIPLE;
                int length = selectedItems.size();
                Object[] children = new Object[length];
                for (int i = 0; i < length; i++) {
                    GridItem item = (GridItem) selectedItems.get(i);
                    children[i] = new Integer(indexOf(item));
                }
                e.children = children;
            }
        }

        public void getState(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // state of items
                e.detail = ACC.STATE_SELECTABLE;
                if (getDisplay().getActiveShell() == getParent().getShell()) {
                    e.detail |= ACC.STATE_FOCUSABLE;
                }
                if (selectedItems.contains(getItem(childID))) {
                    e.detail |= ACC.STATE_SELECTED;
                    if (getDisplay().getActiveShell() == getParent().getShell()) {
                        e.detail |= ACC.STATE_FOCUSED;
                    }
                }
                if (getItem(childID).getChecked()) {
                    e.detail |= ACC.STATE_CHECKED;
                }
                // only for tree type items
                if (getItem(childID).hasChildren()) {
                    if (getItem(childID).isExpanded()) {
                        e.detail |= ACC.STATE_EXPANDED;
                    } else {
                        e.detail |= ACC.STATE_COLLAPSED;
                    }
                }
                if (!getItem(childID).isVisible()) {
                    e.detail |= ACC.STATE_INVISIBLE;
                }
            } else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
                // state of column headers and column group headers
                e.detail = ACC.STATE_READONLY;
            } else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
                // state of toggle button of column group headers
                if (getColumnGroup(childID - items.size() - columns.size() - columnGroups.length).getExpanded()) {
                    e.detail = ACC.STATE_EXPANDED;
                } else {
                    e.detail = ACC.STATE_COLLAPSED;
                }
            }
        }

        public void getValue(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID >= 0 && childID < items.size()) {
                // value for tree items
                if (isTree) {
                    e.result = "" + getItem(childID).getLevel();
                }
            }
        }
    });
    addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (selectedItems.size() > 0) {
                accessible.setFocus(items.indexOf(selectedItems.get(selectedItems.size() - 1)));
            }
        }
    });
    addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent e) {
            if (getFocusItem() != null) {
                accessible.setFocus(items.indexOf(getFocusItem()));
            }
        }

        public void treeExpanded(TreeEvent e) {
            if (getFocusItem() != null) {
                accessible.setFocus(items.indexOf(getFocusItem()));
            }
        }
    });
}
Also used : TreeListener(org.eclipse.swt.events.TreeListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) TypedListener(org.eclipse.swt.widgets.TypedListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeListener(org.eclipse.swt.events.TreeListener) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleControlAdapter(org.eclipse.swt.accessibility.AccessibleControlAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TreeEvent(org.eclipse.swt.events.TreeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Accessible(org.eclipse.swt.accessibility.Accessible)

Example 8 with Accessible

use of org.eclipse.swt.accessibility.Accessible in project dbeaver by dbeaver.

the class Spreadsheet method hookAccessibility.

// //////////////////////////////////////////////////////////
// Accessibility support
private void hookAccessibility() {
    final Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new GridAccessibleListener());
    addCursorChangeListener(new Listener() {

        @Override
        public void handleEvent(Event event) {
            accessible.selectionChanged();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) AccessibleListener(org.eclipse.swt.accessibility.AccessibleListener) IMenuListener(org.eclipse.jface.action.IMenuListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Accessible(org.eclipse.swt.accessibility.Accessible)

Example 9 with Accessible

use of org.eclipse.swt.accessibility.Accessible in project eclipse.platform.swt by eclipse.

the class CTableColumn method getAccessible.

/* Returns the accessible for the column header. */
Accessible getAccessible(final Accessible accessibleTable) {
    if (accessible == null) {
        accessible = new Accessible(accessibleTable);
        accessible.addAccessibleListener(new AccessibleAdapter() {

            @Override
            public void getName(AccessibleEvent e) {
                e.result = getText();
                System.out.println("tableColumn getName = " + e.result);
            }
        });
        accessible.addAccessibleControlListener(new AccessibleControlAdapter() {

            @Override
            public void getChildAtPoint(AccessibleControlEvent e) {
                Point point = parent.toControl(e.x, e.y);
                int x = getX();
                if (x <= point.x && point.x <= x + getWidth()) {
                    e.childID = ACC.CHILDID_SELF;
                } else {
                    e.childID = ACC.CHILDID_NONE;
                }
            }

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

            @Override
            public void getLocation(AccessibleControlEvent e) {
                Rectangle rect = parent.header.getBounds();
                rect.x = getX();
                Point pt = parent.toDisplay(rect.x, rect.y);
                e.x = pt.x;
                e.y = pt.y;
                e.width = width;
                e.height = rect.height;
            }

            @Override
            public void getRole(AccessibleControlEvent e) {
                e.detail = ACC.ROLE_TABLECELL;
            }
        });
        accessible.addAccessibleTableCellListener(new AccessibleTableCellListener() {

            @Override
            public void getColumnHeaders(AccessibleTableCellEvent e) {
            /* Column header does not have a header. */
            }

            @Override
            public void getColumnIndex(AccessibleTableCellEvent e) {
                e.index = getIndex();
            }

            @Override
            public void getColumnSpan(AccessibleTableCellEvent e) {
                e.count = 1;
            /* CTable cells only occupy one column. */
            }

            @Override
            public void getRowHeaders(AccessibleTableCellEvent e) {
            /* CTable does not support row headers. */
            }

            @Override
            public void getRowIndex(AccessibleTableCellEvent e) {
                e.index = 0;
            }

            @Override
            public void getRowSpan(AccessibleTableCellEvent e) {
                e.count = 1;
            /* CTable cells only occupy one row. */
            }

            @Override
            public void getTable(AccessibleTableCellEvent e) {
                e.accessible = accessibleTable;
            }

            @Override
            public void isSelected(AccessibleTableCellEvent e) {
                e.isSelected = false;
            /* CTable columns cannot be selected (only rows can be selected). */
            }
        });
    }
    return accessible;
}
Also used : AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleControlAdapter(org.eclipse.swt.accessibility.AccessibleControlAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) AccessibleTableCellEvent(org.eclipse.swt.accessibility.AccessibleTableCellEvent) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) AccessibleTableCellListener(org.eclipse.swt.accessibility.AccessibleTableCellListener) Point(org.eclipse.swt.graphics.Point) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Accessible(org.eclipse.swt.accessibility.Accessible)

Example 10 with Accessible

use of org.eclipse.swt.accessibility.Accessible in project eclipse.platform.swt by eclipse.

the class CTableItem method getAccessible.

/* Returns the cell accessible for the specified column index in the receiver. */
Accessible getAccessible(final Accessible accessibleTable, final int columnIndex) {
    if (accessibles[columnIndex] == null) {
        Accessible accessible = new Accessible(accessibleTable);
        accessible.addAccessibleListener(new AccessibleAdapter() {

            @Override
            public void getName(AccessibleEvent e) {
                e.result = getText(columnIndex);
                System.out.println("tableItem getName = " + e.result);
            }
        });
        accessible.addAccessibleControlListener(new AccessibleControlAdapter() {

            @Override
            public void getChild(AccessibleControlEvent e) {
                /* CTable cells do not have children, so just return the index in parent. */
                switch(e.childID) {
                    case ACC.CHILDID_CHILD_INDEX:
                        e.detail = index * Math.max(1, parent.getColumnCount()) + columnIndex + parent.getColumnCount();
                        break;
                }
            }

            @Override
            public void getChildAtPoint(AccessibleControlEvent e) {
                Point point = parent.toControl(e.x, e.y);
                if (getBounds(columnIndex).contains(point)) {
                    e.childID = ACC.CHILDID_SELF;
                } else {
                    e.childID = ACC.CHILDID_NONE;
                }
            }

            @Override
            public void getFocus(AccessibleControlEvent e) {
                e.childID = (parent.focusItem == CTableItem.this && parent.isFocusControl()) ? ACC.CHILDID_SELF : ACC.CHILDID_NONE;
            }

            @Override
            public void getLocation(AccessibleControlEvent e) {
                Rectangle location = getBounds(columnIndex);
                Point pt = parent.toDisplay(location.x, location.y);
                e.x = pt.x;
                e.y = pt.y;
                e.width = location.width;
                e.height = location.height;
            }

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

            @Override
            public void getValue(AccessibleControlEvent e) {
                e.result = getText(columnIndex);
            }
        });
        accessible.addAccessibleTableCellListener(new AccessibleTableCellListener() {

            @Override
            public void getColumnHeaders(AccessibleTableCellEvent e) {
                if (parent.columns.length == 0) {
                    /* The CTable is being used as a list, and there are no headers. */
                    e.accessibles = null;
                } else {
                    /* CTable cells only occupy one column. */
                    CTableColumn column = parent.columns[columnIndex];
                    e.accessibles = new Accessible[] { column.getAccessible(accessibleTable) };
                }
            }

            @Override
            public void getColumnIndex(AccessibleTableCellEvent e) {
                e.index = columnIndex;
            }

            @Override
            public void getColumnSpan(AccessibleTableCellEvent e) {
                /* CTable cells only occupy one column. */
                e.count = 1;
            }

            @Override
            public void getRowHeaders(AccessibleTableCellEvent e) {
            /* CTable does not support row headers. */
            }

            @Override
            public void getRowIndex(AccessibleTableCellEvent e) {
                e.index = index;
            }

            @Override
            public void getRowSpan(AccessibleTableCellEvent e) {
                /* CTable cells only occupy one row. */
                e.count = 1;
            }

            @Override
            public void getTable(AccessibleTableCellEvent e) {
                e.accessible = accessibleTable;
            }

            @Override
            public void isSelected(AccessibleTableCellEvent e) {
                e.isSelected = CTableItem.this.isSelected();
            }
        });
        accessibles[columnIndex] = accessible;
    }
    return accessibles[columnIndex];
}
Also used : AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleControlAdapter(org.eclipse.swt.accessibility.AccessibleControlAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) AccessibleTableCellEvent(org.eclipse.swt.accessibility.AccessibleTableCellEvent) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) AccessibleTableCellListener(org.eclipse.swt.accessibility.AccessibleTableCellListener) Point(org.eclipse.swt.graphics.Point) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Accessible(org.eclipse.swt.accessibility.Accessible)

Aggregations

Accessible (org.eclipse.swt.accessibility.Accessible)13 Point (org.eclipse.swt.graphics.Point)10 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)9 AccessibleAdapter (org.eclipse.swt.accessibility.AccessibleAdapter)8 AccessibleControlAdapter (org.eclipse.swt.accessibility.AccessibleControlAdapter)7 AccessibleControlEvent (org.eclipse.swt.accessibility.AccessibleControlEvent)7 Rectangle (org.eclipse.swt.graphics.Rectangle)7 MouseListener (org.eclipse.swt.events.MouseListener)3 GC (org.eclipse.swt.graphics.GC)3 Image (org.eclipse.swt.graphics.Image)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 Canvas (org.eclipse.swt.widgets.Canvas)3 Display (org.eclipse.swt.widgets.Display)3 Event (org.eclipse.swt.widgets.Event)3 Listener (org.eclipse.swt.widgets.Listener)3 Shell (org.eclipse.swt.widgets.Shell)3 AccessibleTableCellEvent (org.eclipse.swt.accessibility.AccessibleTableCellEvent)2 AccessibleTableCellListener (org.eclipse.swt.accessibility.AccessibleTableCellListener)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)2