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.Snippet10.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Advanced Graphics");
    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 . j  a va 2  s.com
    shell.addListener(SWT.Paint, event -> {
        GC gc1 = event.gc;
        Transform tr = new Transform(display);
        tr.translate(50, 120);
        tr.rotate(-30);
        gc1.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
        gc1.setAlpha(100);
        gc1.setTransform(tr);
        Path path = new Path(display);
        path.addString("SWT", 0, 0, font);
        gc1.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc1.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc1.fillPath(path);
        gc1.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:GradientDynamic.java

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

    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle rect = shell.getClientArea();
            Image newImage = new Image(display, Math.max(1, rect.width), 1);
            GC gc = new GC(newImage);
            gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
            gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
            gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
            gc.dispose();/*w  ww .  j a  v a 2s . c  o m*/
            shell.setBackgroundImage(newImage);
            if (oldImage != null) {
                oldImage.dispose();
            }
            oldImage = newImage;
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (oldImage != null)
        oldImage.dispose();
    display.dispose();
}

From source file:StyledTextGradientBackground.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setText(text);//  w ww.jav  a2 s.  com
    FontData data = display.getSystemFont().getFontData()[0];
    Font font = new Font(display, data.getName(), 16, SWT.BOLD);
    styledText.setFont(font);
    styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    styledText.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle rect = styledText.getClientArea();
            Image newImage = new Image(display, 1, Math.max(1, rect.height));
            GC gc = new GC(newImage);
            gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
            gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
            gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
            gc.dispose();
            styledText.setBackgroundImage(newImage);
            if (oldImage != null)
                oldImage.dispose();
            oldImage = newImage;
        }
    });
    shell.setSize(700, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (oldImage != null)
        oldImage.dispose();
    font.dispose();
    display.dispose();
}

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

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

    final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI);
    text.setText("The quick brown fox jumps over the lazy dog.\nThat's all folks!");
    TextStyle textStyle = new TextStyle(new Font(display, "Courier", 12, SWT.BOLD),
            display.getSystemColor(SWT.COLOR_RED), null);
    textStyle.strikeout = true;// ww w . ja  v  a2  s  .c  o  m
    textStyle.underline = true;
    textStyle.underlineStyle = SWT.UNDERLINE_SINGLE;
    text.setStyleRanges(new int[] { 4, 5 }, new StyleRange[] { new StyleRange(textStyle) });

    text.getAccessible().addAccessibleEditableTextListener(new AccessibleEditableTextAdapter() {
        @Override
        public void setTextAttributes(AccessibleTextAttributeEvent e) {
            TextStyle textStyle = e.textStyle;
            if (textStyle != null) {
                /* Copy all of the TextStyle fields into the new StyleRange. */
                StyleRange style = new StyleRange(textStyle);
                /* Create new graphics resources because the old ones are only valid during the event. */
                if (textStyle.font != null)
                    style.font = new Font(display, textStyle.font.getFontData());
                if (textStyle.foreground != null)
                    style.foreground = new Color(display, textStyle.foreground.getRGB());
                if (textStyle.background != null)
                    style.background = new Color(display, textStyle.background.getRGB());
                if (textStyle.underlineColor != null)
                    style.underlineColor = new Color(display, textStyle.underlineColor.getRGB());
                if (textStyle.strikeoutColor != null)
                    style.strikeoutColor = new Color(display, textStyle.strikeoutColor.getRGB());
                if (textStyle.borderColor != null)
                    style.borderColor = new Color(display, textStyle.borderColor.getRGB());
                /* Set the StyleRange into the StyledText. */
                style.start = e.start;
                style.length = e.end - e.start;
                text.setStyleRange(style);
                e.result = ACC.OK;
            } else {
                text.setStyleRanges(e.start, e.end - e.start, null, null);
            }
        }
    });

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

From source file:CursorHideControl.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 200, 200);//  w ww  .j  a v  a  2 s  .  c  o m
    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);
        }
    });

    // 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() });
    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:CTabFolderCTabFolder2Listener.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);//from   ww w .  j a  v a 2  s  .  c  o 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 ");
    new CTabItem(tabFolder, SWT.NONE, 1).setText("Tab index 1 ");

    tabFolder.addCTabFolder2Listener(new CTabFolder2Listener() {

        public void close(CTabFolderEvent arg0) {
            System.out.println("close");

        }

        public void minimize(CTabFolderEvent arg0) {
            // TODO Auto-generated method stub

        }

        public void maximize(CTabFolderEvent arg0) {
            // TODO Auto-generated method stub

        }

        public void restore(CTabFolderEvent arg0) {
            // TODO Auto-generated method stub

        }

        public void showList(CTabFolderEvent arg0) {
            // TODO Auto-generated method stub

        }
    });

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

From source file:FontRegistry.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell();
    shell.setLayout(new GridLayout(1, false));

    FontRegistry fontRegistry = new FontRegistry(display);

    fontRegistry.put("button-text", new FontData[] { new FontData("Arial", 9, SWT.BOLD) });
    fontRegistry.put("code", new FontData[] { new FontData("Courier New", 10, SWT.NORMAL) });

    Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP);
    text.setFont(fontRegistry.get("code"));
    text.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    text.setText("");
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;/*from w  ww. java 2  s.com*/
    text.setLayoutData(gd);
    Button executeButton = new Button(shell, SWT.PUSH);
    executeButton.setText("Execute");
    executeButton.setFont(fontRegistry.get("button-text"));

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

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 218");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setText(text);//from  w w  w  . j  av a  2s . c  om
    FontData data = display.getSystemFont().getFontData()[0];
    Font font = new Font(display, data.getName(), 16, SWT.BOLD);
    styledText.setFont(font);
    styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    styledText.addListener(SWT.Resize, event -> {
        Rectangle rect = styledText.getClientArea();
        Image newImage = new Image(display, 1, Math.max(1, rect.height));
        GC gc = new GC(newImage);
        gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
        gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
        gc.dispose();
        styledText.setBackgroundImage(newImage);
        if (oldImage != null)
            oldImage.dispose();
        oldImage = newImage;
    });
    shell.setSize(700, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (oldImage != null)
        oldImage.dispose();
    font.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Embedding objects in text");
    final Image[] images = { new Image(display, 32, 32), new Image(display, 20, 40),
            new Image(display, 40, 20) };
    int[] colors = { SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN };
    for (int i = 0; i < images.length; i++) {
        GC gc = new GC(images[i]);
        gc.setBackground(display.getSystemColor(colors[i]));
        gc.fillRectangle(images[i].getBounds());
        gc.dispose();//from  ww  w.  j  av a2s.com
    }

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Button");
    button.pack();
    String text = "Here is some text with a blue image \uFFFC, a magenta image \uFFFC, a green image \uFFFC, and a button: \uFFFC.";
    final int[] imageOffsets = { 36, 55, 72 };
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    for (int i = 0; i < images.length; i++) {
        Rectangle bounds = images[i].getBounds();
        TextStyle imageStyle = new TextStyle(null, null, null);
        imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
        layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]);
    }
    Rectangle bounds = button.getBounds();
    TextStyle buttonStyle = new TextStyle(null, null, null);
    buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
    final int buttonOffset = text.length() - 2;
    layout.setStyle(buttonStyle, buttonOffset, buttonOffset);

    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Point margin = new Point(10, 10);
        layout.setWidth(shell.getClientArea().width - 2 * margin.x);
        layout.draw(event.gc, margin.x, margin.y);
        for (int i = 0; i < images.length; i++) {
            int offset = imageOffsets[i];
            int lineIndex1 = layout.getLineIndex(offset);
            FontMetrics lineMetrics1 = layout.getLineMetrics(lineIndex1);
            Point point1 = layout.getLocation(offset, false);
            GlyphMetrics glyphMetrics1 = layout.getStyle(offset).metrics;
            gc.drawImage(images[i], point1.x + margin.x,
                    point1.y + margin.y + lineMetrics1.getAscent() - glyphMetrics1.ascent);
        }
        int lineIndex2 = layout.getLineIndex(buttonOffset);
        FontMetrics lineMetrics2 = layout.getLineMetrics(lineIndex2);
        Point point2 = layout.getLocation(buttonOffset, false);
        GlyphMetrics glyphMetrics2 = layout.getStyle(buttonOffset).metrics;
        button.setLocation(point2.x + margin.x,
                point2.y + margin.y + lineMetrics2.getAscent() - glyphMetrics2.ascent);
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    layout.dispose();
    for (int i = 0; i < images.length; i++) {
        images[i].dispose();
    }
    display.dispose();
}

From source file:TextLayoutImageControl.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Embedding objects in text");
    final Image[] images = { new Image(display, 32, 32), new Image(display, 20, 40),
            new Image(display, 40, 20) };
    int[] colors = { SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN };
    for (int i = 0; i < images.length; i++) {
        GC gc = new GC(images[i]);
        gc.setBackground(display.getSystemColor(colors[i]));
        gc.fillRectangle(images[i].getBounds());
        gc.dispose();/* w w w. ja  v a  2  s  .c  o  m*/
    }

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Button");
    button.pack();
    String text = "Here is some text with a blue image \uFFFC, a magenta image \uFFFC, a green image \uFFFC, and a button: \uFFFC.";
    final int[] imageOffsets = { 36, 55, 72 };
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    for (int i = 0; i < images.length; i++) {
        Rectangle bounds = images[i].getBounds();
        TextStyle imageStyle = new TextStyle(null, null, null);
        imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
        layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]);
    }
    Rectangle bounds = button.getBounds();
    TextStyle buttonStyle = new TextStyle(null, null, null);
    buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
    final int buttonOffset = text.length() - 2;
    layout.setStyle(buttonStyle, buttonOffset, buttonOffset);

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            GC gc = event.gc;
            Point margin = new Point(10, 10);
            layout.setWidth(shell.getClientArea().width - 2 * margin.x);
            layout.draw(event.gc, margin.x, margin.y);
            for (int i = 0; i < images.length; i++) {
                int offset = imageOffsets[i];
                int lineIndex = layout.getLineIndex(offset);
                FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
                Point point = layout.getLocation(offset, false);
                GlyphMetrics glyphMetrics = layout.getStyle(offset).metrics;
                gc.drawImage(images[i], point.x + margin.x,
                        point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
            }
            int lineIndex = layout.getLineIndex(buttonOffset);
            FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
            Point point = layout.getLocation(buttonOffset, false);
            GlyphMetrics glyphMetrics = layout.getStyle(buttonOffset).metrics;
            button.setLocation(point.x + margin.x,
                    point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    layout.dispose();
    for (int i = 0; i < images.length; i++) {
        images[i].dispose();
    }
    display.dispose();
}