List of usage examples for java.awt Desktop open
public void open(File file) throws IOException
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 {/*w ww . jav a2s .c o m*/ desktop.open(new File(url)); } }
From source file:se.trixon.toolbox.idiot.IdiotTopComponent.java
private void openDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDirectoryButtonActionPerformed if (!Desktop.isDesktopSupported()) { return;/*w ww . ja v a 2s. co m*/ } try { Desktop desktop = Desktop.getDesktop(); File dest = new File(tasksPanel.getSelectedTask().getDestination()).getParentFile(); desktop.open(dest); } catch (Exception ex) { NbMessage.error(Dict.Dialog.TITLE_IO_ERROR.toString(), Dict.Dialog.ERROR_CANT_OPEN_DIRECTORY.toString()); } }
From source file:smsapp.utils.Utils.java
public static void openFile(String folderName, String fileName) { File f = new File(folderName + "" + File.separator + "" + fileName); Desktop dt = Desktop.getDesktop(); try {// w ww . j a v a 2s . co m dt.open(f); } catch (IOException ex) { Logger.getLogger(ControllerWhatsapp.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } System.out.println("Done."); }
From source file:smsapp.utils.Utils.java
public static void browseFileLocation(String folderName) { File f = new File(folderName + "" + File.separator + ""); Desktop dt = Desktop.getDesktop(); try {/*from ww w. ja v a 2s .co m*/ dt.open(f); } catch (IOException ex) { Logger.getLogger(ControllerWhatsapp.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } System.out.println("Done."); }
From source file:spartanfinal.ProcessFiles.java
public void openFile(File file) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { for (Desktop.Action action : Desktop.Action.values()) { }/* w w w. jav a2 s.c o m*/ try { desktop.open(file); } catch (Exception t) { String[] commands = { "cmd.exe", "/c", "start", "\"test\"", "\"" + file.getAbsolutePath() + "\"" }; try { Process p = Runtime.getRuntime().exec(commands); p.waitFor(); } catch (Exception l) { } } } else { } }
From source file:ui.HelpUI.java
private void loadPDF() { Desktop ccc=Desktop.getDesktop(); // SwingController controller = new SwingController(); // SwingViewBuilder factory = new SwingViewBuilder(controller); // jPanel1 = factory.buildViewerPanel(); InputStream is=this.getClass().getResourceAsStream("/report/generateInvoice_1001.pdf"); // controller.openDocument(is,"Help Document",null); //from w w w.j a v a 2s . co m try { File file=stream2file(is); ccc.open(file);//(new File("/report/generateInvoice_1001.pdf")); //add(jPanel1); } catch (IOException ex) { Logger.getLogger(HelpUI.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedPhotoLoad(Chat chat, File recievedFile, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override//from w ww. j a va2 s. c o m protected HBox call() throws Exception { Thread.sleep(100); VBox vbox = new VBox(); //to add text ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); String strChatterName = chat.getParticipant(); //add name of the chatter with light color strChatterName = Character.toUpperCase(strChatterName.charAt(0)) + strChatterName.substring(1, strChatterName.indexOf("@")); Label chatterName = new Label(strChatterName); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(recievedFile); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_RIGHT); HBox hbox = new HBox(); //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER); hbox.getChildren().addAll(imageRec, vbox); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedPhotoOnTransmit(Chat chat, File recievedFile, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override//w w w .j av a 2 s .com protected HBox call() throws Exception { VBox vbox = new VBox(); //to add text Thread.sleep(2000); ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); String strChatterName = chat.getParticipant(); //add name of the chatter with light color strChatterName = Character.toUpperCase(strChatterName.charAt(0)) + strChatterName.substring(1, strChatterName.indexOf("@")); Label chatterName = new Label(strChatterName); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(recievedFile); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_RIGHT); HBox hbox = new HBox(); hbox.getChildren().addAll(imageRec, vbox); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); //set the received chat message appear on the screen if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); } Task t = new Task() { @Override protected Object call() throws Exception { Thread.sleep(2500); return new Object(); } }; t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax())); Thread thread1 = new Thread(t); thread1.start(); }
From source file:ui.main.MainViewController.java
private synchronized void paintSentPhoto(Chat chat, File file, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override/*from w w w.jav a 2 s .com*/ protected HBox call() throws Exception { // Thread.sleep(100); VBox vbox = new VBox(); //to add text ImageView imageRec = new ImageView(myAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); Label chatterName = new Label(name.getText()); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(file), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(file); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_LEFT); HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER_RIGHT); //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER); hbox.getChildren().addAll(vbox, imageRec); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:view.ViewRequestedFileStatus.java
private void downloadSelectedFileWithoutDecryption() { String requestedFilePath = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 6) .toString();// ww w . ja v a2s.c o m String requestedFileName = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 1) .toString(); System.out.println(requestedFilePath); File fromFile = new File(Configuration.dataCloud + requestedFilePath); File temporaryFileDirectory = new File(Configuration.temporaryFilePath + System.currentTimeMillis()); if (temporaryFileDirectory.mkdir()) { File toFile = new File(temporaryFileDirectory.getPath() + "/" + requestedFileName + "." + FilenameUtils.getExtension(requestedFilePath)); try { FileUtils.copyFile(fromFile, toFile); Desktop desktop = Desktop.getDesktop(); desktop.open(temporaryFileDirectory); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "Could not open the file. Please check directory " + temporaryFileDirectory); } } else { JOptionPane.showMessageDialog(rootPane, "Could not get file permission in computer to make new folder at " + temporaryFileDirectory); } download_button.setEnabled(false); }