List of usage examples for javax.swing JFileChooser getFileFilter
public FileFilter getFileFilter()
From source file:neg.JRViewerFactura.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 .c o m*/ String archivo = "Pepe.txt"; File f = new File(archivo); fileChooser.setSelectedFile(f); 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) { javax.swing.filechooser.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:neg.JRViewerFactura.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt, String nombre) { // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();//from www . j a v a 2 s. c o m String archivo = nombre; File f = new File(archivo); fileChooser.setSelectedFile(f); 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); fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { javax.swing.filechooser.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:com.att.aro.diagnostics.GraphPanel.java
/** * Implements the saving of the graph snapshot. *//*from w ww. j ava 2s. co m*/ private void saveAs() throws IOException { // Determine save directory File saveDir = traceData.getTraceDir(); if (graphPanelSaveDirectory != null) { saveDir = new File(graphPanelSaveDirectory); } JFileChooser fc = new JFileChooser(saveDir); // Set up file types String[] fileTypesJPG = new String[2]; String fileDisplayTypeJPG = rb.getString("fileChooser.contentDisplayType.jpeg"); fileTypesJPG[0] = rb.getString("fileChooser.contentType.jpeg"); fileTypesJPG[1] = rb.getString("fileChooser.contentType.jpg"); FileFilter filterJPG = new ExtensionFileFilter(fileDisplayTypeJPG, fileTypesJPG); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); String[] fileTypesPng = new String[1]; String fileDisplayTypePng = rb.getString("fileChooser.contentDisplayType.png"); fileTypesPng[0] = rb.getString("fileChooser.contentType.png"); FileFilter filterPng = new ExtensionFileFilter(fileDisplayTypePng, fileTypesPng); fc.addChoosableFileFilter(filterPng); fc.setFileFilter(filterJPG); File plotImageFile = null; boolean bSavedOrCancelled = false; while (!bSavedOrCancelled) { if (fc.showSaveDialog(this.getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) { String strFile = fc.getSelectedFile().toString(); String strFileLowerCase = strFile.toLowerCase(); String fileDesc = fc.getFileFilter().getDescription(); String fileType = rb.getString("fileChooser.contentType.jpg"); if ((fileDesc.equalsIgnoreCase(rb.getString("fileChooser.contentDisplayType.png")) || strFileLowerCase .endsWith(rb.getString("fileType.filters.dot") + fileTypesPng[0].toLowerCase()))) { fileType = fileTypesPng[0]; } if (strFile.length() > 0) { // Save current directory graphPanelSaveDirectory = fc.getCurrentDirectory().getPath(); if ((fileType != null) && (fileType.length() > 0)) { String fileTypeLowerCaseWithDot = rb.getString("fileType.filters.dot") + fileType.toLowerCase(); if (!strFileLowerCase.endsWith(fileTypeLowerCaseWithDot)) { strFile += rb.getString("fileType.filters.dot") + fileType; } } plotImageFile = new File(strFile); boolean bAttemptToWriteToFile = true; if (plotImageFile.exists()) { if (MessageDialogFactory.showConfirmDialog(this, MessageFormat.format(rb.getString("fileChooser.fileExists"), plotImageFile.getAbsolutePath()), rb.getString("fileChooser.confirm"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { bAttemptToWriteToFile = false; } } if (bAttemptToWriteToFile) { try { if (fileType.equalsIgnoreCase(fileTypesPng[0])) { BufferedImage bufImage = createImage(pane); ImageIO.write(bufImage, "png", plotImageFile); } else { BufferedImage bufImage = createImage(pane); ImageIO.write(bufImage, "jpg", plotImageFile); } bSavedOrCancelled = true; } catch (IOException e) { MessageDialogFactory.showMessageDialog(this, rb.getString("fileChooser.errorWritingToFile" + plotImageFile.toString())); } } } } else { bSavedOrCancelled = true; } } }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Initialize the menu/toolbar actions.// w ww .j a va2 s . co m */ private void initActions() { final JFrame glue = this; actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { dispose(); } }; actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { ChartEditor editor = ChartEditorManager .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); } } }; actionReset = new FHAESAction("Reset", "filenew.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { Object[] options = { "Yes", "No", "Cancel" }; int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setToDefault(); } } }; actionRun = new FHAESAction("Run analysis", "run.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { runAnalysis(); } }; actionSaveAll = new FHAESAction("Save all results", "save_all.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } File f; try { f = new File(file.getAbsolutePath() + File.separator + "report.txt"); saveReportTXT(f); f = new File(file.getAbsolutePath() + File.separator + "report.pdf"); saveReportPDF(f); f = new File(file.getAbsolutePath() + File.separator + "chart.png"); saveChartPNG(f); f = new File(file.getAbsolutePath() + File.separator + "chart.pdf"); saveChartPDF(f); f = new File(file.getAbsolutePath() + File.separator + "data.xls"); saveDataXLS(f); f = new File(file.getAbsolutePath()); saveDataCSV(f); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveData = new FHAESAction("Save data tables", "table.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } try { saveDataCSV(file); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveReport = new FHAESAction("Save report", "report.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); TXTFileFilter txtfilter = new TXTFileFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(txtfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(txtfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(txtfilter)) { file = new File(file.getAbsoluteFile() + ".txt"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt") && chosenFilter.equals("pdf")) { chosenFilter = txtfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("txt")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(txtfilter)) { saveReportTXT(file); } else if (chosenFilter.equals(pdffilter)) { saveReportPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save report. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionSaveChart = new FHAESAction("Save chart", "barchart.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); PNGFilter pngfilter = new PNGFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(pngfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(pngfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(pngfilter)) { file = new File(file.getAbsoluteFile() + ".png"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png") && chosenFilter.equals("pdf")) { chosenFilter = pngfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("png")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(pngfilter)) { saveChartPNG(file); } else if (chosenFilter.equals(pdffilter)) { saveChartPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save chart. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionCopy = new FHAESAction("Copy", "edit_copy.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { copyCurrentSelectionToClipboard(); } }; actionLagMap = new FHAESAction("LagMap", "lagmap22.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { launchLagMap(); } }; }
From source file:app.RunApp.java
/** * Action of Save table button in MVML tab * /*from ww w.j a v a 2 s .c o m*/ * @param evt Event */ private void buttonSaveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveTableActionPerformed if (jTable2.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); if (f1.getDescription().equals(".csv")) { try { String path = file.getAbsolutePath() + ".csv"; BufferedWriter bw = new BufferedWriter(new FileWriter(path)); PrintWriter wr = new PrintWriter(bw); ResultsIOUtils.saveMVTableCsv(wr, jTable2, views, dataset); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Action for Export button/* w ww . j av a 2 s . c om*/ * * @param evt Event * @param jtable Table */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable) { if (jtable.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); if (f1.getDescription().equals(".csv")) { try { String path = file.getAbsolutePath() + ".csv"; BufferedWriter bw = new BufferedWriter(new FileWriter(path)); PrintWriter wr = new PrintWriter(bw); switch (comboBoxLabelsInformation.getSelectedIndex()) { case 1: ResultsIOUtils.saveTableLabelsetsFrequencyCsv(wr, jtable, labelsetStringsByFreq); break; case 6: ResultsIOUtils.saveTableLabelsetsIRCsv(wr, jtable, labelsetStringByIR); break; default: ResultsIOUtils.saveTableCsv(wr, jtable); break; } wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Action for Export button/*from www . ja v a2 s. c o m*/ * * @param evt Event * @param jtable Table * @param columns Columns * @param table Table type */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable, JTable columns, String table) { if (jtable.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); //Saving csv chi_phi if (f1.getDescription().equals(".csv")) { BufferedWriter bw; PrintWriter wr; try { String path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); switch (table) { case "ChiPhi": ResultsIOUtils.saveChiPhiTableCsv(wr, chiPhiCoefficients, dataset.getLabelNames()); break; case "Coocurrence": ResultsIOUtils.saveCoocurrenceTableCsv(wr, coocurrenceCoefficients, dataset.getLabelNames()); break; case "Heatmap": ResultsIOUtils.saveHeatmapTableCsv(wr, heatmapCoefficients, dataset.getLabelNames()); break; default: JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); break; } wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file.// ww w . ja v a2 s. co m */ private void openOntologyFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("ONTOLOGY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenRdfFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenRdfFileFilterDescription != null && latestChosenRdfFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open Assertions File"); fileChooser.showOpenDialog(this); try { latestChosenRdfFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { setupToLoadOntologyFile(new FileSource(chosenFile)); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file./*from ww w . j a v a 2s. com*/ */ private void openSparqlQueryFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("SPARQL")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenSparqlFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenSparqlFileFilterDescription != null && latestChosenSparqlFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open SPARQL Query File"); fileChooser.showOpenDialog(this); try { latestChosenSparqlFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which SPARQL file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { loadSparqlQueryFile(chosenFile); } }
From source file:app.RunApp.java
/** * Action for Save button from multiple datasets tab * // www . jav a2 s . co m * @param evt Event * @param jtable Table * @throws IOException */ private void buttonSaveActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) throws IOException { ArrayList<String> metricsList = getSelectedMetricsMulti(jtable); if (listDatasets == null || listDatasets.isEmpty() || datasetNames.isEmpty()) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE); return; } //JFileChooser save JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname = new FileNameExtensionFilter(".txt", "txt"); FileNameExtensionFilter fname2 = new FileNameExtensionFilter(".csv", "csv"); FileNameExtensionFilter fname3 = new FileNameExtensionFilter(".arff", ".arff"); FileNameExtensionFilter fname4 = new FileNameExtensionFilter(".tex", ".tex"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.addChoosableFileFilter(fname); fc.addChoosableFileFilter(fname2); fc.addChoosableFileFilter(fname3); fc.addChoosableFileFilter(fname4); fc.setFileFilter(fname); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); String path; BufferedWriter bw; PrintWriter wr; switch (f1.getDescription()) { case ".txt": path = file.getAbsolutePath() + ".txt"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsTxt(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".tex": path = file.getAbsolutePath() + ".tex"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsTex(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".csv": path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsCsv(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".arff": path = file.getAbsolutePath() + ".arff"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsArff(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; default: break; } Toolkit.getDefaultToolkit().beep(); } }