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:org.eclipse.swt.snippets.Snippet55.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 55");
    Text text = new Text(shell, SWT.BORDER);
    text.setFont(new Font(display, "Courier", 13, SWT.NORMAL)); // Use a fixed size font
    Rectangle clientArea = shell.getClientArea();
    text.setLocation(clientArea.x, clientArea.y);
    int columns = 10;
    GC gc = new GC(text);
    FontMetrics fm = gc.getFontMetrics();
    int width = (int) (columns * fm.getAverageCharacterWidth());
    int height = fm.getHeight();
    gc.dispose();/*from www  . ja  va 2 s.  c o  m*/
    text.setSize(text.computeSize(width, height));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DateTimeDialogCreate.java

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

    DateTime calendar = new DateTime(shell, SWT.CALENDAR);
    calendar.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("calendar date changed");
        }//from   w  ww  .j  av a2  s.  co m
    });

    DateTime time = new DateTime(shell, SWT.TIME);
    time.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("time changed");
        }
    });

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

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

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

            e.gc.drawImage(disable, 10, 10);

            e.gc.drawImage(image, 10, 50);

            image.dispose();//from ww  w.j a  v a  2  s . c o  m
            disable.dispose();
        }
    });

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

From source file:ImageDataManipuatation.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();

            data.setPixel(5, 5, 5);/*from   ww  w . j a  va 2  s. co m*/

            Image anotherImage = new Image(display, data);
            e.gc.drawImage(anotherImage, 10, 10);
            image.dispose();
        }
    });

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

From source file:StyledTextVerifyListenerBackspaceDelete.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 w  w  w  .j av  a 2s .com*/
            // Allow backspace and delete
            if (event.character == '\u0008' || event.character == '\u007F') {
                event.doit = true;
            }
        }
    });

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

}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 20");
    CoolBar bar = new CoolBar(shell, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CoolItem item = new CoolItem(bar, SWT.NONE);
        Button button = new Button(bar, SWT.PUSH);
        button.setText("Button " + i);
        Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        item.setPreferredSize(item.computeSize(size.x, size.y));
        item.setControl(button);/*from   ww  w. j  a  va  2  s . com*/
    }
    Rectangle clientArea = shell.getClientArea();
    bar.setLocation(clientArea.x, clientArea.y);
    bar.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SWTButtonExampleDemo.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(300, 200);//  www  .  j  a  v  a 2  s .  c o m
    shell.setText("Button Example");
    shell.setLayout(new RowLayout());

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Click Me");

    final Text text = new Text(shell, SWT.SHADOW_IN);

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            text.setText("No worries!");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            text.setText("No worries!");
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ControlTabTransversing.java

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

    Text text1 = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text1.setText("Can't Traverse");
    text1.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            switch (e.detail) {
            case SWT.TRAVERSE_TAB_NEXT:
            case SWT.TRAVERSE_TAB_PREVIOUS: {
                e.doit = false;//from w  w  w  .j  a v  a  2s. c om
            }
            }
        }
    });
    Text text2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text2.setText("Can Traverse");
    shell.pack();
    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();
    final Shell s = new Shell(d);

    s.setSize(250, 200);//w  w  w.j  a  v  a2  s.  c  om
    s.setText("A MouseListener Example");
    s.open();

    s.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            System.out.println("Mouse Button Down at:" + e.x + " " + e.y);

        }

        public void mouseUp(MouseEvent e) {
            System.out.println("Mouse Button up at:" + e.x + " " + e.y);
            System.out.println(e.button);

        }

        public void mouseDoubleClick(MouseEvent e) {
            System.out.println("Mouse Double Clicked at:" + e.x + " " + e.y);
        }
    });

    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.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 progress bar
    ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
    pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    pb1.setMinimum(0);//from w w w  . java  2s .  co m
    pb1.setMaximum(30);

    // Create an indeterminate progress bar
    ProgressBar pb2 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.INDETERMINATE);
    pb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

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

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