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.Snippet9.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);
    shell.setText("Snippet 9");
    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setSize(700, 600);/*from w ww . j a va2 s .  co  m*/
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    composite.addPaintListener(e -> {
        e.gc.setBackground(red);
        e.gc.fillOval(5, 5, 690, 590);
    });
    final ScrollBar hBar = shell.getHorizontalBar();
    hBar.addListener(SWT.Selection, e -> {
        Point location = composite.getLocation();
        location.x = -hBar.getSelection();
        composite.setLocation(location);
    });
    final ScrollBar vBar = shell.getVerticalBar();
    vBar.addListener(SWT.Selection, e -> {
        Point location = composite.getLocation();
        location.y = -vBar.getSelection();
        composite.setLocation(location);
    });
    shell.addListener(SWT.Resize, e -> {
        Point size = composite.getSize();
        Rectangle rect = shell.getClientArea();
        hBar.setMaximum(size.x);
        vBar.setMaximum(size.y);
        hBar.setThumb(Math.min(size.x, rect.width));
        vBar.setThumb(Math.min(size.y, rect.height));
        int hPage = size.x - rect.width;
        int vPage = size.y - rect.height;
        int hSelection = hBar.getSelection();
        int vSelection = vBar.getSelection();
        Point location = composite.getLocation();
        if (hSelection >= hPage) {
            if (hPage <= 0)
                hSelection = 0;
            location.x = -hSelection;
        }
        if (vSelection >= vPage) {
            if (vPage <= 0)
                vSelection = 0;
            location.y = -vSelection;
        }
        composite.setLocation(location);
    });
    shell.setSize(600, 500);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

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

    final Image image = new Image(display, 110, 60);
    GC gc = new GC(image);
    Font font = new Font(display, "Times", 30, SWT.BOLD);
    gc.setFont(font);/* w w w .j  a  va  2  s . c  o  m*/
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillRectangle(0, 0, 110, 60);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawText("SWT", 10, 10, true);
    font.dispose();
    gc.dispose();

    final Rectangle rect = image.getBounds();
    Shell shell = new Shell(display);
    shell.setText("Matrix Tranformations");
    shell.setLayout(new FillLayout());
    final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
    canvas.addPaintListener(e -> {
        GC gc1 = e.gc;
        gc1.setAdvanced(true);
        if (!gc1.getAdvanced()) {
            gc1.drawText("Advanced graphics not supported", 30, 30, true);
            return;
        }

        // Original image
        int x = 30, y = 30;
        gc1.drawImage(image, x, y);
        x += rect.width + 30;

        Transform transform = new Transform(display);

        // Note that the tranform is applied to the whole GC therefore
        // the coordinates need to be adjusted too.

        // Reflect around the y axis.
        transform.setElements(-1, 0, 0, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, -1 * x - rect.width, y);

        x = 30;
        y += rect.height + 30;

        // Reflect around the x axis.
        transform.setElements(1, 0, 0, -1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, x, -1 * y - rect.height);

        x += rect.width + 30;

        // Reflect around the x and y axes
        transform.setElements(-1, 0, 0, -1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, -1 * x - rect.width, -1 * y - rect.height);

        x = 30;
        y += rect.height + 30;

        // Shear in the x-direction
        transform.setElements(1, 0, -1, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 300, y);

        // Shear in y-direction
        transform.setElements(1, -1, 0, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 150, 475);

        // Rotate by 45 degrees
        float cos45 = (float) Math.cos(Math.PI / 4);
        float sin45 = (float) Math.sin(Math.PI / 4);
        transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 400, 60);

        transform.dispose();
    });

    shell.setSize(350, 550);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

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

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

    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   ww  w .j a  v a 2  s  . c o  m*/
    layout.setStyle(style2, 8, 10);
    layout.setStyle(style3, 13, 21);

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    shell.addListener(SWT.Paint, 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:CompareStyleRange.java

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

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("12345");

    // Use the empty constructor and set the fields
    StyleRange sr1 = new StyleRange();
    sr1.start = 7;//from w  ww. jav a2s.co  m
    sr1.length = 14;
    sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    sr1.background = display.getSystemColor(SWT.COLOR_WHITE);
    sr1.fontStyle = SWT.BOLD;

    // Use the constructor that accepts the fields
    StyleRange sr2 = new StyleRange(7, 14, display.getSystemColor(SWT.COLOR_GREEN),
            display.getSystemColor(SWT.COLOR_WHITE), SWT.BOLD);

    System.out.println(sr2.similarTo(sr1));

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:StyleRangeStyledTextSet.java

License:asdf

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

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    // Use the empty constructor and set the fields
    StyleRange sr1 = new StyleRange();
    sr1.start = 7;/*from   www.ja v a  2s.c om*/
    sr1.length = 14;
    sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    sr1.background = display.getSystemColor(SWT.COLOR_WHITE);
    sr1.fontStyle = SWT.BOLD;

    styledText.setStyleRange(sr1);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 339");
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginWidth = 20;//from  w ww.jav a 2s.com
    fillLayout.marginHeight = 20;
    shell.setLayout(fillLayout);

    CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
    folder.setBackground(
            new Color[] { display.getSystemColor(SWT.COLOR_YELLOW), display.getSystemColor(SWT.COLOR_RED) },
            new int[] { 100 }, true);

    for (int i = 0; i < 6; i++) {
        CTabItem item = new CTabItem(folder, SWT.CLOSE);
        item.setText("Item " + i);
        Text text = new Text(folder, SWT.MULTI);
        text.setText("Content for Item " + i + "\n\n\n\n");
        item.setControl(text);
    }

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 242");
    shell.setBounds(10, 10, 200, 200);/* w  w  w .  j  a  v a 2 s . c om*/
    Canvas canvas = new Canvas(shell, SWT.BORDER);
    canvas.setBounds(10, 50, 150, 100);
    canvas.addPaintListener(e -> e.gc.drawString("hide Cursor here", 10, 10));

    // 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(white.getRGB(), black.getRGB());
    ImageData sourceData = new ImageData(16, 16, 1, palette);
    sourceData.transparentPixel = 0;
    Cursor cursor = new Cursor(display, sourceData, 0, 0);

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

From source file:AlphaBlending.java

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

    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
    final Image image = new Image(display, 640, 480);
    final Rectangle rect = image.getBounds();
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillOval(rect.x, rect.y, rect.width, rect.height);
    gc.dispose();//  ww  w .  j  a v a  2  s.  co m

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            GC gc = event.gc;
            gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
            gc.setAlpha(100);
            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);
            path.dispose();
        }
    });
    shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    font.dispose();
    display.dispose();
}

From source file:TransformationDrawing.java

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

    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
    final Image image = new Image(display, 640, 480);
    final Rectangle rect = image.getBounds();
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillOval(rect.x, rect.y, rect.width, rect.height);
    gc.dispose();/*from   w  ww  . ja  va  2s  . com*/

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            GC gc = event.gc;
            Transform tr = new Transform(display);
            tr.translate(50, 120);
            tr.rotate(-30);
            gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
            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 / 2, rect.height / 2));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    font.dispose();
    display.dispose();
}

From source file:CTabFolderGradientBackground.java

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

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

    CTabFolder tabFolder = new CTabFolder(shell, SWT.TOP);
    tabFolder.setBorderVisible(true);/*w  w w  .  j  a  v  a 2  s  .co  m*/
    tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Set up a gradient background for the selected tab
    tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
            display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW) }, new int[] { 50, 100 });

    new CTabItem(tabFolder, SWT.NONE, 0).setText("Tab index 1 ");

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