List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.t3.client.TabletopTool.java
/** * Launch the platform's web browser and ask it to open the given URL. Note * that this should not be called from any uncontrolled macros as there are * both security and denial-of-service attacks possible. * // w w w. ja v a 2s . c o m * @param url */ public static void showDocument(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); URI uri = null; try { uri = new URI(url); desktop.browse(uri); } catch (Exception e) { TabletopTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e); } } else { String errorMessage = "msg.error.browser.notFound"; Exception exception = null; String[] envvars = { "T3_BROWSER", "BROWSER" }; String param = envvars[0]; boolean apparentlyItWorked = false; for (String var : envvars) { String browser = System.getenv(var); if (browser != null) { try { param = var + "=\"" + browser + "\""; Runtime.getRuntime().exec(new String[] { browser, url }); apparentlyItWorked = true; } catch (Exception e) { errorMessage = "msg.error.browser.cannotStart"; exception = e; } } } if (apparentlyItWorked == false) { TabletopTool.showError(I18N.getText(errorMessage, param), exception); } } }
From source file:widoco.gui.GuiController.java
public void openBrowser(URI uri) { if (Desktop.isDesktopSupported()) { try {//from w w w . j a v a 2 s.c o m Desktop.getDesktop().browse(uri); } catch (IOException ex) { System.err.println("Could not open browser: " + ex.getMessage()); } } }
From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java
@FXML private void clickOpenTemplateLatLongToLatLong(ActionEvent event) throws IOException { final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; File file = new File(getClass().getResource("latLongToLatLongTemplate.csv").getFile()); if (desktop != null && desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(file);// ww w .java2 s .co m } else { throw new UnsupportedOperationException("Open action not supported"); } }
From source file:dsfixgui.FileIO.DSFixFileController.java
public void uninstallDSFix() { ui.printConsole(UNINSTALLING_DSF);/* w w w. j a va 2 s . co m*/ File fileToDelete = null; boolean deleteError = false; for (int i = DSF_FILES.length - 1; i >= 0; i--) { String file = DSF_FILES[i]; fileToDelete = new File(ui.getDataFolder().getPath() + "\\" + file); if (fileToDelete.exists()) { fileToDelete.delete(); if (fileToDelete.exists()) { deleteError = true; ui.printConsole(FAILED_FILE_DELETE_ERR + file); } else { ui.printConsole(FILE_DELETED + file); } } else { ui.printConsole(DSF_FILE_NOT_FOUND + file); } } if (!deleteError) { if (ui.getDSPWStatus() != 0) { uninstallFPSFix(); } ui.printConsole(DSF_UNINSTALLED_SUCCESS); } else { if (ui.getDSPWStatus() != 0) { uninstallFPSFix(); } ui.printConsole(DSF_UNINSTALLED_ERRORS); ContinueDialog cD = new ContinueDialog(300.0, 80.0, DIALOG_TITLE_OPEN_FOLDER_PROMPT, DIALOG_MSG_DELETE_ERRORS_PROMPT, DIALOG_BUTTON_TEXTS[2], DIALOG_BUTTON_TEXTS[3]); if (cD.show()) { try { Desktop.getDesktop().open(ui.getDataFolder()); } catch (IOException ex) { //Logger.getLogger(DSFixFileController.class.getName()).log(Level.SEVERE, null, ex); ui.printConsole(FAILED_OPEN_FOLDER_ERR); } } } ui.checkForDSFix(); }
From source file:tpp.TPPFrame.java
private static void browseHelp() { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); try {//from w ww. ja v a 2 s .c o m desktop.browse(new URI(TargetedProjectionPursuit.HELP_URL)); } catch (Exception e) { // TODO: error handling } } else { // TODO: error handling } }
From source file:net.rptools.maptool.client.MapTool.java
/** * Launch the platform's web browser and ask it to open the given URL. Note * that this should not be called from any uncontrolled macros as there are * both security and denial-of-service attacks possible. * /*from w w w . ja v a2 s.c o m*/ * @param url */ public static void showDocument(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); URI uri = null; try { uri = new URI(url); desktop.browse(uri); } catch (Exception e) { MapTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e); } } else { String errorMessage = "msg.error.browser.notFound"; Exception exception = null; String[] envvars = { "MAPTOOL_BROWSER", "BROWSER" }; String param = envvars[0]; boolean apparentlyItWorked = false; for (String var : envvars) { String browser = System.getenv(var); if (browser != null) { try { param = var + "=\"" + browser + "\""; Runtime.getRuntime().exec(new String[] { browser, url }); apparentlyItWorked = true; } catch (Exception e) { errorMessage = "msg.error.browser.cannotStart"; exception = e; } } } if (apparentlyItWorked == false) { MapTool.showError(I18N.getText(errorMessage, param), exception); } } }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private void setupTableWithBinomialChanges() { changesTableView.setEditable(false); changesTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); changesTableView.setItems(potentialChanges); changesTableView.getColumns().clear(); TableColumn<PotentialChange, ChangeType> colChangeType = new TableColumn<>("Type"); colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(), ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT, ChangeType.COMPLEX, ChangeType.ERROR)); colChangeType.setCellValueFactory(new PropertyValueFactory<>("type")); colChangeType.setPrefWidth(100.0);// w ww.j av a 2 s . c om colChangeType.setEditable(true); changesTableView.getColumns().add(colChangeType); TableColumn<PotentialChange, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From"); colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from")); colChangeFrom.setPrefWidth(200.0); colChangeFrom.setEditable(true); changesTableView.getColumns().add(colChangeFrom); TableColumn<PotentialChange, ObservableSet<Name>> colChangeTo = new TableColumn<>("To"); colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to")); colChangeTo.setPrefWidth(200.0); colChangeTo.setEditable(true); changesTableView.getColumns().add(colChangeTo); TableColumn<PotentialChange, String> colDataset = new TableColumn<>("Dataset"); colDataset.setCellValueFactory(cvf -> { return new ReadOnlyStringWrapper(cvf.getValue().getDataset().toString()); }); colDataset.setPrefWidth(150.0); changesTableView.getColumns().add(colDataset); TableColumn<PotentialChange, SimplifiedDate> dateCol = new TableColumn<>("Date"); dateCol.setCellFactory( TextFieldTableCell.forTableColumn(new SimplifiedDate.SimplifiedDateStringConverter())); dateCol.setCellValueFactory(cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate())); dateCol.setPrefWidth(150); dateCol.setSortable(true); dateCol.setSortType(SortType.ASCENDING); changesTableView.getColumns().add(dateCol); changesTableView.getSortOrder().add(dateCol); TableColumn<PotentialChange, String> colChangeSummary = new TableColumn<>("Changes summary"); colChangeSummary.setCellValueFactory(cvf -> { Set<Change> changes = changesByPotentialChange.get(cvf.getValue()); return new ReadOnlyStringWrapper(changes.size() + ": " + changes.stream().map(ch -> ch.toString()).collect(Collectors.joining("; "))); }); colChangeSummary.setPrefWidth(200.0); changesTableView.getColumns().add(colChangeSummary); /* TableColumn<PotentialChange, String> colExplicit = new TableColumn<>("Explicit or implicit?"); colExplicit.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getDataset().isChangeImplicit(features.getValue()) ? "Implicit" : "Explicit" ) ); tv.getColumns().add(colExplicit); ChangeFilter cf = binomialChangesView.getProjectView().getProject().getChangeFilter(); TableColumn<Change, String> colFiltered = new TableColumn<>("Eliminated by filter?"); colFiltered.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( cf.test(features.getValue()) ? "Allowed" : "Eliminated" ) ); tv.getColumns().add(colFiltered); */ TableColumn<PotentialChange, String> colNote = new TableColumn<>("Note"); colNote.setCellFactory(TextFieldTableCell.forTableColumn()); colNote.setCellValueFactory(new PropertyValueFactory<>("note")); colNote.setPrefWidth(100.0); changesTableView.getColumns().add(colNote); TableColumn<PotentialChange, String> colReason = new TableColumn<>("Reason"); colReason.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(calculateReason(cvf.getValue()))); colReason.setPrefWidth(100.0); changesTableView.getColumns().add(colReason); TableColumn<PotentialChange, String> colReasonDate = new TableColumn<>("ReasonDate"); colReasonDate.setCellValueFactory(cvf -> { String result; Set<SimplifiedDate> dates = calculateReasonDate(cvf.getValue()); if (dates.size() > 1) { result = "(" + dates.size() + ") " + dates.stream().distinct().sorted() .map(sd -> sd.asYYYYmmDD("-")).collect(Collectors.joining("|")); } else if (dates.size() == 1) { result = dates.iterator().next().asYYYYmmDD("-"); } else { result = "NA"; } return new ReadOnlyStringWrapper(result); }); colReasonDate.setPrefWidth(100.0); changesTableView.getColumns().add(colReasonDate); TableColumn<PotentialChange, String> colCitations = new TableColumn<>("Citations"); colCitations.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colCitations); TableColumn<PotentialChange, String> colGenera = new TableColumn<>("Genera"); colGenera.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus()) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colGenera); TableColumn<PotentialChange, String> colSpecificEpithet = new TableColumn<>("Specific epithets"); colSpecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(String .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet()) .filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colSpecificEpithet); // The infraspecific string. TableColumn<PotentialChange, String> colInfraspecificEpithet = new TableColumn<>("Infraspecific epithets"); colInfraspecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream() .map(n -> n.getInfraspecificEpithetsAsString()).filter(s -> s != null) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colInfraspecificEpithet); // The very last epithet of all TableColumn<PotentialChange, String> colTerminalEpithet = new TableColumn<>("Terminal epithet"); colTerminalEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> { List<Name.InfraspecificEpithet> infraspecificEpithets = n.getInfraspecificEpithets(); if (!infraspecificEpithets.isEmpty()) { return infraspecificEpithets.get(infraspecificEpithets.size() - 1).getValue(); } else { return n.getSpecificEpithet(); } }).filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colTerminalEpithet); TableColumn<PotentialChange, String> dateForRCol = new TableColumn<>("DateYMD"); dateForRCol.setCellValueFactory( cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate().asYYYYmmDD("-"))); changesTableView.getColumns().add(dateForRCol); // Properties TableColumn<PotentialChange, String> colProperties = new TableColumn<>("Properties"); colProperties.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getProperties().entrySet().stream() .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colProperties); fillTableWithBinomialChanges(); // When someone selects a cell in the Table, try to select the appropriate data in the // additional data view. changesTableView.getSelectionModel().getSelectedItems() .addListener((ListChangeListener<PotentialChange>) lcl -> { AdditionalData aData = additionalDataCombobox.getSelectionModel().getSelectedItem(); if (aData != null) { aData.onSelectChange(changesTableView.getSelectionModel().getSelectedItems()); } }); // Create a right-click menu for table rows. changesTableView.setRowFactory(table -> { TableRow<PotentialChange> row = new TableRow<>(); row.setOnContextMenuRequested(event -> { if (row.isEmpty()) return; // We don't currently use the clicked change, since currently all options // change *all* the selected changes, but this may change in the future. PotentialChange change = row.getItem(); ContextMenu changeMenu = new ContextMenu(); Menu lookupChange = new Menu("Look up change"); lookupChange.getItems().addAll(changesByPotentialChange.getOrDefault(change, new HashSet<>()) .stream() .map(ch -> createMenuItem(ch.toString() + " in " + ch.getDataset().toString(), action -> { binomialChangesView.getProjectView().openDetailedView(ch); })).collect(Collectors.toList())); changeMenu.getItems().add(lookupChange); changeMenu.getItems().add(new SeparatorMenuItem()); Menu searchForName = new Menu("Search for name"); searchForName.getItems().addAll( change.getAllNames().stream().sorted().map(n -> createMenuItem(n.getFullName(), action -> { binomialChangesView.getProjectView().openDetailedView(n); })).collect(Collectors.toList())); changeMenu.getItems().add(searchForName); changeMenu.getItems().add(new SeparatorMenuItem()); // Create a submenu for tags and urls. String note = change.noteProperty().get(); Menu removeTags = new Menu("Tags"); removeTags.getItems().addAll(change.getTags().stream().sorted() .map(tag -> new MenuItem(tag.getName())).collect(Collectors.toList())); Menu lookupURLs = new Menu("Lookup URL"); change.getURIs().stream().sorted().map(uri -> { return createMenuItem(uri.toString(), evt -> { try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { LOGGER.warning("Could not open URL '" + uri + "': " + ex); } }); }).forEach(mi -> lookupURLs.getItems().add(mi)); changeMenu.getItems().add(lookupURLs); changeMenu.show(binomialChangesView.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); return row; }); LOGGER.info("setupTableWithChanges() completed"); }
From source file:localization.SplitterUI.java
private void openFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFolderActionPerformed // TODO add your handling code here: String folderpath = filepath.getText(); File fPath = new File(folderpath); if (folderpath.length() > 0) { File folder = null;/*from w w w. j a v a 2 s .c om*/ if (folderpath.endsWith(".lpu") && !fPath.isDirectory()) { folder = new File(folderpath.substring(0, folderpath.lastIndexOf("\\"))); } else if (folderpath.endsWith(".zip") && !fPath.isDirectory()) { File zFile = new File(folderpath.substring(0, folderpath.lastIndexOf("."))); if (!zFile.exists()) { JOptionPane.showMessageDialog(this, "Cannot find the unzip folder, please run it with zip file first.", "Folder Issue", JOptionPane.WARNING_MESSAGE, null); return; } folder = new File(folderpath.substring(0, folderpath.lastIndexOf("."))); } else if (fPath.isDirectory()) { folder = fPath; } if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(folder); } catch (IOException ex) { Logger.getLogger(SplitterUI.class.getName()).log(Level.SEVERE, null, ex); } } } else { String home = System.getProperty("user.home") + "\\Desktop"; File folder = new File(home); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(folder); } catch (IOException ex) { Logger.getLogger(SplitterUI.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java
@FXML private void clickGithubMenuItem(ActionEvent event) { final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; try {/*from w ww . j a v a 2 s .c om*/ URI uri = new URI("https://github.com/CIRDLES/Ambapo"); Desktop dt = Desktop.getDesktop(); dt.browse(uri); } catch (IOException | URISyntaxException ex) { } }
From source file:neembuu.uploader.NeembuuUploader.java
private void initNotification() { final StretchIcon si = new StretchIcon( getClass().getResource("/neembuuuploader/resources/say_yes_to_nu2.png"), true); notificationButton.setIcon(si);//from w w w . j a v a 2 s . co m final ReactiveThread rt = ReactiveThread.create(new Runnable() { @Override public void run() { try { NotificationRequest nr = makeNotificationRequest(); HttpResponse hr = NUHttpClient.newHttpClient().execute(nr.image); BufferedImage bi = ImageIO.read(hr.getEntity().getContent()); hr = NUHttpClient.newHttpClient().execute(nr.redirect); final String redirect = EntityUtils.toString(hr.getEntity()); if (redirect != null && redirect.length() > 0) { if (bi == null) return; //si.setImage(bi); notificationButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(new URI("http://neembuu.com/uploader/donate/")); } catch (Exception a) { a.printStackTrace(); } } }); } else { System.out.println("redirect was nullish " + redirect); } } catch (Exception a) { a.printStackTrace(); } } }, CompletionCallback.DUMMY); rt.start(); }