List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.codejumble.opentube.Main.java
/** * Opens http://www.codejumble.com at System's default browser * * @param evt Swing event/* w w w . j ava2s . co m*/ */ private void helpPagesItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpPagesItemActionPerformed try { URI uri = new URL("http://www.codejumble.com").toURI(); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(uri); } catch (Exception e) { createErrorDialog(this, e.getMessage(), "Error!"); } } } catch (Exception ex) { createErrorDialog(this, ex.getMessage(), "Unexpected error"); } }
From source file:com.commander4j.db.JDBUserReport.java
public boolean runReport() { PreparedStatement prepStatement; boolean result = true; try {//w ww. ja v a 2 s. c o m prepStatement = Common.hostList.getHost(getHostID()).getConnection(getSessionID()) .prepareStatement(getSQL(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); prepStatement.setFetchSize(25); if (isParamDateRequired()) { prepStatement.setTimestamp(1, getParamFromDate()); prepStatement.setTimestamp(2, getParamToDate()); } if (getDestination().equals("SYSTEM")) { for (int x = 0; x < systemParams.size(); x++) { String type = systemParams.get(x).parameterType; if (type.toLowerCase().equals("string")) { prepStatement.setString(systemParams.get(x).parameterPosition, systemParams.get(x).parameterStringValue); } if (type.toLowerCase().equals("integer")) { prepStatement.setInt(systemParams.get(x).parameterPosition, systemParams.get(x).parameterIntegerValue); } if (type.toLowerCase().equals("long")) { prepStatement.setLong(systemParams.get(x).parameterPosition, systemParams.get(x).parameterLongValue); } if (type.toLowerCase().equals("timestamp")) { prepStatement.setTimestamp(systemParams.get(x).parameterPosition, systemParams.get(x).parameterTimestampValue); } } } ResultSet tempResult = prepStatement.executeQuery(); boolean dataReturned = true; if (!tempResult.next()) { dataReturned = false; } tempResult.beforeFirst(); if (dataReturned) { if (getDestination().equals("EXCEL")) { generateExcel(tempResult); } if (getDestination().equals("JASPER_REPORTS")) { generateJasper(prepStatement); } if (getDestination().equals("PDF")) { generatePDF(prepStatement); } if (getDestination().equals("ACCESS")) { generateAccess(tempResult); } if (getDestination().equals("CSV")) { generateCSV(tempResult); } if (getDestination().equals("SYSTEM")) { generateSYSTEM(tempResult); } if (isPreviewRequired()) { try { Desktop.getDesktop().open(new File(getExportFilename())); } catch (IOException e) { e.printStackTrace(); } } if (isEmailEnabled()) { String emailaddresses = getEmailAddresses(); if (isEmailPromptEnabled()) { emailaddresses = JUtility.replaceNullStringwithBlank( JOptionPane.showInputDialog(lang.get("lbl_Email_Addresses"))); } StringConverter stringConverter = new StringConverter(); ArrayConverter arrayConverter = new ArrayConverter(String[].class, stringConverter); arrayConverter.setDelimiter(';'); arrayConverter.setAllowedChars(new char[] { '@', '_' }); String[] emailList = (String[]) arrayConverter.convert(String[].class, emailaddresses); if (emailList.length > 0) { String shortFilename = JUtility.getFilenameFromPath(getExportFilename()); mail.postMail(emailList, "Commande4j User Report requested by " + Common.userList.getUser(Common.sessionID).getUserId() + " from [" + Common.hostList.getHost(getHostID()).getSiteDescription() + "] on " + JUtility.getClientName(), "See attached report.\n", shortFilename, getExportFilename()); com.commander4j.util.JWait.milliSec(2000); } } } else { result = false; setErrorMessage("No data returned by query."); } } catch (Exception ex) { setErrorMessage(ex.getMessage()); result = false; } return result; }
From source file:coreferenceresolver.gui.MainGUI.java
private void trainingBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trainingBtnActionPerformed // TODO add your handling code here: JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose where your training file saved"); inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { trainingFilePathTF// www.j a va 2 s . c om .setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "train.arff"); noteTF.setText("Create training file waiting ..."); new Thread(new Runnable() { @Override public void run() { try { TrainingMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(), trainingFilePathTF.getText(), true); noteTF.setText("Create training file done!"); String folderPathOpen = trainingFilePathTF.getText().substring(0, trainingFilePathTF.getText().lastIndexOf(File.separatorChar)); Desktop.getDesktop().open(new File(folderPathOpen)); } catch (Exception ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } else { noteTF.setText("No training file location selected"); } }
From source file:convcao.com.agent.ConvcaoNeptusInteraction.java
private void jLabel1MouseClicked(MouseEvent evt) throws URISyntaxException, IOException { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { URI uri = new URI("http://www.noptilus-fp7.eu/default.asp?node=page&id=321&lng=2"); desktop.browse(uri);//from w w w .j a v a2 s . c o m } } }
From source file:nl.mvdr.umvc3replayanalyser.controller.Umvc3ReplayManagerController.java
/** Handles the case where the user clicks the Open video button. */ @FXML//from w w w. j a v a 2 s .c o m private void handleOpenVideoAction() { log.info("Open video button clicked."); Replay selectedReplay = replayTableView.getSelectionModel().getSelectedItem(); if (selectedReplay == null) { throw new IllegalStateException("No replay selected; open video button should have been disabled!"); } if (Desktop.isDesktopSupported()) { String videoFilePath = FilenameUtils.normalize(this.configuration.getDataDirectory().getAbsolutePath() + FileUtils.SEPARATOR + selectedReplay.getVideoLocation()); log.info("Playing video: " + videoFilePath); File videoFile = new File(videoFilePath); try { Desktop.getDesktop().open(videoFile); } catch (IOException | IllegalArgumentException e) { log.error("Unable to play video for replay: " + selectedReplay, e); // Show an error message to the user. String errorMessage = "Unable to play video for game: " + selectedReplay.getGame().getDescription(false); if (e.getMessage() != null) { errorMessage = errorMessage + " " + e.getMessage(); } ErrorMessagePopup.show("Unable to play video", errorMessage, e); } } else { log.error("Unable to play video, desktop not supported!"); // Show an error message to the user. ErrorMessagePopup.show("Unable to play video", "Unable to play video files.", null); } }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void openFeedbackPage() { String s = "https://whiledo.de/index.php?s=6"; try {//from w ww . j a v a 2 s. co m Desktop.getDesktop().browse(new URI(s)); } catch (IOException | URISyntaxException e) { showError("Feedbackseite konnte nicht geffnet werden. Besuchen Sie " + s, e); } }
From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java
private void initFX(final JFXPanel fxPanel) { Group group = new Group(); Scene scene = new Scene(group); fxPanel.setScene(scene);// w w w .j a va 2 s .c o m webView = new WebView(); if (javaFXVersionInt >= 8) { webView.setScaleX(1.0); webView.setScaleY(1.0); //webView.setFitToHeight(false); //webView.setFitToWidth(false); //webView.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96); } group.getChildren().add(webView); int w = this.getWidth(); int h = this.getHeight() - 34; webView.setMinSize(w, h); webView.setMaxSize(w, h); webView.setPrefSize(w, h); // Obtain the webEngine to navigate webEngine = webView.getEngine(); webEngine.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { if (newValue.endsWith(".pdf")) { try { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), "Open PDF document in external application?", "Open PDF document in external application?", WandoraOptionPane.YES_NO_OPTION); if (a == WandoraOptionPane.YES_OPTION) { Desktop dt = Desktop.getDesktop(); dt.browse(new URI(newValue)); } } catch (Exception e) { } } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { urlTextField.setText(newValue); } }); } } }); webEngine.titleProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { title = newValue; } }); } }); webEngine.setOnAlert(new EventHandler<WebEvent<java.lang.String>>() { @Override public void handle(WebEvent<String> t) { if (t != null) { String str = t.getData(); if (str != null && str.length() > 0) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), str, "Javascript Alert", WandoraOptionPane.PLAIN_MESSAGE); } } } }); webEngine.setConfirmHandler(new Callback<String, Boolean>() { @Override public Boolean call(String msg) { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), msg, "Javascript Alert", WandoraOptionPane.YES_NO_OPTION); return (a == WandoraOptionPane.YES_OPTION); } }); webEngine.setPromptHandler(new Callback<PromptData, String>() { @Override public String call(PromptData data) { String a = WandoraOptionPane.showInputDialog(Wandora.getWandora(), data.getMessage(), data.getDefaultValue(), "Javascript Alert", WandoraOptionPane.QUESTION_MESSAGE); return a; } }); webEngine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() { @Override public WebEngine call(PopupFeatures features) { if (informPopupBlocking) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A javascript popup has been blocked. Wandora doesn't allow javascript popups in Webview topic panel.", "Javascript popup blocked", WandoraOptionPane.PLAIN_MESSAGE); } informPopupBlocking = false; return null; } }); webEngine.setOnVisibilityChanged(new EventHandler<WebEvent<Boolean>>() { @Override public void handle(WebEvent<Boolean> t) { if (t != null) { Boolean b = t.getData(); if (informVisibilityChanges) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A browser window visibility change has been blocked. Wandora doesn't allow visibility changes of windows in Webview topic panel.", "Javascript visibility chnage blocked", WandoraOptionPane.PLAIN_MESSAGE); informVisibilityChanges = false; } } } }); webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == Worker.State.SCHEDULED) { //System.out.println("Scheduled!"); startLoadingAnimation(); } if (newState == Worker.State.SUCCEEDED) { Document doc = webEngine.getDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); // transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out, "UTF-8"))); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); webSource = stringWriter.toString(); } catch (Exception ex) { ex.printStackTrace(); } stopLoadingAnimation(); } else if (newState == Worker.State.CANCELLED) { //System.out.println("Cancelled!"); stopLoadingAnimation(); } else if (newState == Worker.State.FAILED) { webEngine.loadContent(failedToOpenMessage); stopLoadingAnimation(); } } }); }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void openEMail() { try {/*w w w . j a v a 2 s. c o m*/ Desktop.getDesktop().browse(new URI("mailto:" + EMAIL)); } catch (IOException | URISyntaxException e) { showError("Das E-Mailprogramm konnte nicht geffnet werden. Schreiben Sie an: " + EMAIL, e); } }
From source file:AltiConsole.AltiConsoleMainScreen.java
/** * Handles all the actions.//from ww w . ja va 2 s . c om * * @param e * the action event. */ public void actionPerformed(final ActionEvent e) { final Translator trans = Application.getTranslator(); if (e.getActionCommand().equals("EXIT")) { System.out.println("exit and disconnecting\n"); if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.ClosingWindow"), trans.get("AltiConsoleMainScreen.ReallyClosing"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DisconnectFromAlti(); System.exit(0); } } else if (e.getActionCommand().equals("ABOUT")) { AboutDialog.showPreferences(AltiConsoleMainScreen.this); } // ERASE_FLIGHT else if (e.getActionCommand().equals("ERASE_FLIGHT")) { if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.eraseAllflightData"), trans.get("AltiConsoleMainScreen.eraseAllflightDataTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { System.out.println("erasing flight\n"); ErasingFlight(); } } else if (e.getActionCommand().equals("RETRIEVE_FLIGHT")) { System.out.println("retrieving flight\n"); RetrievingFlight(); } else // SAVE_FLIGHT if (e.getActionCommand().equals("SAVE_FLIGHT")) { System.out.println("Saving current flight\n"); SavingFlight(); } else // RETRIEVE_ALTI_CFG if (e.getActionCommand().equals("RETRIEVE_ALTI_CFG")) { System.out.println("retrieving alti config\n"); AltiConfigData pAlticonfig = retrieveAltiConfig(); if (pAlticonfig != null) AltiConfigDlg.showPreferences(AltiConsoleMainScreen.this, pAlticonfig, Serial); } // LICENSE else if (e.getActionCommand().equals("LICENSE")) { LicenseDialog.showPreferences(AltiConsoleMainScreen.this); } // comPorts else if (e.getActionCommand().equals("comPorts")) { DisconnectFromAlti(); String currentPort; //e. currentPort = (String) comPorts.getSelectedItem(); if (Serial != null) Serial.searchForPorts(); System.out.println("We have a new selected value for comport\n"); comPorts.setSelectedItem(currentPort); } // UPLOAD_FIRMWARE else if (e.getActionCommand().equals("UPLOAD_FIRMWARE")) { System.out.println("upload firmware\n"); //make sure to disconnect first DisconnectFromAlti(); JFileChooser fc = new JFileChooser(); String hexfile = null; File startFile = new File(System.getProperty("user.dir")); //FileNameExtensionFilter filter; fc.setDialogTitle("Select firmware"); //fc.set fc.setCurrentDirectory(startFile); //fc.addChoosableFileFilter(new FileNameExtensionFilter("*.HEX", "hex")); fc.setFileFilter(new FileNameExtensionFilter("*.hex", "hex")); //fc.fil int action = fc.showOpenDialog(SwingUtilities.windowForComponent(this)); if (action == JFileChooser.APPROVE_OPTION) { hexfile = fc.getSelectedFile().getAbsolutePath(); } if (hexfile != null) { String exefile = UserPref.getAvrdudePath(); String conffile = UserPref.getAvrdudeConfigPath(); String opts = " -v -v -v -v -patmega328p -carduino -P\\\\.\\" + (String) this.comPorts.getSelectedItem() + " -b115200 -D -V "; String cmd = exefile + " -C" + conffile + opts + " -Uflash:w:" + hexfile + ":i"; System.out.println(cmd); try { Process p = Runtime.getRuntime().exec(cmd); AfficheurFlux fluxSortie = new AfficheurFlux(p.getInputStream(), this); AfficheurFlux fluxErreur = new AfficheurFlux(p.getErrorStream(), this); new Thread(fluxSortie).start(); new Thread(fluxErreur).start(); p.waitFor(); } catch (IOException e1) { e1.printStackTrace(); } catch (InterruptedException e2) { e2.printStackTrace(); } } } // ON_LINE_HELP else if (e.getActionCommand().equals("ON_LINE_HELP")) { Desktop d = Desktop.getDesktop(); System.out.println("Online help \n"); try { d.browse(new URI(trans.get("help.url"))); } catch (URISyntaxException e1) { System.out.println("Illegal URL: " + trans.get("help.url") + " " + e1.getMessage()); } catch (IOException e1) { System.out.println("Unable to launch browser: " + e1.getMessage()); } } }
From source file:com.wesley.urban_cuts.client.urbancuts.myFrame.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed if (Desktop.isDesktopSupported()) { try {//from w w w.j a v a 2 s . c om File myFile = new File( "C:\\Users\\User\\Documents\\NetBeansProjects\\Urban_Cuts_App\\src\\java\\License_agreement.pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { } } }