List of usage examples for javax.swing JFileChooser removeChoosableFileFilter
public boolean removeChoosableFileFilter(FileFilter f)
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser fc = new JFileChooser(); int ff = fc.getChoosableFileFilters().length; FileFilter[] fft = fc.getChoosableFileFilters(); for (int i = 0; i < ff; i++) { fc.removeChoosableFileFilter(fft[i]); }// w w w.j a va 2 s . co m fc.addChoosableFileFilter(new DocumentFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setDialogTitle(prosa); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR); int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument")); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); uploadFiles(files, unit, viewComponentId, documentId); Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory(); } this.setCursor(Cursor.getDefaultCursor()); }
From source file:app.RunApp.java
/** * Save heatmap graph as image//from ww w. j av a 2 s . c o m * * @throws AWTException * @throws IOException */ private void saveHeatmapGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture( new Rectangle(panelHeatmap.getLocationOnScreen().x + 31, panelHeatmap.getLocationOnScreen().y + 31, panelHeatmap.getWidth() - 61, panelHeatmap.getHeight() - 61)); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Save co-ocurrence graph as image/* ww w. j a va 2 s . c o m*/ * * @throws AWTException * @throws IOException */ private void saveCoocurrenceGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture(new Rectangle( panelCoOcurrenceRight.getLocationOnScreen().x, panelCoOcurrenceRight.getLocationOnScreen().y, panelCoOcurrenceRight.getWidth(), panelCoOcurrenceRight.getHeight())); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Action of Save table button in MVML tab * //w w w . ja 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 w w. j a v a2 s . c o m*/ * * @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 w w w . j a v a 2 s. co 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:app.RunApp.java
/** * Action for Save button from multiple datasets tab * //w w w . j a v a 2s . c o 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(); } }
From source file:app.RunApp.java
/** * Action for Save button from principal tab * /*w w w . jav a 2s . c om*/ * @param evt Event * @param jtable Table * @throws IOException */ private void buttonSaveActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) throws IOException { ArrayList<String> metricsList = getMetricsSelectedPrincipal(jtable); if (dataset == null) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); // extension txt 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.saveMetricsTxt(wr, metricsList, dataset, tableMetrics); 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.saveMetricsTex(wr, metricsList, tableMetrics); 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.saveMetricsCsv(wr, metricsList, dataset, tableMetrics); 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.saveMetricsArff(wr, metricsList, dataset, tableMetrics); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; default: break; } Toolkit.getDefaultToolkit().beep(); } }
From source file:xmv.solutions.commons.ExcelFile.java
/** * Open a filechooser that finds ExcelFiles * * @param startPath starting with path startPath * @return FilePath// ww w . ja va 2 s.c om */ public static ExcelFile openFileChooser(String startPath) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(startPath)); // Remove all FileFilters FileFilter[] filters = fc.getChoosableFileFilters(); for (int i = 0; i < filters.length; i++) { fc.removeChoosableFileFilter(filters[i]); } fc.addChoosableFileFilter(new ExcelFileFilter()); // In response to a button click: int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getAbsolutePath(); return new ExcelFile(path); } return null; }