Search in sources :

Example 1 with AccessibleValueEvent

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

the class AccessibleValueExample method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Accessible Value Example");
    final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
    canvas.addPaintListener(e -> {
        Rectangle rect = canvas.getClientArea();
        String val = String.valueOf(value);
        Point size = e.gc.stringExtent(val);
        e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_LIST_SELECTION));
        e.gc.fillRectangle(0, 0, rect.width * value / (max - min), rect.height);
        e.gc.drawString(val, rect.x + (rect.width - size.x) / 2, rect.y + (rect.height - size.y) / 2, true);
    });
    Accessible accessible = canvas.getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {

        @Override
        public void getName(AccessibleEvent e) {
            e.result = "The value of this canvas is " + value;
        }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {

        @Override
        public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_PROGRESSBAR;
        }
    });
    accessible.addAccessibleValueListener(new AccessibleValueAdapter() {

        @Override
        public void setCurrentValue(AccessibleValueEvent e) {
            value = e.value.intValue();
            canvas.redraw();
        }

        @Override
        public void getMinimumValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(min);
        }

        @Override
        public void getMaximumValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(max);
        }

        @Override
        public void getCurrentValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(value);
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : AccessibleValueEvent(org.eclipse.swt.accessibility.AccessibleValueEvent) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleControlAdapter(org.eclipse.swt.accessibility.AccessibleControlAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) AccessibleValueAdapter(org.eclipse.swt.accessibility.AccessibleValueAdapter) Display(org.eclipse.swt.widgets.Display) Accessible(org.eclipse.swt.accessibility.Accessible)

Aggregations

Accessible (org.eclipse.swt.accessibility.Accessible)1 AccessibleAdapter (org.eclipse.swt.accessibility.AccessibleAdapter)1 AccessibleControlAdapter (org.eclipse.swt.accessibility.AccessibleControlAdapter)1 AccessibleControlEvent (org.eclipse.swt.accessibility.AccessibleControlEvent)1 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)1 AccessibleValueAdapter (org.eclipse.swt.accessibility.AccessibleValueAdapter)1 AccessibleValueEvent (org.eclipse.swt.accessibility.AccessibleValueEvent)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Canvas (org.eclipse.swt.widgets.Canvas)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1