fcb.setTitle(NbBundle.getMessage(this.getClass(), "chooser.shape.title")); fcb.setDefaultWorkingDirectory(userHome); fcb.addFileFilter(ff); fcb.setApproveText(NbBundle.getMessage(this.getClass(), "chooser.shape.approve.text")); File file = fcb.showOpenDialog();
/** * Shows the actual filepicker and return the selected file or dir * @return The selected file */ private File showPicker() { String name = AreaFieldPreference.LAST_SHAPE_DIR.getValue(); File userHome = (name.equals("")) ? new File(System.getProperty(USER_HOME)) : new File(name); List<String> supportedExtensions = new ArrayList<String>(); supportedExtensions.add(".shp"); FileFilter ff = FilePickerUtil.createSwingFileFilter(supportedExtensions, "Shape file (*.shp)"); FileChooserBuilder fcb = new FileChooserBuilder(FILECHOOSER_DIR); fcb.setTitle(FILECHOOSER_TITLE); fcb.setDefaultWorkingDirectory(userHome); fcb.addFileFilter(ff); fcb.setApproveText(FILECHOOSER_APPROVE_TEXT); File file = fcb.showOpenDialog(); // file will be null if cancel is pressed if (file != null) { // save the file path for next time window is opened AreaFieldPreference.LAST_SHAPE_DIR.saveValue(file.getPath()); } return file; }
fcb.addFileFilter(FilePickerUtil.createSwingFileFilter(processorProvider.getSupportedExtentions(), processorProvider.getFormatDescription())); supportedExtensions.addAll(processorProvider.getSupportedExtentions()); fcb.addFileFilter(fileFilter);
/** * Get the save location for the file. * pops up a save dialog * @return a file from the save dialog */ public File getSaveLocation() { if (fcb == null) { fcb = new FileChooserBuilder("Export-directory"); fcb.setTitle(FILECHOOSER_TITLE); fcb.setApproveText(FILECHOOSER_OK); fcb.addFileFilter(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory() && pathname.getName().startsWith(".")) { return false; } return true; } @Override public String getDescription() { return FILECHOOSER_FILE_DESC; } }); } File workingDirectory = new File(SensorPreference.LAST_EXPORT_DIR.getValue()); fcb.setDefaultWorkingDirectory(workingDirectory); return fcb.showSaveDialog(); }
builder.addFileFilter(filter);
builder.addFileFilter(filter);