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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.open();/*from  w w w .  jav a 2  s  .  c om*/
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    dialog.setFilterNames(new String[] { "Batch Files", "All Files (*.*)" });
    dialog.setFilterExtensions(new String[] { "*.bat", "*.*" }); // Windows
    // wild
    // cards
    dialog.setFilterPath("c:\\"); // Windows path
    dialog.setFileName("fred.bat");
    System.out.println("Save to: " + dialog.open());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DisplayFilterEvent.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Left click your mouse");
    shell.setSize(200, 100);//from w  ww.  j  a  v a 2s .co  m
    shell.open();

    shell.addListener(SWT.MouseDown, new SimpleListener("Shell mouse down listener"));

    display.addFilter(SWT.MouseDown, new SimpleListener("Display mouse down Listener"));

    display.addFilter(SWT.MouseUp, new SimpleListener("Display mouse up Listener"));

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

From source file:org.eclipse.swt.examples.controlexample.ControlExample.java

/**
 * Invokes as a standalone program.//  w ww .  j  av a 2s  .  c  o  m
 */
public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setLayout(new FillLayout());
    ControlExample instance = new ControlExample(shell);
    shell.setText(getResourceString("window.title"));
    setShellSize(instance, shell);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    instance.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    /* Relative links: use the HTML base tag */
    String html = "<html><head>" + "<base href=\"http://www.eclipse.org/swt/\" >"
            + "<title>HTML Test</title></head>" + "<body><a href=\"faq.php\">local link</a></body></html>";

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 137");
    shell.setLayout(new FillLayout());
    Browser browser;/*from w  w  w .  j av a  2 s  . c  o m*/
    try {
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    browser.setText(html);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SashFormSashWidth.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");
    new Button(sashForm, SWT.PUSH).setText("Right");

    sashForm.SASH_WIDTH = 20;//w  w  w.j a  va2 s. c  o  m

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

}

From source file:TextKeyEventListener.java

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

    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);//from  w  w  w  . ja v a  2  s .  c  om

    Text t2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t2.setBounds(10, 25, 100, 32);

    t2.addListener(SWT.KeyDown, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("KEY");
        }
    });

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

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

public static void main(String[] args) {
    String html = "<HTML><HEAD><TITLE>HTML Test</TITLE></HEAD><BODY>";
    for (int i = 0; i < 100; i++)
        html += "<P>This is line " + i + "</P>";
    html += "</BODY></HTML>";

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 136");
    shell.setLayout(new FillLayout());
    Browser browser;//from w  ww  .  j av  a2 s. c o  m
    try {
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    browser.setText(html);
    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 ProgressBar
    ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
    pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    pb1.setMinimum(0);/* w w w.  j  a  va  2s . c o m*/
    pb1.setMaximum(30);

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

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

From source file:StyledTextClipboard.java

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

    StyledText text1 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
    StyledText text2 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);

    text1.setText("1234567");

    text1.setSelectionRange(2, 4);/*w  ww  .j a  v a 2 s.com*/

    text1.cut();
    text2.paste();

    text1.setBounds(10, 10, 100, 100);

    text2.setBounds(10, 300, 100, 100);

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

}

From source file:FillRectangle.java

public static void main(String[] args) {
    Display display = new Display();
    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) {
            e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.fillRectangle(30, 40, 400, 200);
        }//from w  ww  . java  2s . co  m
    });

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