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

protected static void setBackground(Display display, Control control) {
    Random randomGenerator = new Random();
    int nextColor = randomGenerator.nextInt(100) + randomGenerator.nextInt(100);
    control.setBackground(display.getSystemColor(colors[nextColor % colors.length]));
}

From source file:Snippet156.java

static ImageData createSampleImage(Display display) {
    Image image = new Image(display, 100, 100);
    Rectangle bounds = image.getBounds();
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
    gc.fillRectangle(bounds);//from  w  w w  .  j  a va 2 s  . com
    gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
    gc.fillOval(0, 0, bounds.width, bounds.height);
    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
    gc.drawLine(0, 0, bounds.width, bounds.height);
    gc.drawLine(bounds.width, 0, 0, bounds.height);
    gc.dispose();
    ImageData data = image.getImageData();
    image.dispose();
    return data;
}

From source file:widgetTest3.java

/** * Images ** */

public static void doubleBuffering(Composite composite) {
    //       Create canvas
    final Canvas canvas = new Canvas(composite, SWT.BORDER);
    //       Get white system color
    Color white = canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    //       Set canvas background to white
    canvas.setBackground(white);//ww w  .  ja va 2 s.  c o  m
    //       Add paint listener
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Get Display instance from the event object
            Display display = e.display;
            // Get black and red system color - don't dispose these
            Color black = display.getSystemColor(SWT.COLOR_BLACK);
            Color red = display.getSystemColor(SWT.COLOR_RED);
            // Get the graphics context from event object
            GC gc = e.gc;
            // Get the widget that caused the event
            Composite source = (Composite) e.widget;
            // Get the size of this widgets client area
            Rectangle rect = source.getClientArea();
            // Create buffer for double buffering
            Image buffer = new Image(display, rect.width, rect.height);
            // Create graphics context for this buffer
            GC bufferGC = new GC(buffer);
            // perform drawing operations
            bufferGC.setBackground(red);
            bufferGC.fillRectangle(5, 5, rect.width - 10, rect.height - 10);
            bufferGC.setForeground(black);
            bufferGC.drawRectangle(5, 5, rect.width - 10, rect.height - 10);
            bufferGC.setBackground(source.getBackground());
            bufferGC.fillRectangle(10, 10, rect.width - 20, rect.height - 20);
            // Now draw the buffered image to the target drawable
            gc.drawImage(buffer, 0, 0);
            // Dispose of the buffer's graphics context
            bufferGC.dispose();
            // Dispose of the buffer
            buffer.dispose();
        }
    });
}

From source file:widgetTest3.java

/** * PaintListener ** */

public static void addPaintListener(Composite composite) {
    composite.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            // Get Display intsance from event object
            Display display = event.display;
            // Get a green system color object - we don't
            // need to dispose that
            Color green = display.getSystemColor(SWT.COLOR_DARK_GREEN);
            // Get the graphics context from the event object
            GC gc = event.gc;//from  w  ww . j  a  v  a2s  .  c o  m
            // Set line color
            gc.setForeground(green);
            // Get size of the Composite's client area
            Rectangle rect = ((Composite) event.widget).getClientArea();
            // Now draw an rectangle
            gc.drawRectangle(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
        }
    });
}

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

private static Image getBackgroundImage(final Display display) {
    if (newImage == null) {
        Rectangle rect = new Rectangle(0, 0, 115, 5);
        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_RED));
        gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
        gc.dispose();//from   w w  w.j  a  va2s.c om
    }
    return newImage;
}

From source file:LineBackgroundListenerTest.java

/**
 * Runs the application//from  w ww. j a v a2 s.  c om
 */
public void run() {
    Display display = new Display();
    red = display.getSystemColor(SWT.COLOR_RED);
    Shell shell = new Shell(display);
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:RedEListener.java

/**
 * Runs the application/*  w  w  w. ja  v  a2 s.c  o  m*/
 */
public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);

    // Get color for style ranges
    red = display.getSystemColor(SWT.COLOR_RED);

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

From source file:StyleRangeTest.java

/**
 * Runs the application/*  w  w w . ja  va2  s .  c om*/
 */
public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);

    // Create colors for style ranges
    orange = new Color(display, 255, 127, 0);
    blue = display.getSystemColor(SWT.COLOR_BLUE);

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

    // We created orange, but not blue
    orange.dispose();

    display.dispose();
}

From source file:ShowCTabFolder.java

/**
 * Creates the window's contents/*from  w  ww .j  a v  a  2  s  .  com*/
 * 
 * @param shell the parent shell
 */
private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(1, true));

    // Create the buttons to create tabs
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    composite.setLayout(new RowLayout());
    createButtons(composite);

    // Create the tabs
    tabFolder = new CTabFolder(shell, SWT.TOP);
    tabFolder.setBorderVisible(true);
    tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    Display display = shell.getDisplay();

    // 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 });

    // Add a listener to get the close button on each tab
    tabFolder.addCTabFolderListener(new CTabFolderAdapter() {
        public void itemClosed(CTabFolderEvent event) {
        }
    });
}

From source file:RadioButtons.java

public RadioButtons() {
    Display display = new Display();
    Shell shell = new Shell(display);

    shell.setLayout(new RowLayout());

    Label label = new Label(shell, SWT.NULL);
    label.setText("Gender: ");
    label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Button femaleButton = new Button(shell, SWT.RADIO);
    femaleButton.setText("F");

    Button maleButton = new Button(shell, SWT.RADIO);
    maleButton.setText("M");

    label = new Label(shell, SWT.NULL);
    label.setText("  Title: ");
    label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Composite composite = new Composite(shell, SWT.NULL);
    composite.setLayout(new RowLayout());

    Button mrButton = new Button(composite, SWT.RADIO);
    mrButton.setText("Mr.");
    Button mrsButton = new Button(composite, SWT.RADIO);
    mrsButton.setText("Mrs.");
    Button msButton = new Button(composite, SWT.RADIO);
    msButton.setText("Ms.");
    Button drButton = new Button(composite, SWT.RADIO);
    drButton.setText("Dr.");

    shell.pack();//  w  w  w . jav  a2  s .  c o m
    shell.open();
    //textUser.forceFocus();

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

    display.dispose();
}