List of usage examples for javax.swing.filechooser FileFilter getDescription
public abstract String getDescription();
From source file:com.googlecode.bpmn_simulator.gui.dialogs.ImageExportChooser.java
public String getSelectedImageFormat() { final FileFilter fileFilter = getFileFilter(); if (fileFilter != null) { return fileFilter.getDescription(); }//from www . j a va 2s. c o m return null; }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
private void fireCreateMapShotEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireCreateMapShotEvent Component parent = this; putOnline = false;/*from w w w. j a v a2 s . c om*/ String dir = GlobalOptions.getProperty("screen.dir"); if (dir == null) { dir = "."; } String type = null; chooser.setSelectedFile(new File(dir)); int ret = chooser.showSaveDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) { try { File f = chooser.getSelectedFile(); javax.swing.filechooser.FileFilter filter = chooser.getFileFilter(); if (filter.getDescription().indexOf("jpeg") > 0) { type = "jpeg"; } else if (filter.getDescription().indexOf("png") > 0) { type = "png"; } else { type = "png"; } String file = f.getCanonicalPath(); if (!file.endsWith(type)) { file += "." + type; } File target = new File(file); if (target.exists()) { //ask if overwrite if (JOptionPaneHelper.showQuestionConfirmBox(parent, "Existierende Datei berschreiben?", "berschreiben", "Nein", "Ja") != JOptionPane.YES_OPTION) { return; } } MapPanel.getSingleton().planMapShot(type, target, this); GlobalOptions.addProperty("screen.dir", target.getPath()); } catch (Exception e) { logger.error("Failed to write map shot", e); } } }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
public void planMapshot() { Component parent = this; putOnline = false;/* w w w . ja va 2 s .c o m*/ String dir = GlobalOptions.getProperty("screen.dir"); if (dir == null) { dir = "."; } String type = null; chooser.setSelectedFile(new File(dir)); int ret = chooser.showSaveDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) { try { File f = chooser.getSelectedFile(); javax.swing.filechooser.FileFilter filter = chooser.getFileFilter(); if (filter.getDescription().indexOf("jpeg") > 0) { type = "jpeg"; } else if (filter.getDescription().indexOf("png") > 0) { type = "png"; } else { type = "png"; } String file = f.getCanonicalPath(); if (!file.endsWith(type)) { file += "." + type; } File target = new File(file); if (target.exists()) { //ask if overwrite if (JOptionPaneHelper.showQuestionConfirmBox(parent, "Existierende Datei berschreiben?", "berschreiben", "Nein", "Ja") != JOptionPane.YES_OPTION) { return; } } MapPanel.getSingleton().planMapShot(type, target, this); GlobalOptions.addProperty("screen.dir", target.getPath()); } catch (Exception e) { logger.error("Failed to write map shot", e); } } }
From source file:app.RunApp.java
/** * Action of Save table button in MVML tab * /*from www .j a va2 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 av a2 s . com * * @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 ww . ja v a 2 s . c om*/ * * @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 * /*from w w w .j a va 2 s . c om*/ * @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 * /*from w ww .j a va 2 s .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:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java
/** * Initializes the components composing the display. * /*from w w w.j a v a2s . c o m*/ * @param filters The filters to handle. * @param importerAction The cancel-all-imports action. */ private void initComponents(FileFilter[] filters, ImporterAction importerAction) { canvas = new QuotaCanvas(); sizeImportLabel = new JLabel(); diskSpacePane = new JPanel(); diskSpacePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); diskSpacePane.add(UIUtilities.setTextFont(TEXT_FREE_SPACE)); diskSpacePane.add(canvas); showThumbnails = new JCheckBox(TEXT_SHOW_THUMBNAILS); showThumbnails.setVisible(false); Registry registry = ImporterAgent.getRegistry(); Boolean loadThumbnails = (Boolean) registry.lookup(LOAD_THUMBNAIL); if (loadThumbnails != null) { if (loadThumbnails.booleanValue()) { showThumbnails.setVisible(true); showThumbnails.setSelected(loadThumbnails.booleanValue()); } } if (!isFastConnection()) // slow connection showThumbnails.setSelected(false); long groupId = -1; if (model.getSelectedGroup() != null) groupId = model.getSelectedGroup().getGroupId(); if (groupId < 0) groupId = ImporterAgent.getUserDetails().getGroupId(); locationDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, true); locationDialog.addPropertyChangeListener(this); int plugin = ImporterAgent.runAsPlugin(); if (plugin == LookupNames.IMAGE_J_IMPORT || plugin == LookupNames.IMAGE_J) { detachedDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, false); detachedDialog.addPropertyChangeListener(this); } tagSelectionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src instanceof JButton) { TagAnnotationData tag = tagsMap.get(src); if (tag != null) { tagsMap.remove(src); handleTagsSelection(tagsMap.values()); } } } }; tabbedPane = new JTabbedPane(); numberOfFolders = new NumericalTextField(); numberOfFolders.setMinimum(0); numberOfFolders.setText("0"); numberOfFolders.setColumns(3); numberOfFolders.addPropertyChangeListener(this); tagsMap = new LinkedHashMap<JButton, TagAnnotationData>(); IconManager icons = IconManager.getInstance(); refreshFilesButton = new JButton(TEXT_REFRESH_FILES); refreshFilesButton.setBackground(UIUtilities.BACKGROUND); refreshFilesButton.setToolTipText(TOOLTIP_REFRESH_FILES); refreshFilesButton.setActionCommand("" + CMD_REFRESH_FILES); refreshFilesButton.addActionListener(this); tagButton = new JButton(icons.getIcon(IconManager.PLUS_12)); UIUtilities.unifiedButtonLookAndFeel(tagButton); tagButton.addActionListener(this); tagButton.setActionCommand("" + CMD_TAG); tagButton.setToolTipText(TOOLTIP_ADD_TAGS); tagsPane = new JPanel(); tagsPane.setLayout(new BoxLayout(tagsPane, BoxLayout.Y_AXIS)); overrideName = new JCheckBox(TEXT_OVERRIDE_FILE_NAMING); overrideName.setToolTipText(UIUtilities.formatToolTipText(WARNING)); overrideName.setSelected(true); ButtonGroup group = new ButtonGroup(); fullName = new JRadioButton(TEXT_NAMING_FULL_PATH); group.add(fullName); partialName = new JRadioButton(); partialName.setText(TEXT_NAMING_PARTIAL_PATH); partialName.setSelected(true); group.add(partialName); table = new FileSelectionTable(this); table.addPropertyChangeListener(this); chooser = new GenericFileChooser(); JList list = (JList) UIUtilities.findComponent(chooser, JList.class); KeyAdapter ka = new KeyAdapter() { /** * Adds the files to the import queue. * * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { handleEnterKeyPressed(e.getSource()); } } }; if (list != null) list.addKeyListener(ka); if (list == null) { JTable t = (JTable) UIUtilities.findComponent(chooser, JTable.class); if (t != null) t.addKeyListener(ka); } try { File f = UIUtilities.getDefaultFolder(); if (f != null) chooser.setCurrentDirectory(f); } catch (Exception e) { // Ignore: could not set the default container } chooser.addPropertyChangeListener(this); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setControlButtonsAreShown(false); chooser.setApproveButtonText(TEXT_IMPORT); chooser.setApproveButtonToolTipText(TOOLTIP_IMPORT); bioFormatsFileFilters = new ArrayList<FileFilter>(); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); for (FileFilter fileFilter : filters) { if (fileFilter instanceof ComboFileFilter) { bioFormatsFileFiltersCombined = fileFilter; ComboFileFilter comboFilter = (ComboFileFilter) fileFilter; FileFilter[] extensionFilters = comboFilter.getFilters(); for (FileFilter combinedFilter : extensionFilters) { bioFormatsFileFilters.add(combinedFilter); } break; } } chooser.addChoosableFileFilter(bioFormatsFileFiltersCombined); for (FileFilter fileFilter : bioFormatsFileFilters) { chooser.addChoosableFileFilter(fileFilter); } chooser.setFileFilter(bioFormatsFileFiltersCombined); } else { chooser.setAcceptAllFileFilterUsed(true); } closeButton = new JButton(TEXT_CLOSE); closeButton.setToolTipText(TOOLTIP_CLOSE); closeButton.setActionCommand("" + CMD_CLOSE); closeButton.addActionListener(this); cancelImportButton = new JButton(importerAction); importerAction.setEnabled(false); importButton = new JButton(TEXT_IMPORT); importButton.setToolTipText(TOOLTIP_IMPORT); importButton.setActionCommand("" + CMD_IMPORT); importButton.addActionListener(this); importButton.setEnabled(false); pixelsSize = new ArrayList<NumericalTextField>(); NumericalTextField field; for (int i = 0; i < 3; i++) { field = new NumericalTextField(); field.setNumberType(Double.class); field.setColumns(2); pixelsSize.add(field); } List<Component> boxes = UIUtilities.findComponents(chooser, JComboBox.class); if (boxes != null) { JComboBox box; JComboBox filterBox = null; Iterator<Component> i = boxes.iterator(); while (i.hasNext()) { box = (JComboBox) i.next(); Object o = box.getItemAt(0); if (o instanceof FileFilter) { filterBox = box; break; } } if (filterBox != null) { filterBox.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { String value = KeyEvent.getKeyText(e.getKeyCode()); JComboBox box = (JComboBox) e.getSource(); int n = box.getItemCount(); FileFilter filter; FileFilter selectedFilter = null; String d; for (int j = 0; j < n; j++) { filter = (FileFilter) box.getItemAt(j); d = filter.getDescription(); if (d.startsWith(value)) { selectedFilter = filter; break; } } if (selectedFilter != null) box.setSelectedItem(selectedFilter); } }); } } }
From source file:org.openmicroscopy.shoola.util.ui.filechooser.CustomizedFileChooser.java
/** * Returns the format corresponding to the specified filter. * //from ww w. j av a2s . c om * @param selectedFilter The filter specified. * @return See above. */ private String getFormat(FileFilter selectedFilter) { List<FileFilter> filters = model.getFilters(); if (filters == null) return ""; for (FileFilter filter : filters) { if (selectedFilter.equals(filter)) return filter.getDescription(); } return ""; }