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:org.sikuli.script.App.java

public static boolean openLink(String url) {
    if (!Desktop.isDesktopSupported()) {
        return false;
    }/*from ww w  . j av  a2  s  .  c  o  m*/
    try {
        Desktop.getDesktop().browse(new URI(url));
    } catch (Exception ex) {
        return false;
    }
    return true;
}

From source file:org.nuxeo.launcher.sync.NuxeoSyncFrame.java

protected Action createLaunchBrowserAction() {
    return new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*from w w  w  .j a v  a  2s.c om*/
        public void actionPerformed(ActionEvent event) {
            try {
                Desktop.getDesktop().browse(java.net.URI.create(getController().getLauncher().getURL()));
            } catch (Exception e) {
                setError("an error occurred while launching browser", e);
            }
        }
    };
}

From source file:com.moandjiezana.tent.client.TentClientTest.java

@Test
@Ignore/*from  ww  w  .j  a  va 2 s .c  om*/
public void post_update_and_delete() throws Exception {
    TentClient tentClient = new TentClient("http://localhost:3000/");
    tentClient.discover();
    tentClient.getProfile();

    HashMap<String, String> scopes = new HashMap<String, String>();
    scopes.put("write_posts", "Mostly test posts.");

    RegistrationRequest registrationRequest = new RegistrationRequest("TentClient for Java for deletion",
            "Running dev tests", "http://www.moandjiezana.com/tent-client-java",
            new String[] { "http://www.moandjiezana.com/tent-test/index.php" }, scopes);
    RegistrationResponse registrationResponse = tentClient.register(registrationRequest);

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(registrationResponse.getId(),
            "http://www.moandjiezana.com/tent-test/index.php");
    authorizationRequest.setScope(Joiner.on(',').join(registrationRequest.getScopes().keySet()));
    authorizationRequest.setState("myState");
    authorizationRequest.setTentPostTypes(Post.Types.status("v0.1.0"));
    authorizationRequest.setTentProfileInfoTypes(Profile.Core.URI, Profile.Basic.URI);

    String authorizationUrl = tentClient.getAsync().buildAuthorizationUrl(authorizationRequest);
    System.out.println("Auth URL: " + authorizationUrl);
    Desktop.getDesktop().browse(new URI(authorizationUrl));

    System.out.println("Code?");
    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
    String code = bufferRead.readLine();

    tentClient.getAsync().getAccessToken(code).get();

    Post post = new Post();
    post.setPublishedAt(System.currentTimeMillis() / 1000);
    Permissions permissions = new Permissions();
    permissions.setPublic(true);
    post.setPermissions(permissions);
    post.setLicenses(new String[] { "http://creativecommons.org/licenses/by/3.0/" });
    StatusContent statusContent = new StatusContent();
    statusContent.setText("To be updated");
    post.setContent(statusContent);

    Post returnedPost = tentClient.write(post);

    System.out.println("post ID=" + returnedPost.getId());
    System.out.println("content=" + returnedPost.getContentAs(StatusContent.class).getText());

    StatusContent status2 = returnedPost.getContentAs(StatusContent.class);
    status2.setText("Has been updated!");
    returnedPost.setContent(status2);
    Post updatedPost = tentClient.put(returnedPost);

    //    tentClient.getAsync().deletePost(updatedPost.getId());
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

public static void openInSystemViewer(@Nonnull final File file) {
    final Runnable startEdit = new Runnable() {
        @Override/*  ww  w.  j  av a  2s  . c  o m*/
        public void run() {
            boolean ok = false;
            if (Desktop.isDesktopSupported()) {
                final Desktop dsk = Desktop.getDesktop();
                if (dsk.isSupported(Desktop.Action.OPEN)) {
                    try {
                        dsk.open(file);
                        ok = true;
                    } catch (Throwable ex) {
                        LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N
                    }
                }
            }
            if (!ok) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        DialogProviderManager.getInstance().getDialogProvider()
                                .msgError("Can't open file in system viewer! See the log!");//NOI18N
                        Toolkit.getDefaultToolkit().beep();
                    }
                });
            }
        }
    };
    final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N
    thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
            LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e);
        }
    });

    thr.setDaemon(true);
    thr.start();
}

From source file:com.rubenlaguna.en4j.NoteContentViewModule.UnrecognizedResourceJPanel.java

private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseReleased
    new SwingWorker<Void, Void>() {

        @Override/*w  w  w. j a v  a  2 s  .  c o  m*/
        protected Void doInBackground() throws Exception {
            try {
                //get temp dir
                //save resource to tmp file
                String extension = FilenameUtils.getExtension(resource.getFilename());
                File tempFile = File.createTempFile("en4j", "." + extension);
                tempFile.deleteOnExit();
                OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile));
                InputStream is = resource.getDataAsInputStream();
                // Transfer bytes from in to out
                byte[] buf = new byte[1024];
                int len;
                while ((len = is.read(buf)) > 0) {
                    os.write(buf, 0, len);
                }
                is.close();
                os.close();
                Desktop dt = Desktop.getDesktop();
                dt.open(tempFile);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
            return null;
        }
    }.execute();
    // desktop api to open file

}

From source file:com.github.cric.app.ui.SettingPanel.java

private Component helpLabel() {

    JLabel help = new JLabel(HELP_TEXT);
    help.addMouseListener(new MouseAdapter() {

        @Override/*from w w w  . j  a v  a2  s  .  c  o  m*/
        public void mouseEntered(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

        @Override
        public void mouseExited(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(HELP_PAGE);
                } catch (Exception ex) {
                    LOG.warn("unable to open link", ex);
                }
            }
        }
    });
    return help;
}

From source file:edu.ku.brc.util.AttachmentUtils.java

/**
 * @param f the file to be opened/*w  w w .  j ava2s.  co m*/
 * @throws Exception
 */
public static void openFile(final File f) throws Exception {
    if (UIHelper.isWindows()) {
        HashSet<String> hashSet = new HashSet<String>();
        Collections.addAll(hashSet, new String[] { "wav", "mp3", "snd", "mid", "aif", "aiff", });
        String ext = FilenameUtils.getExtension(f.getName()).toLowerCase();
        if (hashSet.contains(ext)) {
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + f.getAbsolutePath());
            return;
        }
    }
    Desktop.getDesktop().open(f);
}

From source file:nl.detoren.ijsco.io.ExcelExport.java

public void exportGroepen(Groepen groepen) {
    String password = "abcd";
    try {//from ww w. j a  v a  2 s  . c  o m
        if (groepen == null)
            return;
        // sheetindx geeft index in Excel template op basis van groepsgrootte. -1: geen sheet voor groepsgrootte 
        int[] sheetindx = new int[] { -1, -1, -1, -1, 5, -1, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1, -1 };
        // columnsize geeft lengte in Excel template op basis van groepsgrootte. -1: geen sheet voor groepsgrootte
        int[] columnsize = new int[] { -1, -1, -1, -1, 20, -1, 35, -1, 54, -1, 77, -1, 100, -1, 127, -1, -1,
                -1 };
        // pagelngth geeft lengte in Excel template op basis van groepsgrootte. -1: geen sheet voor groepsgrootte
        int[] pagelngth = new int[] { -1, -1, -1, -1, 20, -1, 35, -1, 54, -1, 77, -1, 100, -1, 127, -1, -1,
                -1 };
        int sheet2row = 2;
        int sheet3row = 2;
        FileInputStream file = new FileInputStream("Indeling.xlsm");
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFCellStyle style1 = workbook.createCellStyle();
        style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(180, 180, 180)));
        XSSFCellStyle my_style = workbook.createCellStyle();
        XSSFColor my_foreground = new XSSFColor(Color.ORANGE);
        XSSFColor my_background = new XSSFColor(Color.RED);
        my_style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        my_style.setFillForegroundColor(my_foreground);
        my_style.setFillBackgroundColor(my_background);
        XSSFSheet sheet2 = workbook.getSheet("Groepsindeling");
        XSSFSheet sheet3 = workbook.getSheet("Deelnemerslijst");
        updateCell(sheet3, sheet3row, 0, "Naam", style1);
        updateCell(sheet3, sheet3row, 1, "KNSB nr", style1);
        updateCell(sheet3, sheet3row, 2, "rating", style1);
        updateCell(sheet3, sheet3row, 3, "groep", style1);
        sheet3row++;
        for (Groep groep : groepen) {
            logger.log(Level.INFO, "Exporteer groep : " + groep.getNaam());
            XSSFSheet sheet = workbook.cloneSheet(sheetindx[groep.getGrootte()], groep.getNaam());
            updateCell(sheet, 0, 6, groep.getNaam());
            updateCell(sheet2, sheet2row, 1, groep.getNaam());
            sheet2row++;
            updateCell(sheet2, sheet2row, 0, "nr", style1);
            updateCell(sheet2, sheet2row, 1, "Naam", style1);
            updateCell(sheet2, sheet2row, 2, "KNSB nr", style1);
            updateCell(sheet2, sheet2row, 3, "rating", style1);
            sheet2row++;
            for (int i = 0; i < groep.getGrootte(); i++) {
                updateCell(sheet, 3 + i, 2, groep.getSpeler(i).getNaam());
                updateCell(sheet, 3 + i, 3, groep.getSpeler(i).getKnsbnummer());
                updateCell(sheet, 3 + i, 5, groep.getSpeler(i).getRating());
                updateCell(sheet2, sheet2row, 0, i + 1);
                updateCell(sheet2, sheet2row, 1,
                        "'" + sheet.getSheetName() + "'!"
                                + org.apache.poi.ss.util.CellReference.convertNumToColString(2) + (4 + i),
                        true);
                updateCell(sheet2, sheet2row, 2,
                        "'" + sheet.getSheetName() + "'!"
                                + org.apache.poi.ss.util.CellReference.convertNumToColString(3) + (4 + i),
                        true);
                updateCell(sheet2, sheet2row, 3,
                        "'" + sheet.getSheetName() + "'!"
                                + org.apache.poi.ss.util.CellReference.convertNumToColString(5) + (4 + i),
                        true);
                if (groep.getSpeler(i).getNaam() != "Bye") {
                    updateCell(sheet3, sheet3row, 0,
                            "'" + sheet.getSheetName() + "'!"
                                    + org.apache.poi.ss.util.CellReference.convertNumToColString(2) + (4 + i),
                            true);
                    updateCell(sheet3, sheet3row, 1,
                            "'" + sheet.getSheetName() + "'!"
                                    + org.apache.poi.ss.util.CellReference.convertNumToColString(3) + (4 + i),
                            true);
                    updateCell(sheet3, sheet3row, 2,
                            "'" + sheet.getSheetName() + "'!"
                                    + org.apache.poi.ss.util.CellReference.convertNumToColString(5) + (4 + i),
                            true);
                    updateCell(sheet3, sheet3row, 3, groep.getNaam());
                }
                sheet2row++;
                sheet3row++;
            }
            sheet2row++;
            sheet.setForceFormulaRecalculation(true);
            // Set print margins
            XSSFPrintSetup ps = sheet.getPrintSetup();
            ps.setLandscape(true);
            ps.setFitWidth((short) 1);
            sheet.setFitToPage(true);
            sheet.setAutobreaks(false);
            workbook.setPrintArea(workbook.getSheetIndex(sheet), 1, 26, 0, pagelngth[groep.getGrootte()]);
            sheet.setColumnBreak(18);
            sheet.protectSheet(password);
            sheet.enableLocking();
        }
        XSSFSheet sheet4 = workbook.cloneSheet(workbook.getSheetIndex(sheet3), "Deelnemerslijst (naam)");
        sortSheet(sheet4, 1, 3, 62);
        //XSSFSheet sheet5 = workbook.cloneSheet(workbook.getSheetIndex(sheet3), "Deelnemerslijst (rating)");
        //sortSheet(sheet5, 1,4);
        sheet2.protectSheet(password);
        sheet3.protectSheet(password);
        sheet4.protectSheet(password);
        //sheet5.protectSheet(password);
        // Remove template sheets
        for (int i = 0; i < 6; i++) {
            workbook.removeSheetAt(0);
        }

        // Close input file
        file.close();
        // Store Excel to new file
        String filename = "Indeling resultaat.xlsm";
        File outputFile = new File(filename);
        FileOutputStream outFile = new FileOutputStream(outputFile);
        workbook.write(outFile);
        // Close output file
        workbook.close();
        outFile.close();
        // And open it in the system editor
        Desktop.getDesktop().open(outputFile);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Fout bij maken indeling excel : " + e.getMessage());

    }
}

From source file:se.trixon.mapollage.ui.MainFrame.java

private void initListeners() {
    mOperationListener = new OperationListener() {
        private boolean success;

        @Override/*from w w w .  java  2s  .  co  m*/
        public void onOperationError(String message) {
            mLogErrPanel.println(message);
        }

        @Override
        public void onOperationFailed(String message) {
            onOperationFinished(message, 0);
            success = false;
        }

        @Override
        public void onOperationFinished(String message, int placemarkCount) {
            setRunningState(false);
            mLogOutPanel.println(message);

            if (mOptions.isAutoOpen() && success && placemarkCount > 0) {
                try {
                    Desktop.getDesktop().open(mDestination);
                } catch (IOException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override
        public void onOperationInterrupted() {
            setRunningState(false);
            success = false;
        }

        @Override
        public void onOperationLog(String message) {
            mLogOutPanel.println(message);
        }

        @Override
        public void onOperationProcessingStarted() {
            SwingUtilities.invokeLater(() -> {
                mProgressBar.setIndeterminate(true);
            });
        }

        @Override
        public void onOperationProgress(String message) {
            SwingUtilities.invokeLater(() -> {
                mProgressBar.setString(message);
                mProgressBar.setValue(mProgressBar.getValue() + 1);
            });
        }

        @Override
        public void onOperationProgressInit(int fileCount) {
            SwingUtilities.invokeLater(() -> {
                mProgressBar.setIndeterminate(false);
                mProgressBar.setMinimum(0);
                mProgressBar.setValue(0);
                mProgressBar.setMaximum(fileCount);
            });
            success = true;
        }

        @Override
        public void onOperationStarted() {
            setRunningState(true);
        }
    };

    mActionManager.addAppListener(new ActionManager.AppListener() {
        @Override
        public void onCancel(ActionEvent actionEvent) {
            mOperationThread.interrupt();
        }

        @Override
        public void onMenu(ActionEvent actionEvent) {
            if (actionEvent.getSource() != menuButton) {
                menuButtonMousePressed(null);
            }
        }

        @Override
        public void onOptions(ActionEvent actionEvent) {
            showOptions();
        }

        @Override
        public void onQuit(ActionEvent actionEvent) {
            quit();
        }

        @Override
        public void onStart(ActionEvent actionEvent) {
            if (!mProfiles.isEmpty()) {
                try {
                    profileRun();
                } catch (CloneNotSupportedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

    mActionManager.addProfileListener(new ActionManager.ProfileListener() {
        @Override
        public void onAdd(ActionEvent actionEvent) {
            profileAdd(null);
        }

        @Override
        public void onClone(ActionEvent actionEvent) {
            try {
                profileClone();
            } catch (CloneNotSupportedException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        @Override
        public void onEdit(ActionEvent actionEvent) {
            profileRename(getSelectedProfile().getName());
        }

        @Override
        public void onRemove(ActionEvent actionEvent) {
            profileRemove();
        }

        @Override
        public void onRemoveAll(ActionEvent actionEvent) {
            profileRemoveAll();
        }
    });
}

From source file:org.keycloak.adapters.installed.KeycloakInstalled.java

private void logoutDesktop() throws IOException, URISyntaxException, InterruptedException {
    CallbackListener callback = new CallbackListener(getLogoutResponseWriter());
    callback.start();//from ww w  .  j  a  v  a 2  s  .  c o m

    String redirectUri = "http://localhost:" + callback.server.getLocalPort();

    String logoutUrl = deployment.getLogoutUrl().queryParam(OAuth2Constants.REDIRECT_URI, redirectUri).build()
            .toString();

    Desktop.getDesktop().browse(new URI(logoutUrl));

    callback.join();

    if (callback.errorException != null) {
        throw callback.errorException;
    }
}