Java Code Examples for javax.swing.JFileChooser#removeChoosableFileFilter()
The following examples show how to use
javax.swing.JFileChooser#removeChoosableFileFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportSnapshotAction.java From netbeans with Apache License 2.0 | 6 votes |
private static JFileChooser createFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption()); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText()); fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.addChoosableFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT); } public String getDescription() { return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT); } }); return fileChooser; }
Example 2
Source File: OpenHeapWalkerAction.java From netbeans with Apache License 2.0 | 6 votes |
private static File getHeapDumpFile() { JFileChooser chooser = new JFileChooser(); if (importDir != null) { chooser.setCurrentDirectory(importDir); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.addChoosableFileFilter(new FileFilterImpl()); chooser.setDialogTitle( Bundle.OpenHeapWalkerAction_DialogCaption() ); if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) { importDir = chooser.getCurrentDirectory(); return chooser.getSelectedFile(); } return null; }
Example 3
Source File: MercurialOptionsPanelController.java From netbeans with Apache License 2.0 | 6 votes |
private void onExportFilenameBrowseClick() { File oldFile = getExecutableFile(); JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_ExportBrowseFolder"), oldFile); // NOI18N fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "ExportBrowse_title")); // NOI18N fileChooser.setMultiSelectionEnabled(false); FileFilter[] old = fileChooser.getChoosableFileFilters(); for (int i = 0; i < old.length; i++) { FileFilter fileFilter = old[i]; fileChooser.removeChoosableFileFilter(fileFilter); } fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button")); // NOI18N File f = fileChooser.getSelectedFile(); if (f != null) { panel.exportFilenameTextField.setText(f.getAbsolutePath()); } }
Example 4
Source File: ExportSnapshotAction.java From visualvm with GNU General Public License v2.0 | 6 votes |
private static JFileChooser createFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption()); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText()); fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.addChoosableFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase(Locale.ENGLISH).endsWith(NPSS_EXT); } public String getDescription() { return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT); } }); return fileChooser; }
Example 5
Source File: OpenHeapWalkerAction.java From visualvm with GNU General Public License v2.0 | 6 votes |
private static File getHeapDumpFile() { JFileChooser chooser = new JFileChooser(); if (importDir != null) { chooser.setCurrentDirectory(importDir); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.addChoosableFileFilter(new FileFilterImpl()); chooser.setDialogTitle( Bundle.OpenHeapWalkerAction_DialogCaption() ); if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) { importDir = chooser.getCurrentDirectory(); return chooser.getSelectedFile(); } return null; }
Example 6
Source File: MPrinter.java From javamelody with Apache License 2.0 | 5 votes |
/** * Choix du fichier pour un export. * * @return File * @param table * JTable * @param extension * String * @throws IOException * Erreur disque */ protected File chooseFile(final JTable table, final String extension) throws IOException { final JFileChooser myFileChooser = getFileChooser(); final MExtensionFileFilter filter = new MExtensionFileFilter(extension); myFileChooser.addChoosableFileFilter(filter); String title = buildTitle(table); if (title != null) { // on remplace par des espaces les caractères interdits dans les noms de fichiers : \ / : * ? " < > | final String notAllowed = "\\/:*?\"<>|"; final int notAllowedLength = notAllowed.length(); for (int i = 0; i < notAllowedLength; i++) { title = title.replace(notAllowed.charAt(i), ' '); } myFileChooser.setSelectedFile(new File(title)); } // l'extension sera ajoutée ci-dessous au nom du fichier try { final Component parent = table.getParent() != null ? table.getParent() : table; if (myFileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) { String fileName = myFileChooser.getSelectedFile().getCanonicalPath(); if (!fileName.endsWith('.' + extension)) { fileName += '.' + extension; // NOPMD } return new File(fileName); } return null; } finally { myFileChooser.removeChoosableFileFilter(filter); } }
Example 7
Source File: SvnProperties.java From netbeans with Apache License 2.0 | 4 votes |
public void loadFromFile() { final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(SvnProperties.class, "ACSD_Properties")); chooser.setDialogTitle(NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title")); chooser.setMultiSelectionEnabled(false); javax.swing.filechooser.FileFilter[] fileFilters = chooser.getChoosableFileFilters(); for (int i = 0; i < fileFilters.length; i++) { javax.swing.filechooser.FileFilter fileFilter = fileFilters[i]; chooser.removeChoosableFileFilter(fileFilter); } chooser.setCurrentDirectory(roots[0].getParentFile()); // NOI18N chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File f) { return f.exists(); } @Override public String getDescription() { return ""; } }); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setApproveButtonMnemonic(NbBundle.getMessage(SvnProperties.class, "MNE_LoadValue").charAt(0)); chooser.setApproveButtonText(NbBundle.getMessage(SvnProperties.class, "CTL_LoadValue")); DialogDescriptor dd = new DialogDescriptor(chooser, NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title")); dd.setOptions(new Object[0]); final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); chooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String state = e.getActionCommand(); if (state.equals(JFileChooser.APPROVE_SELECTION)) { File source = chooser.getSelectedFile(); if (Utils.isFileContentText(source)) { if (source.canRead()) { StringWriter sw = new StringWriter(); try { Utils.copyStreamsCloseAll(sw, new FileReader(source)); panel.txtAreaValue.setText(sw.toString()); } catch (IOException ex) { Subversion.LOG.log(Level.SEVERE, null, ex); } } } else { handleBinaryFile(source); } } dialog.dispose(); } }); dialog.setVisible(true); }
Example 8
Source File: ExportDiffSupport.java From netbeans with Apache License 2.0 | 4 votes |
private JFileChooser createFileChooser(File curentDir) { final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(ExportDiffSupport.class, "ACSD_Export")); chooser.setDialogTitle(NbBundle.getMessage(ExportDiffSupport.class, "CTL_Export_Title")); chooser.setMultiSelectionEnabled(false); javax.swing.filechooser.FileFilter[] old = chooser.getChoosableFileFilters(); for (int i = 0; i < old.length; i++) { javax.swing.filechooser.FileFilter fileFilter = old[i]; chooser.removeChoosableFileFilter(fileFilter); } chooser.setCurrentDirectory(curentDir); // NOI18N chooser.addChoosableFileFilter(getFileFilter()); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonMnemonic(NbBundle.getMessage(ExportDiffSupport.class, "MNE_Export_ExportAction").charAt(0)); chooser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String state = e.getActionCommand(); if (state.equals(JFileChooser.APPROVE_SELECTION)) { File destination = chooser.getSelectedFile(); destination = getTargetFile(destination); if (destination.exists()) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ExportDiffSupport.class, "BK3005", destination.getAbsolutePath())); nd.setOptionType(NotifyDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(nd); if (nd.getValue().equals(NotifyDescriptor.OK_OPTION) == false) { return; } } preferences.put("ExportDiff.saveFolder", destination.getParent()); // NOI18N panel.setOutputFileText(destination.getAbsolutePath()); } else { dd.setValue(null); } if(dialog != null) { dialog.dispose(); } } }); return chooser; }
Example 9
Source File: VideoIO.java From osp with GNU General Public License v3.0 | 4 votes |
/** * Displays a file chooser and returns the chosen files. * * @param type may be "open", "open video", "save", "insert image" * @return the files, or null if no files chosen */ public static File[] getChooserFiles(String type) { JFileChooser chooser = getChooser(); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(true); int result = JFileChooser.CANCEL_OPTION; if(type.toLowerCase().equals("open")) { // open any file //$NON-NLS-1$ chooser.addChoosableFileFilter(videoFileFilter); chooser.setFileFilter(chooser.getAcceptAllFileFilter()); result = chooser.showOpenDialog(null); } else if(type.toLowerCase().equals("open video")) { // open video //$NON-NLS-1$ chooser.addChoosableFileFilter(videoFileFilter); result = chooser.showOpenDialog(null); } else if(type.toLowerCase().equals("save")) { // save any file //$NON-NLS-1$ // note this sets no file filters but does include acceptAll // also sets file name to "untitled" String filename = MediaRes.getString("VideoIO.FileName.Untitled"); //$NON-NLS-1$ chooser.setSelectedFile(new File(filename+"."+defaultXMLExt)); //$NON-NLS-1$ result = chooser.showSaveDialog(null); } else if(type.toLowerCase().equals("insert image")) { //$NON-NLS-1$ chooser.setMultiSelectionEnabled(true); chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(imageFileFilter); chooser.setSelectedFile(new File("")); //$NON-NLS-1$ result = chooser.showOpenDialog(null); File[] files = chooser.getSelectedFiles(); chooser.removeChoosableFileFilter(imageFileFilter); chooser.setSelectedFile(new File("")); //$NON-NLS-1$ if(result==JFileChooser.APPROVE_OPTION) { return files; } } if(result==JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); chooser.removeChoosableFileFilter(videoFileFilter); chooser.setSelectedFile(new File("")); //$NON-NLS-1$ return new File[] {file}; } return null; }