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.snippets.Snippet139.java

public static void main(String[] args) {
    Display display = new Display();

    // create an image with the word "hello" on it
    final Image image0 = new Image(display, 50, 30);
    GC gc = new GC(image0);
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillRectangle(image0.getBounds());
    gc.drawString("hello", 5, 5, true);
    gc.dispose();//from   w  ww  .  jav  a  2s .co  m

    ImageData data = image0.getImageData();
    // rotate and flip this image
    final Image image1 = new Image(display, rotate(data, SWT.LEFT));
    final Image image2 = new Image(display, rotate(data, SWT.RIGHT));
    final Image image3 = new Image(display, rotate(data, SWT.DOWN));
    final Image image4 = new Image(display, flip(data, true));
    final Image image5 = new Image(display, flip(data, false));

    Shell shell = new Shell(display);
    shell.setText("Snippet 139");
    // draw the results on the shell
    shell.addPaintListener(e -> {
        e.gc.drawText("Original Image:", 10, 10, true);
        e.gc.drawImage(image0, 10, 40);
        e.gc.drawText("Left, Right, 180:", 10, 80, true);
        e.gc.drawImage(image1, 10, 110);
        e.gc.drawImage(image2, 50, 110);
        e.gc.drawImage(image3, 90, 110);
        e.gc.drawText("Flipped Vertical, Horizontal:", 10, 170, true);
        e.gc.drawImage(image4, 10, 200);
        e.gc.drawImage(image5, 70, 200);
    });
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image0.dispose();
    image1.dispose();
    image2.dispose();
    image3.dispose();
    image4.dispose();
    image5.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    //Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setText("Snippet 134");
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    //define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));/*from  w  w w.  ja v  a 2s .co m*/
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] { 67, 50, 55, 105, 79, 105 });
    //define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    //add ability to move shell around
    Listener l = new Listener() {
        /** The x/y of the MouseDown, relative to top-left of the shell. */
        Point origin;

        @Override
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
            case SWT.MouseUp:
                origin = null;
                break;
            case SWT.MouseMove:
                if (origin != null) {
                    Point p = display.map(shell, null, e.x, e.y);
                    shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    //add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(SWT.Selection, e -> shell.close());
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    region.dispose();
    display.dispose();
}

From source file:Snippet145.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD);
    Font font2 = new Font(display, "MS Mincho", 20, SWT.ITALIC);
    Font font3 = new Font(display, "Arabic Transparent", 18, SWT.NORMAL);

    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Color green = display.getSystemColor(SWT.COLOR_GREEN);
    Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
    Color gray = display.getSystemColor(SWT.COLOR_GRAY);

    final TextLayout layout = new TextLayout(display);
    TextStyle style1 = new TextStyle(font1, yellow, blue);
    TextStyle style2 = new TextStyle(font2, green, null);
    TextStyle style3 = new TextStyle(font3, blue, gray);

    layout.setText("English \u65E5\u672C\u8A9E  \u0627\u0644\u0639\u0631\u0628\u064A\u0651\u0629");
    layout.setStyle(style1, 0, 6);//from  w w w  .  j ava  2s  . c  o  m
    layout.setStyle(style2, 8, 10);
    layout.setStyle(style3, 13, 21);

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            layout.draw(event.gc, 10, 10);
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    font1.dispose();
    font2.dispose();
    font3.dispose();
    layout.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 220");
    shell.setBounds(10, 10, 350, 200);//from   w  w w  . j  a v a  2  s. c  om
    Image xImage = new Image(display, 16, 16);
    GC gc = new GC(xImage);
    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
    gc.drawLine(1, 1, 14, 14);
    gc.drawLine(1, 14, 14, 1);
    gc.drawOval(2, 2, 11, 11);
    gc.dispose();
    final int IMAGE_MARGIN = 2;
    final Tree tree = new Tree(shell, SWT.CHECK);
    tree.setBounds(10, 10, 300, 150);
    TreeItem item = new TreeItem(tree, SWT.NONE);
    item.setText("root item");
    for (int i = 0; i < 4; i++) {
        TreeItem newItem = new TreeItem(item, SWT.NONE);
        newItem.setText("descendent " + i);
        if (i % 2 == 0)
            newItem.setData(xImage);
        item.setExpanded(true);
        item = newItem;
    }

    /*
     * NOTE: MeasureItem and PaintItem are called repeatedly.  Therefore it is
     * critical for performance that these methods be as efficient as possible.
     */
    tree.addListener(SWT.MeasureItem, event -> {
        TreeItem item1 = (TreeItem) event.item;
        Image trailingImage = (Image) item1.getData();
        if (trailingImage != null) {
            event.width += trailingImage.getBounds().width + IMAGE_MARGIN;
        }
    });
    tree.addListener(SWT.PaintItem, event -> {
        TreeItem item1 = (TreeItem) event.item;
        Image trailingImage = (Image) item1.getData();
        if (trailingImage != null) {
            int x = event.x + event.width + IMAGE_MARGIN;
            int itemHeight = tree.getItemHeight();
            int imageHeight = trailingImage.getBounds().height;
            int y = event.y + (itemHeight - imageHeight) / 2;
            event.gc.drawImage(trailingImage, x, y);
        }
    });

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

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

public static void main(String[] args) {
    final String[] MONTHS = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
            "Dec" };
    final int[] HIGHS = { -7, -4, 1, 11, 18, 24, 26, 25, 20, 13, 5, -4 };
    final int[] LOWS = { -15, -13, -7, 1, 7, 13, 15, 14, 10, 4, -2, -11 };
    final int SCALE_MIN = -30;
    final int SCALE_MAX = 30;
    final int SCALE_RANGE = Math.abs(SCALE_MIN - SCALE_MAX);

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 273");
    shell.setBounds(10, 10, 400, 350);/*from w  w  w . j  a  v  a 2s  .c om*/
    shell.setText("Ottawa Average Daily Temperature Ranges");
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    final Color white = display.getSystemColor(SWT.COLOR_WHITE);
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    // final Image parliamentImage = new Image(display, "./parliament.jpg");
    final Table table = new Table(shell, SWT.NONE);
    table.setBounds(10, 10, 350, 300);
    // table.setBackgroundImage(parliamentImage);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(MONTHS[i] + " (" + LOWS[i] + "C..." + HIGHS[i] + "C)");
    }
    final int clientWidth = table.getClientArea().width;

    /*
     * NOTE: MeasureItem and EraseItem are called repeatedly. Therefore it is
     * critical for performance that these methods be as efficient as possible.
     */
    table.addListener(SWT.MeasureItem, event -> {
        int itemIndex = table.indexOf((TableItem) event.item);
        int rightX = (HIGHS[itemIndex] - SCALE_MIN) * clientWidth / SCALE_RANGE;
        event.width = rightX;
    });
    table.addListener(SWT.EraseItem, event -> {
        int itemIndex = table.indexOf((TableItem) event.item);
        int leftX = (LOWS[itemIndex] - SCALE_MIN) * clientWidth / SCALE_RANGE;
        int rightX = (HIGHS[itemIndex] - SCALE_MIN) * clientWidth / SCALE_RANGE;
        GC gc = event.gc;
        Rectangle clipping = gc.getClipping();
        clipping.x = leftX;
        clipping.width = rightX - leftX;
        gc.setClipping(clipping);
        Color oldForeground = gc.getForeground();
        Color oldBackground = gc.getBackground();
        gc.setForeground(blue);
        gc.setBackground(white);
        gc.fillGradientRectangle(event.x, event.y, event.width / 2, event.height, false);
        gc.setForeground(white);
        gc.setBackground(red);
        gc.fillGradientRectangle(event.x + event.width / 2, event.y, event.width / 2, event.height, false);
        gc.setForeground(oldForeground);
        gc.setBackground(oldBackground);
        event.detail &= ~SWT.BACKGROUND;
        event.detail &= ~SWT.HOT;
    });

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

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    Region region = new Region();
    region.add(createCircle(50, 50, 50));
    region.subtract(createCircle(50, 50, 20));
    shell.setRegion(region);/*from   w w  w  .  j  a  v  a2s  .  co  m*/
    shell.setSize(region.getBounds().width, region.getBounds().height);
    shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    shell.open();

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

From source file:TextLayoutStyleColor.java

License:asdf

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD);
    Font font2 = new Font(display, "MS Mincho", 20, SWT.ITALIC);
    Font font3 = new Font(display, "Arabic Transparent", 18, SWT.NORMAL);

    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Color green = display.getSystemColor(SWT.COLOR_GREEN);
    Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
    Color gray = display.getSystemColor(SWT.COLOR_GRAY);

    final TextLayout layout = new TextLayout(display);
    TextStyle style1 = new TextStyle(font1, yellow, blue);
    TextStyle style2 = new TextStyle(font2, green, null);
    TextStyle style3 = new TextStyle(font3, blue, gray);

    layout.setText("English 1234567890asdfasdfasdf");
    layout.setStyle(style1, 0, 6);/*from   ww w  . j  a  v  a 2  s.c om*/
    layout.setStyle(style2, 8, 10);
    layout.setStyle(style3, 13, 21);

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            layout.draw(event.gc, 10, 10);
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    font1.dispose();
    font2.dispose();
    font3.dispose();
    layout.dispose();
    display.dispose();
}

From source file:TextForeground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    StyleRange style1 = new StyleRange();
    style1.start = 0;//  w ww  .  j  av a 2s  .c o  m
    style1.length = 10;
    style1.foreground = display.getSystemColor(SWT.COLOR_RED);
    text.setStyleRange(style1);

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

From source file:TextBackground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    StyleRange style1 = new StyleRange();
    style1.start = 0;//ww w. ja  va 2 s  .  co m
    style1.length = 10;
    style1.background = display.getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(style1);

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

From source file:GCColorChange.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {

            e.gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
            e.gc.drawText("I'm in blue!", 20, 20);
        }//from   w  w  w.j a  v  a2  s.co  m
    });

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