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

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

    FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);

    fillLayout.marginWidth = 5;//  w  w  w.ja v  a2 s  .  c  o m
    fillLayout.marginHeight = 5;

    // Number of pixels between the edge of a cell and edges of its neighboring cells
    fillLayout.spacing = 10;

    shell.setLayout(fillLayout);

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

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

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

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

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

From source file:CoolBarComboButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar bar = new CoolBar(shell, SWT.BORDER);

    CoolItem item = new CoolItem(bar, SWT.NONE);
    Button button = new Button(bar, SWT.PUSH);
    button.setText("Button ");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(button);//from   w ww .  j a  v  a 2 s .  c om

    item = new CoolItem(bar, SWT.NONE);
    Combo combo = new Combo(bar, SWT.NONE);
    size = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(combo);

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

From source file:GridLayoutMargin.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 20;/* w  ww . j a  va2s.  c  o m*/
    gridLayout.marginWidth = 30;

    shell.setLayout(gridLayout);

    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");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("button #3");

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

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

From source file:ImageCreateForLable.java

public static void main(String[] args) {
    Image image;//  www . jav  a2s. c om
    Image copy;
    Image disable;
    Image gray;

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Show Image Flags");

    image = new Image(display, "yourFile.gif");

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

    disable = new Image(display, image, SWT.IMAGE_DISABLE);

    gray = new Image(display, image, SWT.IMAGE_GRAY);

    shell.setLayout(new FillLayout());

    // Create labels to hold each image
    new Label(shell, SWT.NONE).setImage(image);
    new Label(shell, SWT.NONE).setImage(copy);
    new Label(shell, SWT.NONE).setImage(disable);
    new Label(shell, SWT.NONE).setImage(gray);

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

    image.dispose();
    copy.dispose();
    disable.dispose();
    gray.dispose();

    display.dispose();

}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 164");
    shell.setLayout(new GridLayout());
    Image image = new Image(display, Snippet164.class.getResourceAsStream("eclipse.png"));

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

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setImage(image);//from   ww  w .j  a v a 2  s .  c  om
    button2.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "Eclipse logo";
        }
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 114");
    Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item " + i);
    }//from  w ww.j a  v  a 2 s  . c  o  m
    Rectangle clientArea = shell.getClientArea();
    tree.setBounds(clientArea.x, clientArea.y, 100, 100);
    tree.addListener(SWT.Selection, 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:PopupListUsing.java

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

    // Create a button to launch the list
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Push Me");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            PopupList list = new PopupList(shell);

            list.setItems(new String[] { "A", "B", "C" });

            String selected = list.open(shell.getBounds());
            System.out.println(selected);
        }/*from w w w .j ava2 s  . c  o  m*/
    });

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

}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 49");
    final ToolBar toolBar = new ToolBar(shell, SWT.WRAP);
    for (int i = 0; i < 12; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.PUSH);
        item.setText("Item " + i);
    }/* www.j  a  v  a  2 s .c o m*/
    shell.addListener(SWT.Resize, e -> {
        Rectangle rect = shell.getClientArea();
        Point size = toolBar.computeSize(rect.width, SWT.DEFAULT);
        toolBar.setSize(size);
    });
    Rectangle clientArea = shell.getClientArea();
    toolBar.setLocation(clientArea.x, clientArea.y);
    toolBar.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GridLayoutSpacing.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 20;/*from   w ww .  ja v  a 2 s. c o m*/
    gridLayout.verticalSpacing = 30;

    shell.setLayout(gridLayout);

    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");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("button #3");

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

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

From source file:SashFromMaximizeControl.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    // Fill the parent window with the buttons and sash
    shell.setLayout(new FillLayout());

    // Create the SashForm and the buttons
    SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
    new Button(sashForm, SWT.PUSH).setText("Left");
    Button control = new Button(sashForm, SWT.PUSH);
    control.setText("Right");
    sashForm.setOrientation(SWT.HORIZONTAL);

    if (control == sashForm.getMaximizedControl()) {
        sashForm.setMaximizedControl(null);
    } else {// www . j  a  va  2s.  c  om
        sashForm.setMaximizedControl(control);
    }

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

}