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

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

    // Create a List with a vertical scroll bar
    List list = new List(shell, SWT.V_SCROLL);

    // Add a bunch of items to it
    for (int i = 0; i < 500; i++) {
        list.add("A list item");
    }/*from  ww  w.ja v a 2 s  .  c  o m*/

    // Scroll to the bottom
    list.select(list.getItemCount() - 1);
    list.showSelection();

    // Get the scroll bar
    ScrollBar sb = list.getVerticalBar();

    // Add one more item that shows the selection value
    list.add("Selection: " + sb.getSelection());

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

From source file:MainClass.java

public static void main(String[] a) {
    final Display d = new Display();
    final Shell s = new Shell(d);

    s.setSize(250, 200);//from w  w  w  . j  av a  2s.co m
    s.setText("A Table Shell Example");
    s.setLayout(new FillLayout());
    Tree t = new Tree(s, SWT.SINGLE | SWT.BORDER);
    TreeItem child1 = new TreeItem(t, SWT.NONE, 0);
    child1.setText("1");
    TreeItem child2 = new TreeItem(t, SWT.NONE, 1);
    child2.setText("2");
    TreeItem child2a = new TreeItem(child2, SWT.NONE, 0);
    child2a.setText("2A");
    TreeItem child2b = new TreeItem(child2, SWT.NONE, 1);
    child2b.setText("2B");
    TreeItem child3 = new TreeItem(t, SWT.NONE, 2);
    child3.setText("3");
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();

}

From source file:Snippet113.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Table table = new Table(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }/*from w w  w .j  a  v  a 2  s.  c om*/
    table.setSize(100, 100);
    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
            System.out.println(event.item + " " + string);
        }
    });
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ShellEscapeClose.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event event) {
            switch (event.detail) {
            case SWT.TRAVERSE_ESCAPE:
                shell.close();//from  w  w  w .j a  v  a2s  .c o  m
                event.detail = SWT.TRAVERSE_NONE;
                event.doit = false;
                break;
            }
        }
    });
    Button button = new Button(shell, SWT.PUSH);
    button.setText("A Button (that doesn't process Escape)");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:RadioNoGroup.java

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

    Menu menuBar = new Menu(shell, SWT.BAR);

    Menu fileMenu = new Menu(menuBar);

    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);/*from w w  w  .  j a  v  a2  s. c om*/

    MenuItem itema = new MenuItem(fileMenu, SWT.RADIO);
    itema.setText("Radio A");
    MenuItem itemb = new MenuItem(fileMenu, SWT.RADIO);
    itemb.setText("Radio B");
    MenuItem itemc = new MenuItem(fileMenu, SWT.RADIO);
    itemc.setText("Radio C");

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

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setText("A Shell Menu Example");

    Menu m = new Menu(s, SWT.BAR);

    // create a file menu and add an exit item
    final MenuItem file = new MenuItem(m, SWT.CASCADE);
    file.setText("File");
    final Menu filemenu = new Menu(s, SWT.DROP_DOWN);
    file.setMenu(filemenu);//w w w . j  av a 2  s.  co m
    final MenuItem openItem = new MenuItem(filemenu, SWT.PUSH);
    openItem.setText("Open");
    final MenuItem separator = new MenuItem(filemenu, SWT.SEPARATOR);
    final MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH);
    exitItem.setText("Exit");

    s.setMenuBar(m);

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

}

From source file:EventTypeGet.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            System.out.println(getEventName(e.type));
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }//from www .  j a v a 2 s .  c o  m
        }
    });

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

From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new GraphicsExample().open(display);
    while (shell != null && !shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }//w ww  . j av  a 2s  .  c o  m
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 197");
    final TextLayout layout = new TextLayout(display);
    layout.setText(longString);/*  ww  w.ja v a 2 s.co m*/
    Listener listener = event -> {
        switch (event.type) {
        case SWT.Paint:
            layout.draw(event.gc, 10, 10);
            break;
        case SWT.Resize:
            layout.setWidth(shell.getSize().x - 20);
            break;
        }
    };
    shell.addListener(SWT.Paint, listener);
    shell.addListener(SWT.Resize, listener);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    layout.dispose();
    display.dispose();
}

From source file:ImageCopyCreation.java

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

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Image image = new Image(display, "yourFile.gif");

            Image copy = new Image(display, image, SWT.IMAGE_COPY);

            e.gc.drawImage(copy, 10, 10);

            e.gc.drawImage(copy, 10, 50);

            image.dispose();//from ww  w  . j  av  a 2  s  .c om
            copy.dispose();
        }
    });

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