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

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

Introduction

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

Prototype

public void dispose() 

Source Link

Usage

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

            System.out.println(data.height);

            e.gc.drawImage(image, 10, 10);
            image.dispose();//from  w ww  .j a va 2s . co m
        }
    });

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

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

public static void main(String[] args) {
    final Display display = new Display();
    PrinterData printerData = new PrinterData();
    printerData.orientation = PrinterData.LANDSCAPE;
    Printer printer = new Printer(printerData);
    Point dpi = printer.getDPI();
    if (printer.startJob("SWT Printing Snippet")) {
        GC gc = new GC(printer);
        if (printer.startPage()) {
            int oneInch = dpi.x;
            gc.drawString("Hello World!", oneInch, 2 * oneInch);
            gc.drawString("Printed on " + printerData.name + " using SWT on " + SWT.getPlatform(), oneInch,
                    oneInch * 5 / 2);//from w  w  w. ja v  a 2s .c o  m
            printer.endPage();
        }
        gc.dispose();
        printer.endJob();
    }
    printer.dispose();
    display.dispose();
}

From source file:ImageEmpty.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, 300, 200);
            GC gc = new GC(image);
            gc.drawLine(10, 10, 200, 200);
            gc.dispose();//from   w w  w  .  j  a va 2  s .  c o m

            e.gc.drawImage(image, 10, 10);
            image.dispose();
        }
    });

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

From source file:GCCreateFrom.java

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

    final Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            GC gc = new GC(canvas);
            gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            gc.drawFocus(5, 5, 200, 10);
            gc.drawText("You can draw text directly on a canvas", 60, 60);
            gc.dispose();/*from   ww  w  . j  a  v a  2  s. co  m*/
        }
    });

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

From source file:TextLink.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    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(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            text1.setTopIndex(text0.getTopIndex());
            text1.setSelection(event.start, event.end);
            text1.insert(event.text);//w  ww  .j av  a 2  s.  c  om
        }
    });

    shell.setBounds(10, 10, 200, 200);
    shell.open();

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

    display.dispose();
}

From source file:TimerRepeating.java

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

    Runnable timer = new Runnable() {
        public void run() {
            Point point = display.getCursorLocation();
            Rectangle rect = shell.getBounds();
            if (rect.contains(point)) {
                System.out.println("In");
            } else {
                System.out.println("Out");
            }/*from w  ww .j  a  v  a 2s  .c  o m*/
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);

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

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 123");
    shell.setLayout(new FillLayout());
    OleControlSite controlSite;/*w w w.  ja v  a 2  s .  c  om*/
    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.open();

    // IWebBrowser
    final OleAutomation webBrowser = new OleAutomation(controlSite);

    // When a new document is loaded, access the document object for the new page.
    int DownloadComplete = 104;
    controlSite.addEventListener(DownloadComplete, new OleListener() {
        @Override
        public void handleEvent(OleEvent event) {
            int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" });
            if (htmlDocumentID == null)
                return;
            Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]);
            if (pVarResult == null || pVarResult.getType() == 0)
                return;
            //IHTMLDocument2
            OleAutomation htmlDocument = pVarResult.getAutomation();

            // Request to be notified of click, double click and key down events
            EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick);
            IDispatch idispatch = new IDispatch(myDispatch.getAddress());
            Variant dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.onclick, dispatch);

            myDispatch = new EventDispatch(EventDispatch.ondblclick);
            idispatch = new IDispatch(myDispatch.getAddress());
            dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.ondblclick, dispatch);

            myDispatch = new EventDispatch(EventDispatch.onkeydown);
            idispatch = new IDispatch(myDispatch.getAddress());
            dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.onkeydown, dispatch);

            //Remember to release OleAutomation Object
            htmlDocument.dispose();
        }
    });

    // Navigate to a web site
    int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] rgvarg = new Variant[] { new Variant("http://www.google.com") };
    int[] rgdispidNamedArgs = new int[] { ids[1] };
    webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    //Remember to release OleAutomation Object
    webBrowser.dispose();
    display.dispose();

}

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setSize(250, 250);//w  w  w  . j  av a  2 s  .c o m
    s.setText("A Slider Example");

    final Slider slide = new Slider(s, SWT.HORIZONTAL);
    slide.setBounds(15, 50, 125, 15);
    slide.setMinimum(0);
    slide.setMaximum(100);
    slide.setIncrement(1);

    final Text t = new Text(s, SWT.BORDER);
    t.setBounds(115, 25, 25, 25);
    t.setText("0");

    slide.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            t.setText(new Integer(slide.getSelection()).toString());
        }
    });

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

From source file:Snippet14.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(100, 100);//from   w w  w  .j ava  2s  . c o  m
    shell.addListener(SWT.MouseEnter, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("ENTER");
        }
    });
    shell.addListener(SWT.MouseExit, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("EXIT");
        }
    });
    shell.addListener(SWT.MouseHover, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("HOVER");
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 29");
    Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);// www. j a  v a2s .com
    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, e -> System.out.println("Select All"));
    item.setText("Select &All\tCtrl+A");
    item.setAccelerator(SWT.MOD1 + 'A');
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}