List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:org.isatools.gui.datamanager.exportisa.ExportISAGUI.java
private JFileChooser createFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Select directory to output to"); fileChooser.setApproveButtonText("Output here"); return fileChooser; }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
protected void resolveFileLocations() { int[] selectedRows = spreadsheet.getTable().getSelectedRows(); int selectedColumn = spreadsheet.getTable().getSelectedColumn(); JFileChooser fileLocChooser = new JFileChooser(); fileLocChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileLocChooser.setDialogTitle("Select directory to search through"); fileLocChooser.setApproveButtonText("Select directory"); if (fileLocChooser.showOpenDialog(spreadsheet) == JFileChooser.APPROVE_OPTION) { File dir = fileLocChooser.getSelectedFile(); String[] files = new String[selectedRows.length]; for (int row = 0; row < selectedRows.length; row++) { files[row] = spreadsheet.getTable().getValueAt(selectedRows[row], selectedColumn).toString(); }/*from w ww. jav a 2 s . c om*/ FileLocationMapperUtil fmu = new FileLocationMapperUtil(); Map<String, String> result = fmu.findProperFileLocations(files, dir); for (int selectedRow : selectedRows) { String candidateVal = spreadsheet.getTable().getValueAt(selectedRow, selectedColumn).toString(); if (result.keySet().contains(candidateVal)) { spreadsheet.getTable().setValueAt(result.get(candidateVal), selectedRow, selectedColumn); } } } // otherwise, do nothing }
From source file:org.javaswift.cloudie.CloudiePanel.java
protected void onDownloadStoredObject() { Container container = getSelectedContainer(); List<StoredObject> obj = getSelectedStoredObjects(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(lastFolder); if (obj.size() == 1) { chooser.setSelectedFile(new File(obj.get(0).getName())); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } else {//from w ww. j ava2 s . c o m chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); for (StoredObject so : obj) { File target = selected; if (target.isDirectory()) { target = new File(selected, so.getName()); } if (target.exists()) { if (confirm("File '" + target.getName() + "' already exists. Overwrite?")) { doSaveStoredObject(target, container, so); } } else { doSaveStoredObject(target, container, so); } } lastFolder = selected.isFile() ? selected.getParentFile() : selected; } }
From source file:org.jax.haplotype.io.SnpStreamUtil.java
/** * A main for snp data conversion//from ww w . ja v a 2s .c o m * @param args * dont care * @throws IOException * if we get one */ public static void main(String[] args) throws IOException { JFileChooser inputFileChooser = new JFileChooser(); inputFileChooser.setDialogTitle("Select CSV Chromosome Input Files"); inputFileChooser.setMultiSelectionEnabled(true); inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int userSelection = inputFileChooser.showOpenDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) { JFileChooser outputDirectoryChooser = new JFileChooser(); outputDirectoryChooser.setDialogTitle("Select an Output Directory"); outputDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int outputUserSelection = outputDirectoryChooser.showOpenDialog(null); if (outputUserSelection == JFileChooser.APPROVE_OPTION) { File selectedOutputDirectory = outputDirectoryChooser.getSelectedFile(); File[] selectedInputFiles = inputFileChooser.getSelectedFiles(); for (File selectedInputFile : selectedInputFiles) { writeBinaryChromosomeData(new GenotypeParser(), selectedInputFile, selectedOutputDirectory); } } } else { System.out.println("user doesn't want to open the file"); } }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Event handler for this application, handles all menu items. *///from www .j a v a 2s . com public void actionPerformed(ActionEvent event) { if (event.getSource().equals(loginButton)) { new Thread() { @Override public void run() { listObjects(); } }.start(); } // Object Events else if ("ViewObjectProperties".equals(event.getActionCommand())) { listObjectProperties(); } else if ("RefreshObjects".equals(event.getActionCommand())) { new Thread() { @Override public void run() { listObjects(); } }.start(); } else if ("TogglePublicPrivate".equals(event.getActionCommand())) { new Thread() { @Override public void run() { S3Object object = getSelectedObjects()[0]; String aclStatus = objectTableModel.getObjectAclStatus(object); boolean originalAclWasPublic = ACL_PUBLIC_DESCRIPTION.equals(aclStatus); ToggleAclDialog dialog = new ToggleAclDialog(ownerFrame, originalAclWasPublic, null, cockpitLiteProperties.getProperties()); dialog.setVisible(true); // Update ACL setting. S3Object minimalObject = new S3Object(object.getKey()); AccessControlList newAcl = (dialog.isPublicAclSet() ? AccessControlList.REST_CANNED_PUBLIC_READ : AccessControlList.REST_CANNED_PRIVATE); if (newAcl != null) { if (AccessControlList.REST_CANNED_PRIVATE.equals(newAcl)) { minimalObject.addMetadata(Constants.REST_HEADER_PREFIX + "acl", "private"); } else if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(newAcl)) { minimalObject.addMetadata(Constants.REST_HEADER_PREFIX + "acl", "public-read"); } } updateObjectsAccessControlLists(new S3Object[] { minimalObject }, newAcl); dialog.dispose(); } }.start(); } else if ("GeneratePublicGetURL".equals(event.getActionCommand())) { generatePublicGetUrl(); } else if ("DeleteObjects".equals(event.getActionCommand())) { deleteSelectedObjects(); } else if ("DownloadObjects".equals(event.getActionCommand())) { try { downloadSelectedObjects(); } catch (Exception ex) { String message = "Unable to download objects from S3"; log.error(message, ex); ErrorDialog.showDialog(ownerFrame, this, cockpitLiteProperties.getProperties(), message, ex); } } else if ("UploadFiles".equals(event.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setDialogTitle("Choose file(s) to upload"); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setApproveButtonText("Upload files"); fileChooser.setCurrentDirectory(fileChoosersLastUploadDirectory); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } final File[] uploadFiles = fileChooser.getSelectedFiles(); if (uploadFiles.length == 0) { return; } // Save the chosen directory location for next time. fileChoosersLastUploadDirectory = uploadFiles[0].getParentFile(); new Thread() { @Override public void run() { prepareForFilesUpload(uploadFiles); } }.start(); } else if (event.getSource().equals(filterObjectsCheckBox)) { if (filterObjectsCheckBox.isSelected()) { filterObjectsPanel.setVisible(true); } else { filterObjectsPanel.setVisible(false); filterObjectsPrefix.setText(""); } } // Ooops... else { log.warn("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event); } }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Prepares to perform a download of objects from S3 by prompting the user for a directory * to store the files in, then performing the download. * * @throws IOException// w w w . j a v a2 s . c o m */ private void downloadSelectedObjects() throws IOException { // Prompt user to choose directory location for downloaded files (or cancel download altogether) JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Choose directory to save S3 files in"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setSelectedFile(downloadDirectory); int returnVal = fileChooser.showDialog(ownerFrame, "Choose Directory"); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } downloadDirectory = fileChooser.getSelectedFile(); prepareForObjectsDownload(); }
From source file:org.kuali.test.creator.TestCreator.java
private void handleBackupRepository() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileChooser.getSelectedFile(); new SplashDisplay(this, "Back Up", "Backing up repository...") { @Override// ww w . j ava 2 s . c om protected void runProcess() { try { new ZipDirectory(new File(getConfiguration().getRepositoryLocation()), getBackupFile(selectedFile)); } catch (Exception ex) { LOG.error(ex.toString(), ex); } } }; } }
From source file:org.kuali.test.ui.components.panels.FileTestPanel.java
/** * * @param e// w w w . j a v a 2 s. co m */ @Override protected void handleUnprocessedActionEvent(ActionEvent e) { if (Constants.FILE_SEARCH_ACTION.equals(e.getActionCommand())) { Preferences proot = Preferences.userRoot(); Preferences node = proot.node(Constants.PREFS_FILES_NODE); String lastDir = node.get(Constants.PREFS_LAST_FILE_TEST_DIR, System.getProperty("user.home")); JFileChooser chooser = new JFileChooser(lastDir); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return (f.isDirectory() && f.exists()); } @Override public String getDescription() { return "file inquiry directory"; } }); int returnVal = chooser.showOpenDialog(getMainframe()); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); fileDirectory.setText(f.getPath()); node.put(Constants.PREFS_LAST_FILE_TEST_DIR, f.getPath()); } } else if (Constants.FILE_EXISTS.equals(e.getActionCommand())) { getFileCheckCondition(Constants.FILE_DOES_NOT_EXIST).setSelected(false); getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(true); getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(true); getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(true); containingText.setEnabled(true); } else if (Constants.FILE_DOES_NOT_EXIST.equals(e.getActionCommand())) { getFileCheckCondition(Constants.FILE_EXISTS).setSelected(false); getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setSelected(false); getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(false); getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false); getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(false); getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false); getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(false); containingText.setText(""); containingText.setEnabled(false); } else if (Constants.FILE_CREATED_TODAY.equals(e.getActionCommand())) { getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false); } else if (Constants.FILE_CREATED_YESTERDAY.equals(e.getActionCommand())) { getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false); } }
From source file:org.languagetool.gui.Tools.java
private static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir, int mode) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(mode); jfc.setCurrentDirectory(initialDir); jfc.setFileFilter(fileFilter);//from w ww. j a va 2 s. co m jfc.showOpenDialog(frame); return jfc.getSelectedFile(); }
From source file:org.lnicholls.galleon.apps.iTunes.iTunesOptionsPanel.java
public void actionPerformed(ActionEvent e) { if ("pick".equals(e.getActionCommand())) { final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.addChoosableFileFilter(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } else if (f.isFile() && f.getName().toLowerCase().endsWith("xml")) { return true; }//from www . j a v a 2 s. co m return false; } //The description of this filter public String getDescription() { return "Playlist Library"; } }); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); mPlaylistPathField.setText(file.getAbsolutePath()); } } }