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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("PowerPoint Example");
    shell.setLayout(new FillLayout());
    try {//from   ww w . j  a  v  a  2 s.co m
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        clientSite = new OleClientSite(frame, SWT.NONE, "PowerPoint.Slide");
        addFileMenu(frame);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.setSize(800, 600);
    shell.open();

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

From source file:StyledTextExtendedModifyListener.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.addExtendedModifyListener(new ExtendedModifyListener() {
        public void modifyText(ExtendedModifyEvent event) {
            System.out.println(event.start);
            System.out.println(event.length);
            System.out.println(event.replacedText);
        }/*from  ww  w.ja  va  2  s . c om*/
    });

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 290");
    shell.addMouseListener(new MouseAdapter() {
        @Override/*from   w w w  .  j ava2  s  .  com*/
        public void mouseUp(MouseEvent e) {
            if (e.count == 1) {
                System.out.println("Mouse up");
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            System.out.println("Double-click");
        }
    });
    shell.setBounds(10, 10, 200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 243");
    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(event -> {
        text1.setTopIndex(text0.getTopIndex());
        text1.setSelection(event.start, event.end);
        text1.insert(event.text);// w  w  w.j a v a2s . c  o  m
    });
    shell.setBounds(10, 10, 200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Word Example");
    shell.setLayout(new FillLayout());
    try {//w  ww.j a v a 2  s. co m
        frame = new OleFrame(shell, SWT.NONE);
        clientSite = new OleClientSite(frame, SWT.NONE, "Word.Document");
        addFileMenu(frame);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.setSize(800, 600);
    shell.open();

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

From source file:cit.workflow.engine.manager.test.SWTTimeSeriesDemo.java

/**
 * Starting point for the demonstration application.
 *
 * @param args  ignored./* w  w  w.  jav a 2 s. c  o  m*/
 */
public static void main(String[] args) {
    final JFreeChart chart = createChart(createDataset());
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 300);
    shell.setLayout(new FillLayout());
    shell.setText("Time series demo for jfreechart running with SWT");
    ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true);
    frame.setDisplayToolTips(true);
    frame.setHorizontalAxisTrace(false);
    frame.setVerticalAxisTrace(false);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();

    // Create the main window
    Shell shell = new Shell(display);

    Text fahrenheit = new Text(shell, SWT.BORDER);
    fahrenheit.setData("Type a temperature in Fahrenheit");
    fahrenheit.setBounds(20, 20, 100, 20);

    fahrenheit.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            // Get the widget whose text was modified
            Text text = (Text) event.widget;
            System.out.println(text.getText());
        }/*  ww  w.ja va  2  s  .  c  o m*/
    });

    shell.open();

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

From source file:FontDataConstruct.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) {

            Font font = new Font(shell.getDisplay(), new FontData("Helvetica", 18, SWT.NORMAL));
            e.gc.setFont(font);/*from ww  w .ja  v a  2 s  .  c o  m*/
            e.gc.drawText("My Text", 0, 0);
            font.dispose();

        }
    });

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

From source file:UntypedEventListener.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) {

            System.out.println(e.button);

            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/*  w  w w . j  a v a 2 s .  com*/
        }
    });

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

From source file:FormLayoutFormAttachmentSetButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;//from  ww  w. ja  va2  s  .  c  o  m
    layout.marginWidth = 10;
    shell.setLayout(layout);

    Button one = new Button(shell, SWT.PUSH);
    one.setText("One");
    FormData data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(0, 5);
    data.bottom = new FormAttachment(50, -5);
    data.right = new FormAttachment(50, -5);
    one.setLayoutData(data);

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