Example usage for java.applet AppletContext showDocument

List of usage examples for java.applet AppletContext showDocument

Introduction

In this page you can find the example usage for java.applet AppletContext showDocument.

Prototype

void showDocument(URL url);

Source Link

Document

Requests that the browser or applet viewer show the Web page indicated by the url argument.

Usage

From source file:biomine.bmvis2.Vis.java

public void setClipboard(String str) {
    assert str != null : "Null str";
    AppletContext appletContext = null;
    try {//from  w  ww .java 2 s . c  om
        appletContext = getAppletContext();
    } catch (Exception e) {
    }

    Clipboard clipboard;
    StringSelection data = new StringSelection(str);

    try {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        if (clipboard != null) {
            clipboard.setContents(data, null);
        }
    } catch (java.security.AccessControlException e) {
        if (appletContext != null) {
            try {
                str = str.replace('\'', '"');
                appletContext
                        .showDocument(new URL("javascript:copyToClipboard(encodeURIComponent('" + str + "'))"));
            } catch (Exception e2) {
                JOptionPane.showMessageDialog(null, e2.getMessage(), "Copying to clipboard failed",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "Copying to clipboard failed",
                JOptionPane.ERROR_MESSAGE);
    }
}