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.Snippet4.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 4");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();/*from  www.  j a va 2s  . c  o m*/
    Rectangle clientArea = shell.getClientArea();
    b.setLocation(clientArea.x + 10, clientArea.y + 10);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
        dialog.addListener(SWT.Traverse, t -> {
            if (t.detail == SWT.TRAVERSE_ESCAPE) {
                t.doit = false;
            }
        });
        dialog.open();
    }));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Image image = new Image(display, 20, 20);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);//from  w  ww  . java  2s .co  m
    gc.fillRectangle(image.getBounds());
    gc.dispose();

    Shell shell = new Shell(display);
    shell.setText("Snippet 112");
    shell.setLayout(new FillLayout());
    Group group = new Group(shell, SWT.NONE);
    group.setLayout(new FillLayout());
    group.setText("a square");
    Canvas canvas = new Canvas(group, SWT.NONE);
    canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));

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

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

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 369");
    shell.setLayout(new FillLayout());
    shell.setText("Line spacing provider in action");

    StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setText("// Type your custom line spacing \n10\n5\nabcd\n20\nefgh");

    text.setLineSpacingProvider(lineIndex -> {
        String line = text.getLine(lineIndex).trim();
        try {/* w  w w.ja  v  a2  s  .  com*/
            return Integer.parseInt(line);
        } catch (NumberFormatException e) {
            return null;
        }
    });

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

From source file:RowLayoutTest.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 12;/*  w w  w  . j  a va  2 s . com*/
    layout.marginTop = 0;
    layout.justify = true;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");
    new Button(shell, SWT.PUSH).setText("five");
    new Button(shell, SWT.PUSH).setText("six");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("seven");
    b.setLayoutData(new RowData(100, 100));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:RowLayoutTest.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 20;//w w w  .j a v  a2 s  . c  o m
    layout.marginTop = 20;
    layout.justify = true;
    shell.setLayout(layout);

    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");
    new Button(shell, SWT.PUSH).setText("five");
    new Button(shell, SWT.PUSH).setText("six");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("seven");
    b.setLayoutData(new RowData(100, 100));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell();
    shell.setText("Snippet 345");
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    String string = "The quick brown fox jumps over the lazy dog";
    Button button;//from w  w w.  j  av  a2s . co  m
    button = new Button(shell, SWT.PUSH | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.RADIO | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.TOGGLE | SWT.WRAP);
    button.setText(string);
    button = new Button(shell, SWT.CHECK | SWT.WRAP);
    button.setText(string);
    shell.setSize(shell.computeSize(200, SWT.DEFAULT));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:Snippet29.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);/*from w w  w  . jav a 2  s  . c  o 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, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("Select All");
        }
    });
    item.setText("Select &All\tCtrl+A");
    item.setAccelerator(SWT.CTRL + 'A');
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyledTextListenerVerify.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    styledText.setText("text");

    // use a verify listener to keep the offsets up to date
    styledText.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent e) {
            System.out.println(e.start);
            System.out.println(e.start);
            System.out.println(e.text.length());
        }/*from  w  w w  . j  a v a  2  s.co  m*/
    });

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

From source file:CLabelGradientBackgroundThreeColors.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("CLabel Gradient");

    shell.setLayout(new GridLayout(1, false));

    CLabel one = new CLabel(shell, SWT.LEFT);
    one.setText("Second Gradient Example");
    one.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Set the background gradient
    one.setBackground(new Color[] { shell.getDisplay().getSystemColor(SWT.COLOR_WHITE),
            shell.getDisplay().getSystemColor(SWT.COLOR_GRAY),
            shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY),
            shell.getDisplay().getSystemColor(SWT.COLOR_BLACK) }, new int[] { 33, 67, 100 });

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

From source file:LayoutSpaceProperties.java

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

    FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);

    fillLayout.marginWidth = 5;//from  w  ww .  ja  v  a 2  s  . co  m
    fillLayout.marginHeight = 5;

    // Number of pixels between the edge of a cell and edges of its neighboring cells
    fillLayout.spacing = 10;

    shell.setLayout(fillLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button number 2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");

    shell.setSize(450, 100);
    shell.open();

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