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.kotcrab.vis.editor.CrashReporter.java

@FXML
private void handleShowReport(ActionEvent event) throws IOException {
    new Thread(() -> {
        try {/*ww  w .ja  v a2 s.c om*/
            Desktop.getDesktop().open(reportFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).start();
}

From source file:wo.trade.Util.java

public static void openUrlViaBrowser(String url) {
    String s = url;//from   w  ww.j  a  v a2 s .  c o  m
    if (Desktop.isDesktopSupported()) {
        try {
            Desktop.getDesktop().browse(new URI(s));
        } catch (Exception e) {
            log.error("Error on opening browser, address: " + s + ": " + e.getMessage(), e);
        }
    } else {
        log.error(("Launch browser failed, please manually visit: " + s));
    }
}

From source file:edu.umn.natsrl.evaluation.ContourPlotter.java

public void saveImage(boolean viewImage) {
    if (!createContourPlot()) {
        return;// ww  w. j  a  va2  s.co m
    }

    try {
        File img = new File(getFileName(null, "jpg"));
        ChartUtilities.saveChartAsJPEG(img, chart, 1000, 800);
        try {
            if (viewImage) {
                Desktop.getDesktop().open(img);
            }
        } catch (Exception e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.antelink.sourcesquare.gui.controller.ExitController.java

public void bind() {

    this.view.getOpenButtonLabel().addMouseListener(new MouseListener() {

        @Override//from  ww w .  j  av  a 2 s .c om
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URI("http://localhost:9524/"));
            } catch (IOException e) {
                logger.error("Error opening the browser", e);
            } catch (URISyntaxException e) {
                logger.error("Error opening the browser", e);
            }
        }
    });

    this.eventBus.addHandler(StartScanEvent.TYPE, new StartScanEventHandler() {

        @Override
        public String getId() {
            return "Exit Controller is now Handling";
        }

        @Override
        public void handle(File toScan) {
            display();
        }
    });
    this.eventBus.addHandler(ErrorEvent.TYPE, new ErrorEventHandler() {

        @Override
        public String getId() {
            return "Handling error";
        }

        @Override
        public void handle(String error) {
            JOptionPane.showMessageDialog(ExitController.this.view, error, null, JOptionPane.ERROR_MESSAGE);
            System.exit(0);
        }
    });

}

From source file:com.photon.phresco.framework.actions.FrameworkBaseAction.java

public void openFolder() {
    if (debugEnabled) {
        S_LOGGER.debug("Entered FrameworkBaseAction.openFolder()");
    }/*from   w w  w.  j  av  a 2s. c  o m*/
    try {
        if (Desktop.isDesktopSupported()) {
            File dir = new File(Utility.getProjectHome() + path);
            if (dir.exists()) {
                Desktop.getDesktop().open(new File(Utility.getProjectHome() + path));
            } else {
                Desktop.getDesktop().open(new File(Utility.getProjectHome()));
            }
        }
    } catch (Exception e) {
        if (debugEnabled) {
            S_LOGGER.error("Unable to open the Path, " + FrameworkUtil.getStackTraceAsString(e));
            new LogErrorReport(e, "Open Folder");
        }
    }
}

From source file:processing.app.macosx.Platform.java

@Override
public void openURL(String url) throws Exception {
    Desktop desktop = Desktop.getDesktop();
    if (url.startsWith("http") || url.startsWith("file:")) {
        desktop.browse(new URI(url));
    } else {//from  w  ww  .j a  v a  2 s.  c  om
        desktop.open(new File(url));
    }
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

public void showMessage(final String message) throws HeadlessException {

    final JPanel messagePanel = new JPanel(new GridBagLayout());
    final JEditorPane textField = new JEditorPane();
    textField.setContentType("text/html");
    textField.setText(message);//from w  w  w . ja v a  2  s  .co  m
    textField.setEditable(false);
    textField.setBackground(null);
    textField.setBorder(null);
    textField.setEditable(false);
    textField.setForeground(UIManager.getColor("Label.foreground"));
    textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textField.setFont(UIManager.getFont("Label.font"));
    textField.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // Ignore failure to launch URL
                    } catch (URISyntaxException e1) {
                        // Ignore failure to launch URL
                    }
                }
            }
        }
    });

    messagePanel.add(textField);
    textField.setAlignmentX(SwingConstants.CENTER);

    JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName,
            JOptionPane.INFORMATION_MESSAGE, icon);
}

From source file:gmailclientfx.core.GmailClient.java

public static void authorizeUser() throws IOException {

    FLOW = new GoogleAuthorizationCodeFlow.Builder(TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, SCOPES)
            //.setApprovalPrompt("select_account")
            .setAccessType("offline").build();

    String url = FLOW.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
    String txtURI = url + "&prompt=select_account";
    String code = "";

    if (Desktop.isDesktopSupported()) {
        try {/*  w  ww .  j  a  va 2  s  .  c o m*/
            Desktop.getDesktop().browse(new URI(txtURI));

            TextInputDialog dialog = new TextInputDialog();
            dialog.setTitle("Verifikacija");
            dialog.setHeaderText(null);
            dialog.setContentText("Unesite verifikacijski kod: ");

            Optional<String> result = dialog.showAndWait();
            if (result.isPresent()) {
                code = result.get();
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(GmailClient.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Greska prilikom logiranja!");
        }
    }

    GoogleTokenResponse tokenResponse = FLOW.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
    CREDENTIAL = new GoogleCredential.Builder().setTransport(TRANSPORT).setJsonFactory(JSON_FACTORY)
            .setClientSecrets(CLIENT_ID, CLIENT_SECRET).addRefreshListener(new CredentialRefreshListener() {
                @Override
                public void onTokenResponse(Credential credential, TokenResponse tokenResponse) {
                    // Handle success.
                }

                @Override
                public void onTokenErrorResponse(Credential credential, TokenErrorResponse tokenErrorResponse) {
                    // Handle error.
                }
            }).build();

    CREDENTIAL.setFromTokenResponse(tokenResponse);
    GMAIL = new Gmail.Builder(TRANSPORT, JSON_FACTORY, CREDENTIAL).setApplicationName("JavaGmailSend").build();
    PROFILE = GMAIL.users().getProfile("me").execute();
    EMAIL = PROFILE.getEmailAddress();
    USER_ID = PROFILE.getHistoryId();
    ACCESS_TOKEN = CREDENTIAL.getAccessToken();
    REFRESH_TOKEN = CREDENTIAL.getRefreshToken();
    /*Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Verifikacija");
    alert.setHeaderText(null);
    alert.setContentText("Uspjena verifikacija!");
    alert.showAndWait();*/
}

From source file:eu.esdihumboldt.hale.ui.application.handler.ShowHandbookHandler.java

/**
 * @see IHandler#execute(ExecutionEvent)
 *///from   w w w  .j a v a  2  s  .c  o  m
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    String tempDirName = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
    if (!tempDirName.endsWith("/")) { //$NON-NLS-1$
        tempDirName = tempDirName + "/"; //$NON-NLS-1$
    }
    tempDirName = tempDirName + HALEApplicationPlugin.PLUGIN_ID + "/"; //$NON-NLS-1$

    File tempDir = new File(tempDirName);
    tempDir.mkdirs();
    tempDir.deleteOnExit();

    File pdfFile = new File(tempDirName + PDFFILE);
    if (pdfFile.exists()) {
        FileUtils.deleteQuietly(pdfFile);
    }

    pdfFile.deleteOnExit();

    URL pdfUrl = this.getClass().getResource("/documentation/" + PDFFILE); //$NON-NLS-1$
    if (pdfUrl == null) {
        throw new RuntimeException("Manual could not be retrieved."); //$NON-NLS-1$
    }

    InputStream in;
    try {
        in = pdfUrl.openStream();
    } catch (IOException e) {
        ExceptionHelper.handleException("Could not open Streaming.", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
        return null;
    }

    FileOutputStream fos = null;
    byte[] buffer = new byte[4096];
    int read;
    try {
        fos = new FileOutputStream(pdfFile);

        while ((read = in.read(buffer)) != -1) {
            fos.write(buffer, 0, read);
        }
    } catch (IOException e) {
        ExceptionHelper.handleException("Error while reading the file.", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
        return null;
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
            in.close();
        } catch (IOException e) {
            // ignore
        }
    }

    try {
        Desktop.getDesktop().open(pdfFile);
    } catch (IOException e) {
        ExceptionHelper.handleException("The file could not be opened", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
    }

    return null;
}

From source file:dpcs.About.java

public About() {
    setIconImage(Toolkit.getDefaultToolkit().getImage(About.class.getResource("/graphics/Icon.png")));
    setResizable(false);//from w  w  w. j  av a  2 s  .c o  m
    setType(Type.UTILITY);
    setTitle("About");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 540, 400);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
    try {
        InputStreamReader reader2 = new InputStreamReader(
                getClass().getResourceAsStream("/others/app-version.txt"));
        String tmp = IOUtils.toString(reader2);
        AppVersion = Double.parseDouble(tmp);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    JButton btnGitHub = new JButton("GitHub");
    btnGitHub.setToolTipText("Access Droid PC Suite github repository");
    btnGitHub.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URL("https://github.com/kvsjxd/Droid-PC-Suite/").toURI());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    btnGitHub.setBounds(369, 295, 111, 25);
    contentPane.add(btnGitHub);

    JLabel lblMyFriend4 = new JLabel("Gulati-kun");
    lblMyFriend4.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend4.setBounds(25, 266, 242, 24);
    contentPane.add(lblMyFriend4);

    JLabel lblMyFriend3 = new JLabel("Anil-kun");
    lblMyFriend3.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend3.setBounds(25, 242, 242, 24);
    contentPane.add(lblMyFriend3);

    JLabel lblMyFriend2 = new JLabel("Suri-kun");
    lblMyFriend2.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend2.setBounds(25, 217, 242, 24);
    contentPane.add(lblMyFriend2);

    JLabel lblApplicationVersion = new JLabel("Version: " + AppVersion);
    lblApplicationVersion.setFont(new Font("Dialog", Font.BOLD, 14));
    lblApplicationVersion.setBounds(382, 16, 132, 18);
    contentPane.add(lblApplicationVersion);

    JLabel lblForMyOther = new JLabel("For my other Android stuff visit me on XDA - Developers (@kvsjxd)");
    lblForMyOther.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URL(
                        "http://forum.xda-developers.com/member.php?s=82fb1dacfee601c8f79084b30d57d5a2&u=5640594")
                                .toURI());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblForMyOther.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblForMyOther.setForeground(Color.BLACK);
        }
    });
    lblForMyOther.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblForMyOther.setBounds(25, 321, 502, 24);
    contentPane.add(lblForMyOther);

    JLabel lblMySensei2 = new JLabel("Karun Sensei");
    lblMySensei2.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMySensei2.setBounds(25, 120, 242, 24);
    contentPane.add(lblMySensei2);

    JLabel lblMySensei1 = new JLabel("Prashotam Sensei");
    lblMySensei1.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMySensei1.setBounds(25, 98, 242, 24);
    contentPane.add(lblMySensei1);

    JLabel lblDaretobe = new JLabel("D4r3T0B3");
    lblDaretobe.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblDaretobe.setBounds(25, 194, 242, 24);
    contentPane.add(lblDaretobe);

    JLabel label_9 = new JLabel("");
    label_9.setToolTipText("This variation of android robot is created using Androidify");
    label_9.setIcon(new ImageIcon(About.class.getResource("/graphics/Droidrobot.png")));
    label_9.setBounds(334, 50, 180, 270);
    contentPane.add(label_9);

    JLabel lblDeveloper = new JLabel("Developer");
    lblDeveloper.setFont(new Font("Dialog", Font.BOLD, 16));
    lblDeveloper.setBounds(25, 12, 233, 24);
    contentPane.add(lblDeveloper);

    JLabel lblMrAleksandarDespotovski_shi = new JLabel("Aleksandar Despotovski-shi");
    lblMrAleksandarDespotovski_shi.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMrAleksandarDespotovski_shi.setBounds(25, 169, 242, 24);
    contentPane.add(lblMrAleksandarDespotovski_shi);

    JLabel lblMyname = new JLabel("Karanvir Singh");
    lblMyname.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try {
                Desktop.getDesktop().browse(new URL(
                        "http://forum.xda-developers.com/member.php?s=82fb1dacfee601c8f79084b30d57d5a2&u=5640594")
                                .toURI());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblMyname.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblMyname.setForeground(Color.RED);
        }
    });
    lblMyname.setForeground(Color.RED);
    lblMyname.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 16));
    lblMyname.setBounds(25, 36, 242, 24);
    contentPane.add(lblMyname);

    JLabel lblMyFriend1 = new JLabel("My friend - Chetan-kun");
    lblMyFriend1.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend1.setBounds(25, 145, 242, 24);
    contentPane.add(lblMyFriend1);

    JLabel label_6 = new JLabel("Special thanks to");
    label_6.setForeground(UIManager.getColor("OptionPane.questionDialog.titlePane.shadow"));
    label_6.setFont(new Font("Dialog", Font.BOLD, 16));
    label_6.setBounds(25, 71, 240, 25);
    contentPane.add(label_6);

    JLabel lblGoogle = new JLabel(
            "Android, android green colored robot are trademarks of Google, Inc. We are not affliated with Google, Inc. in any way.");
    lblGoogle.setHorizontalAlignment(SwingConstants.LEFT);
    lblGoogle.setFont(new Font("Dialog", Font.PLAIN, 8));
    lblGoogle.setBounds(25, 341, 514, 24);
    contentPane.add(lblGoogle);
}