Example usage for org.eclipse.swt.widgets Display readAndDispatch

List of usage examples for org.eclipse.swt.widgets Display readAndDispatch

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display readAndDispatch.

Prototype

public boolean readAndDispatch() 

Source Link

Document

Reads an event from the event queue, dispatches it appropriately, and returns true if there is potentially more work to do, or false if the caller can sleep until another event is placed on the event queue.

Usage

From source file:ComboAddItem.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  ww w. ja  va  2 s .co  m*/

    combo.add("new");

    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: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. ja  v a2  s. co  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 v a2 s .  c o m
    });
    childShell.setLayout(new FillLayout());
    childShell.setText("little brother");
    childShell.open();

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

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  .ja v  a  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: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  . ja  va2s . c  o m*/
    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: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);//  ww  w  . ja  v a  2  s.  c  o m
        }
    });

    shell.setBounds(10, 10, 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;
            }/*from ww  w  . j  a v  a  2 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: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 w  w  w .  j a  v  a 2  s.  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: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 ww w  . j  av  a2 s  . c  o m

        }
    });

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

From source file:Snippet14.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(100, 100);/* w  w  w .  j ava  2s .  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();
}