Java Code Examples for javax.swing.JFileChooser#setDialogType()

The following examples show how to use javax.swing.JFileChooser#setDialogType() . 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: AddServerPropertiesVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JFileChooser getJFileChooser(){
    JFileChooser chooser = new JFileChooser();
    
    chooser.setDialogTitle("LBL_Chooser_Name"); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new dirFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); //NOI18N
    
    chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); //NOI18N
    
    return chooser;
}
 
Example 2
Source File: OperatorMenu.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter parameterFileFilter = createParameterFileFilter();
    fileChooser.addChoosableFileFilter(parameterFileFilter);
    fileChooser.setFileFilter(parameterFileFilter);
    fileChooser.setDialogTitle(TITLE);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    applyCurrentDirectory(fileChooser);
    int response = fileChooser.showDialog(parentComponent, "Load");
    if (JFileChooser.APPROVE_OPTION == response) {
        try {
            preserveCurrentDirectory(fileChooser);
            readFromFile(fileChooser.getSelectedFile());
        } catch (Exception e) {
            Debug.trace(e);
            AbstractDialog.showErrorDialog(parentComponent, "Could not load parameters.\n" + e.getMessage(), TITLE);
        }
    }
}
 
Example 3
Source File: ExportSnapshotAction.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: MainFrame.java    From mpcmaid with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void batchCreate() {
	final JFileChooser batchDialog = new JFileChooser(Preferences.getInstance().getSavePath());
	batchDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

	// final FileDialog saveDialog = new FileDialog(this);
	batchDialog.setDialogType(JFileChooser.OPEN_DIALOG);
	batchDialog.setDialogTitle("Choose the base directory to browse recursively");

	batchDialog.showDialog(this, "Batch Create Program");
	final File dir = batchDialog.getSelectedFile();
	if (dir != null) {
		try {
			programEditor.batchCreate(dir);
		} catch (Exception e) {
			e.printStackTrace();// error occurred
		}
	}
}
 
Example 5
Source File: OpenHeapWalkerAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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: OperatorMenu.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    JFileChooser fileChooser = new JFileChooser();
    final FileNameExtensionFilter parameterFileFilter = createParameterFileFilter();
    fileChooser.addChoosableFileFilter(parameterFileFilter);
    fileChooser.setFileFilter(parameterFileFilter);
    fileChooser.setDialogTitle(TITLE);
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    applyCurrentDirectory(fileChooser);
    int response = fileChooser.showDialog(parentComponent, "Save");
    if (JFileChooser.APPROVE_OPTION == response) {
        try {
            preserveCurrentDirectory(fileChooser);
            File selectedFile = fileChooser.getSelectedFile();
            selectedFile = FileUtils.ensureExtension(selectedFile,
                                                     "." + parameterFileFilter.getExtensions()[0]);
            DomElement domElement = parameterSupport.toDomElement();
            escapeXmlElements(domElement);
            String xmlString = domElement.toXml();
            writeToFile(xmlString, selectedFile);
        } catch (Exception e) {
            Debug.trace(e);
            Dialogs.showError(TITLE, "Could not load parameters.\n" + e.getMessage());
        }
    }
}
 
Example 7
Source File: ExportTool.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
void createFileChooser() {
  formats = new Hashtable<String, ExportFormat>();
  registerFormat(new ExportGnuplotFormat());
  registerFormat(new ExportXMLFormat());
  // Set the "filesOfTypeLabelText" to "File Format:"
  Object oldFilesOfTypeLabelText = UIManager.put("FileChooser.filesOfTypeLabelText", //$NON-NLS-1$
    ToolsRes.getString("ExportTool.FileChooser.Label.FileFormat"));                  //$NON-NLS-1$
  // Create a new FileChooser
  fc = new JFileChooser(OSPRuntime.chooserDir);
  // Reset the "filesOfTypeLabelText" to previous value
  UIManager.put("FileChooser.filesOfTypeLabelText", oldFilesOfTypeLabelText);          //$NON-NLS-1$
  fc.setDialogType(JFileChooser.SAVE_DIALOG);
  fc.setDialogTitle(ToolsRes.getString("ExportTool.FileChooser.Title"));               //$NON-NLS-1$
  fc.setApproveButtonText(ToolsRes.getString("ExportTool.FileChooser.Button.Export")); // Set export formats //$NON-NLS-1$
  setChooserFormats();
}
 
Example 8
Source File: PluginTester.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void saveImage(){
	int result;
	String path=null;
	
	JFileChooser chooser = new JFileChooser();
	chooser.setDialogType(JFileChooser.SAVE_DIALOG);
	result = chooser.showSaveDialog(this);
	
	if(result == JFileChooser.CANCEL_OPTION){
		return;
	}

	try{
		path = chooser.getSelectedFile().getCanonicalPath();
		newImage.update();
		MarvinImageIO.saveImage(imagePanel.getImage(), path);
	}
	catch(Exception e){
		e.printStackTrace();
	}
}
 
Example 9
Source File: AddServerPropertiesVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JFileChooser getJFileChooser(){
    JFileChooser chooser = new JFileChooser();

    chooser.setDialogTitle("LBL_Chooser_Name"); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new dirFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); //NOI18N

    chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); //NOI18N

    return chooser;
}
 
Example 10
Source File: AddServerLocationVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JFileChooser getJFileChooser() {
    JFileChooser chooser = new JFileChooser();
    String t = NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName");
    chooser.setDialogTitle(t); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new DirFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setApproveButtonToolTipText(t); //NOI18N
    chooser.getAccessibleContext().setAccessibleName(t); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(t); //NOI18N

    // set the current directory
    File currentLocation = new File(hk2HomeTextField.getText());
    File currentLocationParent = currentLocation.getParentFile();
    if(currentLocationParent != null && currentLocationParent.exists()) {
        chooser.setCurrentDirectory(currentLocationParent);
    }
    if (currentLocation.exists() && currentLocation.isDirectory()) {
        chooser.setSelectedFile(currentLocation);
    } 
    
    return chooser;
}
 
Example 11
Source File: LoadDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 */
public LoadDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setControlButtonsAreShown(true);
    fileChooser.setApproveButtonText(Messages.message("ok"));
    //fileChooser.setCancelButtonText(Messages.message("cancel"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.addActionListener((ActionEvent ae) -> {
            final String cmd = ae.getActionCommand();
            File value = (JFileChooser.APPROVE_SELECTION.equals(cmd))
                ? ((JFileChooser)ae.getSource()).getSelectedFile()
                : cancelFile;
            setValue(value);
        });

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 12
Source File: FileSaveAsEventHandler.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Action performed.
 *
 * @param event the event
 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
 */
@Override
public void actionPerformed(ActionEvent event) {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setDialogTitle("Save file as...");
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
  if (this.main.getFileOpenDir() != null) {
    fileChooser.setCurrentDirectory(this.main.getFileOpenDir());
  }
  int rc = fileChooser.showSaveDialog(this.main);
  if (rc == JFileChooser.APPROVE_OPTION) {
    File tmp = this.main.getTextFile();
    File fileToSaveTo = fileChooser.getSelectedFile();
    if (!this.main.confirmOverwrite(fileToSaveTo)) {
      return;
    }      
    this.main.setTextFile(fileToSaveTo);
    boolean fileSaved = this.main.saveFile();
    if (fileSaved) {
      this.main.setDirty(false);
      this.main.setTitle();
      this.main.setSaveTextFileEnable(true);
      this.main.setFileStatusMessage();
      this.main.setStatusbarMessage("Text file " + this.main.getTextFile().getName() + " saved.");
    } else {
      this.main.setTextFile(tmp);
    }
  }
}
 
Example 13
Source File: DirectorySelectorCombo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void browseFiles() {
  final JFileChooser chooser = new JFileChooser();
  
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  
  chooser.setDialogType(JFileChooser.OPEN_DIALOG);
  chooser.setDialogTitle(Bundle.DirectorySelectorCombo_DialogCaption());
  chooser.setSelectedFile(new File(lastSelectedPath));
  chooser.setFileFilter(new FileFilter() {
    public boolean accept(File f) {
      if (f.isDirectory())
        return true;
      String path = f.getAbsolutePath();
      String ext = path.substring(path.lastIndexOf('.') + 1); // NOI18N
      return supportedExtensions.contains(ext);
    }
    public String getDescription() {
      return Bundle.DirectorySelectorCombo_DialogFilter();
    }
  });
  final int returnVal = chooser.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    final File dir = chooser.getSelectedFile();
    ComboListElement newPath = addPath(dir.getAbsolutePath());
    fileMRU.setSelectedItem(newPath);
    newPath.select();
  } else if (returnVal == JFileChooser.CANCEL_OPTION) {
    fileMRU.setSelectedItem(lastSelectedObject);
  }
}
 
Example 14
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static File showSaveFileDialog( final Component parent, final String title, final File initialPath ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.SAVE_DIALOG);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fc.setCurrentDirectory(initialPath);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            File selectedFile = fc.getSelectedFile();
            if (selectedFile != null && selectedFile.getParentFile().exists())
                PreferencesHandler.setLastPath(selectedFile.getParentFile().getAbsolutePath());
            this.returnValue = selectedFile;

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File) runnable.getReturnValue();
}
 
Example 15
Source File: DialogProviderManager.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public File msgOpenFileDialog(@Nullable final Component parentComponent, @Nonnull String id, @Nonnull String title, @Nullable File defaultFolder, boolean filesOnly, @Nonnull @MustNotContainNull FileFilter[] fileFilters, @Nonnull String approveButtonText) {
  final File folderToUse;
  if (defaultFolder == null) {
    folderToUse = cacheOpenFileThroughDialog.find(null, id);
  } else {
    folderToUse = defaultFolder;
  }

  final JFileChooser fileChooser = new JFileChooser(folderToUse);
  fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
  fileChooser.setDialogTitle(title);
  fileChooser.setApproveButtonText(approveButtonText);
  for (final FileFilter f : fileFilters) {
    fileChooser.addChoosableFileFilter(f);
  }
  if (fileFilters.length != 0) {
    fileChooser.setFileFilter(fileFilters[0]);
  }
  fileChooser.setAcceptAllFileFilterUsed(true);
  fileChooser.setMultiSelectionEnabled(false);

  File result = null;
  if (fileChooser.showDialog(GetUtils.ensureNonNull(
      parentComponent == null ? null : SwingUtilities.windowForComponent(parentComponent),
      Main.getApplicationFrame()),
      approveButtonText) == JFileChooser.APPROVE_OPTION) {
    result = cacheOpenFileThroughDialog.put(id, fileChooser.getSelectedFile());
  }

  return result;
}
 
Example 16
Source File: Hk2Cookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy module from directory on Payara server.
 * <p/>
 * @return Result of undeploy task execution.
 */
@Override
public Future<ResultString> deployDirectory() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(Hk2ItemNode.class,
            "LBL_ChooseButton"));
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);

    int returnValue = chooser.showDialog(WindowManager.getDefault()
            .getMainWindow(), NbBundle.getMessage(
            Hk2ItemNode.class, "LBL_ChooseButton"));
    if (instance != null
            || returnValue != JFileChooser.APPROVE_OPTION) {
        return null;
    }

    final File dir
            = new File(chooser.getSelectedFile().getAbsolutePath());
    Future<ResultString> future = ServerAdmin.<ResultString>exec(
            instance, new CommandDeploy(dir.getParentFile().getName(),
            Util.computeTarget(instance.getProperties()),
            dir, null, null, null, instance.isHotDeployEnabled()));
    status = new WeakReference<Future<ResultString>>(future);
    return future;
}
 
Example 17
Source File: SnapshotCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JFileChooser getFileChooser() {
    if (fileChooser == null) {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
        chooser.setDialogTitle(Bundle.SnapshotCustomizer_SelectSnapshotDialogCaption());
        fileChooser = chooser;
    }

    return fileChooser;
}
 
Example 18
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static File[] showOpenFolderDialog( final Component parent, final String title, final boolean multiselection,
        final File initialPath ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setMultiSelectionEnabled(multiselection);
            fc.setCurrentDirectory(initialPath);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            if (fc.isMultiSelectionEnabled()) {
                File[] selectedFiles = fc.getSelectedFiles();
                this.returnValue = selectedFiles;
            } else {
                File selectedFile = fc.getSelectedFile();
                if (selectedFile != null && selectedFile.exists())
                    PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
                this.returnValue = new File[]{selectedFile};
            }

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File[]) runnable.getReturnValue();
}
 
Example 19
Source File: Utils.java    From j-j-jvm with Apache License 2.0 5 votes vote down vote up
public static File selectFileForOpen(final Component parent, final FileFilter[] fileFilters, final String title, final FileFilter[] selectedFilters, final File initFile) {
  JFileChooser chooser = new JFileChooser();
  chooser.setMultiSelectionEnabled(false);
  chooser.setDragEnabled(false);
  chooser.setControlButtonsAreShown(true);
  chooser.setDialogType(JFileChooser.OPEN_DIALOG);
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

  for (final FileFilter fileFilter : fileFilters) {
    chooser.addChoosableFileFilter(fileFilter);
  }

  chooser.setDialogTitle(title);
  chooser.setAcceptAllFileFilterUsed(false);

  if (initFile != null) {
    chooser.setCurrentDirectory(initFile);
    chooser.setName(initFile.getName());
  }

  int returnVal = chooser.showDialog(parent, "Open");
  selectedFilters[0] = chooser.getFileFilter();

  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File p_file = chooser.getSelectedFile();
    return p_file;
  } else {
    return null;
  }

}
 
Example 20
Source File: ApplyDiffPatchAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void performContextAction(Node[] nodes) {
    VCSContext ctx = HgUtils.getCurrentContext(nodes);
    final File roots[] = HgUtils.getActionRoots(ctx);
    if (roots == null || roots.length == 0) {
        return;
    }
    final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);

    final JFileChooser fileChooser = new AccessibleJFileChooser(Bundle.ACSD_ApplyDiffPatchBrowseFolder(), null);
    fileChooser.setDialogTitle(Bundle.ApplyDiffPatchBrowse_title());
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setApproveButtonMnemonic(Bundle.ApplyDiffPatch_Apply().charAt(0));
    fileChooser.setApproveButtonText(Bundle.ApplyDiffPatch_Apply());
    fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
    // 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 Bundle.CTL_PatchDialog_FileFilter();
        }
    };
    fileChooser.addChoosableFileFilter(patchFilter);
    fileChooser.setFileFilter(patchFilter);

    DialogDescriptor dd = new DialogDescriptor(fileChooser, Bundle.ApplyDiffPatchBrowse_title());
    dd.setOptions(new Object[0]);
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    
    fileChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                final File patchFile = fileChooser.getSelectedFile();
                final RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
                new HgProgressSupport() {

                    @Override
                    protected void perform () {
                        if (isNetBeansPatch(patchFile)) {
                            PatchAction.performPatch(patchFile, roots[0]);
                        } else {
                            new ImportDiffAction.ImportDiffProgressSupport(root, patchFile, false, ImportDiffAction.ImportDiffProgressSupport.Kind.PATCH)
                                    .start(rp, root, Bundle.MSG_ApplyDiffPatch_importingPatch());
                        }
                    }
                }.start(rp, root, Bundle.MSG_ApplyDiffPatch_checkingFile());
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);
}