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:carolina.pegaLatLong.LatLong.java
private void geraCsv(List<InformacaoGerada> gerados) throws IOException { JFileChooser escolha = new JFileChooser(); escolha.setAcceptAllFileFilterUsed(false); escolha.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int i = escolha.showSaveDialog(null); if (i != 1) { System.err.println(escolha.getSelectedFile().getPath() + "\\teste.txt"); String caminho = escolha.getSelectedFile().getPath(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(caminho + "\\teste.csv"), StandardCharsets.ISO_8859_1)); //FileWriter arquivo = new FileWriter(caminho + "\\teste.csv"); //PrintWriter writer = new PrintWriter(arquivo); writer.write("Endereco;Latitude;Longitude"); writer.newLine();/*from w w w . j av a 2 s.c o m*/ gerados.stream().forEach((gerado) -> { try { System.err.println(gerado.getEnderecoFormatado() + ";" + gerado.getLatitude() + ";" + gerado.getLongitude() + "\n"); writer.write(gerado.getEnderecoFormatado() + ";" + gerado.getLatitude() + ";" + gerado.getLongitude()); writer.newLine(); } catch (IOException ex) { System.err.println("Erro"); } }); writer.close(); JOptionPane.showMessageDialog(null, "Finalizado!"); } }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Choose the directory and load its data into a given JTree. * * @param dataTree/* ww w . j av a2 s .c o m*/ */ private void chooseDirectoryAndLoadData() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Please select a root folder containing your files"); // allow for directories only fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // removing "All Files" option from FileType fileChooser.setAcceptAllFileFilterUsed(false); int returnVal = fileChooser.showOpenDialog(cellCoordController.getCellCoordFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { // the directory for the data directory = fileChooser.getSelectedFile(); try { loadDataIntoTree(); } catch (LoadDirectoryException ex) { LOG.error(ex.getMessage()); cellCoordController.showMessage(ex.getMessage(), "wrong directory structure error", JOptionPane.ERROR_MESSAGE); } } else { cellCoordController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobRecheckForTemplates.java
private List<ICImage> getFileList() { List<ICImage> files = new ArrayList<ICImage>(); if (scan != SCAN_ALL) { String pathToCheck = ""; // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;/*from ww w. j ava 2 s.c o m*/ // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); // retrieve a list of image records in the selected directory ICImageLifeCycle ils = new ICImageLifeCycle(); ICImage pattern = new ICImage(); pattern.setPath(pathToCheck); pattern.setTemplateId(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS); files = ils.findByExample(pattern); if (files != null) { log.debug(files.size()); } } } } } else { try { // retrieve a list of all image records with no template ICImageLifeCycle ils = new ICImageLifeCycle(); files = ils.findNotDrawerNoTemplateImages(); if (files != null) { log.debug(files.size()); } } catch (HibernateException e) { log.error(e.getMessage()); runStatus = RunStatus.STATUS_FAILED; String message = "Error loading the list of images with no templates. " + e.getMessage(); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Error loading image records.", JOptionPane.YES_NO_OPTION); } } log.debug("Found " + files.size() + " Image files without templates in directory to check."); return files; }
From source file:com.enderville.enderinstaller.ui.Installer.java
private void chooseTargetMinecraftFolder() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); int opt = chooser.showOpenDialog(getMainPane()); if (opt == JFileChooser.APPROVE_OPTION) { File dir = chooser.getSelectedFile(); String oldDir = InstallerConfig.getMinecraftFolder(); InstallerConfig.setMinecraftFolder(dir.getAbsolutePath()); File mcjar = new File(InstallerConfig.getMinecraftJar()); if (!mcjar.exists()) { JOptionPane.showMessageDialog(getMainPane(), "The installer couldn't find a minecraft installation in the specified folder.\n" + "Restoring minecraft folder to " + oldDir, "Error setting target Minecraft installation", JOptionPane.ERROR_MESSAGE); InstallerConfig.setMinecraftFolder(oldDir); }//from ww w.j a v a2 s. c o m } }
From source file:ru.develgame.jflickrorganizer.MainForm.java
private void jButtonChooseBackupFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChooseBackupFolderActionPerformed JFileChooser jFileChooserSaveBackup = new JFileChooser(); jFileChooserSaveBackup.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = jFileChooserSaveBackup.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { jTextFieldBackupFolder.setText(jFileChooserSaveBackup.getSelectedFile().getAbsolutePath()); }/* w ww . j a v a 2s .c o m*/ }
From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void localStorageDirjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localStorageDirjButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setSelectedFile(new File(gp.getProperty(CamSyncProperties.LOCALSTORAGE_PATH))); if (jfc.showDialog(jPanel1, "Choose as local directory") == JFileChooser.APPROVE_OPTION) { File f = new File(jfc.getSelectedFile().getAbsolutePath(), "azocamsynctest"); success = f.mkdir();//from w ww . ja va 2s . c om success = f.delete(); gp.setProperty(CamSyncProperties.LOCALSTORAGE_PATH, jfc.getSelectedFile().getAbsolutePath()); } if (success) { JOptionPane.showMessageDialog(rootPane, "You've setup the path for incoming files.\nAll configuration steps are performed now.\n Let's start the service!", "Success!", JOptionPane.INFORMATION_MESSAGE); step2jCheckBox.setSelected(true); step2jCheckBox.setText("Success"); this.setVisible(false); } else { JOptionPane.showConfirmDialog(rootPane, "This directory cannot read &write. Please choose another one.", "Local storage directory not working", JOptionPane.WARNING_MESSAGE); } }
From source file:edu.synth.SynthHelper.java
public String openDialogFileChooser(String path, boolean dirOnly, String name, String button, String filterType) {/*from ww w. j a v a 2 s .com*/ JFileChooser fileOpen = new JFileChooser(); if (!path.isEmpty()) fileOpen.setCurrentDirectory(new File(path)); else fileOpen.setCurrentDirectory(new File(".")); if (dirOnly) fileOpen.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else { fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); switch (filterType) { case "abn": FileFilter filter = new FileNameExtensionFilter("*.abn - Abundances file", "abn"); fileOpen.setFileFilter(filter); break; case "model": filter = new FileNameExtensionFilter("*.atl - Kurucz's format model file", "atl"); fileOpen.setFileFilter(filter); break; case "lns": filter = new FileNameExtensionFilter("*.lns - Lines file", "lns"); fileOpen.setFileFilter(filter); break; } } fileOpen.setDialogTitle(name); fileOpen.setApproveButtonText(button); int returnVal = fileOpen.showOpenDialog(fileOpen); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedPath = fileOpen.getSelectedFile(); if (selectedPath != null) return selectedPath.getAbsolutePath(); } return ""; }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX:/*from w w w .j a va2 s . c o m*/ System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void autoruninstalljButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoruninstalljButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Prepare card..."); File startFile = new File(System.getProperty("user.dir")); //Get the current directory // Find System Root while (!FileSystemView.getFileSystemView().isFileSystemRoot(startFile)) { startFile = startFile.getParentFile(); }/*from ww w . ja v a 2s. c om*/ jfc.setCurrentDirectory(startFile); int origDriveChooserRetVal = jfc.showDialog(rootPane, "Open"); if (origDriveChooserRetVal == JFileChooser.APPROVE_OPTION) { try { File myfile = new File(jfc.getSelectedFile().getAbsolutePath(), "autorun.sh"); myfile.createNewFile(); FileOutputStream fos; try { fos = new FileOutputStream(myfile); IOUtils.copy(getClass().getResourceAsStream( "/de/quadrillenschule/azocamsyncd/ftpservice/res/autorun.sh"), fos); fos.close(); success = true; } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } if (!success) { JOptionPane.showMessageDialog(rootPane, "The WiFi is SD card could not be written to. Please check if you selected the right card and it is not write-protected.", "SD card could not be prepared", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(rootPane, "The WiFi SD card is prepared for operating an FTP and Telnet server.", "Success!", JOptionPane.INFORMATION_MESSAGE); step0jCheckBox.setSelected(true); step0jCheckBox.setText("Done"); updateSelectedPanel(1); } }
From source file:com.nwn.NwnUpdaterHomeView.java
/** * Allow user to specify their NWN directory * @param evt // w ww .jav a 2s. c o m */ private void btnSelectNwnDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectNwnDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle("NWN Updater"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showOpenDialog(txtNwnDir); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); txtNwnDir.setText(file.getAbsolutePath()); } }