private void init() { setAcceptAllFileFilterUsed(false); addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, evt -> { Object newValue = evt.getNewValue(); if (newValue instanceof File) { lastFilename = ((File) newValue).getName(); } }); addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, evt -> { final SnapFileFilter snapFileFilter = getSnapFileFilter(); if (snapFileFilter != null) { setFileSelectionMode(snapFileFilter.getFileSelectionMode().getValue()); } else { setFileSelectionMode(FILES_ONLY); } if (getSelectedFile() != null) { return; } if (lastFilename == null || lastFilename.length() == 0) { return; } setCurrentFilename(lastFilename); }); }
private static File requestFolderForSave2(String title, final String preferenceKey) { Assert.notNull(preferenceKey, "preferenceKey"); String lastDir = SnapApp.getDefault().getPreferences().get(preferenceKey, SystemUtils.getUserHomeDir().getPath()); File currentDir = new File(lastDir); SnapFileChooser fileChooser = new SnapFileChooser(); fileChooser.setCurrentDirectory(currentDir); fileChooser.setDialogTitle(Dialogs.getDialogTitle(title)); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setAcceptAllFileFilterUsed(false); int result = fileChooser.showSaveDialog(SnapApp.getDefault().getMainFrame()); if (fileChooser.getCurrentDirectory() != null) { SnapApp.getDefault().getPreferences().put(preferenceKey, fileChooser.getCurrentDirectory().getPath()); } if (result == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (file == null || file.getName().equals("")) { return null; } String path = file.getPath(); return new File(path); } return null; }
fileChooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); if (accessory != null) { fileChooser.setAccessory(accessory);
private JFileChooser createFileChooser() { String lastDirPath = Config.instance().load().preferences().get(GCP_EXPORT_DIR_PREFERENCES_KEY, SystemUtils.getUserHomeDir().getPath()); SnapFileChooser fileChooser = new SnapFileChooser(); HelpCtx.setHelpIDString(fileChooser, getHelpCtx().getHelpID()); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setCurrentDirectory(new File(lastDirPath)); fileChooser.setFileFilter( new SnapFileFilter(GCP_FILE_DESCRIPTION, GCP_FILE_EXTENSION, GCP_FILE_DESCRIPTION)); fileChooser.setDialogTitle(Bundle.CTL_ExportEnviGcpFileAction_DialogTitle()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); return fileChooser; }
fileChooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); int result = fileChooser.showOpenDialog(SnapApp.getDefault().getMainFrame()); if (fileChooser.getCurrentDirectory() != null) {
configureFileChooser(fileChooser, view, imageBaseName); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setCurrentFilename(currentFilename); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);