@Override public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = table.rowAtPoint(p); if (me.getClickCount() == 2) { int fila = grid.getSelectedRow(); System.out.println("Seleccionada " + grid.getSelectedRow()); if (grid.getModel().getValueAt(fila, 1) != null) { String openFile = grid.getModel().getValueAt(fila, 1).toString(); System.out.println("Abrir:" + openFile); if (new File(openFile).exists()) { if (Desktop.isDesktopSupported()) { try { File myFile = new File(openFile); Desktop.getDesktop().open(myFile); } catch (IOException ex) { JOptionPane.showMessageDialog( SiSeOnFrame.this, "No fue posible abrir el archivo.", "Archivo no encontrado o dañado.", JOptionPane.WARNING_MESSAGE); } } else { System.out.println("DESKTOP NO SOPORTADO"); } // if } else { JOptionPane.showMessageDialog( SiSeOnFrame.this, "El archivo ya no se encuentra en la ruta donde fue indexado."); } } } }
void lookUpTaxonID(String taxonID) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI( "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=" + taxonID); } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
@Test public void deve_gerar_boleto_em_arquivo() throws Exception { Cedente cedenteSistema = new Cedente(); cedenteSistema.setNome("AlgaWorks"); cedenteSistema.setCnpj("10.687.566/0001-97"); ContaBancaria contaBancaria = new ContaBancaria(); contaBancaria.setAgencia(1111); contaBancaria.setDigitoAgencia("0"); contaBancaria.setNumero(2222); contaBancaria.setDigitoConta("9"); contaBancaria.setCodigoCarteira(6); cedenteSistema.setContaBancaria(contaBancaria); Cobranca cobrancaSistema = new Cobranca(); cobrancaSistema.setCodigo(1L); cobrancaSistema.setDataVencimento(new Date()); cobrancaSistema.setValor(new BigDecimal("200.22")); Sacado sacado = new Sacado(); sacado.setNome("Maria Santos"); cobrancaSistema.setSacado(sacado); File boleto = this.emissorBoleto.gerarBoletoEmArquivo( "boletoTeste1.pdf", cedenteSistema, cobrancaSistema); Desktop desktop = Desktop.getDesktop(); desktop.open(boleto); }
void searchName(String nameToMatch) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch); // I think the URI handles the URL encoding? } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
/** * 抓屏方法 * * @see 该方法抓的是全屏,并且当传入的fileName参数为空时会将抓屏图片默认保存到用户桌面上 * @param fileName 抓屏后的图片保存名称(含保存路径及后缀),传空时会把图片自动保存到桌面 * @param isAutoOpenImage 是否自动打开图片 * @return 抓屏成功返回true,反之false */ public static boolean captureScreen(String fileName, boolean isAutoOpenImage) { if (isEmpty(fileName)) { String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getPath(); String separator = System.getProperty("file.separator"); String imageName = "截屏_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".png"; fileName = desktop + separator + imageName; } String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1); File file = new File(fileName); // 获取屏幕大小 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); try { Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); ImageIO.write(image, fileSuffix, file); // 自动打开图片 if (isAutoOpenImage) { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { Desktop.getDesktop().open(file); } } } catch (AWTException e) { return false; } catch (IOException e) { return false; } return true; }
private static void getStudentPass(String facultyNumber) throws IOException, JAXBException, SAXException, TransformerException, ParserConfigurationException { if (Pattern.matches("\\d{5,6}", facultyNumber)) { InputStream inputStream = new FileInputStream(Constants.CONFIG_FILE_PATH.toString()); properties.load(inputStream); File protocolFile = new File(properties.getProperty("protocol")); ReadWriteUtils utils = new ReadWriteUtils(Protocol.class); Protocol protocol = (Protocol) utils.readFromXml(protocolFile); StudentPass studentPass = protocol.getStudentPass(Integer.parseInt(facultyNumber)); utils.setType(StudentPass.class); File outputFile = new File(properties.getProperty("output") + "\\StudentPass" + facultyNumber + ".xml"); if (outputFile.createNewFile()) System.out.println("File created!"); utils.writeXml(studentPass, outputFile); utils.writeXml(studentPass, System.out); System.out.println( "Do you want to open the generated XML Document with your default viewing program?"); if (awaitResponse()) Desktop.getDesktop().open(outputFile); System.out.println( "Do you want to transform the generated XML Document to html file and open with your default viewing program?"); if (awaitResponse()) { Desktop.getDesktop() .open(transformXML(outputFile, new File(Constants.STUDENT_STYLE.toString()))); } inputStream.close(); } else throw new IllegalArgumentException("Invalid faculty number is entered!"); }
private void facebookConnect() throws FacebookException { // auth.createToken returns a string // http://wiki.developers.facebook.com/index.php/Auth.createToken facebookAuthToken = facebookClient.executeQuery("auth.createToken", String.class); String url = "http://www.facebook.com/login.php" + "?api_key=" + FACEBOOK_API_KEY + "&fbconnect=true" + "&v=1.0" + "&connect_display=page" + "&session_key_only=true" + "&req_perms=read_stream,publish_stream,offline_access" + "&auth_token=" + facebookAuthToken; // Here we launch a browser with the above URL so the user can login to Facebook, grant our // requested permissions and send our token for pickup later if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(new URI(url)); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } } } }
// eventMenuPopup ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private void eventMenuPopup() { try { URI uri = new URI(Data.WIKI_URL + underscoreName(getWikiTopic())); Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } // if if (desktop != null) { desktop.browse(uri); } // if } // try catch (IOException error) { JOptionPane.showMessageDialog( Data.getView(), "^Wiki Error: " + error.getMessage(), "Wiki Error: " + Data.APP_TITLE, JOptionPane.ERROR_MESSAGE); } // catch catch (URISyntaxException error) { JOptionPane.showMessageDialog( Data.getView(), "@Wiki Error: " + error.getMessage(), "Wiki Error: " + Data.APP_TITLE, JOptionPane.ERROR_MESSAGE); } // catch } // eventMenuPopup ----------------------------------------------------------
private void prepareMailAll() { // TODO Auto-generated method stub String list = ""; for (DimensionsUser user : users) { // list += user.getUserId()+"@ac.bankit.it"; list += user.getUserId(); list += ";"; } GestConfFrame.getInstance().cmdOutAppend("\n" + list); Desktop desktop; if (Desktop.isDesktopSupported() && (desktop = Desktop.getDesktop()).isSupported(Desktop.Action.MAIL)) { URI mailto = null; try { mailto = new URI("mailto:" + list + "?subject=Hello%20World"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { desktop.mail(mailto); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // TODO fallback to some Runtime.exec(..) voodoo? throw new RuntimeException("desktop doesn't support mailto; mail is dead anyway ;)"); } setVisible(false); }
private static void openBrowser(OAuthV1 oAuth) { String authorizationUrl = OAuthV1Client.generateAuthorizationURL(oAuth); System.out.println("Get verification code......"); if (!java.awt.Desktop.isDesktopSupported()) { System.err.println("Desktop is not supported (fatal)"); System.exit(1); } java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop == null || !desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { System.err.println("Desktop doesn't support the browse action (fatal)"); System.exit(1); } try { desktop.browse(new URI(authorizationUrl)); } catch (IOException e) { e.printStackTrace(); System.exit(1); } catch (URISyntaxException e) { e.printStackTrace(); System.exit(1); } }
private static void openUpWebSite(String url) { Desktop d = Desktop.getDesktop(); try { d.browse(new URI(url)); } catch (Exception e) { } }
/** @param helpAddress */ public OpenHelpUrl(String helpAddress) { if (!java.awt.Desktop.isDesktopSupported()) { System.err.println("Desktop is not supported (fatal)"); System.exit(1); } java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { System.err.println("Desktop doesn't support the browse action (fatal)"); System.exit(1); } try { java.net.URI uri = new java.net.URI(helpAddress); desktop.browse(uri); } catch (Exception e) { System.err.println(e.getMessage()); } }
public static void openURL(String url) { try { // Since Java6 this is a much easier method to open the browser if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); desktop.browse(new URI(url)); } // Only if desktop is not supported we try the old main specific code else { if (SystemInfo.OS == Os.MAC) { Class<?> fileMgr = Class.forName("com.apple.eio.FileManager"); Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class}); openURL.invoke(null, new Object[] {url}); } else if (SystemInfo.OS == Os.WINDOWS) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); else { // assume Unix or Linux String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"}; String browser = null; for (int count = 0; (count < browsers.length) && (browser == null); count++) if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) browser = browsers[count]; if (browser == null) throw new Exception("Could not find web browser"); else Runtime.getRuntime().exec(new String[] {browser, url}); } } } catch (Exception e) { log.error("Error at opening the URL.", e); } }
/** * @param he hiperlik Event. * @see * javax.help.plaf.basic.BasicContentViewerUI#hyperlinkUpdate(javax.swing.event.HyperlinkEvent) */ @Override public void hyperlinkUpdate(final HyperlinkEvent he) { if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { URL u = he.getURL(); if ("mailto".equalsIgnoreCase(u.getProtocol()) || "http".equalsIgnoreCase(u.getProtocol()) || "ftp".equalsIgnoreCase(u.getProtocol())) { Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(u.toURI()); } catch (MalformedURLException e1) { DialogUtils.showGeneralErrorDialog( new Frame(), "MalformedURLException", "Invalid URL."); } catch (IOException e1) { DialogUtils.showGeneralErrorDialog(new Frame(), "IOException", "Resource not found."); } catch (URISyntaxException uriSyntaxEx) { DialogUtils.showGeneralErrorDialog(new Frame(), "URISyntaxException", "Invalid URI."); } } } } else { super.hyperlinkUpdate(he); } } }
public static void main(String[] args) { if (!java.awt.Desktop.isDesktopSupported()) { System.err.println("Desktop is not supported (fatal)"); System.exit(1); } java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { System.err.println("Desktop doesn't support the browse action (fatal)"); System.exit(1); } try { java.net.URI uri = new java.net.URI("http://www.d3js.org"); desktop.browse(uri); } catch (Exception e) { System.err.println(e.getMessage()); } }
public HyberLinkLabel(String text, String url) { this.text = text; this.url = url; try { this.isSupported = Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); } catch (Exception e) { System.out.println("Browse is not supported"); this.isSupported = false; } setActive(false); addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent e) { setActive(isSupported); if (isSupported) setCursor(new Cursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { setActive(false); } public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new java.net.URI(HyberLinkLabel.this.url)); } catch (Exception ex) { System.out.println(ex.toString()); } } }); }
private static void sendMail() throws URISyntaxException, IOException { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(new URI("mailto:[email protected]")); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Can't access."); } }
private void openContentDirectory() { try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(new File(ForgeConstants.CACHE_DIR)); } } catch (final Exception e) { System.out.println("Unable to open Directory: " + e.toString()); } }
private static void mostreBoletoNaTela(File arquivoBoleto) { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); try { desktop.open(arquivoBoleto); } catch (IOException e) { e.printStackTrace(); } }
/** * Opens the default mail application. * * @throws IOException * @since 0.7.0 */ public static void mail() throws IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart()); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().mail(); } else { throw new RuntimeException("Mail application not supported by your machine"); // $NON-NLS-1$ } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
private JMenu createHelpMenu() { List<JComponent> menuItems = new ArrayList<JComponent>(); MenuAction menuAction = null; menuAction = new MenuAction("User Guide ... ") { @Override public void actionPerformed(ActionEvent e) { try { BrowserLauncher.openURL(SERVER_BASE_URL + "igv/UserGuide"); } catch (IOException ex) { log.error("Error opening browser", ex); } } }; menuAction.setToolTipText(HELP_TOOLTIP); menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction)); if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.MAIL)) { menuAction = new MenuAction("Help Forum...") { @Override public void actionPerformed(ActionEvent e) { try { URI uri = new URI("http://groups.google.com/forum/#!forum/igv-help"); Desktop.getDesktop().browse(uri); } catch (Exception ex) { log.error("Error opening igv-help uri", ex); } } }; menuAction.setToolTipText("Email support"); menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction)); } } menuAction = new MenuAction("About IGV ") { @Override public void actionPerformed(ActionEvent e) { (new AboutDialog(IGV.getMainFrame(), true)).setVisible(true); } }; menuAction.setToolTipText(ABOUT_TOOLTIP); menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction)); MenuAction helpMenuAction = new MenuAction("Help"); return MenuAndToolbarUtils.createMenu(menuItems, helpMenuAction); }
public static void filmAbspielen(Frame parent, String datei) { boolean gut = false; File sFile; if (datei.isEmpty()) { return; } sFile = new File(datei); if (!sFile.exists()) { MVMessageDialog.showMessageDialog( parent, "Film existiert noch nicht!", "Fehler", JOptionPane.ERROR_MESSAGE); return; } try { if (!MVConfig.get(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN).isEmpty()) { String programm = MVConfig.get(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN); String[] cmd = {programm, sFile.getAbsolutePath()}; Runtime.getRuntime().exec(cmd); gut = true; } else { if (Desktop.isDesktopSupported()) { Desktop d = Desktop.getDesktop(); if (d.isSupported(Desktop.Action.OPEN)) { d.open(sFile); gut = true; } } } } catch (Exception ex) { try { gut = false; String programm = ""; String text = "\n Ein Videoplayer zum Abspielen wird nicht gefunden.\n Videoplayer selbst auswählen."; DialogProgrammOrdnerOeffnen dialog = new DialogProgrammOrdnerOeffnen(parent, true, "", "Videoplayer suchen", text); dialog.setVisible(true); if (dialog.ok) { programm = dialog.ziel; } String[] cmd = {programm, sFile.getAbsolutePath()}; Runtime.getRuntime().exec(cmd); MVConfig.add(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN, programm); Listener.notify(Listener.EREIGNIS_PROGRAMM_OEFFNEN, GuiDownloads.class.getSimpleName()); gut = true; } catch (Exception eex) { Log.errorLog(959632369, ex, "Ordner öffnen: " + datei); } } finally { if (!gut) { MVConfig.add(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN, ""); Listener.notify(Listener.EREIGNIS_PROGRAMM_OEFFNEN, GuiDownloads.class.getSimpleName()); MVMessageDialog.showMessageDialog( parent, "Kann den Videoplayer nicht öffnen!", "Fehler", JOptionPane.ERROR_MESSAGE); } } }
public static void openwebsite(String url) { try { Desktop dt = Desktop.getDesktop(); URI uri = new URI(url); dt.browse(uri.resolve(uri)); } catch (Exception e) { e.printStackTrace(); } }
private static void openWebpage(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(uri); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void actionPerformed(ActionEvent evt) { if (Desktop.isDesktopSupported()) { try { URI uri = new URI(evt.getActionCommand()); Desktop.getDesktop().browse(uri); } catch (Exception e) { } } }
public static void openUrl(final String url) throws IOException, URISyntaxException { if (java.awt.Desktop.isDesktopSupported()) { final java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { final java.net.URI uri = new java.net.URI(url); desktop.browse(uri); } } }
@Override public void HUDAreaClicked(HUDArea ha) { HUDArea hudArea = null; for (int i = 0; i < hudAreas.size(); i++) { hudArea = hudAreas.get(i); if (hudArea == ha) { if (hudArea.getType().equals("single_player")) { hudManager.unloadHUD(name); hudManager.loadHUD(HUDManager.HUDType.ScreenCharacterSelection); } else if (hudArea.getType().equals("multi_player")) { if (hudManager.getIsOnline() && Game.VERSION.equals(hudManager.getCurrentVersion())) { hudManager.unloadHUD(name); hudManager.loadHUD(HUDManager.HUDType.ScreenMultiPlayer); } else { registry.showMessage( "Error", "Must be online and have latest version to play. Try updating and restarting."); } } else if (hudArea.getType().equals("settings")) { hudManager.unloadHUD(name); hudManager.loadHUD(HUDManager.HUDType.ScreenSettings); } else if (hudArea.getType().equals("exit")) { hudManager.gameExit(); } else if (hudArea.getType().equals("donate")) { String url = "http://www.epicinventor.com/donate.html"; try { Desktop.getDesktop().browse(java.net.URI.create(url)); } catch (Exception e) { } } else if (hudArea.getType().equals("help")) { String url = "http://www.epicinventor.com/help.html"; try { Desktop.getDesktop().browse(java.net.URI.create(url)); } catch (Exception e) { } } else if (hudArea.getType().equals("download")) { Process p = null; try { p = Runtime.getRuntime().exec("EpicInventorUpdater"); } catch (IOException ex) { } if (p == null) { registry.showMessage( "Error", "Could not launch auto-updater, run manually from folder"); } else { hudManager.gameExit(); } } } } }
@Override public void actionPerformed(ActionEvent ae) { if (ae.getSource().equals(openItem)) { File f = null; if (null == (f = SpeedyGrader.getInstance().getFilesLoc())) { f = new File(System.getProperty("user.home")); } JFileChooser chooser = new JFileChooser(f); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int ret = chooser.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { newFolderSelected(chooser.getSelectedFile()); } } else if (ae.getSource().equals(inputItem)) { new InputDialog(); } else if (ae.getSource().equals(saveItem)) { for (EditorPanel ep : editorPanels) { ep.save(); } SpeedyGrader.getInstance().startComplieAndRun(); } else if (ae.getSource().equals(refreshItem)) { newFolderSelected(null); } else if (ae.getSource().equals(githubItem)) { String url = "https://github.com/MitchellSlavik/SpeedyGrader"; Desktop d = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (d != null && d.isSupported(Action.BROWSE)) { try { d.browse(URI.create(url)); } catch (IOException e) { e.printStackTrace(); } } else { JOptionPane.showMessageDialog( this, "We were unable to open a web browser. The url has been copied to your clipboard.", "Unable to preform operation", JOptionPane.ERROR_MESSAGE); StringSelection selection = new StringSelection(url); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); } } else if (ae.getSource().equals(aboutItem)) { new AboutDialog(); } else if (ae.getSource().equals(installItem)) { new InstallDialog(); } else if (ae.getSource().equals(upgradeItem)) { new AutoUpdater(); } else if (ae.getSource().equals(editorSplitToggle)) { splitEditorPane.setOrientation( editorSplitToggle.isSelected() ? JSplitPane.VERTICAL_SPLIT : JSplitPane.HORIZONTAL_SPLIT); this.validate(); this.repaint(); } }
public void imprimir(List<ComissaoRepresModel> itens) throws Exception { JasperReport report = JasperCompileManager.compileReport(this.getPathToReportPackage() + "ComisRep.jrxml"); JasperPrint print = JasperFillManager.fillReport(report, null, new JRBeanCollectionDataSource(itens)); JasperExportManager.exportReportToPdfFile( print, this.getPathToReportPackage() + "RelatorioComisRep.pdf"); Desktop desktop = Desktop.getDesktop(); desktop.open(new File(this.getPathToReportPackage() + "RelatorioComisRep.pdf")); }
@Override public void act(int button, boolean ctrl, boolean shft) { if (button == 1) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI(url)); } catch (Exception e) { ALS.alDebugPrint("Desktop exception..."); } } } }