List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:com.openbravo.pos.util.JRViewer411.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();//from ww w . java2s.c o m for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter(saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter(saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle); } } lastSaveContributor = contributor; try { contributor.save(jasperPrint, file); } catch (JRException e) { if (log.isErrorEnabled()) { log.error("Save error.", e); } JOptionPane.showMessageDialog(this, getBundleString("error.saving")); } } }
From source file:musite.ui.MusiteResultPanel.java
private void exportComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportComboBoxActionPerformed String name = panelName.replaceAll("[\\\\/:\\*\\?\"<>\\|]+", "-"); String defaultFile = MusiteInit.defaultPath + File.separator + name; if (sliderTitleComboBox.getSelectedItem().equals(SPECIFICITY)) { defaultFile += String.format("-Sp_%.2f", specificity); } else {/*from ww w . j ava2 s. c o m*/ defaultFile += String.format("-Score_%.3f", threshold); } defaultFile += ".result"; switch (exportComboBox.getSelectedIndex()) { case 1: // tab-delimited text file { JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); fc.setSelectedFile(new File(defaultFile)); ArrayList<String> exts = new ArrayList<String>(1); String fasta = "txt"; exts.add(fasta); FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts, "Tab-delimited file (.txt)"); fc.addChoosableFileFilter(fastaFilter); //fc.setAcceptAllFileFilterUsed(true); fc.setDialogTitle("Save the the result to..."); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); MusiteInit.defaultPath = file.getParent(); String filePath = MusiteInit.defaultPath + File.separator + file.getName(); String ext = FilePathParser.getExt(filePath); if (ext == null || !ext.equalsIgnoreCase("txt")) { filePath += ".txt"; } if (IOUtil.fileExist(filePath)) { int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) break; } Vector<Vector> data = formatData(proteinList, false, true); int n = data.size(); ArrayList<String> dataOut = new ArrayList(n + 1); dataOut.add(StringUtils.join(header.iterator(), '\t')); for (Vector vec : data) { dataOut.add(StringUtils.join(vec.iterator(), '\t')); } try { IOUtil.writeCollectionAscii(dataOut, filePath); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error: failed to write the file."); break; } JOptionPane.showMessageDialog(this, "Successfully exported."); } break; } // case 2: // fasta // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String fasta = "fasta"; // exts.add(fasta); // FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts,"Fasta file (.fasta)"); // fc.addChoosableFileFilter(fastaFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("fasta")) { // filePath += ".fasta"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsWriter writer = new ModifiedProteinsFastaWriter(); // WriteTask writeTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(writeTask); // if (!writeTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } // case 3: // xml // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String xml = "xml"; // exts.add(xml); // FileExtensionsFilter xmlFilter = new FileExtensionsFilter(exts,"XML file (.xml)"); // fc.addChoosableFileFilter(xmlFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("xml")) { // filePath += ".xml"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsXMLWriter writer = ProteinsXMLWriter.createWriter(); // WriteTask xmlWriteTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(xmlWriteTask); // if (!xmlWriteTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } } exportComboBox.setSelectedIndex(0); }
From source file:neg.JRViewer.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();/*from w w w. j a v a 2s .co m*/ for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = (JRSaveContributor) saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle); } } lastSaveContributor = contributor; try { contributor.save(jasperPrint, file); } catch (JRException e) { if (log.isErrorEnabled()) log.error("Save error.", e); JOptionPane.showMessageDialog(this, getBundleString("error.saving")); } } }
From source file:org.fhaes.jsea.JSEAFrame.java
@Override public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("SegmentationMode")) { Boolean $success = this.validateDataFiles(); if ($success == null) { log.debug("Files not set yet"); return; } else if ($success == false) { log.debug("Invalid file ranges"); return; }/*from w ww . ja va 2 s. c om*/ if (segmentationPanel.chkSegmentation.isSelected() && chronologyYears.size() > 1) { segmentationPanel.table.setEarliestYear(Integer.parseInt(this.firstPossibleYear.toString())); segmentationPanel.table.setLatestYear(Integer.parseInt(this.lastPossibleYear.toString())); } else { // cannot perform segmentation if there are less than 2 years in the chronology segmentationPanel.chkSegmentation.setSelected(false); } } else if (event.getActionCommand().equals("AllYearsCheckbox")) { setYearRangeGUI(); } else if (event.getActionCommand().equals("TimeSeriesFileBrowse")) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER, App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null)); JFileChooser fc; if (lastVisitedFolder != null) { fc = new JFileChooser(lastVisitedFolder); } else { fc = new JFileChooser(); } fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Open file"); fc.addChoosableFileFilter(new TXTFileFilter()); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(new CSVFileFilter()); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { txtTimeSeriesFile.setText(fc.getSelectedFile().getAbsolutePath()); txtwrapper.updatePref(); App.prefs.setPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER, fc.getSelectedFile().getPath()); if (parseTimeSeriesFile()) { setYearRangeGUI(); } else { txtTimeSeriesFile.setText(""); } validateForm(); } } else if (event.getActionCommand().equals("EventListFileBrowse")) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER, App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null)); JFileChooser fc; if (lastVisitedFolder != null) { fc = new JFileChooser(lastVisitedFolder); } else { fc = new JFileChooser(); } fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Open file"); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { txtEventListFile.setText(fc.getSelectedFile().getAbsolutePath()); App.prefs.setPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER, fc.getSelectedFile().getPath()); parseEventListFile(); validateForm(); } } }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
@Override public void doExport(IExporter exporter) throws IOException { JFileChooser fileChooser = new JFileChooser(); String currentDirectory = System.getProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL); if (currentDirectory != null) { File savePath = new File(currentDirectory); if (savePath.exists() && savePath.isDirectory()) { fileChooser.setCurrentDirectory(savePath); }//from ww w. j av a2s .c om } String fileExtension = exporter.getExtensionName(); ExtensionFileFilter extensionFilter = new ExtensionFileFilter(exporter.toString(), "." + fileExtension); fileChooser.addChoosableFileFilter(extensionFilter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); // String selectedDescription = fileChooser.getFileFilter().getDescription(); if (!filename.toLowerCase().endsWith("." + fileExtension)) { filename = filename + "." + fileExtension; } File selectedFile = new File(filename); int confirm = JOptionPane.YES_OPTION; if (selectedFile.exists()) { confirm = JOptionPane.showConfirmDialog(this, selectedFile.getName() + " exists, overwrite?", "Confirm Overwriting", JOptionPane.YES_NO_OPTION); } else { selectedFile.createNewFile(); } if (confirm == JOptionPane.YES_OPTION) { exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getParent()); } } }
From source file:cn.pholance.datamanager.common.components.JRViewer.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();/*ww w. ja v a 2 s. c om*/ for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter(saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter(saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(this.jasperReportsContext, getLocale(), this.resourceBundle); } } lastSaveContributor = contributor; try { contributor.save(jasperPrint, file); } catch (JRException e) { if (log.isErrorEnabled()) { log.error("Save error.", e); } JOptionPane.showMessageDialog(this, getBundleString("error.saving")); } } }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildBasicPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); // BASIC: Top panel final JPanel logoPanel = new JPanel(); logoPanel.setLayout(new FlowLayout()); logoPanel.setBorder(/*from w w w . j av a 2s. co m*/ new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logoPanel.border"))); //$NON-NLS-1$ jlMTLogo.setIcon(icon); logoPanel.add(jlMTLogo); // BASIC: Middle panel final JPanel memPanel = new JPanel(); memPanel.setLayout(new GridLayout(3, 2)); memPanel.setBorder(new LineBorder(Color.WHITE)); jtfMaxMem.setHorizontalAlignment(SwingConstants.RIGHT); jtfMaxMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMaxMem", DEFAULT_MAXMEM)); //$NON-NLS-1$ jtfMaxMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMaxMem")); //$NON-NLS-1$ jtfMaxMem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfMaxMemActionPerformed(evt); } }); jtfMaxMem.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfMaxMemFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfMaxMemFocusLost(evt); } }); jtfMaxMem.addKeyListener(new InputValidator()); jtfMinMem.setHorizontalAlignment(SwingConstants.RIGHT); jtfMinMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMinMem", DEFAULT_MINMEM)); //$NON-NLS-1$ jtfMinMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMinMem")); //$NON-NLS-1$ jtfMinMem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfMinMemActionPerformed(evt); } }); jtfMinMem.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfMinMemFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfMinMemFocusLost(evt); } }); jtfMinMem.addKeyListener(new InputValidator()); jtfStackSize.setHorizontalAlignment(SwingConstants.RIGHT); jtfStackSize.setInfo(CopiedFromOtherJars.getText("msg.info.javaStackSize", DEFAULT_STACKSIZE)); //$NON-NLS-1$ jtfStackSize.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaStackSize")); //$NON-NLS-1$ jtfStackSize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfStackSizeActionPerformed(evt); } }); jtfStackSize.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfStackSizeFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfStackSizeFocusLost(evt); } }); jtfStackSize.addKeyListener(new InputValidator()); memPanel.add(jtfMaxMem); memPanel.add(jtfMinMem); memPanel.add(jtfStackSize); // BASIC: Bottom panel final JPanel southPanel = new JPanel(); southPanel.setLayout(new BorderLayout()); final JPanel cbPanel = new JPanel(); cbPanel.setLayout(new GridLayout(2, 1)); cbPanel.setBorder(new LineBorder(Color.GRAY)); jcbPromptUser.setSelected(true); jcbPromptUser.setText(CopiedFromOtherJars.getText("msg.info.promptAtNextLaunch")); //$NON-NLS-1$ jcbPromptUser.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.promptAtNextLaunch")); //$NON-NLS-1$ jcbPromptUser.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { promptUser = jcbPromptUser.isSelected(); } }); jbMTJar.setText(jbMTJarText); jbMTJar.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.registerMapToolJar")); //$NON-NLS-1$ jbMTJar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter( CopiedFromOtherJars.getText("msg.chooser.javaExecutable"), "jar"); //$NON-NLS-1$ //$NON-NLS-2$ jfc.addChoosableFileFilter(filter); jfc.setFileFilter(filter); if (IS_MAC) { filter = new FileNameExtensionFilter( CopiedFromOtherJars.getText("msg.chooser.appleApplicationBundle"), "app"); //$NON-NLS-1$ //$NON-NLS-2$ jfc.addChoosableFileFilter(filter); } jfc.setCurrentDirectory(mapToolJarDir); final int returnVal = jfc.showOpenDialog(jbMTJar); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = jfc.getSelectedFile(); final String fileName = f.getName(); if (IS_MAC && fileName.endsWith(".app")) { //$NON-NLS-1$ File jarDir = new File(f.getParentFile(), fileName); if (jarDir.isDirectory()) { jarDir = new File(jarDir, "Contents/Resources/Java"); //$NON-NLS-1$ if (jarDir.isDirectory()) { mapToolJarDir = jarDir; mapToolJarName = fileName.replace(".app", ".jar"); //$NON-NLS-1$ //$NON-NLS-2$ } else { logMsg(Level.SEVERE, "{0} does not contain 'Contents/Resources/Java' like it should!", //$NON-NLS-1$ "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$ return; } } else { logMsg(Level.SEVERE, "{0} is not a directory and it should be!", //$NON-NLS-1$ "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$ return; } } else { mapToolJarName = fileName; mapToolJarDir = f.getParentFile(); } logMsg(Level.INFO, f.toString(), null); jbMTJar.setText(fileName.replace(".jar", EMPTY)); //$NON-NLS-1$ if (fileName.toLowerCase().startsWith("maptool-")) { // We expect the name matches 'maptool-1.3.b89.jar' mapToolVersion = " " + fileName.substring(8, 11); } else { logMsg(Level.SEVERE, "Cannot determine MapTool version number from JAR filename: {0}", //$NON-NLS-1$ "msg.info.noMapToolVersion", fileName); mapToolVersion = EMPTY; } jbLaunch.setEnabled(true); updateCommand(); jbLaunch.requestFocusInWindow(); } } }); cbPanel.add(jcbPromptUser); cbPanel.add(jbMTJar); southPanel.add(cbPanel, BorderLayout.CENTER); p.add(memPanel, BorderLayout.CENTER); p.add(logoPanel, BorderLayout.NORTH); p.add(southPanel, BorderLayout.SOUTH); p.setBorder(new LineBorder(Color.BLACK)); return p; }
From source file:ded.ui.DiagramController.java
/** Prompt for a file name to load, then replace the current diagram with it. */ public void loadFromFile() { if (this.isDirty()) { int res = JOptionPane.showConfirmDialog(this, "There are unsaved changes. Load new diagram anyway?", "Load Confirmation", JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { return; }//from www . j a va2s . c o m } JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(this.currentFileChooserDirectory); chooser.addChoosableFileFilter( new FileNameExtensionFilter("Diagram and ER Editor Files (.ded, .png, .er)", "ded", "png", "er")); int res = chooser.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { this.currentFileChooserDirectory = chooser.getCurrentDirectory(); this.loadFromNamedFile(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:ded.ui.DiagramController.java
/** Prompt user for file name and save to it. */ public void chooseAndSaveToFile() { // Prompt for a file name, confirming if the file already exists. String result = this.fileName; while (true) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(this.currentFileChooserDirectory); chooser.addChoosableFileFilter(new FileNameExtensionFilter("Diagram Editor Files (.ded)", "ded")); int res = chooser.showSaveDialog(this); if (res != JFileChooser.APPROVE_OPTION) { return; }/*www . j a v a2s.c o m*/ this.currentFileChooserDirectory = chooser.getCurrentDirectory(); result = chooser.getSelectedFile().getAbsolutePath(); if (new File(result).exists()) { res = JOptionPane.showConfirmDialog(this, "A file called \"" + result + "\" already exists. Overwrite it?", "Confirm Overwrite", JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { continue; // Ask again. } } break; } // Save to the chosen file. this.saveToNamedFile(result); }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void doExport(IExporter exporter) throws IOException { boolean isMultipleSeries = getDataset().getSeriesCount() > 1; JFileChooser fileChooser = new JFileChooser(); String currentDirectory = System.getProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL); if (currentDirectory != null) { File savePath = new File(currentDirectory); if (savePath.exists() && savePath.isDirectory()) { fileChooser.setCurrentDirectory(savePath); }/* ww w .j a va2 s .co m*/ } String fileExtension = exporter.getExtensionName(); ExtensionFileFilter extensionFilter = new ExtensionFileFilter(exporter.toString(), "." + fileExtension); fileChooser.addChoosableFileFilter(extensionFilter); if (isMultipleSeries) { fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); int confirm = JOptionPane.YES_OPTION; File selectedFile; if (isMultipleSeries) { selectedFile = new File(filename); if (!selectedFile.exists()) { selectedFile.mkdirs(); } exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getAbsolutePath()); } else { if (!filename.toLowerCase().endsWith("." + fileExtension)) { filename = filename + "." + fileExtension; } selectedFile = new File(filename); if (selectedFile.exists()) { confirm = JOptionPane.showConfirmDialog(this, selectedFile.getName() + " exists, overwrite?", "Confirm Overwriting", JOptionPane.YES_NO_OPTION); } else { selectedFile.createNewFile(); } if (confirm == JOptionPane.YES_OPTION) { exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getParent()); } } } }