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:GraphicsExample.java

public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
        return;//from  w  w w.  j  a v  a2 s. c om
    Display display = Display.getCurrent();
    if (image == null) {
        image = example.loadImage(Display.getCurrent(), "irmaos.jpg");
        Rectangle rect = image.getBounds();
        FontData fd = display.getSystemFont().getFontData()[0];
        font = new Font(display, fd.getName(), rect.height / 4, SWT.BOLD);
        gc.setFont(font);
        Point size = gc.stringExtent(text);
        textWidth = size.x;
        textHeight = size.y;
    }
    Path path = new Path(display);
    path.addString(text, x, y, font);
    gc.setClipping(path);
    Rectangle rect = image.getBounds();
    gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, width, height);
    gc.setClipping((Rectangle) null);
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    gc.drawPath(path);
}

From source file:GraphicsExample.java

void createToolBar(final Composite parent) {
    final Display display = parent.getDisplay();

    toolBar = new ToolBar(parent, SWT.FLAT);
    Listener toolBarListener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Selection: {
                if (event.widget == playItem) {
                    animate = true;// w  ww  .  ja  v a2s  .c o m
                    playItem.setEnabled(!animate);
                    pauseItem.setEnabled(animate);
                } else if (event.widget == pauseItem) {
                    animate = false;
                    playItem.setEnabled(!animate);
                    pauseItem.setEnabled(animate);
                } else if (event.widget == backItem) {
                    final ToolItem toolItem = (ToolItem) event.widget;
                    final ToolBar toolBar = toolItem.getParent();
                    Rectangle toolItemBounds = toolItem.getBounds();
                    Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y));
                    backMenu.setLocation(point.x, point.y + toolItemBounds.height);
                    backMenu.setVisible(true);
                }
            }
                break;
            }
        }
    };

    playItem = new ToolItem(toolBar, SWT.PUSH);
    playItem.setText(getResourceString("Play")); //$NON-NLS-1$
    playItem.setImage(loadImage(display, "play.gif")); //$NON-NLS-1$
    playItem.addListener(SWT.Selection, toolBarListener);

    pauseItem = new ToolItem(toolBar, SWT.PUSH);
    pauseItem.setText(getResourceString("Pause")); //$NON-NLS-1$
    pauseItem.setImage(loadImage(display, "pause.gif")); //$NON-NLS-1$
    pauseItem.addListener(SWT.Selection, toolBarListener);

    backItem = new ToolItem(toolBar, SWT.PUSH);
    backItem.setText(getResourceString("Background")); //$NON-NLS-1$
    backItem.addListener(SWT.Selection, toolBarListener);
    String[] names = new String[] { getResourceString("White"), //$NON-NLS-1$
            getResourceString("Black"), //$NON-NLS-1$
            getResourceString("Red"), //$NON-NLS-1$
            getResourceString("Green"), //$NON-NLS-1$
            getResourceString("Blue"), //$NON-NLS-1$
            getResourceString("CustomColor"), //$NON-NLS-1$
    };
    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), null, };
    backMenu = new Menu(parent);
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            MenuItem item = (MenuItem) event.widget;
            if (customMI == item) {
                ColorDialog dialog = new ColorDialog(parent.getShell());
                RGB rgb = dialog.open();
                if (rgb == null)
                    return;
                if (customColor != null)
                    customColor.dispose();
                customColor = new Color(display, rgb);
                if (customImage != null)
                    customImage.dispose();
                customImage = createImage(display, customColor);
                item.setData(new Object[] { customColor, customImage });
                item.setImage(customImage);
            }
            tabBackground = (Object[]) item.getData();
            backItem.setImage((Image) tabBackground[1]);
            canvas.redraw();
        }
    };
    for (int i = 0; i < names.length; i++) {
        MenuItem item = new MenuItem(backMenu, SWT.NONE);
        item.setText(names[i]);
        item.addListener(SWT.Selection, listener);
        Image image = null;
        if (colors[i] != null) {
            image = createImage(display, colors[i]);
            images.addElement(image);
            item.setImage(image);
        } else {
            // custom menu item
            customMI = item;
        }
        item.setData(new Object[] { colors[i], image });
        if (tabBackground == null) {
            tabBackground = (Object[]) item.getData();
            backItem.setImage((Image) tabBackground[1]);
        }
    }

    dbItem = new ToolItem(toolBar, SWT.CHECK);
    dbItem.setText(getResourceString("DoubleBuffer")); //$NON-NLS-1$
    dbItem.setImage(loadImage(display, "db.gif")); //$NON-NLS-1$

    ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR);
    Composite comp = new Composite(toolBar, SWT.NONE);
    GridData data;
    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 0;
    layout.marginWidth = layout.marginHeight = 3;
    comp.setLayout(layout);
    timerSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    timerSpinner.setLayoutData(data);
    Label label = new Label(comp, SWT.NONE);
    label.setText(getResourceString("Animation")); //$NON-NLS-1$
    data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    label.setLayoutData(data);
    timerSpinner.setMaximum(1000);
    timerSpinner.setSelection(TIMER);
    timerSpinner.setSelection(TIMER);
    separator.setControl(comp);
    separator.setWidth(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
}

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

void headerShowToolTip(int x) {
    String tooltip = headerGetToolTip(x);
    if (tooltip == null || tooltip.length() == 0)
        return;//from  w w w  . j a va2  s  .  c  om

    if (toolTipShell == null) {
        toolTipShell = new Shell(getShell(), SWT.ON_TOP | SWT.TOOL);
        toolTipLabel = new Label(toolTipShell, SWT.CENTER);
        Display display = toolTipShell.getDisplay();
        toolTipLabel.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        toolTipLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
        for (int toolTipEvent : toolTipEvents) {
            header.addListener(toolTipEvent, toolTipListener);
        }
    }
    if (headerUpdateToolTip(x)) {
        toolTipShell.setVisible(true);
    } else {
        headerHideToolTip();
    }
}

From source file:PrintKTableExample.java

public static void drawButtonDeepDown(GC gc, String text, int textAlign, Image image, int imageAlign, int x,
        int y, int w, int h) {
    Display display = Display.getCurrent();
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.drawLine(x, y, x + w - 2, y);/*from  ww w.j a v a  2s .c o m*/
    gc.drawLine(x, y, x, y + h - 2);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
    gc.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
    gc.drawLine(x + w - 2, y + h - 2, x + w - 2, y + 1);
    //
    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
    gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(x + 2, y + 2, w - 4, 1);
    gc.fillRectangle(x + 1, y + 2, 2, h - 4);
    //
    gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    drawTextImage(gc, text, textAlign, image, imageAlign, x + 2 + 1, y + 2 + 1, w - 4, h - 3 - 1);
}

From source file:PrintKTableExample.java

public static void drawButtonUp(GC gc, String text, int textAlign, Image image, int imageAlign, int x, int y,
        int w, int h) {
    Display display = Display.getCurrent();
    drawButtonUp(gc, text, textAlign, image, imageAlign, x, y, w, h,
            display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
            display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW), 2, 2);
}

From source file:PrintKTableExample.java

public static void drawButtonDown(GC gc, String text, int textAlign, Image image, int imageAlign, int x, int y,
        int w, int h) {
    Display display = Display.getCurrent();
    drawButtonDown(gc, text, textAlign, image, imageAlign, x, y, w, h,
            display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), 2, 2);
}

From source file:PrintKTableExample.java

public static void drawButtonUp(GC gc, String text, int textAlign, Image image, int imageAlign, int x, int y,
        int w, int h, Color face) {
    Display display = Display.getCurrent();
    drawButtonUp(gc, text, textAlign, image, imageAlign, x, y, w, h, face,
            display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW), 2, 2);
}

From source file:PrintKTableExample.java

public static void drawButtonDown(GC gc, String text, int textAlign, Image image, int imageAlign, int x, int y,
        int w, int h, Color face) {
    Display display = Display.getCurrent();
    drawButtonDown(gc, text, textAlign, image, imageAlign, x, y, w, h, face,
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), 2, 2);
}

From source file:PrintKTableExample.java

public static void drawButtonUp(GC gc, String text, int textAlign, Image image, int imageAlign, Rectangle r,
        int leftMargin, int topMargin) {
    Display display = Display.getCurrent();
    drawButtonUp(gc, text, textAlign, image, imageAlign, r.x, r.y, r.width, r.height,
            display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
            display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW), leftMargin, topMargin);
}

From source file:PrintKTableExample.java

public MsgBox(Display d, String title, String message, String buttons) {
    this.d = d;//from   w ww.j  a  v a  2  s  .  c  om
    this.s = new Shell(d, SWT.TITLE | SWT.APPLICATION_MODAL);
    this.s.setText(title);
    additionalControl = null;
    ende = false;

    FormLayout fl = new FormLayout();
    this.s.setLayout(fl);

    bild = new Label(this.s, SWT.LEFT);
    bild.setImage(IconSource.getImage("MsgBox"));
    bild.setBackground(d.getSystemColor(SWT.COLOR_WHITE));

    FormData f = new FormData();
    f.top = new FormAttachment(0, 0);
    f.left = new FormAttachment(0, 0);
    f.bottom = new FormAttachment(100, 0);
    bild.setLayoutData(f);

    Label separator = new Label(this.s, SWT.SEPARATOR);

    f = new FormData();
    f.top = new FormAttachment(0, 0);
    f.left = new FormAttachment(bild, 0);
    f.bottom = new FormAttachment(100, 0);
    separator.setLayoutData(f);

    meldung = new Label(s, SWT.LEFT | SWT.WRAP);
    meldung.setText(message);

    f = new FormData();
    f.top = new FormAttachment(0, 25);
    f.left = new FormAttachment(bild, 25);
    f.right = new FormAttachment(100, -25);
    f.bottom = new FormAttachment(100, -55);
    meldung.setLayoutData(f);

    ButtonBar butBar = new ButtonBar(s, 80);
    StringTokenizer t = new StringTokenizer(buttons, ",");
    boolean first = true;
    while (t.hasMoreTokens()) {
        Button but = butBar.addButton(t.nextToken(), "", new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                pressedButton = ((Button) e.getSource()).getText();
                ende = true;
            }
        });
        if (first) {
            first = false;
            s.setDefaultButton(but);
        }
    }
    f = new FormData();
    f.bottom = new FormAttachment(100, -4);
    f.left = new FormAttachment(bild, 15);
    f.right = new FormAttachment(100, -15);
    butBar.setLayoutData(f);

}