Example usage for org.eclipse.swt.widgets Display sleep

List of usage examples for org.eclipse.swt.widgets Display sleep

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display sleep.

Prototype

public boolean sleep() 

Source Link

Document

Causes the user-interface thread to sleep (that is, to be put in a state where it does not consume CPU cycles) until an event is received or it is otherwise awakened.

Usage

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

public static void main(String[] args) {
    Display display = new Display();
    final Image image = new Image(display, 20, 20);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);/*from www . ja  v  a  2s  . co m*/
    gc.fillRectangle(image.getBounds());
    gc.dispose();

    Shell shell = new Shell(display);
    shell.setText("Snippet 112");
    shell.setLayout(new FillLayout());
    Group group = new Group(shell, SWT.NONE);
    group.setLayout(new FillLayout());
    group.setText("a square");
    Canvas canvas = new Canvas(group, SWT.NONE);
    canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));

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

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

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 369");
    shell.setLayout(new FillLayout());
    shell.setText("Line spacing provider in action");

    StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setText("// Type your custom line spacing \n10\n5\nabcd\n20\nefgh");

    text.setLineSpacingProvider(lineIndex -> {
        String line = text.getLine(lineIndex).trim();
        try {//w  w  w.j  a  v a 2  s  .co m
            return Integer.parseInt(line);
        } catch (NumberFormatException e) {
            return null;
        }
    });

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

From source file:ProgressBarExample.java

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

    // Create a smooth progress bar
    ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
    pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    pb1.setMinimum(0);/*from  w  ww  .ja va  2  s.c o m*/
    pb1.setMaximum(30);

    // Create an indeterminate progress bar
    ProgressBar pb2 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.INDETERMINATE);
    pb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Start the first progress bar
    new LongRunningOperation(display, pb1).start();

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

From source file:RowLayoutTest.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 12;// w  w w  . ja  va 2s  . c o  m
    layout.marginTop = 0;
    layout.justify = true;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");
    new Button(shell, SWT.PUSH).setText("five");
    new Button(shell, SWT.PUSH).setText("six");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("seven");
    b.setLayoutData(new RowData(100, 100));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:RowLayoutTest.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 20;/*from  w ww .  ja v a 2s .co m*/
    layout.marginTop = 20;
    layout.justify = true;
    shell.setLayout(layout);

    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");
    new Button(shell, SWT.PUSH).setText("five");
    new Button(shell, SWT.PUSH).setText("six");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("seven");
    b.setLayoutData(new RowData(100, 100));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:Snippet29.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);/*w  w  w  . j a  v  a 2 s . c om*/
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText("File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    MenuItem item = new MenuItem(submenu, SWT.PUSH);
    item.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("Select All");
        }
    });
    item.setText("Select &All\tCtrl+A");
    item.setAccelerator(SWT.CTRL + 'A');
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell();
    shell.setText("Snippet 345");
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    String string = "The quick brown fox jumps over the lazy dog";
    Button button;//from  w ww. j a  v a2  s.  co m
    button = new Button(shell, SWT.PUSH | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.RADIO | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.TOGGLE | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.CHECK | SWT.WRAP);
    button.setText(string);
    shell.setSize(shell.computeSize(200, SWT.DEFAULT));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:StyledTextListenerVerify.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    styledText.setText("text");

    // use a verify listener to keep the offsets up to date
    styledText.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent e) {
            System.out.println(e.start);
            System.out.println(e.start);
            System.out.println(e.text.length());
        }//  w  w  w.  ja v  a2 s .co  m
    });

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

From source file:Snippet19.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setBounds(10, 10, 200, 200);/*from   w  ww  .  j  av  a 2  s.  co  m*/
    text.addListener(SWT.Verify, new Listener() {
        public void handleEvent(Event e) {
            String string = e.text;
            char[] chars = new char[string.length()];
            string.getChars(0, chars.length, chars, 0);
            for (int i = 0; i < chars.length; i++) {
                if (!('0' <= chars[i] && chars[i] <= '9')) {
                    e.doit = false;
                    return;
                }
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:CLabelGradientBackgroundThreeColors.java

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

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

    CLabel one = new CLabel(shell, SWT.LEFT);
    one.setText("Second Gradient Example");
    one.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Set the background gradient
    one.setBackground(new Color[] { shell.getDisplay().getSystemColor(SWT.COLOR_WHITE),
            shell.getDisplay().getSystemColor(SWT.COLOR_GRAY),
            shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY),
            shell.getDisplay().getSystemColor(SWT.COLOR_BLACK) }, new int[] { 33, 67, 100 });

    shell.open();/*from  w  ww.  j  a  v  a 2s .c  o m*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}