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

License:asdf

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

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null);
    ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null);

    styledText.setStyleRanges(ranges);/*from ww  w.j  a va2  s  .co m*/

    styledText.replaceStyleRanges(5, 9, ranges);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 127");
    shell.setLayout(new RowLayout());
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Can't Traverse");
    button1.addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS: {
            e.doit = false;//from   w  ww.j  a va2  s .  co  m
        }
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Can Traverse");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyledTextVerifyListenerReturn.java

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

    StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("12345");

    styledText.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent event) {
            System.out.println(event.character);
            event.doit = false;//from www .  j av  a2 s  . c  o m

            // Allow return
            if (event.character == '\r')
                event.doit = true;
        }
    });

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:BrowserExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Browser example");
    BrowserExample instance = new BrowserExample(shell);
    Image icon = new Image(display, "java2s.gif");
    shell.setImage(icon);/*from  www.  j av  a2  s  .  com*/
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    icon.dispose();
    instance.dispose();
    display.dispose();
}

From source file:OpenWindowListenerUsing.java

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

    Browser browser = new Browser(shell, SWT.NONE);
    browser.setBounds(5, 5, 600, 600);/*w ww . j  a  v  a 2  s.  co m*/

    browser.addOpenWindowListener(new OpenWindowListener() {
        public void open(WindowEvent event) {
            Shell shell = new Shell(display);
            shell.setText("New Window");
            shell.setLayout(new FillLayout());
            Browser browser = new Browser(shell, SWT.NONE);
            event.browser = browser;
        }
    });

    browser.setUrl("http://java2s.com");
    shell.open();

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

From source file:MainClass.java

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

    s.setText("A Tabbed Shell Example");
    final CoolBar bar = new CoolBar(s, SWT.BORDER);
    bar.setSize(280, 70);// w  w w .j  a  v  a  2 s.c om
    bar.setLocation(0, 0);
    // final Image openIcon = new Image(d, "c:\\icons\\open.jpg");

    final CoolItem openCoolItem = new CoolItem(bar, SWT.NONE);
    final Button openBtn = new Button(bar, SWT.PUSH);
    // openBtn.setImage(openIcon);
    openBtn.pack();
    Point size = openBtn.getSize();
    openCoolItem.setControl(openBtn);
    openCoolItem.setSize(openCoolItem.computeSize(size.x, size.y));

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

From source file:SpinnerFloatPoint.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);//www. j  a v  a2 s .  c  o m
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Main Window");
    shell.setLayout(new FillLayout());
    final Browser browser;
    try {//from w  w w. j  a v a 2 s .co m
        browser = new Browser(shell, BROWSER_STYLE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    initialize(display, browser);
    shell.open();
    browser.setUrl("http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ImageDataFromImage.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");

            ImageData data = image.getImageData();

            System.out.println(data.height);

            e.gc.drawImage(image, 10, 10);
            image.dispose();/*w  w  w  .  j a  va  2 s .co m*/
        }
    });

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

From source file:TabListFocusTransfer.java

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

    Button b1 = new Button(shell, SWT.PUSH);
    b1.setText("1");
    Button b2 = new Button(shell, SWT.RADIO);
    b2.setText("2");
    Button b3 = new Button(shell, SWT.RADIO);
    b3.setText("3");
    Button b4 = new Button(shell, SWT.RADIO);
    b4.setText("4");
    Button b5 = new Button(shell, SWT.PUSH);
    b5.setText("5");

    Control[] tabList1 = new Control[] { b2, b1, b3, b5, b4 };
    shell.setTabList(tabList1);/*from  ww  w  . j  ava 2  s. c o m*/

    shell.pack();
    shell.open();

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