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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("The SWT.Settings Event");
    shell.setLayout(new GridLayout());
    Label label = new Label(shell, SWT.WRAP);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    label.setText("Change a system setting and the table below will be updated.");
    final Table table = new Table(shell, SWT.BORDER);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumn column = new TableColumn(table, SWT.NONE);
    column = new TableColumn(table, SWT.NONE);
    column.setWidth(150);//from  w ww. j  a va  2s.  c  om
    column = new TableColumn(table, SWT.NONE);
    for (int i = 0; i < colorIds.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        Color color = display.getSystemColor(colorIds[i]);
        item.setText(0, colorNames[i]);
        item.setBackground(1, color);
        item.setText(2, color.toString());
    }
    TableColumn[] columns = table.getColumns();
    columns[0].pack();
    columns[2].pack();
    display.addListener(SWT.Settings, event -> {
        for (int i = 0; i < colorIds.length; i++) {
            Color color = display.getSystemColor(colorIds[i]);
            TableItem item = table.getItem(i);
            item.setBackground(1, color);
        }
        TableColumn[] columns1 = table.getColumns();
        columns1[0].pack();
        columns1[2].pack();
    });

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

From source file:DetectSystemSettingChange.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("The SWT.Settings Event");
    shell.setLayout(new GridLayout());
    Label label = new Label(shell, SWT.WRAP);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    label.setText("Change a system setting and the table below will be updated.");
    final Table table = new Table(shell, SWT.BORDER);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumn column = new TableColumn(table, SWT.NONE);
    column = new TableColumn(table, SWT.NONE);
    column.setWidth(150);//ww  w . jav a  2s  .  c o  m
    column = new TableColumn(table, SWT.NONE);
    for (int i = 0; i < colorIds.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        Color color = display.getSystemColor(colorIds[i]);
        item.setText(0, colorNames[i]);
        item.setBackground(1, color);
        item.setText(2, color.toString());
    }
    TableColumn[] columns = table.getColumns();
    columns[0].pack();
    columns[2].pack();
    display.addListener(SWT.Settings, new Listener() {
        public void handleEvent(Event event) {
            for (int i = 0; i < colorIds.length; i++) {
                Color color = display.getSystemColor(colorIds[i]);
                TableItem item = table.getItem(i);
                item.setBackground(1, color);
            }
            TableColumn[] columns = table.getColumns();
            columns[0].pack();
            columns[2].pack();
        }
    });

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

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

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

    TouchListener tl = e -> {//from   w  ww.  j  ava 2 s . c o m

        Touch touches[] = e.touches;

        for (int i = 0; i < touches.length; i++) {
            Touch currTouch = touches[i];

            if ((currTouch.state & (SWT.TOUCHSTATE_UP)) != 0) {
                touchLocations.remove(currTouch.id);
            } else {
                CircleInfo info = touchLocations.get(currTouch.id);
                Point newPoint = Display.getCurrent().map(null, (Control) e.widget,
                        new Point(currTouch.x, currTouch.y));

                if (info == null) {
                    info = new CircleInfo(newPoint,
                            display.getSystemColor((colorIndex + 2) % PAINTABLE_COLORS));
                    colorIndex++;
                }

                info.center = newPoint;
                touchLocations.put(currTouch.id, info);
            }
        }

        Control c = (Control) e.widget;
        c.redraw();
    };

    PaintListener pl = e -> {
        for (CircleInfo ci : touchLocations.values()) {
            e.gc.setBackground(ci.color);
            e.gc.fillOval(ci.center.x - CIRCLE_RADIUS, ci.center.y - CIRCLE_RADIUS, CIRCLE_RADIUS * 2,
                    CIRCLE_RADIUS * 2);
        }
    };

    Canvas c = new Canvas(shell, SWT.NONE);
    c.setTouchEnabled(true);
    c.setSize(800, 800);
    c.addTouchListener(tl);
    c.addPaintListener(pl);

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

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 214");
    shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    FillLayout layout1 = new FillLayout(SWT.VERTICAL);
    layout1.marginWidth = layout1.marginHeight = 10;
    shell.setLayout(layout1);//from  w  ww  . j a v a 2  s.co m
    Group group = new Group(shell, SWT.NONE);
    group.setText("Group ");
    RowLayout layout2 = new RowLayout(SWT.VERTICAL);
    layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10;
    group.setLayout(layout2);
    for (int i = 0; i < 8; i++) {
        Button button = new Button(group, SWT.RADIO);
        button.setText("Button " + i);
    }
    shell.addListener(SWT.Resize, 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();
        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:org.eclipse.swt.snippets.Snippet285.java

public static void main(String[] args) {
    int width = 250, height = 250;
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.NO_TRIM);
    shell.setText("Snippet 285");
    final Path path = new Path(display);
    path.addArc(0, 0, width, height, 0, 360);
    Path path2 = new Path(display, path, 0.1f);
    path.dispose();/*from  www  . j  a  v a 2 s.  co  m*/
    PathData data = path2.getPathData();
    path2.dispose();
    Region region = new Region(display);
    loadPath(region, data.points, data.types);
    shell.setRegion(region);
    Listener listener = event -> {
        switch (event.type) {
        case SWT.MouseDown: {
            shell.dispose();
            break;
        }
        case SWT.Paint: {
            GC gc = event.gc;
            Rectangle rect = shell.getClientArea();
            Pattern pattern = new Pattern(display, rect.x, rect.y + rect.height, rect.x + rect.width, rect.y,
                    display.getSystemColor(SWT.COLOR_BLUE), display.getSystemColor(SWT.COLOR_WHITE));
            gc.setBackgroundPattern(pattern);
            gc.fillRectangle(rect);
            pattern.dispose();
            break;
        }
        }
    };
    shell.addListener(SWT.MouseDown, listener);
    shell.addListener(SWT.Paint, listener);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    region.dispose();
    display.dispose();
}

From source file:BackgroundImageControl.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    FillLayout layout1 = new FillLayout(SWT.VERTICAL);
    layout1.marginWidth = layout1.marginHeight = 10;
    shell.setLayout(layout1);/*from  w  w w .  j  a v  a 2 s  .c o m*/
    Group group = new Group(shell, SWT.NONE);
    group.setText("Group ");
    RowLayout layout2 = new RowLayout(SWT.VERTICAL);
    layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10;
    group.setLayout(layout2);
    for (int i = 0; i < 8; i++) {
        Button button = new Button(group, SWT.RADIO);
        button.setText("Button " + i);
    }
    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();
            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:org.eclipse.swt.snippets.Snippet222.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText Bullet Example");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    StringBuilder text = new StringBuilder();
    text.append("Here is StyledText with some bulleted lists:\n\n");
    for (int i = 0; i < 4; i++)
        text.append("Red Bullet List Item " + i + "\n");
    text.append("\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + i + "\n");
    for (int i = 0; i < 4; i++)
        text.append("Sub List Item " + i + "\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + (2 + i) + "\n");
    text.append("\n");
    for (int i = 0; i < 4; i++)
        text.append("Custom Draw List Item " + i + "\n");
    styledText.setText(text.toString());

    StyleRange style0 = new StyleRange();
    style0.metrics = new GlyphMetrics(0, 0, 40);
    style0.foreground = display.getSystemColor(SWT.COLOR_RED);
    Bullet bullet0 = new Bullet(style0);
    StyleRange style1 = new StyleRange();
    style1.metrics = new GlyphMetrics(0, 0, 50);
    style1.foreground = display.getSystemColor(SWT.COLOR_BLUE);
    Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1);
    bullet1.text = ".";
    StyleRange style2 = new StyleRange();
    style2.metrics = new GlyphMetrics(0, 0, 80);
    style2.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2);
    bullet2.text = "\u2713";
    StyleRange style3 = new StyleRange();
    style3.metrics = new GlyphMetrics(0, 0, 50);
    Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2);

    styledText.setLineBullet(2, 4, bullet0);
    styledText.setLineBullet(7, 2, bullet1);
    styledText.setLineBullet(9, 4, bullet2);
    styledText.setLineBullet(13, 2, bullet1);
    styledText.setLineBullet(16, 4, bullet3);

    styledText.addPaintObjectListener(event -> {
        Display display1 = event.display;
        StyleRange style = event.style;//from   w  w w  .j a  v  a2 s . c o m
        Font font = style.font;
        if (font == null)
            font = styledText.getFont();
        TextLayout layout = new TextLayout(display1);
        layout.setAscent(event.ascent);
        layout.setDescent(event.descent);
        layout.setFont(font);
        layout.setText("\u2023 1." + event.bulletIndex + ")");
        layout.draw(event.gc, event.x + 10, event.y);
        layout.dispose();
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyledTextBulletedList.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText Bullet Example");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    StringBuffer text = new StringBuffer();
    text.append("Here is StyledText with some bulleted lists:\n\n");
    for (int i = 0; i < 4; i++)
        text.append("Red Bullet List Item " + i + "\n");
    text.append("\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + i + "\n");
    for (int i = 0; i < 4; i++)
        text.append("Sub List Item " + i + "\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + (2 + i) + "\n");
    text.append("\n");
    for (int i = 0; i < 4; i++)
        text.append("Custom Draw List Item " + i + "\n");
    styledText.setText(text.toString());

    StyleRange style0 = new StyleRange();
    style0.metrics = new GlyphMetrics(0, 0, 40);
    style0.foreground = display.getSystemColor(SWT.COLOR_RED);
    Bullet bullet0 = new Bullet(style0);
    StyleRange style1 = new StyleRange();
    style1.metrics = new GlyphMetrics(0, 0, 50);
    style1.foreground = display.getSystemColor(SWT.COLOR_BLUE);
    Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1);
    bullet1.text = ".";
    StyleRange style2 = new StyleRange();
    style2.metrics = new GlyphMetrics(0, 0, 80);
    style2.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2);
    bullet2.text = "\u2713";
    StyleRange style3 = new StyleRange();
    style3.metrics = new GlyphMetrics(0, 0, 50);
    Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2);

    styledText.setLineBullet(2, 4, bullet0);
    styledText.setLineBullet(7, 2, bullet1);
    styledText.setLineBullet(9, 4, bullet2);
    styledText.setLineBullet(13, 2, bullet1);
    styledText.setLineBullet(16, 4, bullet3);

    styledText.addPaintObjectListener(new PaintObjectListener() {
        public void paintObject(PaintObjectEvent event) {
            Display display = event.display;
            StyleRange style = event.style;
            Font font = style.font;
            if (font == null)
                font = styledText.getFont();
            TextLayout layout = new TextLayout(display);
            layout.setAscent(event.ascent);
            layout.setDescent(event.descent);
            layout.setFont(font);/*from ww  w  .j av a2s  . com*/
            layout.setText("\u2023 1." + event.bulletIndex + ")");
            layout.draw(event.gc, event.x + 10, event.y);
            layout.dispose();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Text spans two columns in a TableItem");
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);/*from   w  w w.j  a va 2 s  . c om*/
    int columnCount = 4;
    for (int i = 0; i < columnCount; i++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Column " + i);
    }
    int itemCount = 8;
    for (int i = 0; i < itemCount; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, "item " + i + " a");
        item.setText(3, "item " + i + " d");
    }
    /*
     * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly.
     * Therefore, it is critical for performance that these methods be
     * as efficient as possible.
     */
    final String string = "text that spans two columns";
    GC gc = new GC(table);
    final Point extent = gc.stringExtent(string);
    gc.dispose();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    Listener paintListener = event -> {
        switch (event.type) {
        case SWT.MeasureItem: {
            if (event.index == 1 || event.index == 2) {
                event.width = extent.x / 2;
                event.height = Math.max(event.height, extent.y + 2);
            }
            break;
        }
        case SWT.PaintItem: {
            if (event.index == 1 || event.index == 2) {
                int offset = 0;
                if (event.index == 2) {
                    TableColumn column1 = table.getColumn(1);
                    offset = column1.getWidth();
                }
                event.gc.setForeground(red);
                int y = event.y + (event.height - extent.y) / 2;
                event.gc.drawString(string, event.x - offset, y, true);
            }
            break;
        }
        }
    };
    table.addListener(SWT.MeasureItem, paintListener);
    table.addListener(SWT.PaintItem, paintListener);
    for (int i = 0; i < columnCount; i++) {
        table.getColumn(i).pack();
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextSpanMultipleColumns.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Text spans two columns in a TableItem");
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);// w  w  w .  j a v a 2  s.c  o  m
    int columnCount = 4;
    for (int i = 0; i < columnCount; i++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Column " + i);
    }
    int itemCount = 8;
    for (int i = 0; i < itemCount; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, "item " + i + " a");
        item.setText(3, "item " + i + " d");
    }
    /*
     * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly.
     * Therefore, it is critical for performance that these methods be as
     * efficient as possible.
     */
    final String string = "text that spans two columns";
    GC gc = new GC(table);
    final Point extent = gc.stringExtent(string);
    gc.dispose();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    Listener paintListener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.MeasureItem: {
                if (event.index == 1 || event.index == 2) {
                    event.width = extent.x / 2;
                    event.height = Math.max(event.height, extent.y + 2);
                }
                break;
            }
            case SWT.PaintItem: {
                if (event.index == 1 || event.index == 2) {
                    int offset = 0;
                    if (event.index == 2) {
                        TableColumn column1 = table.getColumn(1);
                        offset = column1.getWidth();
                    }
                    event.gc.setForeground(red);
                    int y = event.y + (event.height - extent.y) / 2;
                    event.gc.drawString(string, event.x - offset, y);
                }
                break;
            }
            }
        }
    };
    table.addListener(SWT.MeasureItem, paintListener);
    table.addListener(SWT.PaintItem, paintListener);
    for (int i = 0; i < columnCount; i++) {
        table.getColumn(i).pack();
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}