List of usage examples for javax.swing JFileChooser FILES_AND_DIRECTORIES
int FILES_AND_DIRECTORIES
To view the source code for javax.swing JFileChooser FILES_AND_DIRECTORIES.
Click Source Link
From source file:gdsc.smlm.ij.plugins.PeakFit.java
/** * @return An input directory containing a series of images *//* ww w .j a va 2 s . co m*/ @SuppressWarnings("unused") private String getInputDirectory(String title) { final JFileChooser chooser = new JFileChooser() { private static final long serialVersionUID = 275144634537614122L; public void approveSelection() { if (getSelectedFile().isFile()) { return; } else super.approveSelection(); } }; if (System.getProperty("os.name").startsWith("Mac OS X")) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } else { chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } chooser.setDialogTitle(title); int returnVal = chooser.showOpenDialog(IJ.getInstance()); if (returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().getPath(); } return null; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java
/** * Ask user to choose for a directory and invoke swing worker for creating * PDF report//from w ww. jav a2s .co m * * @throws IOException */ protected void createPdfReport() throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // needs more information chooseDirectory.setSelectedFile( new File("Dose Response Report " + importedDRDataHolder.getExperimentNumber() + ".pdf")); // in response to the button click, show open dialog // TEST WHETHER THIS PARENT PANEL/FRAME IS OKAY int returnVal = chooseDirectory.showSaveDialog(cellMissyController.getCellMissyFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); DoseResponseReportSwingWorker doseResponseReportSwingWorker = new DoseResponseReportSwingWorker( directory, chooseDirectory.getSelectedFile().getName()); doseResponseReportSwingWorker.execute(); } else { cellMissyController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:jatoo.app.App.java
/** * Provides a simple mechanism for the user to select a file or a directory. * /* w w w .ja v a2 s . c o m*/ * @param currentDirectory * the current directory to point to */ public File selectFileOrDirectory(final File currentDirectory) { return select(currentDirectory, JFileChooser.FILES_AND_DIRECTORIES); }
From source file:baocaoxla.compare.java
private void btInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btInputActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.showOpenDialog(this); File dir = fc.getSelectedFile(); txtInput.setText(dir.toString());// ww w.j a v a2 s .c o m /* File[] file=dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".jpg"); //To change body of generated methods, choose Tools | Templates. } });*/ //File[] file = dir.listFiles(); //for (int i = 0; i < file.length; i++) { // System.out.println(file[i].getName()); //} }
From source file:baocaoxla.compare.java
private void btOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOutputActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.showOpenDialog(this); File dir = fc.getSelectedFile(); txtOutput.setText(dir.toString());//from w ww . jav a 2 s . c o m }
From source file:com.nbt.TreeFrame.java
protected JFileChooser createFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileHidingEnabled(false);/*ww w . j a v a 2 s. c o m*/ fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); String description = "named binary tag"; FileFilter filter = new FileNameExtensionFilter(description, "mcr", "dat", "dat_old"); fc.setFileFilter(filter); Preferences prefs = getPreferences(); String exportFile = prefs.get(KEY_FILE, null); if (exportFile == null) { File cwd = new File("."); fc.setCurrentDirectory(cwd); } else { File selectedFile = new File(exportFile); fc.setSelectedFile(selectedFile); } return fc; }
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
private Set getFiles() { JFileChooser chooser = new JFileChooser(DODDLEConstants.PROJECT_HOME); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int retval = chooser.showOpenDialog(DODDLE_OWL.rootPane); if (retval != JFileChooser.APPROVE_OPTION) { return null; }/*from w w w .j av a2 s. c o m*/ File[] files = chooser.getSelectedFiles(); Set fileSet = new TreeSet(); getFiles(files, fileSet); return fileSet; }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Event handler for this application, handles all menu items. *//*from ww w .j a va 2 s. co m*/ public void actionPerformed(ActionEvent event) { // Service Menu Events if ("LoginEvent".equals(event.getActionCommand())) { loginEvent(null); } else if ("LogoutEvent".equals(event.getActionCommand())) { logoutEvent(); } else if (event.getActionCommand() != null && event.getActionCommand().startsWith("LoginSwitch")) { String loginName = event.getActionCommand().substring("LoginSwitch:".length()); ProviderCredentials credentials = loginAwsCredentialsMap.get(loginName); loginEvent(credentials); } else if ("QuitEvent".equals(event.getActionCommand())) { System.exit(0); } // Bucket Events. else if ("ViewBucketProperties".equals(event.getActionCommand())) { listBucketProperties(); } else if ("RefreshBuckets".equals(event.getActionCommand())) { listAllBuckets(); } else if ("CreateBucket".equals(event.getActionCommand())) { createBucketAction(); } else if ("DeleteBucket".equals(event.getActionCommand())) { deleteSelectedBucket(); } else if ("ManageDistributions".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); String[] bucketNames = new String[buckets.length]; for (int i = 0; i < buckets.length; i++) { bucketNames[i] = buckets[i].getName(); } ManageDistributionsDialog.showDialog(ownerFrame, cloudFrontService, bucketNames, this); } else if ("AddThirdPartyBucket".equals(event.getActionCommand())) { addThirdPartyBucket(); } else if ("UpdateBucketACL".equals(event.getActionCommand())) { updateBucketAccessControlList(); } else if ("UpdateBucketRequesterPaysStatus".equals(event.getActionCommand())) { updateBucketRequesterPaysSetting(); } // Object Events else if ("ViewOrModifyObjectAttributes".equals(event.getActionCommand())) { displayObjectsAttributesDialog(); } else if ("CopyObjects".equals(event.getActionCommand())) { copyObjects(); } else if ("RefreshObjects".equals(event.getActionCommand())) { listObjects(); } else if ("UpdateObjectACL".equals(event.getActionCommand())) { displayAclModificationDialog(); } else if ("GeneratePublicGetURLs".equals(event.getActionCommand())) { generatePublicGetUrls(); } else if ("GenerateTorrentURL".equals(event.getActionCommand())) { generateTorrentUrl(); } else if ("DeleteObjects".equals(event.getActionCommand())) { deleteSelectedObjects(); } else if ("DownloadObjects".equals(event.getActionCommand())) { downloadSelectedObjects(); } else if ("UploadFiles".equals(event.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setDialogTitle("Choose files 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(); uploadFiles(uploadFiles); } else if (event.getSource().equals(filterObjectsCheckBox)) { if (filterObjectsCheckBox.isSelected()) { filterObjectsPanel.setVisible(true); } else { filterObjectsPanel.setVisible(false); filterObjectsPrefix.setText(""); if (filterObjectsDelimiter.getSelectedIndex() != 0) { filterObjectsDelimiter.setSelectedIndex(0); } } } // Tools events else if ("BucketLogging".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); BucketLoggingDialog.showDialog(ownerFrame, s3ServiceMulti.getS3Service(), buckets, this); } // Preference Events else if ("PreferencesDialog".equals(event.getActionCommand())) { PreferencesDialog.showDialog(cockpitPreferences, ownerFrame, this); // Save a user's preferences if requested, otherwise wipe any existing preferences file. File cockpitPreferencesPropertiesFile = new File(cockpitHomeDirectory, Constants.COCKPIT_PROPERTIES_FILENAME); if (cockpitPreferences.isRememberPreferences()) { try { Properties properties = cockpitPreferences.toProperties(); if (!cockpitHomeDirectory.exists()) { cockpitHomeDirectory.mkdir(); } properties.list(new PrintStream(new FileOutputStream(cockpitPreferencesPropertiesFile))); } catch (IOException e) { String message = "Unable to save your preferences"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else if (cockpitPreferencesPropertiesFile.exists()) { // User elected not to store preferences, delete the existing preferences file. cockpitPreferencesPropertiesFile.delete(); } if (cockpitPreferences.isEncryptionPasswordSet()) { try { encryptionUtil = new EncryptionUtil(cockpitPreferences.getEncryptionPassword(), cockpitPreferences.getEncryptionAlgorithm(), EncryptionUtil.DEFAULT_VERSION); } catch (Exception e) { String message = "Unable to start encryption utility"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else { encryptionUtil = null; } } // Ooops... else { log.debug("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event); } }
From source file:configuration.Util.java
public static String[] simpleSearchBox(String type, boolean multi, boolean hide) { JFrame f = createSearchFrame(); JFileChooser jf;//w w w . j ava 2 s. c om jf = new JFileChooser(config.getExplorerPath()); if (type.contains("d") || type.contains("D")) jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else if (type.contains("f") || type.contains("F")) jf.setFileSelectionMode(JFileChooser.FILES_ONLY); else jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jf.setAcceptAllFileFilterUsed(false); jf.setMultiSelectionEnabled(multi); jf.setFileHidingEnabled(hide); int result = jf.showOpenDialog(f); f.dispose(); if (result == JFileChooser.APPROVE_OPTION) { if (multi) { //--Save new filepath and files File[] files = jf.getSelectedFiles(); String[] path = new String[files.length]; for (int i = 0; i < files.length; i++) { path[i] = getCanonicalPath(files[i].getPath()); } return path; } else { File file = jf.getSelectedFile(); String[] path = new String[1]; path[0] = getCanonicalPath(file.getPath()); return path; } } String[] empty = new String[0]; return empty; }
From source file:v800_trainer.JCicloTronic.java
private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenActionPerformed // Add your handling code here: byte Data[] = new byte[81930]; File Datei;//from w w w . ja v a 2 s . co m int i, j; chooser.setCurrentDirectory( new java.io.File(Properties.getProperty("import.dir", Properties.getProperty("data.dir")))); chooser.setDialogType(JFileChooser.OPEN_DIALOG); ExampleFileFilter filtera = new ExampleFileFilter(); ExampleFileFilter filterb = new ExampleFileFilter(); ExampleFileFilter filterc = new ExampleFileFilter(); ExampleFileFilter filterd = new ExampleFileFilter(); ExampleFileFilter filtere = new ExampleFileFilter(); // ExampleFileFilter filterc = new ExampleFileFilter(); filtera.addExtension("dat"); filtera.setDescription("HAC Rohdaten"); filterb.addExtension("tur"); filterb.setDescription("Hactronic Dateien"); filterc.addExtension("hrm"); filterc.setDescription("Polar Daten"); filterd.addExtension(""); filterd.setDescription("Polar V800 Verzeichnis"); filtere.addExtension("csv"); filtere.setDescription("Polar V800 CSV Flow export"); chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(filtera); chooser.addChoosableFileFilter(filterb); chooser.addChoosableFileFilter(filterc); chooser.addChoosableFileFilter(filterd); chooser.addChoosableFileFilter(filtere); chooser.setFileFilter(filtere); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int returnVal = chooser.showDialog(this, null); if (returnVal == JFileChooser.APPROVE_OPTION) { try { if (chooser.getFileFilter().equals(filterd)) { if (chooser.getSelectedFile().isDirectory() == true) { ArrayList<String> files = new ArrayList(); files.add(chooser.getSelectedFile().getPath()); v800export V800_export = new v800export(); V800_export.export_sessions(this, files); } else { return; } } else { Datei = new File(chooser.getSelectedFile().toString()); Data = new byte[(int) Datei.length()]; Eingabedatei = new java.io.FileInputStream(chooser.getSelectedFile()); Eingabedatei.read(Data); Eingabedatei.close(); if (chooser.getFileFilter().equals(filtera)) { ExtractTour(Data); } if (chooser.getFileFilter().equals(filterb)) { ExtractHactronicFile(Data); } if (chooser.getFileFilter().equals(filterc)) { ExtractPolarFile(Data); } if (chooser.getFileFilter().equals(filtere)) { ExtractCSV(Data); } } } catch (IOException e) { JOptionPane.showMessageDialog(null, "IO-Fehler bei Datenlesen", "Achtung!", JOptionPane.ERROR_MESSAGE); } } else { return; } Properties.setProperty("import.dir", chooser.getCurrentDirectory().getPath()); JOptionPane.showMessageDialog(null, "Daten Ende", "Achtung!", JOptionPane.ERROR_MESSAGE); ChangeModel(); }