List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java
/** * Saving Root CA certificate to disk./*from w ww .j a v a 2s. c o m*/ */ private void doSave() { if (txt_PubCert.getDocument().getLength() < MIN_CERT_LENGTH) { logger.error("Illegal state! There seems to be no certificate available."); bt_save.setEnabled(false); } final JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setSelectedFile(new File(OWASP_ZAP_ROOT_CA_FILENAME)); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { final File f = fc.getSelectedFile(); if (logger.isInfoEnabled()) { logger.info("Saving Root CA certificate to " + f); } try { writePubCertificateToFile(f); } catch (final Exception e) { logger.error("Error while writing certificate data to file " + f, e); } } }
From source file:org.zaproxy.zap.extension.history.PopupMenuExportURLs.java
private File getOutputFile() { JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory()); chooser.setFileFilter(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".htm")) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".html")) { return true; }//from w w w.j av a2 s .c om return false; } public String getDescription() { return Constant.messages.getString("file.format.textOrHtml"); } }); File file = null; int rc = chooser.showSaveDialog(extension.getView().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return file; } extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory()); String fileName = file.getAbsolutePath().toLowerCase(); if (!fileName.endsWith(".txt") && !fileName.endsWith(".htm") && !fileName.endsWith(".html")) { fileName += ".txt"; file = new File(fileName); } return file; } return file; }
From source file:paintbasico2d.VentanaPrincipal.java
private void jMenuItemGuardarImagenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemGuardarImagenActionPerformed VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); BufferedImage img = vi.getLienzo().getImage(); JFileChooser dlg = new JFileChooser(); dlg.setFileFilter(filterImgJPG);/*from w w w . j a va 2 s . c o m*/ dlg.setFileFilter(filterImgPNG); int resp = dlg.showSaveDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { try { File f = dlg.getSelectedFile(); File newFile = null; vi.getLienzo().volcarImg(img); newFile = new File(f.getAbsolutePath() + ".jpg"); ImageIO.write(img, "jpg", newFile); } catch (Exception ex) { System.err.println("Error al guardar la imagen."); } } }
From source file:paintbasico2d.VentanaPrincipal.java
private void jMenuItemGrabar_SonidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemGrabar_SonidoActionPerformed JFileChooser dlg = new JFileChooser(); dlg.setFileFilter(filter);/*from w ww . j a va 2 s . c om*/ int resp = dlg.showSaveDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { try { File f = dlg.getSelectedFile(); VentanaInternaGrabacion rec = new VentanaInternaGrabacion(f); this.escritorio.add(rec); rec.setTitle(f.getName()); rec.setVisible(true); } catch (Exception ex) { System.err.println("Error"); } } }
From source file:patientmanagerv1.HomeController.java
public void export() {//this is not unlike old age, and eventually death //"Save As" Dialog Box: JFrame parentFrame = new JFrame(); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(//from w w w. j a v a 2 s. c om "Save to/Save as/Save file as.../Where would you like to save this file?/ Where would you like to save this evaluation?"); int selectedPathAndName = fileChooser.showSaveDialog(parentFrame); String path = ""; if (selectedPathAndName == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); path = fileToSave.getAbsolutePath(); writeEvalToDocX(true, path); //A Basic Browse Box: try { /*JFileChooser chooser = new JFileChooser(); int value = chooser.showOpenDialog(null); if(value == JFileChooser.APPROVE_OPTION) { XWPFDocument docToAppend = new XWPFDocument(new FileInputStream(chooser.getSelectedFile())); XWPFWordExtractor extract = new XWPFWordExtractor(docToAppend); Primary.appendText(extract.getText()); } save(); Primary.selectAll(); Primary.clear(); reinitializePrimary();*/ } catch (Exception e) { } JOptionPane.showMessageDialog(null, "Export Successful!"); } else { } }
From source file:pcgen.gui2.dialog.ExportDialog.java
private void export(boolean pdf) { UIPropertyContext context = UIPropertyContext.createContext("ExportDialog"); final JFileChooser fcExport = new JFileChooser(); fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY); File baseDir = null;/*from w w w.j a va2s . co m*/ { String path; if (pdf) { path = context.getProperty(PDF_EXPORT_DIR_PROP); } else { path = context.getProperty(HTML_EXPORT_DIR_PROP); } if (path != null) { baseDir = new File(path); } } if (baseDir == null || !baseDir.isDirectory()) { baseDir = SystemUtils.getUserHome(); } fcExport.setCurrentDirectory(baseDir); URI uri = fileList.getSelectedValue(); String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf); if (pdf) { FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("xml".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else { String desc = extension + " Files (*." + extension + ")"; fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension)); } String name; File path; if (!partyBox.isSelected()) { CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem(); path = character.getFileRef().get(); if (path != null) { path = path.getParentFile(); } else { path = new File(PCGenSettings.getPcgDir()); } name = character.getTabNameRef().get(); if (StringUtils.isEmpty(name)) { name = character.getNameRef().get(); } } else { path = new File(PCGenSettings.getPcgDir()); name = "Entire Party"; } if (pdf) { fcExport.setSelectedFile(new File(path, name + ".pdf")); } else { fcExport.setSelectedFile(new File(path, name + "." + extension)); } fcExport.setDialogTitle("Export " + name); if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { return; } final File outFile = fcExport.getSelectedFile(); if (pdf) { context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent()); } else { context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent()); } if (StringUtils.isEmpty(outFile.getName())) { pcgenFrame.showErrorMessage("PCGen", "You must set a filename."); return; } if (outFile.isDirectory()) { pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file."); return; } if (outFile.exists() && !SettingsHandler.getAlwaysOverwrite()) { int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION); if (reallyClose != JOptionPane.YES_OPTION) { return; } } if (pdf) { new PDFExporter(outFile, extension, name).execute(); } else { if (!printToFile(outFile)) { String message = "The character export failed. Please see the log for details."; pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message); return; } maybeOpenFile(outFile); Globals.executePostExportCommandStandard(outFile.getAbsolutePath()); } }
From source file:pcgen.gui2.facade.SpellSupportFacadeImpl.java
@Override public void exportSpells() { final String template = PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH); if (StringUtils.isEmpty(template)) { delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); //$NON-NLS-1$ return;// w w w . jav a 2s . c om } String ext = template.substring(template.lastIndexOf('.')); // Get the name of the file to output to. JFileChooser fcExport = new JFileChooser(); fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir())); fcExport.setDialogTitle( LanguageBundle.getString("InfoSpells.export.spells.for") + charDisplay.getDisplayName()); //$NON-NLS-1$ if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) { return; } final String aFileName = fcExport.getSelectedFile().getAbsolutePath(); if (aFileName.length() < 1) { delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("InfoSpells.must.set.filename")); //$NON-NLS-1$ return; } try { final File outFile = new File(aFileName); if (outFile.isDirectory()) { delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("InfoSpells.can.not.overwrite.directory")); //$NON-NLS-1$ return; } if (outFile.exists()) { int reallyClose = JOptionPane.showConfirmDialog(null, LanguageBundle.getFormattedString("InfoSpells.confirm.overwrite", outFile.getName()), //$NON-NLS-1$ LanguageBundle.getFormattedString("InfoSpells.overwriting", //$NON-NLS-1$ outFile.getName()), JOptionPane.YES_NO_OPTION); if (reallyClose != JOptionPane.YES_OPTION) { return; } } // Output the file File templateFile = new File(template); boolean success; if (ExportUtilities.isPdfTemplate(templateFile)) { success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile); } else { success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile); } if (!success) { delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle .getFormattedString("InfoSpells.export.failed", charDisplay.getDisplayName())); //$NON-NLS-1$ } } catch (Exception ex) { Logging.errorPrint( LanguageBundle.getFormattedString("InfoSpells.export.failed", charDisplay.getDisplayName()), //$NON-NLS-1$ ex); delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle .getFormattedString("InfoSpells.export.failed.retry", charDisplay.getDisplayName())); //$NON-NLS-1$ } }
From source file:pdfreader.PDFReader.java
public void convertToStandardHtml() { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); // String typee = JOptionPane.showInputDialog("Type","3"); // int type = Integer.parseInt(typee); // String zooom = JOptionPane.showInputDialog("Zoom","2"); // int zoom = new Float(zooom); // System.out.println(type+"<---type and zoom--->"+zoom); try {//from w w w .ja va 2s . c om // HtmFile htmlFile = new HtmFile(outputFileName, type, zoom); // StandardHtml shtml = new StandardHtml(outputFileName, 3, 2); // shtml.convertPdfToHtml(name); // shtml.closeFile(); HtmlFile htmlFile; htmlFile = new HtmlFile(outputFileName, 3, 2); htmlFile.convertPdfToHtml(name); htmlFile.endTable();//used for spanning htmlFile.getAllCell();//used for spanning htmlFile.closeFile(); } catch (Exception e) { System.err.println("Filed to convert Pdf to Html."); e.printStackTrace(); } }
From source file:pdfreader.PDFReader.java
public void regionTextAllOnce(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); File saveFile1 = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); String outputFileName1;//from w ww. j av a2 s . c o m outputFileName1 = saveFile1.toString().substring(0, (saveFile1.toString().length() - 5)) + ".xml"; HtmlFileGen htmlFileGen = new HtmlFileGen(name, "C:\\blazeds\\tomcat\\webapps\\pictures\\", "localhost:8080/pictures/", getTheFileName(name), ""); TaggedRegion tr; BufferedWriter xmlFile = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outputFileName1), "UTF8")); xmlFile.write("<?xml version=\"1.0\"?><Pages>"); int tempPageNumber = -1; try (BufferedWriter htmlFile = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outputFileName), "UTF8"))) { for (int i = 0; i < listOfSelectedRegionInRectangle.size(); i++) { tr = listOfSelectedRegionInRectangle.get(i); if (tempPageNumber == -1) xmlFile.write("<Page No = \"" + tr.pageNumber + "\">"); else if (tempPageNumber != tr.pageNumber) xmlFile.write("</Page><Page No = \"" + tr.pageNumber + "\">"); // else // xmlFile.write("<Page No = \""+tr.pageNumber+"\">"); tempPageNumber = tr.pageNumber; String s = htmlFileGen.getHtmlContent(tr.pageNumber, tr.rectangle, tr.tag); if ("table".equals(tr.tag) || "list".equals(tr.tag)) { twoDRect = htmlFileGen.twoDRect; } htmlFile.write(s); xmlFile.write("<Region x = \"" + tr.rectangle.x + "\" y = \"" + tr.rectangle.y + "\" height = \"" + tr.rectangle.height + "\" width = \"" + tr.rectangle.width + "\" type = \"" + tr.tag + "\">"); xmlFile.write("<HtmlContent>" + StringEscapeUtils.escapeXml(s) + "</HtmlContent></Region>"); // System.out.println(s); } } xmlFile.write("</Page></Pages>"); xmlFile.close(); listOfSelectedRegionInRectangle = new ArrayList<>(); }
From source file:pdfreader.PDFReader.java
private void listExtract(java.awt.event.ActionEvent evt) { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); try {//w ww .j ava2 s. c o m ListExtraction list = new ListExtraction(outputFileName, 2, 2); PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition(true); stripper.addRegion("class1", rectangle); List allPages = document.getDocumentCatalog().getAllPages(); PDPage firstPage = (PDPage) allPages.get(currentPage); stripper.extractRegions(firstPage); System.out.println("Text in the area:" + rectangle); String region = stripper.getTextForRegion("class1"); System.out.println(region); List<TextPosition> TextinArea = stripper.getAllSelectedText(); for (Iterator<TextPosition> it = TextinArea.iterator(); it.hasNext();) { TextPosition text = it.next(); list.processTextt(text); } // list.endOfTable(); list.closeFile(); } catch (Exception e) { System.err.println("Filed to convert Pdf to Html."); } }