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

public static void main(String[] args) {
    final Graphics2DRenderer renderer = new Graphics2DRenderer();
    Shell shell = new Shell();
    shell.setSize(350, 350);/*from   w  ww. ja va  2s.co m*/

    shell.open();
    shell.setText("Draw2d Hello World");
    LightweightSystem lws = new LightweightSystem(shell);
    IFigure figure = new Figure() {
        protected void paintClientArea(org.eclipse.draw2d.Graphics graphics) {
            Dimension controlSize = getSize();

            renderer.prepareRendering(graphics);
            // prepares the Graphics2D renderer

            // gets the Graphics2D context and switch on the antialiasing
            Graphics2D g2d = renderer.getGraphics2D();
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

            // paints the background with a color gradient
            g2d.setPaint(new GradientPaint(0.0f, 0.0f, java.awt.Color.yellow, (float) controlSize.width,
                    (float) controlSize.width, java.awt.Color.white));
            g2d.fillRect(0, 0, controlSize.width, controlSize.width);

            // draws rotated text
            g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16));
            g2d.setColor(java.awt.Color.blue);

            g2d.translate(controlSize.width / 2, controlSize.width / 2);
            int nbOfSlices = 18;
            for (int i = 0; i < nbOfSlices; i++) {
                g2d.drawString("Angle = " + (i * 360 / nbOfSlices) + "\u00B0", 30, 0);
                g2d.rotate(-2 * Math.PI / nbOfSlices);
            }

            // now that we are done with Java2D, renders Graphics2D
            // operation
            // on the SWT graphics context
            renderer.render(graphics);

            // now we can continue with pure SWT paint operations
            graphics.drawOval(0, 0, controlSize.width, controlSize.width);
        }
    };
    lws.setContents(figure);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    renderer.dispose();
}

From source file:StyledTextReadOnly.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.setEditable(false);//from   ww  w  . j  a  va 2 s. co m

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

}

From source file:FormLayoutSimple.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;/* w ww.j  a  v a2 s . c o  m*/
    layout.marginWidth = 10;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("Button");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:GetPreferredSize.java

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

    shell.setLayout(new GridLayout());

    Button button = new Button(shell, SWT.PUSH | SWT.LEFT);
    button.setText("Button");

    System.out.println("toControl: " + button.toControl(100, 200));

    shell.open();/* www. ja  v  a  2 s. c o m*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:DisplayPositionRelative.java

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

    shell.setLayout(new GridLayout());

    Button button = new Button(shell, SWT.PUSH | SWT.LEFT);
    button.setText("Button");

    System.out.println("toDisplay: " + button.toDisplay(100, 200));

    shell.open();/* www.  j a va 2 s .c o  m*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);/*  w  ww  . java  2  s  . c o m*/

    shell.setLayout(new FillLayout());

    Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new ArcExamplePaintListener());

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

From source file:CreateMultipleLineText.java

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

    // Create a multiple-line text field
    Text t = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    t.setLayoutData(new GridData(GridData.FILL_BOTH));

    shell.open();//w ww .  j a v  a  2s  .c  om
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

    styledText.replaceTextRange(2, 3, "A");

    styledText.setBounds(10, 10, 100, 100);
    shell.open();//from   w  w  w .j  ava  2s  . com
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:HorizontalSeparatorLabelExample.java

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

    // Create a horizontal separator
    Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
    separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    shell.open();//from   w  w w  .j a  v  a  2  s.com
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

    int zAction = styledText.getKeyBinding('z');

    styledText.setBounds(10, 10, 100, 100);
    shell.open();//from www . ja v  a  2  s  . co  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}