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

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

Introduction

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

Prototype

public Display() 

Source Link

Document

Constructs a new instance of this class.

Usage

From source file:Snippet22.java

License:asdf

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, 0);
    text.setText("ASDF");
    text.setSize(64, 32);/*from ww w .  j  a va 2 s  .  c o m*/
    text.selectAll();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FormLayoutAttachEachOther.java

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

    shell.setLayout(new FormLayout());

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

    FormData formData = new FormData();
    formData.left = new FormAttachment(20);
    formData.top = new FormAttachment(20);
    button1.setLayoutData(formData);//from  w ww .  ja  v  a  2s.c  o  m

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

    formData = new FormData();
    formData.left = new FormAttachment(button1, 0, SWT.CENTER);
    formData.top = new FormAttachment(button1, 0, SWT.CENTER);
    button2.setLayoutData(formData);

    shell.pack();
    shell.open();
    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }
    display.dispose();
}

From source file:GridLayoutGrabExpressionSpace.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;//from   ww w  .ja  v a2 s  . c o  m
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    list.setLayoutData(gridData);

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));

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

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

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

From source file:FormLayoutCenterAnotherControl.java

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

    shell.setLayout(new FormLayout());

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

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

    FormData formData = new FormData();
    formData.left = new FormAttachment(button1);
    button2.setLayoutData(formData);/*from w ww .j a v  a  2s  . com*/

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

    formData = new FormData();
    formData.top = new FormAttachment(button2, 10);
    formData.left = new FormAttachment(button2, 0, SWT.CENTER);
    button3.setLayoutData(formData);

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

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

From source file:Snippet74.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Caret caret = new Caret(shell, SWT.NONE);
    caret.setBounds(10, 10, 2, 32);//from  ww  w  .j av  a 2 s  .  c o  m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SpinnerSelectionListener.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);//w  ww.j  a va 2 s.c o  m
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);

    spinner.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selection = spinner.getSelection();
            int digits = spinner.getDigits();
            System.out.println("Selection is " + (selection / Math.pow(10, digits)));
        }
    });

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

From source file:MainClass.java

public static void main(String[] args) {

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

    final Image image = new Image(display, new MainClass().getClass().getResourceAsStream("swt.png"));
    System.out.println(image.getImageData().scanlinePad);
    image.getImageData().scanlinePad = 40;
    System.out.println(image.getImageData().scanlinePad);

    shell.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            event.gc.drawImage(image, 0, 0);
            Rectangle rect = shell.getClientArea();
            ImageData data = image.getImageData();

            int srcX = data.width / 4;
            int srcY = data.height / 4;
            int srcWidth = data.width / 2;
            int srcHeight = data.height / 2;
            int destWidth = 2 * srcWidth;
            int destHeight = 2 * srcHeight;

            event.gc.drawImage(image, srcX, srcY, srcWidth, srcHeight, rect.width - destWidth,
                    rect.height - destHeight, destWidth, destHeight);
        }//from   w w w  . jav a2 s. c  o m
    });
    shell.setText("Draw Images");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    image.dispose();
    display.dispose();
}

From source file:SineFunctionPlotting.java

public static void main(String[] args) {
    Display display = new Display();
    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) {
            Canvas canvas = (Canvas) e.widget;
            int maxX = canvas.getSize().x;
            int maxY = canvas.getSize().y;

            // Calculate the middle
            int halfX = (int) maxX / 2;
            int halfY = (int) maxY / 2;

            // Set the line color and draw a horizontal axis
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
            e.gc.drawLine(0, halfY, maxX, halfY);

            // Draw the sine wave
            for (int i = 0; i < maxX; i++) {
                e.gc.drawPoint(i, getNormalizedSine(i, halfY, maxX));
            }/*from  w w  w  . java2s .c o  m*/
        }
    });

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

From source file:MainClass.java

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

    PrintDialog dlg = new PrintDialog(shell);

    dlg.setScope(PrinterData.SELECTION);

    PrinterData printerData = dlg.open();
    if (printerData != null) {
        Printer printer = new Printer(printerData);
        System.out.println(printer.getClientArea());

        Point dpi = printer.getDPI(); // Get the DPI
        Rectangle rect = printer.getClientArea(); // Get the printable area
        Rectangle trim = printer.computeTrim(0, 0, 0, 0); // Get the whole page
        int left = trim.x + dpi.x; // Set left margin one inch from left side of paper
        int top = trim.y + dpi.y; // Set top margin
        int right = (rect.width + trim.x + trim.width) - dpi.x; // 1st three
                                                                // values give
                                                                // you the right side of the page
        int bottom = (rect.height + trim.y + trim.height) - dpi.y; // Set bottom
                                                                   // margin

        // use left, top, right, and bottom as the boundaries that govern where
        // you draw on the page.

        printer.dispose();/*from  w ww . j  av  a  2  s.co m*/
    }

    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();
    Shell s = new Shell(d);

    final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
    bar.setSize(300, 70);/* w  w  w.  ja  v a  2s. c o  m*/
    bar.setLocation(0, 0);

    // create images for toolbar buttons
    // final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
    // final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
    // final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
    // final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
    // final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");

    // create and add the button for performing an open operation
    final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
    // openToolItem.setImage(openIcon);
    openToolItem.setText("Open");
    openToolItem.setToolTipText("Open File");

    // create and add the button for performing a save operation
    final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
    // saveToolItem.setImage(saveIcon);
    saveToolItem.setText("Save");
    saveToolItem.setToolTipText("Save File");

    // create inner classes for SelectionListeners
    class Open implements SelectionListener {
        public void widgetSelected(SelectionEvent event) {
            System.out.println("Open");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }
    }
    openToolItem.addSelectionListener(new Open());

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