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:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);/*from   w  ww.  j a va2  s  .  c  o  m*/

    final String RUN = "Press to Run";
    final String IS_RUNNING = "Running...";

    shell.setLayout(new FillLayout());
    final Button button = new Button(shell, SWT.PUSH);
    button.setText(RUN);
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            button.setText(IS_RUNNING);

            BusyIndicator.showWhile(button.getDisplay(), new SleepThread(1000));

            button.setText(RUN);
        }
    });

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

}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 57");
    final ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH);
    Rectangle clientArea = shell.getClientArea();
    bar.setBounds(clientArea.x, clientArea.y, 200, 32);
    shell.open();/*from  ww w .  j a v  a2s. c o m*/

    display.timerExec(100, new Runnable() {
        int i = 0;

        @Override
        public void run() {
            if (bar.isDisposed())
                return;
            bar.setSelection(i++);
            if (i <= bar.getMaximum())
                display.timerExec(100, this);
        }
    });

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

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
    for (int i = 0; i < 5; i++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
    }//  w  w  w.  java 2s  .com
    for (int i = 0; i < 10; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        for (int j = 0; j < 5; j++) {
            item.setText(j, "Row " + i + ", Column " + j);
        }
    }
    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:ComboTransferFocus.java

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

    Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("Press TAB");

    Combo combo = new Combo(shell, SWT.NONE);
    combo.setItems(new String[] { "Press enter to select", "B-1", "C-1" });

    combo.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT) {
                e.doit = false;// w  w w. j  av  a  2s.  c  o  m
                e.detail = SWT.TRAVERSE_NONE;
            }
        }
    });

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

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

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

    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;/*from  w w w  .  ja  va2 s .com*/

        gc.setLineAttributes(new LineAttributes(10, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10));
        gc.drawPolyline(new int[] { 50, 100, 50, 20, 60, 30, 50, 45 });

        gc.setLineAttributes(
                new LineAttributes(1 / 2f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_DOT, null, 0, 10));
        gc.drawPolyline(new int[] { 100, 100, 100, 20, 110, 30, 100, 45 });
    });

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

From source file:RowLayoutMargin.java

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

    RowLayout rowLayout = new RowLayout();

    rowLayout.marginLeft = 20;//from w  ww .j a v  a  2s.c  o m
    rowLayout.marginRight = 20;
    rowLayout.marginTop = 20;
    rowLayout.marginBottom = 20;

    shell.setLayout(rowLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");

    shell.setSize(450, 100);
    shell.open();

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

From source file:LineCapsSetting.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            int x = 20, y = 20, w = 120, h = 60;
            GC gc = event.gc;/*w w  w .java 2s .c om*/
            gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
            gc.setLineWidth(10);
            int[] caps = { SWT.CAP_FLAT, SWT.CAP_ROUND, SWT.CAP_SQUARE };
            for (int i = 0; i < caps.length; i++) {
                gc.setLineCap(caps[i]);
                gc.drawLine(x, y, x + w, y);
                y += 20;
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DialogEmptyDisplay.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);

    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new RowLayout());

    dialog.pack();//from   w w  w .j  a  va  2 s  .  c  om
    dialog.open();

    // Move the dialog to the center of the top level shell.
    Rectangle shellBounds = shell.getBounds();
    Point dialogSize = dialog.getSize();

    dialog.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
            shellBounds.y + (shellBounds.height - dialogSize.y) / 2);

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 55");
    Text text = new Text(shell, SWT.BORDER);
    text.setFont(new Font(display, "Courier", 13, SWT.NORMAL)); // Use a fixed size font
    Rectangle clientArea = shell.getClientArea();
    text.setLocation(clientArea.x, clientArea.y);
    int columns = 10;
    GC gc = new GC(text);
    FontMetrics fm = gc.getFontMetrics();
    int width = (int) (columns * fm.getAverageCharacterWidth());
    int height = fm.getHeight();
    gc.dispose();/* w w w . ja v  a  2s.  c  o  m*/
    text.setSize(text.computeSize(width, height));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StackLayoutTest.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    StackLayout layout = new StackLayout();
    shell.setLayout(layout);/*from   w  w  w .ja va 2s. co  m*/
    StackLayoutSelectionAdapter adapter = new StackLayoutSelectionAdapter(shell, layout);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.addSelectionListener(adapter);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.addSelectionListener(adapter);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.addSelectionListener(adapter);
    layout.topControl = one;
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}