List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:pdfreader.PDFReader.java
private void converttoTable(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("G:/From Fuad sir DOCX to PDF"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); int[] regioon = null; ExtractTextByArea ETB = new ExtractTextByArea(); try {/* www .ja v a 2s .c o m*/ regioon = ETB.extractTextByArea(name, rectangle, currentPage, 0); } catch (IOException | CryptographyException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } int positionOfRowStart[] = ETB.getPointOfRowStart(); int numberofRows = ETB.returnNumberofRows(); int numberofColumns = ETB.returnNumberofColumns(); ExtractTextByColumn ETBC = new ExtractTextByColumn(); Rectangle[] ColumnWiseRect = new Rectangle[(numberofColumns - 1) * numberofRows]; int q = 0; for (int row = 0; row <= numberofRows - 1; row++) { for (int column = 0; column < numberofColumns - 1; column++) { if (column == 0 && row == 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, rectangle.y, (regioon[column + 1] * 5 - rectangle.x) - 2, positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(rectangle.x,rectangle.y,(regioon[column+1]*5-rectangle.x)-2,positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (row == 0 && column > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, rectangle.y, (regioon[column + 1] * 5 - regioon[column] * 5), positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(regioon[column]*5-2,rectangle.y,(regioon[column+1]*5-regioon[column]*5),positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column == 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - rectangle.x), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(rectangle.x,positionOfRowStart[row-1]+2,(regioon[column+1]*5-rectangle.x),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column > 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - regioon[column] * 5), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(regioon[column]*5-2,positionOfRowStart[row-1]+2,(regioon[column+1]*5-regioon[column]*5),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } q++; } } // pdfPagePanel.pdfpagepanelrec = ColumnWiseRect; // try { // ETBC.getTable(numberofRows,numberofColumns,saveFile,true); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } }
From source file:pdfreader.PDFReader.java
private void converttoList(java.awt.event.ActionEvent evt) throws IOException, CryptographyException { JFileChooser jfc = new JFileChooser("G:/From Fuad sir DOCX to PDF"); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); int[] regioon = null; ExtractTextByArea ETB = new ExtractTextByArea(); try {//from w w w . j a v a2 s.c om regioon = ETB.extractTextByArea(name, rectangle, currentPage, 0); } catch (IOException | CryptographyException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } int positionOfRowStart[] = ETB.getPointOfRowStart(); int numberofRows = ETB.returnNumberofRows(); int numberofColumns = ETB.returnNumberofColumns(); ExtractTextByColumn ETBC = new ExtractTextByColumn(); Rectangle[] ColumnWiseRect = new Rectangle[(numberofColumns - 1) * numberofRows]; int q = 0; for (int row = 0; row <= numberofRows - 1; row++) { for (int column = 0; column < numberofColumns - 1; column++) { if (column == 0 && row == 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, rectangle.y, (regioon[column + 1] * 5 - rectangle.x) - 2, positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(rectangle.x,rectangle.y,(regioon[column+1]*5-rectangle.x)-2,positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (row == 0 && column > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, rectangle.y, (regioon[column + 1] * 5 - regioon[column] * 5), positionOfRowStart[row] - rectangle.y); // pdfPagePanel.drawrect(regioon[column]*5-2,rectangle.y,(regioon[column+1]*5-regioon[column]*5),positionOfRowStart[row]-rectangle.y); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column == 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(rectangle.x, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - rectangle.x), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(rectangle.x,positionOfRowStart[row-1]+2,(regioon[column+1]*5-rectangle.x),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } else if (column > 0 && row > 0) { ColumnWiseRect[q] = new Rectangle(regioon[column] * 5 - 2, positionOfRowStart[row - 1], (regioon[column + 1] * 5 - regioon[column] * 5), (positionOfRowStart[row] - positionOfRowStart[row - 1])); // pdfPagePanel.drawrect(regioon[column]*5-2,positionOfRowStart[row-1]+2,(regioon[column+1]*5-regioon[column]*5),(positionOfRowStart[row]-positionOfRowStart[row-1])); // System.out.println("Cell["+row+"]["+column+"]:--"+ColumnWiseRect[q].x+","+ColumnWiseRect[q].y+","+ColumnWiseRect[q].width+","+ColumnWiseRect[q].height); // try { // ETBC.ExtractTextByArea(name,ColumnWiseRect[q],currentPage,row,column); // } catch (IOException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } catch (CryptographyException ex) { // Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); // } } q++; } } //pdfPagePanel.pdfpagepanelrec = ColumnWiseRect; try { ETBC.getList(numberofRows, numberofColumns, saveFile); } catch (IOException ex) { Logger.getLogger(PageWrapper.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:picocash.Picocash.java
@Action(enabledProperty = "accountsAvailable") public void exportAll() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new BackupFileFilter()); int retValue = fileChooser.showSaveDialog(getMainFrame()); if (retValue == JFileChooser.APPROVE_OPTION) { String fileName = fileChooser.getSelectedFile().getAbsolutePath(); if (!fileName.endsWith(".mbck")) { fileName = fileName + ".mbck"; }//from ww w. j av a 2 s .c om List<Account> allAccounts = Services.getSelectedPersistenceMan().getAllAccounts(); List<Payee> allPayees = Services.getSelectedPersistenceMan().getAllPayees(); List<Category> allCategories = Services.getSelectedPersistenceMan().getAllCategories(); List<Transaction> allTransactions = Services.getSelectedPersistenceMan().getAllTransactions(); ModelExporter exporter = new ModelExporter(fileName); exporter.setAccounts(allAccounts); exporter.setCategories(allCategories); exporter.setPayees(allPayees); exporter.setTransactions(allTransactions); try { exporter.export(); } catch (Exception ex) { log.info("exception occured while exporting:", ex); } } }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Zapisz plik jako..."); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss"); fileChooser.setSelectedFile(new File(df.format(new Date()))); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("umldump")) { fileToSave = new File(fileToSave.getParentFile(), FilenameUtils.getBaseName(fileToSave.getName()) + ".umldump"); }/*from w w w .j a v a 2 s. c o m*/ try { FileHandler.saveFile(Paths.get(fileToSave.getAbsolutePath()), server.messages.toString(selectSystem.getSelectedItem().toString())); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si zapisa pliku.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } } }
From source file:pl.edu.pw.appt.GUI.java
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Zapisz obraz jako..."); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki BMP (*.bmp)", "bmp"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss"); fileChooser.setSelectedFile(new File(df.format(new Date()))); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("bmp")) { fileToSave = new File(fileToSave.getParentFile(), FilenameUtils.getBaseName(fileToSave.getName()) + ".bmp"); }/* ww w . ja va2 s . c om*/ try { ImageIO.write((RenderedImage) image, "bmp", fileToSave); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si zapisa obrazu.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } } }
From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java
protected void saveParser() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(AllPluginables.USER_LOG_IMPORTERS); chooser.addChoosableFileFilter(new FileFilter() { @Override/*from w ww.ja v a 2 s . c om*/ public String getDescription() { return "*.pattern files"; } @Override public boolean accept(File f) { return f.getName().endsWith(".pattern") || f.isDirectory(); } }); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getAbsolutePath() + ".pattern"); } if (selectedFile.exists() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "Do you want to overwrite file " + selectedFile.getName() + "?", "Save parser", JOptionPane.YES_NO_OPTION)) { return; } String text = propertyEditor.getText(); FileOutputStream output = null; try { output = new FileOutputStream(selectedFile); IOUtils.write(text, output); LogImporterUsingParser log4jImporter = createLog4jImporter(text); otrosApplication.getAllPluginables().getLogImportersContainer().addElement(log4jImporter); } catch (Exception e) { LOGGER.severe("Can't save parser: " + e.getMessage()); JOptionPane.showMessageDialog(this, "Can't save parser: " + e.getMessage(), "Error saving parser", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } finally { IOUtils.closeQuietly(output); } } }
From source file:plugin.notes.gui.NotesView.java
/** * Exports a node out to a gmn file./*from w ww. ja va 2s.co m*/ * *@param node node to export to file */ private void exportFile(NotesTreeNode node) { JFileChooser fLoad = new JFileChooser(); String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, ""); new File(sFile); FileFilter ff = getFileType(); fLoad.addChoosableFileFilter(ff); fLoad.setFileFilter(ff); int returnVal = fLoad.showSaveDialog(this); try { if (returnVal == JFileChooser.APPROVE_OPTION) { String fileName = fLoad.getSelectedFile().getName(); String dirName = fLoad.getSelectedFile().getParent(); String extension = EXTENSION; if (fileName.indexOf(extension) < 0) { fileName += extension; } File expFile = new File(dirName + File.separator + fileName); if (expFile.exists()) { int choice = JOptionPane.showConfirmDialog(this, "File Exists, Overwrite?", "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, expFile.toString()); writeNotesFile(expFile, node); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error Writing File"); Logging.errorPrint("Error Writing to file: " + e.getMessage(), e); } }
From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java
/** * Save the configuration presets. From Micro-Manager. *//*from w w w . jav a2s. com*/ protected void saveConfig() { MicroscopeModel model = new MicroscopeModel(); try { model.loadFromFile(_sysConfigFile); model.createSetupConfigsFromHardware(mCore); model.createResolutionsFromHardware(mCore); JFileChooser fc = new JFileChooser(); boolean saveFile = true; File f; do { fc.setSelectedFile(new File(model.getFileName())); int retVal = fc.showSaveDialog(null); if (retVal == 0) { f = fc.getSelectedFile(); if (f.exists()) { int sel = JOptionPane.showConfirmDialog(null, "Overwrite " + f.getName(), "File Save", 0); if (sel == 0) saveFile = true; else saveFile = false; } } else { return; } } while (!saveFile); model.saveToFile(f.getAbsolutePath()); _sysConfigFile = f.getAbsolutePath(); _configChanged_ = false; setConfigSaveButtonStatus(_configChanged_); } catch (MMConfigFileException e) { ReportingUtils.showError(e); } }
From source file:psidev.psi.mi.filemakers.xmlFlattener.XmlFlattenerGui.java
public void save() { try {/* w ww . j ava2 s . co m*/ JFileChooser fc = new JFileChooser("."); int returnVal = fc.showSaveDialog(new JFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); // Create XML encoder. JAXBContext jaxbContext = JAXBContext.newInstance(TreeMapping.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.marshal(((XsdTreeStructImpl) treePanel.xsdTree).getMapping(), fos); fos.close(); } catch (FileNotFoundException fe) { JOptionPane.showMessageDialog(new JFrame(), "Unable to write file", "[PSI makers: PSI maker] save mapping", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { log.error("problem", ex); } }
From source file:psidev.psi.mi.filemakers.xmlMaker.XmlMakerGui.java
public void save() { try {/*from w w w. ja v a 2s .com*/ JFileChooser fc; if (Utils.lastVisitedMappingDirectory != null) { fc = new JFileChooser(Utils.lastVisitedMappingDirectory); } else fc = new JFileChooser("."); int returnVal = fc.showSaveDialog(new JFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); // Create XML encoder. XMLEncoder xenc = new XMLEncoder(fos); Mapping mapping = new Mapping(); mapping.setTree(((XsdTreeStructImpl) treePanel.xsdTree).getMapping()); /* dictionaries */ for (int i = 0; i < treePanel.dictionaryPanel.dictionaries.getDictionaries().size(); i++) { // DictionaryMapping dm = ((Dictionary) xsdTree.dictionaries // .getDictionaries().get(i)).getMapping(); mapping.dictionaries.add(((Dictionary) xsdTree.dictionaries.getDictionaries().get(i)).getMapping()); } /* flat files */ for (int i = 0; i < xsdTree.flatFiles.flatFiles.size(); i++) { // FlatFileMapping fm = (xsdTree.flatFiles.getFlatFile(i)) // .getMapping(); mapping.flatFiles.add((xsdTree.flatFiles.getFlatFile(i)).getMapping()); } xenc.writeObject(mapping); xenc.close(); fos.close(); } catch (FileNotFoundException fe) { JOptionPane.showMessageDialog(new JFrame(), "Unable to write file", "[PSI makers: PSI maker] save mapping", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { System.out.println("pb: " + ex); StackTraceElement[] s = ex.getStackTrace(); for (int i = 0; i < s.length; i++) { System.out.println(s[i]); } } }