private static File getFilePath(Component component, String title) { final File graphPath = new File(SnapApp.getDefault().getPreferences().get("batch.last_graph_path", defaultGraphPath.toFile().getAbsolutePath())); final JFileChooser chooser = FileChooserFactory.getInstance().createFileChooser(graphPath); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(title); if (chooser.showDialog(component, "OK") == JFileChooser.APPROVE_OPTION) { final File file = chooser.getSelectedFile(); SnapApp.getDefault().getPreferences().put("batch.last_graph_path", file.getAbsolutePath()); return file; } return null; }
@Override public void actionPerformed(ActionEvent event) { Window windowAncestor = null; if (event.getSource() instanceof JComponent) { JComponent eventSource = (JComponent) event.getSource(); windowAncestor = SwingUtilities.getWindowAncestor(eventSource); } final JFileChooser chooser = FileChooserFactory.getInstance().createDirChooser(model.getProductDir()); chooser.setDialogTitle("Select Target Directory"); if (chooser.showDialog(windowAncestor, APPROVE_BUTTON_TEXT) == JFileChooser.APPROVE_OPTION) { final File selectedDir = chooser.getSelectedFile(); if (selectedDir != null) { model.setProductDir(selectedDir); } else { model.setProductDir(new File(".")); } } } }
private static File[] GetFilePath(Component component, String title) { File[] files = null; final File openDir = new File(SnapApp.getDefault().getPreferences(). get(OpenProductAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, ".")); final JFileChooser chooser = FileChooserFactory.getInstance().createFileChooser(openDir); chooser.setMultiSelectionEnabled(true); chooser.setDialogTitle(title); if (chooser.showDialog(component, "OK") == JFileChooser.APPROVE_OPTION) { files = chooser.getSelectedFiles(); SnapApp.getDefault().getPreferences(). put(OpenProductAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, chooser.getCurrentDirectory().getAbsolutePath()); } return files; }