Java Code Examples for javax.swing.JFileChooser.setFileSelectionMode()

The following are Jave code examples for showing how to use setFileSelectionMode() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: grade-buddy   File: Toolbar.java   Source Code and License Vote up 6 votes
/**
 * Export the report.
 */
private void export() {
    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (JFileChooser.APPROVE_OPTION == fc.showOpenDialog(this)) {
        final File file = new File(fc.getSelectedFile(), "report.csv");
        try {
            Files.write(
                Paths.get(file.getAbsolutePath()),
                new CsvReport(this.marking.submissions())
                    .report(true)
                    .getBytes()
            );
        } catch (IOException e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(
                this, e1.getMessage(), "Export error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: BuildContextVisual.java   Source Code and License Vote up 6 votes
private void buildContextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildContextButtonActionPerformed
    FileChooserBuilder builder = FileChooserBuilder.create(fileSystem);
    JFileChooser fileChooser = builder.createFileChooser();
    fileChooser.setApproveButtonText(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.button")); // NOI18M
    fileChooser.setDialogTitle(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.dialogTitle")); // NOI18M
    fileChooser.setFileSelectionMode(0);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    String buildText = UiUtils.getValue(buildContextTextField);
    if (buildText != null) {
        fileChooser.setSelectedFile(new File(buildText));

    }
    if (fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        buildContextTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 3
Project: incubator-netbeans   File: BasicProjectInfoPanel.java   Source Code and License Vote up 6 votes
private void browseAntScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseAntScriptActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    if (antScript.getText().length() > 0 && getAntScript().exists()) {
        chooser.setSelectedFile(getAntScript());
    } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
        chooser.setSelectedFile(getProjectLocation());
    } else {
        chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
    }
    chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Build_Script"));  //NOI18N
    if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File script = FileUtil.normalizeFile(chooser.getSelectedFile());
        antScript.setText(script.getAbsolutePath());
    }            
}
 
Example 4
Project: incubator-netbeans   File: RunJarPanel.java   Source Code and License Vote up 6 votes
private void btnWorkDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWorkDirActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    
    String workDir = txtWorkDir.getText();
    if (workDir.equals("")) { //NOI18N
        workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
    }
    chooser.setSelectedFile(new File(workDir));
    chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(RunJarPanel.class, "TIT_SelectWorkingDirectory"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        txtWorkDir.setText(file.getAbsolutePath());
    }
}
 
Example 5
Project: nb-clojure   File: ClojureTemplatePanelVisual.java   Source Code and License Vote up 6 votes
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
        chooser.setDialogTitle("Select Project Location");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists()) {
                chooser.setSelectedFile(f);
            }
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
        }
        panel.fireChangeEvent();
    }

}
 
Example 6
Project: zooracle   File: FileUtils.java   Source Code and License Vote up 6 votes
public static String selectDirectory(Component component, String choosertitle)
{
	JFileChooser chooser = new JFileChooser(); 
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    
    if (chooser.showOpenDialog(component) == JFileChooser.APPROVE_OPTION) { 
      System.out.println("getCurrentDirectory(): "  +  chooser.getCurrentDirectory());
      System.out.println("getSelectedFile() : "  +  chooser.getSelectedFile());
      return chooser.getSelectedFile().toString();
      }
    else {
      System.out.println("No Selection ");
      return null;
      }
    
}
 
Example 7
Project: incubator-netbeans   File: JFXIconsPanel.java   Source Code and License Vote up 6 votes
private void splashButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_splashButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new IconFileFilter(false));
    String current = splashTextField.getText();
    File lastFolder = current!=null ? getFileFromPath(current) : null;
    if (lastFolder != null) {
        chooser.setSelectedFile(lastFolder);
    } else if (lastImageFolder != null) {
        chooser.setSelectedFile(lastImageFolder);
    } else { // ???
        // workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
        // chooser.setSelectedFile(new File(workDir));
    }
    chooser.setDialogTitle(NbBundle.getMessage(JFXIconsPanel.class, "LBL_Select_Icon_Image")); // NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        String relPath = JFXProjectUtils.getRelativePath(project.getProjectDirectory(), FileUtil.toFileObject(file));
        splashTextField.setText(relPath);
        lastImageFolder = file;
    }
}
 
Example 8
Project: geomapapp   File: ImportImage.java   Source Code and License Vote up 6 votes
void open() throws IOException {
	JFileChooser chooser = haxby.map.MapApp.getFileChooser();
	int mode = chooser.getFileSelectionMode();
	boolean multi = chooser.isMultiSelectionEnabled();
	chooser.setMultiSelectionEnabled( true );
	chooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
	chooser.addChoosableFileFilter(imageFileFilter);
	
	int ok = chooser.showOpenDialog(frame);
	File[] choice = null;
	if( ok!=chooser.CANCEL_OPTION ) choice = chooser.getSelectedFiles();
	chooser.setMultiSelectionEnabled(multi);
	chooser.setFileSelectionMode( mode );
	chooser.removeChoosableFileFilter(imageFileFilter);

	if( ok==chooser.CANCEL_OPTION ) {
		return;
	}
	
	if (mapType == MapApp.MERCATOR_MAP)
		openImagesMercator(choice);
	else
		openImagesPolar(choice);
}
 
Example 9
Project: incubator-netbeans   File: InstallPanel.java   Source Code and License Vote up 5 votes
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
// TODO add your handling code here:
        JFileChooser chooser = new JFileChooser(lastFolder);
        chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select_Artifact"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar"));//NOI18N
            }
            @Override
            public String getDescription() {
                return org.openide.util.NbBundle.getMessage(InstallPanel.class, "SEL_Jars");
            }
        });
        chooser.setMultiSelectionEnabled(false);
        if (txtFile.getText().trim().length() > 0) {
            File fil = new File(txtFile.getText().trim());
            if (fil.exists()) {
                chooser.setSelectedFile(fil);
            }
        }
        int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select"));
        if (ret == JFileChooser.APPROVE_OPTION) {
            txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
            txtFile.requestFocusInWindow();
        }

    }
 
Example 10
Project: OrthancAnonymization   File: CSV.java   Source Code and License Vote up 5 votes
private void fileChooser(){
	JFileChooser chooser = new JFileChooser();
	chooser.setCurrentDirectory(new java.io.File(jpreferAnon.get("csvLocation", System.getProperty("user.dir"))));
	chooser.setDialogTitle("Export csv to...");
	chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	chooser.setAcceptAllFileFilterUsed(false);
	if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
		this.path = chooser.getSelectedFile().toPath();
		jpreferAnon.put("csvLocation", this.path.toString());
		this.choix[0] = true;
	} else {
		this.choix[0] = false;
	}
}
 
Example 11
Project: DBan-Config-Generator   File: InputFrame.java   Source Code and License Vote up 5 votes
public File getChosenExportFile(){
    //! eigene Methode und nicht alte weiterverwenden deswegen, weilst
    //! das mit dem 'Ordner auswählen' wolltest...
    //! dann iss allerdings blöd mit filenamen festlegen, ich vermute,
    //! der gibt dir den path zum ordner zrück. aber vllt sinds eh fixe
    //! namen dann passts ja, stells halt OBEN um
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // user can only select directories
    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
        return fc.getSelectedFile();
    else
        return null;
}
 
Example 12
Project: incubator-netbeans   File: InstallDocSourcePanel.java   Source Code and License Vote up 5 votes
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
    JFileChooser chooser = new JFileChooser(lastFolder);
    chooser.setDialogTitle(isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_javadoc_zip")
                                       : NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_source_zip"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".zip")); //NOI18N
        }
        @Override
        public String getDescription() {
            
            return isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_javadoc_zip")
                               : NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_source_zip");
        }
    });
    chooser.setMultiSelectionEnabled(false);
    if (txtFile.getText().trim().length() > 0) {
        File fil = new File(txtFile.getText().trim());
        if (fil.exists()) {
            chooser.setSelectedFile(fil);
        }
    }
    int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), BTN_Select());
    if (ret == JFileChooser.APPROVE_OPTION) {
        txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
        txtFile.requestFocusInWindow();
    }

}
 
Example 13
Project: SER316-Dresden   File: SetApplicationPanel.java   Source Code and License Vote up 5 votes
void selectAppBrowseB_actionPerformed(ActionEvent e) {
// Fix until Sun's JVM supports more locales...
UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");

JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(Local.getString("Path to executable"));
chooser.setFileHidingEnabled(false);
chooser.setAcceptAllFileFilterUsed(true);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (System.getProperty("os.name").startsWith("Win")) {
    chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.EXE));
    chooser.setCurrentDirectory(new File("C:\\Program Files"));
}
chooser.setPreferredSize(new Dimension(550, 375));
/*
    java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_IMPORT_FILE");
    if (lastSel != null)
        chooser.setCurrentDirectory(lastSel);
*/
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
    applicationField.setText(chooser.getSelectedFile().getPath());
}
 
Example 14
Project: call-IDE   File: StudentMain.java   Source Code and License Vote up 5 votes
private void chooseSubPathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseSubPathBtnActionPerformed
    // TODO add your handling code here:
    JFileChooser f = new JFileChooser();
    f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    f.showOpenDialog(this);
    
    subPathToSend = f.getSelectedFile();
    subPathField.setText(subPathToSend.getAbsolutePath());
    
}
 
Example 15
Project: Equella   File: JFileSelector.java   Source Code and License Vote up 5 votes
@Override
protected void buttonSelected()
{
	JFileChooser chooser = new JFileChooser(currentDirectory);
	chooser.setMultiSelectionEnabled(false);
	chooser.setFileSelectionMode(selectionMode);
	chooser.setFileFilter(filter);

	int result = chooser.showOpenDialog(this);
	if( result == JFileChooser.APPROVE_OPTION )
	{
		setSelectedFile(chooser.getSelectedFile());
	}
}
 
Example 16
Project: incubator-netbeans   File: SigningPanel.java   Source Code and License Vote up 5 votes
private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle(NbBundle.getMessage(JWSCustomizerPanel.class, "TITLE_KeystoreBrowser")); //NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        path.setText(file.getAbsolutePath());
    }
}
 
Example 17
Project: incubator-netbeans   File: NbPlatformCustomizerSources.java   Source Code and License Vote up 5 votes
private void addZipOrFolder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addZipOrFolder
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastUsedNbPlatformLocation());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileFilter(new FileFilter() {
        public boolean accept(File f)  {
            return f.isDirectory() || isValidNbSourceRoot(f);
        }
        public String getDescription() {
            return getMessage("CTL_SourcesTab");
        }
    });
    int ret = chooser.showOpenDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        if (!file.exists() || (file.isFile() && !isValidNbSourceRoot(file))) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    getMessage("MSG_NotValidNBSrcZIP")));
        } else {
            URL newUrl = FileUtil.urlForArchiveOrDir(file);
            if (model.containsRoot(newUrl)) {
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    getMessage("MSG_ExistingNBSrcZIP")));
            } else {
                ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(file.getParentFile().getAbsolutePath());
                model.addSourceRoot(newUrl);
                sourceList.setSelectedValue(newUrl, true);
            }
        }
    }
}
 
Example 18
Project: guetzliconverter   File: GuetzliConverter.java   Source Code and License Vote up 5 votes
private void buttonChooseFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFolderActionPerformed
    String lastFile = ConfigManager.loadConfig(boxArch, boxLimit, sliderQuality, labelQualityValue, false, boxProcessCount);
    JFileChooser chooser = new JFileChooser(lastFile);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        sourceFolderComplete.clear();
        ConfigManager.saveConfig(chooser.getSelectedFile().getAbsolutePath().toString(), boxArch.getSelectedIndex(), boxLimit.getSelectedIndex(), sliderQuality.getValue(), boxProcessCount.getSelectedIndex());
        displayDirectoryContents(chooser.getSelectedFile());
        textFieldSelectedFile.setText(chooser.getSelectedFile().getAbsolutePath().toString() + "\\*->*_guetzli.jpg");
        buttonConvert.setEnabled(true);
        convertType = "folder";
    }
}
 
Example 19
Project: Neukoelln_SER316   File: AppFrame.java   Source Code and License Vote up 4 votes
protected void ppExport_actionPerformed(ActionEvent e) {
// Fix until Sun's JVM supports more locales...
UIManager.put(
        "FileChooser.lookInLabelText",
        Local.getString("Save in:"));
UIManager.put(
        "FileChooser.upFolderToolTipText",
        Local.getString("Up One Level"));
UIManager.put(
        "FileChooser.newFolderToolTipText",
        Local.getString("Create New Folder"));
UIManager.put(
        "FileChooser.listViewButtonToolTipText",
        Local.getString("List"));
UIManager.put(
        "FileChooser.detailsViewButtonToolTipText",
        Local.getString("Details"));
UIManager.put(
        "FileChooser.fileNameLabelText",
        Local.getString("File Name:"));
UIManager.put(
        "FileChooser.filesOfTypeLabelText",
        Local.getString("Files of Type:"));
UIManager.put("FileChooser.saveButtonText", Local.getString("Save"));
UIManager.put(
        "FileChooser.saveButtonToolTipText",
        Local.getString("Save selected file"));
UIManager.put(
        "FileChooser.cancelButtonText",
        Local.getString("Cancel"));
UIManager.put(
        "FileChooser.cancelButtonToolTipText",
        Local.getString("Cancel"));

JFileChooser chooser = new JFileChooser();
chooser.setFileHidingEnabled(false);
chooser.setDialogTitle(Local.getString("Export notes"));
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.addChoosableFileFilter(
        new AllFilesFilter(AllFilesFilter.XHTML));
chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));

String lastSel = (String) Context.get("LAST_SELECTED_EXPORT_FILE");
if (lastSel != null)
        chooser.setCurrentDirectory(new File(lastSel));

ProjectExportDialog dlg =
        new ProjectExportDialog(
                App.getFrame(),
                Local.getString("Export notes"),
                chooser);
String enc = (String) Context.get("EXPORT_FILE_ENCODING");
if (enc != null)
        dlg.encCB.setSelectedItem(enc);
Dimension dlgSize = new Dimension(550, 500);
dlg.setSize(dlgSize);
Dimension frmSize = App.getFrame().getSize();
Point loc = App.getFrame().getLocation();
dlg.setLocation(
        (frmSize.width - dlgSize.width) / 2 + loc.x,
        (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setVisible(true);
if (dlg.CANCELLED)
        return;                
        Context.put(
                "LAST_SELECTED_EXPORT_FILE",
                chooser.getSelectedFile().getPath());                
int ei = dlg.encCB.getSelectedIndex();
enc = null;
if (ei == 1)
        enc = "UTF-8";
boolean nument = (ei == 2);
File f = chooser.getSelectedFile();
boolean xhtml =
        chooser.getFileFilter().getDescription().indexOf("XHTML") > -1;
 CurrentProject.save();
 ProjectExporter.export(CurrentProject.get(), chooser.getSelectedFile(), enc, xhtml, 
                 false, true, nument, false, false); 
}
 
Example 20
Project: incubator-netbeans   File: PatchAction.java   Source Code and License Vote up 4 votes
private File getPatchFor(FileObject fo) {
       JFileChooser chooser = new JFileChooser();
       String patchDirPath = DiffModuleConfig.getDefault().getPreferences().get(PREF_RECENT_PATCH_PATH, System.getProperty("user.home"));
       File patchDir = new File(patchDirPath);
       while (!patchDir.isDirectory()) {
           patchDir = patchDir.getParentFile();
           if (patchDir == null) {
               patchDir = new File(System.getProperty("user.home"));
               break;
           }
       }
       FileUtil.preventFileChooserSymlinkTraversal(chooser, patchDir);
       chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
       String title = NbBundle.getMessage(PatchAction.class,
           (fo.isData()) ? "TITLE_SelectPatchForFile"
                         : "TITLE_SelectPatchForFolder", fo.getNameExt());
       chooser.setDialogTitle(title);

       // setup filters, default one filters patch files
       FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
           @Override
           public boolean accept(File f) {
               return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory();  // NOI18N
           }
           @Override
           public String getDescription() {
               return NbBundle.getMessage(PatchAction.class, "CTL_PatchDialog_FileFilter");
           }
       };
       chooser.addChoosableFileFilter(patchFilter);
       chooser.setFileFilter(patchFilter);

       chooser.setApproveButtonText(NbBundle.getMessage(PatchAction.class, "BTN_Patch"));
       chooser.setApproveButtonMnemonic(NbBundle.getMessage(PatchAction.class, "BTN_Patch_mnc").charAt(0));
       chooser.setApproveButtonToolTipText(NbBundle.getMessage(PatchAction.class, "BTN_Patch_tooltip"));
       HelpCtx ctx = new HelpCtx(PatchAction.class.getName());
       DialogDescriptor descriptor = new DialogDescriptor( chooser, title, true, new Object[0], null, 0, ctx, null );
       final Dialog dialog = DialogDisplayer.getDefault().createDialog( descriptor );
       dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PatchAction.class, "ACSD_PatchDialog"));

       ChooserListener listener = new PatchAction.ChooserListener(dialog,chooser);
chooser.addActionListener(listener);
       dialog.setVisible(true);

       File selectedFile = listener.getFile();
       if (selectedFile != null) {
           DiffModuleConfig.getDefault().getPreferences().put(PREF_RECENT_PATCH_PATH, selectedFile.getParentFile().getAbsolutePath());
       }
       return selectedFile;
   }