Search in sources :

Example 1 with CloseWindowListener

use of org.eclipse.swt.browser.CloseWindowListener in project pentaho-kettle by pentaho.

the class GoogleAuthorizationDialog method createDialog.

private void createDialog(String title, String url, int options, Image logo) {
    Shell parent = getParent();
    display = parent.getDisplay();
    dialog = new Shell(parent, options);
    dialog.setText(title);
    dialog.setImage(logo);
    PropsUI props = PropsUI.getInstance();
    props.setLook(dialog);
    dialog.setSize(width, height);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    dialog.setLayout(formLayout);
    try {
        Label helpButton = new Label(dialog, SWT.NONE);
        helpButton.setImage(new Image(display, GoogleAuthorizationDialog.class.getResourceAsStream("/images/help.png")));
        FormData helpButtonFormData = new FormData();
        helpButtonFormData.left = new FormAttachment(0, 15);
        helpButtonFormData.bottom = new FormAttachment(100, -24);
        helpButton.setLayoutData(helpButtonFormData);
        StyledText helpLabel = new StyledText(dialog, SWT.NONE);
        helpLabel.setText("Help");
        helpLabel.setCaret(null);
        helpLabel.setEditable(false);
        props.setLook(helpLabel);
        helpLabel.setFont(new Font(display, "Open Sans Regular", 11, SWT.NORMAL));
        helpLabel.setForeground(new Color(display, 0, 94, 170));
        FormData helpLabelFormData = new FormData();
        helpLabelFormData.left = new FormAttachment(0, 40);
        helpLabelFormData.bottom = new FormAttachment(100, -27);
        helpLabel.setLayoutData(helpLabelFormData);
        helpLabel.addListener(SWT.MouseUp, new Listener() {

            public void handleEvent(Event event) {
            }
        });
        helpLabel.addListener(SWT.MouseEnter, new Listener() {

            public void handleEvent(Event event) {
                StyleRange style1 = new StyleRange();
                style1.start = 0;
                style1.length = 4;
                style1.underline = true;
                helpLabel.setStyleRange(style1);
                helpLabel.setForeground(new Color(display, 0, 0, 0));
                helpLabel.setCursor(new Cursor(display, SWT.CURSOR_HAND));
            }
        });
        helpLabel.addListener(SWT.MouseExit, new Listener() {

            public void handleEvent(Event event) {
                StyleRange style1 = new StyleRange();
                style1.start = 0;
                style1.length = 4;
                style1.underline = false;
                helpLabel.setStyleRange(style1);
                helpLabel.setForeground(new Color(display, 0, 94, 170));
            }
        });
        Label cancelButton = new Label(dialog, SWT.NONE);
        cancelButton.setImage(new Image(display, GoogleAuthorizationDialog.class.getResourceAsStream("/images/close-button.png")));
        FormData cancelButtonFormData = new FormData();
        cancelButtonFormData.right = new FormAttachment(100, -15);
        cancelButtonFormData.bottom = new FormAttachment(100, -15);
        cancelButton.setLayoutData(cancelButtonFormData);
        cancelButton.addListener(SWT.MouseUp, new Listener() {

            public void handleEvent(Event event) {
                browser.dispose();
                dialog.close();
                dialog.dispose();
            }
        });
        cancelButton.addListener(SWT.MouseEnter, new Listener() {

            public void handleEvent(Event event) {
                cancelButton.setImage(new Image(display, GoogleAuthorizationDialog.class.getResourceAsStream("/images/close-button-hover.png")));
                cancelButton.setCursor(new Cursor(display, SWT.CURSOR_HAND));
            }
        });
        cancelButton.addListener(SWT.MouseExit, new Listener() {

            public void handleEvent(Event event) {
                cancelButton.setImage(new Image(display, GoogleAuthorizationDialog.class.getResourceAsStream("/images/close-button.png")));
            }
        });
        Label separator = new Label(dialog, SWT.HORIZONTAL | SWT.SEPARATOR);
        FormData separatorFormData = new FormData();
        separatorFormData.left = new FormAttachment(0, 15);
        separatorFormData.right = new FormAttachment(100, -15);
        separatorFormData.bottom = new FormAttachment(cancelButton, -15);
        separator.setLayoutData(separatorFormData);
        browser = new Browser(dialog, SWT.NONE);
        browser.setUrl(url);
        FormData browserFormData = new FormData();
        browserFormData.top = new FormAttachment(0, 5);
        browserFormData.bottom = new FormAttachment(separator, -5);
        browserFormData.left = new FormAttachment(0, 5);
        browserFormData.right = new FormAttachment(100, -5);
        browser.setLayoutData(browserFormData);
        browser.addCloseWindowListener(new CloseWindowListener() {

            @Override
            public void close(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                Shell shell = browser.getShell();
                shell.close();
            }
        });
    } catch (Exception e) {
        MessageBox messageBox = new MessageBox(dialog, SWT.ICON_ERROR | SWT.OK);
        messageBox.setMessage("Browser cannot be initialized.");
        messageBox.setText("Exit");
        messageBox.open();
    }
    setPosition();
    dialog.open();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) StyleRange(org.eclipse.swt.custom.StyleRange) Label(org.eclipse.swt.widgets.Label) PropsUI(org.pentaho.di.ui.core.PropsUI) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) Event(org.eclipse.swt.widgets.Event) WindowEvent(org.eclipse.swt.browser.WindowEvent) Browser(org.eclipse.swt.browser.Browser)

Example 2 with CloseWindowListener

use of org.eclipse.swt.browser.CloseWindowListener in project BiglyBT by BiglySoftware.

the class BrowserWindow method init.

public void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal) {
    int style = SWT.DIALOG_TRIM;
    if (allowResize) {
        style |= SWT.RESIZE;
    }
    if (isModal) {
        style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, style);
    shell.setLayout(new FillLayout());
    Utils.setShellIcon(shell);
    shell.setText(url);
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
                e.doit = false;
            }
        }
    });
    final Listener escListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.keyCode == 27) {
                shell.dispose();
            }
        }
    };
    shell.getDisplay().addFilter(SWT.KeyDown, escListener);
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.display.removeFilter(SWT.KeyDown, escListener);
        }
    });
    browser = Utils.createSafeBrowser(shell, SWT.NONE);
    if (browser == null) {
        shell.dispose();
        return;
    }
    context = new BrowserContext("browser-window" + Math.random(), browser, null, true);
    context.addMessageListener(new TorrentListener());
    context.addMessageListener(new VuzeListener());
    context.addMessageListener(new DisplayListener());
    context.addMessageListener(new ConfigListener(browser));
    context.addMessageListener(new MetaSearchListener(new OpenCloseSearchDetailsListener() {

        @Override
        public void resizeSecondaryBrowser() {
        }

        @Override
        public void resizeMainBrowser() {
        }

        @Override
        public void openSearchResults(Map params) {
        }

        @Override
        public void closeSearchResults(Map params) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.dispose();
        }
    }));
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.open();
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    browser.addCloseWindowListener(new CloseWindowListener() {

        @Override
        public void close(WindowEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            context.debug("window.close called");
            shell.dispose();
        }
    });
    browser.addTitleListener(new TitleListener() {

        @Override
        public void changed(TitleEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    browser.addStatusTextListener(new StatusTextListener() {

        @Override
        public void changed(StatusTextEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            if (MessageBoxShell.STATUS_TEXT_CLOSE.equals(event.text)) {
                // For some reason disposing the shell / browser in the same Thread makes
                // ieframe.dll crash on windows.
                Utils.execSWTThreadLater(0, new Runnable() {

                    @Override
                    public void run() {
                        if (!browser.isDisposed() && !shell.isDisposed()) {
                            shell.close();
                        }
                    }
                });
            }
        }
    });
    SimpleTimer.addEvent("showWin", SystemTime.getOffsetTime(3000), new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (shell != null && !shell.isDisposed()) {
                        shell.open();
                    }
                }
            });
        }
    });
    if (w > 0 && h > 0) {
        Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
        shell.setSize(computeTrim.width, computeTrim.height);
    // shell.setSize(w, h);
    }
    Utils.centerWindowRelativeTo(shell, parent);
    browser.setUrl(url);
    browser.setData("StartURL", url);
}
Also used : OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) Rectangle(org.eclipse.swt.graphics.Rectangle) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) BrowserContext(com.biglybt.ui.swt.browser.BrowserContext) FillLayout(org.eclipse.swt.layout.FillLayout) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) WindowEvent(org.eclipse.swt.browser.WindowEvent) TitleEvent(org.eclipse.swt.browser.TitleEvent) Map(java.util.Map)

Example 3 with CloseWindowListener

use of org.eclipse.swt.browser.CloseWindowListener in project pentaho-kettle by pentaho.

the class ThinDialog method createDialog.

public void createDialog(String title, String url, int options, Image logo) {
    Shell parent = getParent();
    display = parent.getDisplay();
    dialog = new Shell(parent, options);
    dialog.setText(title);
    dialog.setImage(logo);
    dialog.setSize(width, height);
    dialog.setLayout(new FillLayout());
    try {
        browser = new Browser(dialog, SWT.NONE);
        browser.setUrl(url);
        browser.addCloseWindowListener(new CloseWindowListener() {

            @Override
            public void close(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                Shell shell = browser.getShell();
                shell.close();
            }
        });
    } catch (Exception e) {
        MessageBox messageBox = new MessageBox(dialog, SWT.ICON_ERROR | SWT.OK);
        messageBox.setMessage("Browser cannot be initialized.");
        messageBox.setText("Exit");
        messageBox.open();
    }
    setPosition();
    dialog.open();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) Browser(org.eclipse.swt.browser.Browser) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)3 WindowEvent (org.eclipse.swt.browser.WindowEvent)3 Browser (org.eclipse.swt.browser.Browser)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 BrowserContext (com.biglybt.ui.swt.browser.BrowserContext)1 OpenCloseSearchDetailsListener (com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener)1 Map (java.util.Map)1 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)1 ProgressListener (org.eclipse.swt.browser.ProgressListener)1 StatusTextEvent (org.eclipse.swt.browser.StatusTextEvent)1 StatusTextListener (org.eclipse.swt.browser.StatusTextListener)1 TitleEvent (org.eclipse.swt.browser.TitleEvent)1 TitleListener (org.eclipse.swt.browser.TitleListener)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledText (org.eclipse.swt.custom.StyledText)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Event (org.eclipse.swt.widgets.Event)1 Label (org.eclipse.swt.widgets.Label)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Shell (org.eclipse.swt.widgets.Shell)1