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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 200, 200);//from   w w w  .j  a v  a 2  s  . c  o  m

    // create a cursor with a transparent image
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB() });
    final ImageData sourceData = new ImageData(30, 30, 1, palette);
    sourceData.transparentPixel = 0;

    Canvas canvas = new Canvas(shell, SWT.BORDER);
    canvas.setBounds(10, 50, 150, 100);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawString("hide Cursor here", 10, 10);
            e.gc.drawImage(new Image(display, sourceData), 0, 0);
        }
    });

    shell.open();

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

    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    FontData data = display.getSystemFont().getFontData()[0];
    Font font = new Font(display, data.getName(), 96, SWT.BOLD | SWT.ITALIC);
    final Color green = display.getSystemColor(SWT.COLOR_GREEN);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    final Path path;
    try {//from w w w .  ja v  a2 s. c o  m
        path = new Path(display);
        path.addString("SWT", 0, 0, font);
    } catch (SWTException e) {
        //Advanced Graphics not supported.
        //This new API requires the Cairo Vector engine on GTK and GDI+ on Windows.
        System.out.println(e.getMessage());
        display.dispose();
        return;
    }
    Shell shell = new Shell(display);
    shell.setText("Snippet 198");
    shell.addListener(SWT.Paint, e -> {
        GC gc = e.gc;
        gc.setBackground(green);
        gc.setForeground(blue);
        gc.fillPath(path);
        gc.drawPath(path);
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    path.dispose();
    font.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 47");

    Image image = new Image(display, 20, 20);
    Color color = display.getSystemColor(SWT.COLOR_BLUE);
    GC gc = new GC(image);
    gc.setBackground(color);//  w  w  w .j  a v a2  s. c  o m
    gc.fillRectangle(image.getBounds());
    gc.dispose();

    Image disabledImage = new Image(display, 20, 20);
    color = display.getSystemColor(SWT.COLOR_GREEN);
    gc = new GC(disabledImage);
    gc.setBackground(color);
    gc.fillRectangle(disabledImage.getBounds());
    gc.dispose();

    Image hotImage = new Image(display, 20, 20);
    color = display.getSystemColor(SWT.COLOR_RED);
    gc = new GC(hotImage);
    gc.setBackground(color);
    gc.fillRectangle(hotImage.getBounds());
    gc.dispose();

    ToolBar bar = new ToolBar(shell, SWT.BORDER | SWT.FLAT);
    Rectangle clientArea = shell.getClientArea();
    bar.setBounds(clientArea.x, clientArea.y, 200, 32);
    for (int i = 0; i < 12; i++) {
        ToolItem item = new ToolItem(bar, 0);
        item.setImage(image);
        item.setDisabledImage(disabledImage);
        item.setHotImage(hotImage);
        if (i % 3 == 0)
            item.setEnabled(false);
    }

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

From source file:LayoutTerm.java

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

    System.out.println("Bounds: " + shell.getBounds());
    System.out.println("Client area: " + shell.getClientArea());

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    RowLayout rowLayout = new RowLayout();

    shell.setLayout(rowLayout);/*from  ww  w .  j  av a2s .  c om*/

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("button33333333333333333333333333333333333333");

    shell.pack();
    shell.open();

    System.out.println("button1: " + button1.getBounds());
    System.out.println("button2: " + button2.getBounds());

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

From source file:CompositePaintListener.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL);

    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setSize(700, 600);/*  w w w  . ja  v a 2  s . co  m*/

    final Color red = display.getSystemColor(SWT.COLOR_RED);
    composite.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setBackground(red);
            e.gc.fillOval(5, 5, 690, 590);
        }
    });

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

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

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

    final Shell shell = new Shell(display);
    shell.setText("Regions on a Control");
    shell.setLayout(new FillLayout());
    shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_RED));

    Button b2 = new Button(shell, SWT.PUSH);
    b2.setText("Button with Regions");

    // define a region that looks like a circle with two holes in ot
    Region region = new Region();
    region.add(circle(67, 87, 77));//from  w ww.  ja va  2s .  c o m
    region.subtract(circle(20, 87, 47));
    region.subtract(circle(20, 87, 113));

    // define the shape of the button using setRegion
    b2.setRegion(region);
    b2.setLocation(100, 50);

    b2.addListener(SWT.Selection, e -> shell.close());

    shell.setSize(200, 200);
    shell.open();

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

From source file:CanvasKeyEvent.java

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

    shell.setLayout(new RowLayout());
    final Canvas canvas = new Canvas(shell, SWT.NULL);
    canvas.setSize(500, 500);/*ww w . ja  v  a 2  s .co  m*/
    canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    canvas.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            GC gc = new GC(canvas);
            Rectangle rect = canvas.getClientArea();
            gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);

            Font font = new Font(display, "Arial", 32, SWT.BOLD);
            gc.setFont(font);

            gc.drawString("" + e.character, 15, 10);

            gc.dispose();
            font.dispose();
        }

        public void keyReleased(KeyEvent e) {
        }
    });

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

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Composite.setBackgroundMode()");
    shell.setLayout(new RowLayout(SWT.VERTICAL));

    Color color = display.getSystemColor(SWT.COLOR_CYAN);

    Group group = new Group(shell, SWT.NONE);
    group.setText("SWT.INHERIT_NONE");
    group.setBackground(color);/*from   w  ww  .ja  v a  2s  . c o  m*/
    group.setBackgroundMode(SWT.INHERIT_NONE);
    createChildren(group);

    group = new Group(shell, SWT.NONE);
    group.setBackground(color);
    group.setText("SWT.INHERIT_DEFAULT");
    group.setBackgroundMode(SWT.INHERIT_DEFAULT);
    createChildren(group);

    group = new Group(shell, SWT.NONE);
    group.setBackground(color);
    group.setText("SWT.INHERIT_FORCE");
    group.setBackgroundMode(SWT.INHERIT_FORCE);
    createChildren(group);

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

From source file:ScrollBarSelectionListener.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL);

    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setSize(700, 600);//from ww w.j a va  2 s.c  o m

    final Color red = display.getSystemColor(SWT.COLOR_RED);
    composite.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setBackground(red);
            e.gc.fillOval(5, 5, 690, 590);
        }
    });

    final ScrollBar hBar = shell.getHorizontalBar();
    hBar.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("ScrollBar selection listener");
        }
    });

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

From source file:PopupMenuComposite.java

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

    shell.setLayout(new GridLayout(2, true));

    final Composite composite1 = new Composite(shell, SWT.BORDER);
    composite1.setBackground(display.getSystemColor(SWT.COLOR_BLACK));

    final Composite composite2 = new Composite(shell, SWT.BORDER);
    composite2.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    Menu menu = new Menu(composite1);
    MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
    menuItem.setText("Popup menu");

    menuItem.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            System.out.println("Menu item is disposed.");
        }//from w  ww.  j a  v  a2 s  .  c om
    });

    menuItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Dispsoing ...");
            composite2.setMenu(null);
            composite2.dispose();
        }
    });

    composite1.setMenu(menu);
    composite2.setMenu(menu);

    shell.pack();
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}