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

public static void main(String[] args) {
    Display display = new Display();
    Image image = new Image(display, 16, 16);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);/*from w w  w  .j  a va  2 s  .c  o  m*/
    gc.fillRectangle(image.getBounds());
    gc.dispose();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.BORDER);
    label.setImage(image);
    label.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

From source file:TimeStopWhenButtonPressing.java

public static void main(String[] args) {
    final Display display = new Display();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Stop Timer");
    final Label label = new Label(shell, SWT.BORDER);
    label.setBackground(red);//from  w  w  w.  j a  va 2 s.co  m
    final int time = 500;
    final Runnable timer = new Runnable() {
        public void run() {
            if (label.isDisposed())
                return;
            Color color = label.getBackground().equals(red) ? blue : red;
            label.setBackground(color);
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            display.timerExec(-1, timer);
        }
    });
    button.pack();
    label.setLayoutData(new RowData(button.getSize()));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet36.java

public static void main(String[] args) {
    Display display = new Display();
    Image image = new Image(display, 16, 16);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);/*from  ww  w  .  ja  v a  2 s  .c  o m*/
    gc.fillRectangle(image.getBounds());
    gc.dispose();
    Shell shell = new Shell(display);
    ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
    for (int i = 0; i < 12; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.DROP_DOWN);
        item.setImage(image);
    }
    toolBar.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

From source file:ImageFromByteArray.java

public static void main(String[] args) {
    Display display = new Display();
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color green = display.getSystemColor(SWT.COLOR_GREEN);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);

    // Create a source ImageData of depth 4
    PaletteData palette = new PaletteData(new RGB[] { black.getRGB(), white.getRGB(), yellow.getRGB(),
            red.getRGB(), blue.getRGB(), green.getRGB() });
    ImageData sourceData = new ImageData(16, 16, 4, palette, 1, srcData);

    Shell shell = new Shell(display);
    final Image source = new Image(display, sourceData);
    shell.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            GC gc = e.gc;//from www  . jav a  2  s.  c o m
            gc.drawImage(source, 20, 20);
        }
    });
    shell.setSize(150, 150);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    source.dispose();
    display.dispose();
}

From source file:Snippet129.java

public static void main(String[] args) {
    Display display = new Display();
    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color gray = display.getSystemColor(SWT.COLOR_GRAY);
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Table table = new Table(shell, SWT.BORDER);
    table.setBackground(gray);/*from ww w  .j  av  a 2s  .  c o  m*/
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "entire", "row", "red foreground" });
    item.setForeground(red);
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "entire", "row", "red background" });
    item.setBackground(red);
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "entire", "row", "white fore/red back" });
    item.setForeground(white);
    item.setBackground(red);
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "normal", "blue foreground", "red foreground" });
    item.setForeground(1, blue);
    item.setForeground(2, red);
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "normal", "blue background", "red background" });
    item.setBackground(1, blue);
    item.setBackground(2, red);
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "white fore/blue back", "normal", "white fore/red back" });
    item.setForeground(0, white);
    item.setBackground(0, blue);
    item.setForeground(2, white);
    item.setBackground(2, red);

    column1.pack();
    column2.pack();
    column3.pack();

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

From source file:GCBackgroundForeground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.open();//w  ww .  j  a v  a 2s . c  o m

    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);

    GC gc = new GC(shell);
    gc.setBackground(black);
    gc.setForeground(white);

    gc.drawString("Test", 12, 12);

    gc.dispose();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet21.java

public static void main(String[] args) {
    Display display = new Display();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setText("Snippet 21");
    Button b = new Button(shell, SWT.PUSH);
    Rectangle clientArea = shell.getClientArea();
    b.setBounds(clientArea.x + 10, clientArea.y + 10, 100, 32);
    b.setText("Button");
    shell.setDefaultButton(b);// w  ww . ja  v a 2 s  .com
    final Canvas c = new Canvas(shell, SWT.BORDER);
    c.setBounds(10, 50, 100, 32);
    c.addListener(SWT.Traverse, e -> {
        switch (e.detail) {
        /* Do tab group traversal */
        case SWT.TRAVERSE_ESCAPE:
        case SWT.TRAVERSE_RETURN:
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS:
        case SWT.TRAVERSE_PAGE_NEXT:
        case SWT.TRAVERSE_PAGE_PREVIOUS:
            e.doit = true;
            break;
        }
    });
    c.addListener(SWT.FocusIn, e -> c.setBackground(red));
    c.addListener(SWT.FocusOut, e -> c.setBackground(blue));
    c.addListener(SWT.KeyDown, e -> System.out.println("KEY"));
    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);

    Text r = new Text(shell, SWT.MULTI | SWT.BORDER);
    r.setBounds(10, 120, 100, 32);

    c.setFocus();
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet216.java

public static void main(String[] args) {
    Display display = new Display();
    final Color[] colors = { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_GREEN),
            display.getSystemColor(SWT.COLOR_BLUE), };
    final Rectangle[] rects = { new Rectangle(10, 10, 30, 30), new Rectangle(20, 45, 25, 35),
            new Rectangle(80, 80, 10, 10), };
    final Shell shell = new Shell(display);
    shell.setText("Snippet 216");
    Listener mouseListener = event -> {
        switch (event.type) {
        case SWT.MouseEnter:
        case SWT.MouseMove:
            for (int i = 0; i < rects.length; i++) {
                if (rects[i].contains(event.x, event.y)) {
                    String text = "ToolTip " + i;
                    if (!(text.equals(shell.getToolTipText()))) {
                        shell.setToolTipText("ToolTip " + i);
                    }/*from   w ww . j ava  2s  .c  om*/
                    return;
                }
            }
            shell.setToolTipText(null);
            break;
        }
    };
    shell.addListener(SWT.MouseMove, mouseListener);
    shell.addListener(SWT.MouseEnter, mouseListener);
    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        for (int i = 0; i < rects.length; i++) {
            gc.setBackground(colors[i]);
            gc.fillRectangle(rects[i]);
            gc.drawRectangle(rects[i]);
        }
    });
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet92.java

public static void main(String[] args) {
    Display display = new Display();
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);

    //Create a source ImageData of depth 1 (monochrome)
    PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB(), });
    ImageData sourceData = new ImageData(20, 20, 1, palette);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 20; j++) {
            sourceData.setPixel(i, j, 1);
        }//www  . ja v  a  2  s . c o  m
    }

    //Create a mask ImageData of depth 1 (monochrome)
    palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB(), });
    ImageData maskData = new ImageData(20, 20, 1, palette);
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 10; j++) {
            maskData.setPixel(i, j, 1);
        }
    }
    //Create cursor
    Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10);

    Shell shell = new Shell(display);
    final Image source = new Image(display, sourceData);
    final Image mask = new Image(display, maskData);
    //Draw source and mask just to show what they look like
    shell.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            GC gc = e.gc;
            gc.drawString("source: ", 10, 10);
            gc.drawImage(source, 0, 0, 20, 20, 50, 10, 20, 20);
            gc.drawString("mask: ", 10, 40);
            gc.drawImage(mask, 0, 0, 20, 20, 50, 40, 20, 20);
        }
    });
    shell.setSize(150, 150);
    shell.open();
    shell.setCursor(cursor);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    cursor.dispose();
    source.dispose();
    mask.dispose();
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet34.java

public static void main(String[] args) {
    Display display = new Display();
    Image image = new Image(display, 16, 16);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);//from   w w  w .ja  v a 2s  .com
    gc.fillRectangle(image.getBounds());
    gc.dispose();
    Shell shell = new Shell(display);
    shell.setText("Snippet 34");
    Label label = new Label(shell, SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    label.setLocation(clientArea.x, clientArea.y);
    label.setImage(image);
    label.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}