Example usage for java.awt Desktop getDesktop

List of usage examples for java.awt Desktop getDesktop

Introduction

In this page you can find the example usage for java.awt Desktop getDesktop.

Prototype

public static synchronized Desktop getDesktop() 

Source Link

Document

Returns the Desktop instance of the current desktop context.

Usage

From source file:com.igormaznitsa.zxpoly.ui.AboutDialog.java

public AboutDialog(final java.awt.Frame parent) {
    super(parent, true);
    initComponents();//from   w  w  w.j  a v a  2 s.c  o m

    this.editorPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception ex) {
                }
            } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                editorPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                editorPane.setCursor(Cursor.getDefaultCursor());
            }
        }
    });

    this.editorPane.setContentType("text/html");
    try {
        final String htmlText = IOUtils.toString(openAboutResource("index.html"), "UTF-8");
        this.editorPane.setText(htmlText);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    setLocationRelativeTo(parent);
}

From source file:com.decypher.threadsclient.JPanelChart.java

public void saveAsImage() {

    String folder = getFolder();//w w w.  jav a 2  s. co m
    if (!folder.isEmpty()) {
        String location = folder + "/" + UUID.randomUUID().toString() + ".jpeg";
        int width = 1280;
        int height = 960;
        try {
            File imgChart = new File(location);
            ChartUtilities.saveChartAsJPEG(imgChart, chart, width, height);
            Desktop.getDesktop().open(new File(folder));
        } catch (IOException ex) {
            Extra.MessageBox.Show(ex.getMessage(), Extra.Title.Error);
        }
    }
}

From source file:kindleclippings.quizlet.GetAccessToken.java

static JSONObject oauthDance() throws IOException, URISyntaxException, InterruptedException, JSONException {

    // start HTTP server, so when can get the authorization code
    InetSocketAddress addr = new InetSocketAddress(7777);
    HttpServer server = HttpServer.create(addr, 0);
    AuthCodeHandler handler = new AuthCodeHandler();
    server.createContext("/", handler);
    ExecutorService ex = Executors.newCachedThreadPool();
    server.setExecutor(ex);/*w  w  w  .  j a  va2  s  .  com*/
    server.start();
    String authCode;
    try {
        Desktop.getDesktop()
                .browse(new URI(new StringBuilder("https://quizlet.com/authorize/")
                        .append("?scope=read%20write_set").append("&client_id=" + clientId)
                        .append("&response_type=code").append("&state=" + handler.state).toString()));

        authCode = handler.result.take();
    } finally {
        server.stop(0);
        ex.shutdownNow();
    }

    if (authCode == null || authCode.length() == 0)
        return null;

    HttpPost post = new HttpPost("https://api.quizlet.com/oauth/token");
    post.setHeader("Authorization", authHeader);

    post.setEntity(
            new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("grant_type", "authorization_code"),
                    new BasicNameValuePair("code", authCode))));
    HttpResponse response = new DefaultHttpClient().execute(post);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream(1000);
    response.getEntity().writeTo(buffer);
    return new JSONObject(new String(buffer.toByteArray(), "UTF-8"));
}

From source file:com.tascape.qa.th.Utils.java

public static void openFile(File file) {
    Desktop desktop = Desktop.getDesktop();
    try {/*from   w  w w.java  2 s.c o m*/
        desktop.open(file);
    } catch (IOException ex) {
        LOG.warn("Cannot open file {}", file, ex);
    }
}

From source file:de.xirp.managers.PrintManager.java

/**
 * Prints the given {@link java.io.File} using the
 * {@link java.awt.Desktop} class.//  ww  w .  j  a va 2  s  .  c  o  m
 * 
 * @param document
 *            The file to print.
 * @throws IOException
 *             if something went wrong printing.
 * @see java.awt.Desktop
 */
public static void print(final File document) throws IOException {
    // TODO: remove awt print stuff, use swt.
    Desktop desktop;
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
        try {
            desktop.print(document);
        } catch (IOException e) {
            throw e;
        }
    } else {
        logClass.error(I18n.getString("PrintManager.log.printingNotSupported") + Constants.LINE_SEPARATOR); //$NON-NLS-1$
    }
}

From source file:com.gameminers.mav.firstrun.GoogleScreen.java

@Override
public void onKeyDown(int k, char c, long nanos) {
    if (k == Keyboard.KEY_RETURN) {
        String str = tf.getText();
        if (Strings.similarity(str.toLowerCase(), "yes") > 0.6) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI("https://mav.gameminers.com/using-google.html"));
                    try {
                        Mav.ttsInterface.say(
                                "Okay, then I'll need you to get a Google API key. I've opened a page on my website explaining how to do this.");
                    } catch (SynthesisException e) {
                        // TODO
                        e.printStackTrace();
                    }//from   w w  w. j  a va  2 s .  c  o  m
                    return;
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
            }
            try {
                Mav.ttsInterface.say(
                        "Okay, then I'll need you to get a Google API key. I can't open your browser, so you'll need to go to my site yourself. Near the bottom is a link titled 'Using Google'. That page explains how to get an API key.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        } else if (Strings.similarity(str.toLowerCase(), "no") > 0.6) {
            try {
                Mav.ttsInterface.say(
                        "Okay. Next, I need to learn the sound of your voice. Read the sentences I show out loud.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
            Mav.currentScreen = new TeachSphinxScreen();
        } else if (StringUtils.isBlank(str)) {
            try {
                Mav.ttsInterface.say("Please enter Yes or No.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        } else {
            try {
                Mav.ttsInterface.say("Sorry, I don't understand.");
            } catch (SynthesisException e) {
                // TODO
                e.printStackTrace();
            }
        }
        tf.setText("");
    }
}

From source file:vazkii.psi.client.core.helper.SharingHelper.java

public static void uploadAndOpen(String title, String export) {
    String url = uploadImage(title, export);
    try {/*from www  . ja v  a 2 s  .c  om*/
        if (Desktop.isDesktopSupported())
            Desktop.getDesktop().browse(new URI(url));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.tag.Hyperlink.java

private void init() {
    setHorizontalAlignment(SwingConstants.LEFT);
    setBackground(Color.WHITE);//from w w w  . j a  va2 s  .  c  o m
    setBorder(null);
    setBorderPainted(false);
    setOpaque(false);

    String toolTip = getUri().toString();
    setToolTipText(toolTip);

    addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Desktop desktop = Desktop.getDesktop();
            boolean mail = desktop.isSupported(Action.BROWSE);
            if (mail) {
                try {
                    desktop.browse(uri);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

    });
}

From source file:ca.sfu.federation.action.ShowWebSiteAction.java

/**
 * Handle action performed event.//from  ww w. j  a v a 2  s  .c  o  m
 * @param ae Event
 */
public void actionPerformed(ActionEvent ae) {
    try {
        URI uri = new URI(ApplicationContext.PROJECT_WEBSITE_URL);
        // open the default web browser for the HTML page
        logger.log(Level.INFO, "Opening desktop browser to {0}", uri.toString());
        Desktop.getDesktop().browse(uri);
    } catch (Exception ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "Could not open browser for URL {0}\n\n{1}",
                new Object[] { ApplicationContext.PROJECT_WEBSITE_URL, stack });
    }
}

From source file:org.openpythia.aboutdialog.AboutController.java

public AboutController(JFrame owner) {
    view = new AboutView(owner);
    view.getEditorPaneAbout().setContentType("text/html");

    String aboutText = "";

    try {/* w ww.j  ava2s.  c o  m*/
        InputStream inputStream = this.getClass().getResourceAsStream(ABOUT_HTML);
        aboutText = String.format(IOUtils.toString(inputStream), FileResourceUtility.getVersion());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

    view.getEditorPaneAbout().setText(aboutText);

    view.getEditorPaneAbout().addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(evt.getURL().toURI());
                } catch (Exception e) {
                    // If we can't open the URL we just ignore it (no error
                    // message)
                }
            }
        }
    });

    view.getEditorPaneAbout().setCaretPosition(0);

    view.getBtnOK().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            view.dispose();
        }
    });

    view.getRootPane().setDefaultButton(view.getBtnOK());
    view.getBtnOK().requestFocus();

    view.setSize(600, 400);
    view.setVisible(true);
}