List of usage examples for javax.swing JFileChooser setAcceptAllFileFilterUsed
@BeanProperty(preferred = true, description = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.") public void setAcceptAllFileFilterUsed(boolean b)
AcceptAll FileFilter
is used as an available choice in the choosable filter list. From source file:org.yccheok.jstock.gui.NewBrokingFirmJDialog.java
private void letUserSelectAnImage() { JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new MyFilter()); int returnVal = fc.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return;/* w w w. j a v a2s .c o m*/ } File file = fc.getSelectedFile(); if (fileNameEndWithImageExtension(file.getName())) { loadImage(file); } }
From source file:org.yccheok.jstock.gui.Utils.java
public static FileEx promptSavePortfolioCSVAndExcelJFileChooser(final String suggestedFileName) { final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final JFileChooser chooser = new JFileChooser(jStockOptions.getLastFileIODirectory()); final FileNameExtensionFilter csvFilter = new FileNameExtensionFilter("CSV Documents (*.csv)", "csv"); final FileNameExtensionFilter xlsFilter = new FileNameExtensionFilter("Microsoft Excel (*.xls)", "xls"); chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(csvFilter); chooser.addChoosableFileFilter(xlsFilter); final org.yccheok.jstock.gui.file.PortfolioSelectionJPanel portfolioSelectionJPanel = new org.yccheok.jstock.gui.file.PortfolioSelectionJPanel(); chooser.setAccessory(portfolioSelectionJPanel); chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() { @Override//from w w w . j a va 2 s .c o m public void propertyChange(PropertyChangeEvent evt) { final boolean flag = ((FileNameExtensionFilter) evt.getNewValue()).equals(csvFilter); portfolioSelectionJPanel.setEnabled(flag); chooser.setSelectedFile(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription()) ? new File(portfolioSelectionJPanel.getSuggestedFileName()) : new File(suggestedFileName)); } }); portfolioSelectionJPanel.addJRadioButtonsActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chooser.setSelectedFile(new File(portfolioSelectionJPanel.getSuggestedFileName())); } }); final java.util.Map<String, FileNameExtensionFilter> map = new HashMap<String, FileNameExtensionFilter>(); map.put(csvFilter.getDescription(), csvFilter); map.put(xlsFilter.getDescription(), xlsFilter); final FileNameExtensionFilter filter = map.get(jStockOptions.getLastSavedFileNameExtensionDescription()); if (filter != null) { chooser.setFileFilter(filter); } // Only enable portfolioSelectionJPanel, if CSV is being selected. portfolioSelectionJPanel .setEnabled(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription())); chooser.setSelectedFile(chooser.getFileFilter().getDescription().equals(csvFilter.getDescription()) ? new File(portfolioSelectionJPanel.getSuggestedFileName()) : new File(suggestedFileName)); while (true) { final int returnVal = chooser.showSaveDialog(JStock.instance()); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } File file = chooser.getSelectedFile(); if (file == null) { return null; } // Ensure the saved file is in correct extension. If user provide correct // file extension explicitly, leave it as is. If not, mutate the filename. final String extension = Utils.getFileExtension(file); if (extension.equals("csv") == false && extension.equals("xls") == false) { if (chooser.getFileFilter().getDescription().equals(csvFilter.getDescription())) { file = new File(file.getAbsolutePath() + ".csv"); } else if (chooser.getFileFilter().getDescription().equals(xlsFilter.getDescription())) { file = new File(file.getAbsolutePath() + ".xls"); } else { // Impossible. return null; } } if (file.exists()) { final String output = MessageFormat .format(MessagesBundle.getString("question_message_replace_old_template"), file.getName()); final int result = javax.swing.JOptionPane.showConfirmDialog(JStock.instance(), output, MessagesBundle.getString("question_title_replace_old"), javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE); if (result != javax.swing.JOptionPane.YES_OPTION) { continue; } } final String parent = chooser.getSelectedFile().getParent(); if (parent != null) { jStockOptions.setLastFileIODirectory(parent); } if (Utils.getFileExtension(file).equals("csv")) { jStockOptions.setLastFileNameExtensionDescription(csvFilter.getDescription()); } else if (Utils.getFileExtension(file).equals("xls")) { jStockOptions.setLastFileNameExtensionDescription(xlsFilter.getDescription()); } else { // Impossible. return null; } return new FileEx(file, portfolioSelectionJPanel.getType()); } }
From source file:org.yccheok.jstock.gui.Utils.java
private static File promptOpenJFileChooser(FileNameExtensionFilter... fileNameExtensionFilters) { final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final JFileChooser chooser = new JFileChooser(jStockOptions.getLastFileIODirectory()); chooser.setAcceptAllFileFilterUsed(false); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { chooser.addChoosableFileFilter(fileNameExtensionFilter); }/*from w w w . j av a2 s . c om*/ final java.util.Map<String, FileNameExtensionFilter> map = new HashMap<String, FileNameExtensionFilter>(); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { map.put(fileNameExtensionFilter.getDescription(), fileNameExtensionFilter); } final FileNameExtensionFilter filter = map.get(jStockOptions.getLastSavedFileNameExtensionDescription()); if (filter != null) { chooser.setFileFilter(filter); } int returnVal = chooser.showOpenDialog(JStock.instance()); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } File file = chooser.getSelectedFile(); if (file == null || !file.exists()) { return null; } final String parent = chooser.getSelectedFile().getParent(); if (parent != null) { jStockOptions.setLastFileIODirectory(parent); } final String extension = Utils.getFileExtension(file); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { final String[] extensions = fileNameExtensionFilter.getExtensions(); if (extensions.length <= 0) { continue; } if (extension.equals(extensions[0])) { jStockOptions.setLastFileNameExtensionDescription(fileNameExtensionFilter.getDescription()); return file; } } return null; }
From source file:org.yccheok.jstock.gui.Utils.java
private static File promptSaveJFileChooser(String suggestedFileName, FileNameExtensionFilter... fileNameExtensionFilters) { final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final JFileChooser chooser = new JFileChooser(jStockOptions.getLastFileIODirectory()); chooser.setAcceptAllFileFilterUsed(false); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { chooser.addChoosableFileFilter(fileNameExtensionFilter); }//from ww w .j a v a 2 s .c o m chooser.setSelectedFile(new File(suggestedFileName)); final java.util.Map<String, FileNameExtensionFilter> map = new HashMap<String, FileNameExtensionFilter>(); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { map.put(fileNameExtensionFilter.getDescription(), fileNameExtensionFilter); } final FileNameExtensionFilter filter = map.get(jStockOptions.getLastSavedFileNameExtensionDescription()); if (filter != null) { chooser.setFileFilter(filter); } while (true) { final int returnVal = chooser.showSaveDialog(JStock.instance()); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } File file = chooser.getSelectedFile(); if (file == null) { return null; } // Ensure the saved file is in correct extension. If user provide correct // file extension explicitly, leave it as is. If not, mutate the filename. final String extension = Utils.getFileExtension(file); boolean found = false; root: for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { String[] extensions = fileNameExtensionFilter.getExtensions(); for (String e : extensions) { if (e.equals(extension)) { found = true; break root; } } } if (!found) { for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { String[] extensions = fileNameExtensionFilter.getExtensions(); if (extensions.length <= 0) { continue; } final String e = extensions[0]; if (chooser.getFileFilter().getDescription().equals(fileNameExtensionFilter.getDescription())) { if (e.startsWith(".")) { file = new File(file.getAbsolutePath() + e); } else { file = new File(file.getAbsolutePath() + "." + e); } break; } } } if (file.exists()) { final String output = MessageFormat .format(MessagesBundle.getString("question_message_replace_old_template"), file.getName()); final int result = javax.swing.JOptionPane.showConfirmDialog(JStock.instance(), output, MessagesBundle.getString("question_title_replace_old"), javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE); if (result != javax.swing.JOptionPane.YES_OPTION) { continue; } } final String parent = chooser.getSelectedFile().getParent(); if (parent != null) { jStockOptions.setLastFileIODirectory(parent); } final String e = Utils.getFileExtension(file); for (FileNameExtensionFilter fileNameExtensionFilter : fileNameExtensionFilters) { String[] extensions = fileNameExtensionFilter.getExtensions(); if (extensions.length <= 0) { continue; } if (e.equals(extensions[0])) { jStockOptions.setLastFileNameExtensionDescription(fileNameExtensionFilter.getDescription()); break; } } return file; } }
From source file:os.Controller.java
public void browse() { FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf", "PDF"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(filter);// www . j av a 2s . c o m fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setMultiSelectionEnabled(true); fileChooser.showOpenDialog(null); File[] files = fileChooser.getSelectedFiles(); try { // if (checkSelection(files) == true) { // singleThread(files); multiThread(files); } catch (Exception ex) { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex); } selectedTxt.append("You've selected " + files.length + " PDF file(s).\n"); // } else { // JOptionPane.showMessageDialog(fileChooser, "Please select PDF file(s) only"); // } }
From source file:osu.beatmapdownloader.JFrame.java
private void B_DirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_DirectoryActionPerformed JFileChooser chooser; chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("Open Osu! Installation Directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File route = chooser.getSelectedFile(); if (route.toString().endsWith("Songs")) { Directory = route.getAbsolutePath(); T_Directory.setText(Directory); } else { if (route.isDirectory()) { String[] Files = route.list(); boolean found = false; for (String f : Files) if (f.contains("Songs")) { Directory = route + File.separator + f; T_Directory.setText(Directory); set("SongDirectory", Directory); found = true; break; }//from w w w.ja va2s . c om if (found == false) Alert("Incorrect Osu! Directory"); } } } }
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 ww.ja va 2 s .co 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 jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump"); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(xmlfilter); int returnValue = fileChooser.showOpenDialog(this); String data = null;/* w w w .j a v a2s . com*/ if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try { data = FileHandler.getFile(Paths.get(selectedFile.getAbsolutePath())); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Nie udao si otworzy pliku.", "Wystpi bd", JOptionPane.ERROR_MESSAGE); } server.messages.clear(selectedFile.getName()); String[] lines = data.split("[\\r?\\n]+"); for (String line : lines) { String[] parts = line.split("-"); if (parts.length < 8) { break; } Message message = new Message(parts[0], parts[1], parts[2], parts[3], parts[5], parts[4], parts[6], parts[7]); server.messages.add(selectedFile.getName(), message); } if (((DefaultComboBoxModel) selectSystem.getModel()).getIndexOf(selectedFile.getName()) == -1) { selectSystem.addItem(selectedFile.getName()); selectSystem.setSelectedItem(selectedFile.getName()); } else { selectSystem.setSelectedItem(selectedFile.getName()); } updateUml(server.messages.toUml(selectedFile.getName(), startMsg.getText(), stopMsg.getText())); } }
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"); }//w w w . jav a2 s. c o m 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:pt.lsts.neptus.mra.exporters.MRAExporterFilter.java
private File chooseSaveFile(String path) { JFileChooser fileChooser = GuiUtils.getFileChooser(path, I18n.text("LSF logs"), FileUtil.FILE_TYPE_LSF, FileUtil.FILE_TYPE_LSF_COMPRESSED, FileUtil.FILE_TYPE_LSF_COMPRESSED_BZIP2); fileChooser.setSelectedFile(new File(path.concat("/Data_filtered.lsf.gz"))); fileChooser.setAcceptAllFileFilterUsed(false); int status = fileChooser.showSaveDialog(ConfigFetch.getSuperParentFrame()); String fileName = null;/*from ww w . java 2 s.c o m*/ if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try { fileName = selectedFile.getCanonicalPath(); if (fileName.endsWith("." + FileUtil.FILE_TYPE_LSF_COMPRESSED) || fileName.endsWith("." + FileUtil.FILE_TYPE_LSF_COMPRESSED_BZIP2)) { return selectedFile = new File(fileName); } if (!fileName.endsWith("." + FileUtil.FILE_TYPE_LSF)) { return selectedFile = new File(fileName + "." + FileUtil.FILE_TYPE_LSF_COMPRESSED); } if (fileName.endsWith("." + FileUtil.FILE_TYPE_LSF)) { return selectedFile = new File(fileName); } } catch (IOException e) { e.printStackTrace(); } } return null; }