Example usage for org.eclipse.swt.widgets Display getSystemColor

List of usage examples for org.eclipse.swt.widgets Display getSystemColor

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display getSystemColor.

Prototype

@Override
    public Color getSystemColor(int id) 

Source Link

Usage

From source file:org.eclipse.swt.examples.accessibility.Shape.java

void addListeners() {
    addPaintListener(e -> {//from  w ww.  j  a v a 2  s  .  c om
        GC gc = e.gc;
        Display display = getDisplay();
        Color c = display.getSystemColor(color);
        gc.setBackground(c);
        Rectangle rect = getClientArea();
        int length = Math.min(rect.width, rect.height);
        if (shape == CIRCLE) {
            gc.fillOval(0, 0, length, length);
        } else {
            gc.fillRectangle(0, 0, length, length);
        }
        if (isFocusControl())
            gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
    });

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            redraw();
        }

        @Override
        public void focusLost(FocusEvent e) {
            redraw();
        }
    });

    addMouseListener(MouseListener.mouseDownAdapter(e -> {
        if (getClientArea().contains(e.x, e.y)) {
            setFocus();
        }
    }));

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            // key listener enables traversal out
        }
    });

    addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS:
            e.doit = true;
            break;
        }
    });

    getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            MessageFormat formatter = new MessageFormat("");
            formatter.applyPattern(bundle.getString("name")); //$NON_NLS$
            String colorName = bundle.getString("color" + color); //$NON_NLS$
            String shapeName = bundle.getString("shape" + shape); //$NON_NLS$
            e.result = formatter.format(new String[] { colorName, shapeName }); //$NON_NLS$
        }
    });

    getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
        @Override
        public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_GRAPHIC;
        }

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

From source file:SyntaxTest.java

/**
 * Runs the application/* w w w  .  j ava  2  s.co m*/
 */
public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);

    // Get color for style ranges
    red = display.getSystemColor(SWT.COLOR_RED);

    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    // No need to dispose red

    display.dispose();
}

From source file:KalendarDialog.java

public Object open() {
    Shell parent = getParent();//from ww w.j  a  v a  2  s.c om
    display = Display.getDefault();
    shell = new Shell(parent, SWT.TITLE | SWT.PRIMARY_MODAL);
    shell.setText("Calendar ver0.02");
    shell.setSize(230, 220);

    gridLayout = new GridLayout();
    gridLayout.numColumns = 7;
    shell.setLayout(gridLayout);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    yearUp = new Button(shell, SWT.PUSH | SWT.FLAT);
    yearUp.setText("<");
    yearUp.setLayoutData(gridData);
    yearUp.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            previousYear();
        }
    });

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    monthUp = new Button(shell, SWT.PUSH | SWT.FLAT);
    monthUp.setText("<<");
    monthUp.setLayoutData(gridData);
    monthUp.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            previousMonth();
        }
    });

    nowLabel = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    nowLabel.setLayoutData(gridData);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
    nowLabel.setText(formatter.format(new Date()));

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    monthNext = new Button(shell, SWT.PUSH | SWT.FLAT);
    monthNext.setText(">>");
    monthNext.setLayoutData(gridData);
    monthNext.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            nextMonth();
        }
    });

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    yearNext = new Button(shell, SWT.PUSH | SWT.FLAT);
    yearNext.setText(">");
    yearNext.setLayoutData(gridData);
    yearNext.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            nextYear();
        }
    });

    sunday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    sunday.setLayoutData(gridData);
    sunday.setText("Sun");

    monday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    monday.setLayoutData(gridData);
    monday.setText("Mon");

    tuesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    tuesday.setLayoutData(gridData);
    tuesday.setText("Tue");

    wednesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    wednesday.setLayoutData(gridData);
    wednesday.setText("Wed");

    thursday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    thursday.setLayoutData(gridData);
    thursday.setText("Thu");

    friday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    friday.setLayoutData(gridData);
    friday.setText("Fri");

    saturday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    saturday.setLayoutData(gridData);
    saturday.setText("Sat");

    for (int i = 0; i < 42; i++) {
        days[i] = new CLabel(shell, SWT.FLAT | SWT.CENTER);
        gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
        days[i].setLayoutData(gridData);
        days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        days[i].addMouseListener(this);
        days[i].setToolTipText("double click get current date.");
    }

    Calendar now = Calendar.getInstance(); //
    nowDate = new Date(now.getTimeInMillis());
    setDayForDisplay(now);

    shell.open();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return selectedDate;
}

From source file:GraphicsExample.java

public void paint(GC gc, int width, int height) {
    Display display = Display.getCurrent();
    gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.fillOval((width - size) / 2, (height - size) / 2, size, size);
}

From source file:org.eclipse.swt.examples.graphics.GradientDialog.java

/**
 * Creates the controls of the dialog./*ww w. j a va  2s  .  co m*/
 * */
public void createDialogControls(final Shell parent) {
    final Display display = parent.getDisplay();

    // message
    Label message = new Label(parent, SWT.NONE);
    message.setText(GraphicsExample.getResourceString("GradientDlgMsg"));
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    message.setLayoutData(gridData);

    // default colors are white and black
    if (rgb1 == null || rgb2 == null) {
        rgb1 = display.getSystemColor(SWT.COLOR_WHITE).getRGB();
        rgb2 = display.getSystemColor(SWT.COLOR_BLACK).getRGB();
    }

    // canvas
    canvas = new Canvas(parent, SWT.NONE);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 200;
    gridData.heightHint = 100;
    canvas.setLayoutData(gridData);
    canvas.addListener(SWT.Paint, e -> {
        Image preview = null;
        Point size = canvas.getSize();
        Color color1 = new Color(display, rgb1);
        Color color2 = new Color(display, rgb2);
        preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y);
        if (preview != null) {
            e.gc.drawImage(preview, 0, 0);
        }
        preview.dispose();
        color1.dispose();
        color2.dispose();
    });

    // composite used for both color buttons
    Composite colorButtonComp = new Composite(parent, SWT.NONE);

    // layout buttons
    RowLayout layout = new RowLayout();
    layout.type = SWT.VERTICAL;
    layout.pack = false;
    colorButtonComp.setLayout(layout);

    // position composite
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    colorButtonComp.setLayoutData(gridData);

    ColorMenu colorMenu = new ColorMenu();

    // color controls: first color
    colorButton1 = new Button(colorButtonComp, SWT.PUSH);
    colorButton1.setText(GraphicsExample.getResourceString("GradientDlgButton1"));
    Color color1 = new Color(display, rgb1);
    Image img1 = GraphicsExample.createImage(display, color1);
    color1.dispose();
    colorButton1.setImage(img1);
    resources.add(img1);
    menu1 = colorMenu.createMenu(parent.getParent(), gb -> {
        rgb1 = gb.getBgColor1().getRGB();
        colorButton1.setImage(gb.getThumbNail());
        if (canvas != null)
            canvas.redraw();
    });
    colorButton1.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu1.setLocation(point.x, point.y + bounds.height);
        menu1.setVisible(true);
    });

    // color controls: second color
    colorButton2 = new Button(colorButtonComp, SWT.PUSH);
    colorButton2.setText(GraphicsExample.getResourceString("GradientDlgButton2"));
    Color color2 = new Color(display, rgb2);
    Image img2 = GraphicsExample.createImage(display, color2);
    color2.dispose();
    colorButton2.setImage(img2);
    resources.add(img2);
    menu2 = colorMenu.createMenu(parent.getParent(), gb -> {
        rgb2 = gb.getBgColor1().getRGB();
        colorButton2.setImage(gb.getThumbNail());
        if (canvas != null)
            canvas.redraw();
    });
    colorButton2.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu2.setLocation(point.x, point.y + bounds.height);
        menu2.setVisible(true);
    });

    // composite used for ok and cancel buttons
    Composite okCancelComp = new Composite(parent, SWT.NONE);

    // layout buttons
    RowLayout rowLayout = new RowLayout();
    rowLayout.pack = false;
    rowLayout.marginTop = 5;
    okCancelComp.setLayout(rowLayout);

    // position composite
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = 2;
    okCancelComp.setLayoutData(gridData);

    // OK button
    okButton = new Button(okCancelComp, SWT.PUSH);
    okButton.setText("&OK");
    okButton.addListener(SWT.Selection, event -> {
        returnVal = SWT.OK;
        parent.close();
    });

    // cancel button
    cancelButton = new Button(okCancelComp, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.addListener(SWT.Selection, event -> parent.close());
}

From source file:GraphicsExample.java

public void paint(GC gc, int width, int height) {
    int centerX = width / 2;
    int centerY = height / 2;
    int pos = 0;//w w  w. j  a  v  a 2  s . c om
    for (int i = 0; i < POINTS; ++i) {
        double r = Math.PI * 2 * pos / POINTS;
        radial[i * 2] = (int) ((1 + Math.cos(r)) * centerX);
        radial[i * 2 + 1] = (int) ((1 + Math.sin(r)) * centerY);
        pos = (pos + POINTS / 2) % POINTS;
    }
    Display display = Display.getCurrent();
    gc.setFillRule(fillRuleCb.getSelectionIndex() != 0 ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD);
    gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.fillPolygon(radial);
    gc.drawPolygon(radial);
}

From source file:GraphicsExample.java

Image createImage(Display display, Color color) {
    Image image = new Image(display, 16, 16);
    GC gc = new GC(image);
    gc.setBackground(color);//from   w  w w .  j  av a2  s .com
    Rectangle rect = image.getBounds();
    gc.fillRectangle(rect);
    if (color.equals(display.getSystemColor(SWT.COLOR_BLACK))) {
        gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    }
    gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
    gc.dispose();
    return image;
}

From source file:org.eclipse.swt.examples.graphics.ColorMenu.java

/** Adds the colors items to the menu. */
private void addColorItems(Menu menu, MenuItemListener menuListener, List<Resource> menuResources) {
    Display display = menu.getDisplay();

    if (menu.getItemCount() != 0) {
        new MenuItem(menu, SWT.SEPARATOR);
    }//from   www  .j av a  2s.  c o m

    // color names
    String[] names = new String[] { GraphicsExample.getResourceString("White"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Black"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Red"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Green"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Blue"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Yellow"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Cyan"), //$NON-NLS-1$
    };

    // colors needed for the background menu
    Color[] colors = new Color[] { display.getSystemColor(SWT.COLOR_WHITE),
            display.getSystemColor(SWT.COLOR_BLACK), display.getSystemColor(SWT.COLOR_RED),
            display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_BLUE),
            display.getSystemColor(SWT.COLOR_YELLOW), display.getSystemColor(SWT.COLOR_CYAN), };

    // add standard color items to menu
    for (int i = 0; i < names.length; i++) {
        MenuItem item = new MenuItem(menu, SWT.NONE);
        item.setText(names[i]);
        item.addListener(SWT.Selection, menuListener);
        Color color = colors[i];
        GraphicsBackground gb = new GraphicsBackground();
        Image image = GraphicsExample.createImage(display, color);
        gb.setBgColor1(color);
        gb.setBgImage(image);
        gb.setThumbNail(image);
        menuResources.add(image);
        item.setImage(image);
        item.setData(gb);
    }

    // add custom color item to menu
    menuListener.customColorMI = new MenuItem(menu, SWT.NONE);
    menuListener.customColorMI.setText(GraphicsExample.getResourceString("CustomColor")); //$NON-NLS-1$
    menuListener.customColorMI.addListener(SWT.Selection, menuListener);
    GraphicsBackground gb = new GraphicsBackground();
    menuListener.customColorMI.setData(gb);
}

From source file:org.eclipse.swt.examples.accessibility.BarChart.java

void addListeners() {
    addPaintListener(e -> {//from   ww  w .  j  av  a2s  . c  om
        GC gc = e.gc;
        Rectangle rect = getClientArea();
        Display display = getDisplay();
        int count = data.size();
        Point valueSize = gc.stringExtent(Integer.valueOf(valueMax).toString());
        int leftX = rect.x + 2 * GAP + valueSize.x;
        int bottomY = rect.y + rect.height - 2 * GAP - valueSize.y;
        int unitWidth = (rect.width - 4 * GAP - valueSize.x - AXIS_WIDTH) / count - GAP;
        int unitHeight = (rect.height - 3 * GAP - AXIS_WIDTH - 2 * valueSize.y)
                / ((valueMax - valueMin) / valueIncrement);
        // draw the title
        int titleWidth = gc.stringExtent(title).x;
        int center = (Math.max(titleWidth, count * (unitWidth + GAP) + GAP) - titleWidth) / 2;
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
        gc.drawString(title, leftX + AXIS_WIDTH + center, rect.y + GAP);
        // draw the y axis and value labels
        gc.setLineWidth(AXIS_WIDTH);
        gc.drawLine(leftX, rect.y + GAP + valueSize.y, leftX, bottomY);
        for (int i1 = valueMin; i1 <= valueMax; i1 += valueIncrement) {
            int y = bottomY - i1 * unitHeight;
            gc.drawLine(leftX, y, leftX - GAP, y);
            gc.drawString(Integer.valueOf(i1).toString(), rect.x + GAP, y - valueSize.y);
        }
        // draw the x axis and item labels
        gc.drawLine(leftX, bottomY, rect.x + rect.width - GAP, bottomY);
        for (int i2 = 0; i2 < count; i2++) {
            Object[] dataItem1 = data.get(i2);
            String itemLabel = (String) dataItem1[0];
            int x1 = leftX + AXIS_WIDTH + GAP + i2 * (unitWidth + GAP);
            gc.drawString(itemLabel, x1, bottomY + GAP);
        }
        // draw the bars
        gc.setBackground(display.getSystemColor(color));
        for (int i3 = 0; i3 < count; i3++) {
            Object[] dataItem2 = data.get(i3);
            int itemValue1 = ((Integer) dataItem2[1]).intValue();
            int x2 = leftX + AXIS_WIDTH + GAP + i3 * (unitWidth + GAP);
            gc.fillRectangle(x2, bottomY - AXIS_WIDTH - itemValue1 * unitHeight, unitWidth,
                    itemValue1 * unitHeight);
        }
        if (isFocusControl()) {
            if (selectedItem == -1) {
                // draw the focus rectangle around the whole bar chart
                gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
            } else {
                // draw the focus rectangle around the selected item
                Object[] dataItem3 = data.get(selectedItem);
                int itemValue2 = ((Integer) dataItem3[1]).intValue();
                int x3 = leftX + AXIS_WIDTH + GAP + selectedItem * (unitWidth + GAP);
                gc.drawFocus(x3, bottomY - itemValue2 * unitHeight - AXIS_WIDTH, unitWidth,
                        itemValue2 * unitHeight + AXIS_WIDTH + GAP + valueSize.y);
            }
        }
    });

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            redraw();
        }

        @Override
        public void focusLost(FocusEvent e) {
            redraw();
        }
    });

    addMouseListener(MouseListener.mouseDownAdapter(e -> {
        if (getClientArea().contains(e.x, e.y)) {
            setFocus();
            int item = -1;
            int count = data.size();
            for (int i = 0; i < count; i++) {
                if (itemBounds(i).contains(e.x, e.y)) {
                    item = i;
                    break;
                }
            }
            if (item != selectedItem) {
                selectedItem = item;
                redraw();
                getAccessible().setFocus(item);
                getAccessible().selectionChanged();
            }
        }
    }));

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            boolean change = false;
            switch (e.keyCode) {
            case SWT.ARROW_DOWN:
            case SWT.ARROW_RIGHT:
                selectedItem++;
                if (selectedItem >= data.size())
                    selectedItem = 0;
                change = true;
                break;
            case SWT.ARROW_UP:
            case SWT.ARROW_LEFT:
                selectedItem--;
                if (selectedItem <= -1)
                    selectedItem = data.size() - 1;
                change = true;
                break;
            case SWT.HOME:
                selectedItem = 0;
                change = true;
                break;
            case SWT.END:
                selectedItem = data.size() - 1;
                change = true;
                break;
            }
            if (change) {
                redraw();
                getAccessible().setFocus(selectedItem);
                getAccessible().selectionChanged();
            }
        }
    });

    addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS:
            e.doit = true;
            break;
        }
    });

    getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            MessageFormat formatter = new MessageFormat(""); //$NON_NLS$
            formatter.applyPattern(bundle.getString("name")); //$NON_NLS$
            int childID = e.childID;
            if (childID == ACC.CHILDID_SELF) {
                e.result = title;
            } else {
                Object[] item = data.get(childID);
                e.result = formatter.format(item);
            }
        }

        @Override
        public void getDescription(AccessibleEvent e) {
            int childID = e.childID;
            if (childID != ACC.CHILDID_SELF) {
                Object[] item = data.get(childID);
                String value = item[1].toString();
                String colorName = bundle.getString("color" + color); //$NON_NLS$
                MessageFormat formatter = new MessageFormat(""); //$NON_NLS$
                formatter.applyPattern(bundle.getString("color_value")); //$NON_NLS$
                e.result = formatter.format(new String[] { colorName, value });
            }
        }
    });

    getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
        @Override
        public void getRole(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                e.detail = ACC.ROLE_LIST;
            } else {
                e.detail = ACC.ROLE_LISTITEM;
            }
        }

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

        @Override
        public void getChildren(AccessibleControlEvent e) {
            int count = data.size();
            Object[] children = new Object[count];
            for (int i = 0; i < count; i++) {
                children[i] = Integer.valueOf(i);
            }
            e.children = children;
        }

        @Override
        public void getChildAtPoint(AccessibleControlEvent e) {
            Point testPoint = toControl(e.x, e.y);
            int childID = ACC.CHILDID_NONE;
            if (getClientArea().contains(testPoint)) {
                childID = ACC.CHILDID_SELF;
                int count = data.size();
                for (int i = 0; i < count; i++) {
                    if (itemBounds(i).contains(testPoint)) {
                        childID = i;
                        break;
                    }
                }
            }
            e.childID = childID;
        }

        @Override
        public void getLocation(AccessibleControlEvent e) {
            Rectangle location = null;
            Point pt = null;
            int childID = e.childID;
            if (childID == ACC.CHILDID_SELF) {
                location = getClientArea();
                pt = getParent().toDisplay(location.x, location.y);
            } else {
                location = itemBounds(childID);
                pt = toDisplay(location.x, location.y);
            }
            e.x = pt.x;
            e.y = pt.y;
            e.width = location.width;
            e.height = location.height;
        }

        @Override
        public void getFocus(AccessibleControlEvent e) {
            int childID = ACC.CHILDID_NONE;
            if (isFocusControl()) {
                if (selectedItem == -1) {
                    childID = ACC.CHILDID_SELF;
                } else {
                    childID = selectedItem;
                }
            }
            e.childID = childID;

        }

        @Override
        public void getSelection(AccessibleControlEvent e) {
            e.childID = (selectedItem == -1) ? ACC.CHILDID_NONE : selectedItem;
        }

        @Override
        public void getValue(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID != ACC.CHILDID_SELF) {
                Object[] dataItem = data.get(childID);
                e.result = ((Integer) dataItem[1]).toString();
            }
        }

        @Override
        public void getState(AccessibleControlEvent e) {
            int childID = e.childID;
            e.detail = ACC.STATE_FOCUSABLE;
            if (isFocusControl())
                e.detail |= ACC.STATE_FOCUSED;
            if (childID != ACC.CHILDID_SELF) {
                e.detail |= ACC.STATE_SELECTABLE;
                if (childID == selectedItem)
                    e.detail |= ACC.STATE_SELECTED;
            }
        }
    });
}

From source file:org.eclipse.swt.examples.graphics.AdvancedGraphics.java

public Shell open(final Display display) {
    final Shell shell = new Shell(display);
    shell.setText(RESOURCE_BUNDLE.getString("AdvancedGraphics")); //$NON-NLS-1$
    try {//from ww  w  . ja v a  2 s  . c  o m
        Path path = new Path(display);
        path.dispose();
    } catch (SWTException e) {
        MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
        dialog.setText(RESOURCE_BUNDLE.getString("Warning")); //$NON-NLS-1$
        dialog.setMessage(RESOURCE_BUNDLE.getString("LibNotFound")); //$NON-NLS-1$
        dialog.open();
        shell.dispose();
        return null;
    }
    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC);
    final Image image = loadImage(display, AdvancedGraphics.class, "irmaos.jpg");
    final Rectangle rect = image.getBounds();
    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Transform tr = new Transform(display);
        tr.translate(rect.width / 4, rect.height / 2);
        tr.rotate(-30);
        if (image != null) {
            gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height);
        }
        gc.setAlpha(100);
        gc.setTransform(tr);
        Path path = new Path(display);
        path.addString("SWT", 0, 0, font);
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillPath(path);
        gc.drawPath(path);
        tr.dispose();
        path.dispose();
    });
    shell.setSize(shell.computeSize(rect.width, rect.height));
    shell.open();
    shell.addListener(SWT.Dispose, event -> {
        if (image != null)
            image.dispose();
        font.dispose();
    });
    return shell;
}