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

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);/*from   w w  w  .j a v  a  2  s .c  o  m*/

    combo.deselect(0);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

From source file:DisposeListenerWithShell.java

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

    // Create the child shell and the dispose listener
    final Shell childShell = new Shell(shell);
    childShell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            // When the child shell is disposed, change the message on the main shell
            System.out.println("Dispoase");
        }//from  w  w  w .  j a va  2  s.  c om
    });
    childShell.setLayout(new FillLayout());
    childShell.setText("little brother");
    childShell.open();

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 40");
    shell.setLayout(new GridLayout(2, false));
    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setLayoutData(new GridData(100, 100));
    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setLayoutData(new GridData(100, 100));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Popup");
    c1.setMenu(menu);//from w  ww . j ava 2 s  . c  om
    c2.setMenu(menu);
    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComboAddingItem.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);//w w  w  .j a va 2 s . c  o  m

    combo.add("new", 2);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

From source file:TextLink.java

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

    final Text text0 = new Text(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final Text text1 = new Text(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

    text0.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            text1.setTopIndex(text0.getTopIndex());
            text1.setSelection(event.start, event.end);
            text1.insert(event.text);//from w  ww  . j  a  va2 s  . c om
        }
    });

    shell.setBounds(10, 10, 200, 200);
    shell.open();

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

    display.dispose();
}

From source file:TimerRepeating.java

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

    Runnable timer = new Runnable() {
        public void run() {
            Point point = display.getCursorLocation();
            Rectangle rect = shell.getBounds();
            if (rect.contains(point)) {
                System.out.println("In");
            } else {
                System.out.println("Out");
            }//from  ww  w. j a v a 2s . co m
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);

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

From source file:DisplayEventFilerMouseDown.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) {
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/* w w  w .jav a2 s.co m*/
        }
    });

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

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

From source file:Snippet14.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(100, 100);/*from  w  w  w  .j  a v a  2 s.  c  o  m*/
    shell.addListener(SWT.MouseEnter, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("ENTER");
        }
    });
    shell.addListener(SWT.MouseExit, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("EXIT");
        }
    });
    shell.addListener(SWT.MouseHover, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("HOVER");
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 29");
    Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);//from  www.ja  v  a  2  s .co  m
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText("&File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    MenuItem item = new MenuItem(submenu, SWT.PUSH);
    item.addListener(SWT.Selection, e -> System.out.println("Select All"));
    item.setText("Select &All\tCtrl+A");
    item.setAccelerator(SWT.MOD1 + 'A');
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyledTextLineBackgroundListener.java

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("\n1234\n124\n\1234\n12314\n\1241234\n");

    styledText.addLineBackgroundListener(new LineBackgroundListener() {

        public void lineGetBackground(LineBackgroundEvent event) {
            if (event.lineText.indexOf("SWT") > -1) {
                event.lineBackground = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
            }/*from w  ww .  j  a va  2s  .c  o m*/

        }
    });

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