List of usage examples for javax.swing JFileChooser FILES_ONLY
int FILES_ONLY
To view the source code for javax.swing JFileChooser FILES_ONLY.
Click Source Link
From source file:org.fhaes.gui.ShapeFileDialog.java
/** * Prompt the user for an output filename * //from ww w . j a v a 2 s . c o m * @param filter * @return */ private File getOutputFile(FileFilter filter) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null); File outputFile; // Create a file chooser final JFileChooser fc = new JFileChooser(lastVisitedFolder); fc.setAcceptAllFileFilterUsed(true); if (filter != null) { fc.addChoosableFileFilter(filter); fc.setFileFilter(filter); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Save as..."); // In response to a button click: int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { outputFile = fc.getSelectedFile(); if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") { log.debug("Output file extension not set by user"); if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription())) { log.debug("Adding shp extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".shp"); } } else { log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'"); } App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath()); } else { return null; } if (outputFile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; int response = JOptionPane.showOptionDialog(this, "The file '" + outputFile.getName() + "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon options, // the titles of buttons options[0]); // default button title if (response != JOptionPane.YES_OPTION) { return null; } } return outputFile; }
From source file:org.geopublishing.geopublisher.GpUtil.java
/** * Performs a file OPEN choose as a fallback * //from w ww. j av a2s .c o m * @param parent * component for the dialog (can be {@code null}) * @param startFolder * start folder for the chooser (if {@code null} "/" is used) * @param filter * defines which files can be selected. Only the last filter in * the list will be offered due to limitations * @return {@code null} if the dialog was not approved */ public static File chooseFileOpenFallback(Component parent, File startFolder, String title, FileExtensionFilter... filters) { if (startFolder == null) startFolder = new File("/"); if (startFolder.isFile()) startFolder = startFolder.getParentFile(); JFileChooser chooser = new JFileChooser(startFolder); chooser.setDialogType(JFileChooser.OPEN_DIALOG); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(filters[0].toJFileChooserFilter()); } if (title != null) chooser.setDialogTitle(title); int ret = chooser.showOpenDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
From source file:org.giswater.controller.MenuController.java
private String chooseSqlFile(boolean save) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("SQL extension file", "sql"); chooser.setFileFilter(filter);/*from www . j a v a2 s .c o m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.file_sql")); File file = new File(PropertiesDao.getLastSqlPath()); chooser.setCurrentDirectory(file.getParentFile()); int returnVal; if (save) { returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".sql"; fileSql = new File(path); } PropertiesDao.setLastSqlPath(path); } return path; }
From source file:org.giswater.controller.MenuController.java
private File gswChooseFile(boolean save) { String path = ""; File file = null;//from w w w . j a v a2 s .c om JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("GSW extension file", "gsw"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.gsw_file")); File fileProp = new File(prop.get("FILE_GSW", Utils.getLogFolder())); chooser.setCurrentDirectory(fileProp.getParentFile()); int returnVal; if (save) { returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); path = file.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".gsw"; file = new File(path); } } return file; }
From source file:org.giswater.controller.MenuController.java
private String chooseFileSetup(String fileName) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("EXE extension file", "exe"); chooser.setFileFilter(filter);/*w w w. j av a2 s .c o m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("file_exe")); File file = new File(usersFolder + fileName); chooser.setCurrentDirectory(file); chooser.setSelectedFile(file); int returnVal = chooser.showOpenDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".exe"; fileSql = new File(path); } } return path; }
From source file:org.graphwalker.GUI.App.java
private void load() { status.setStopped();/*w ww.j a va 2 s . c om*/ statusBar.setMessage("Stopped"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML files", "xml"); fileChooser.setFileFilter(filter); int returnVal = fileChooser.showOpenDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { xmlFile = fileChooser.getSelectedFile(); logger.debug("Got file: " + xmlFile.getAbsolutePath()); loadModel(); if (appEvent != null) { appEvent.getLoadEvent(); } } }
From source file:org.gtdfree.GTDFree.java
private JFileChooser getFileChooser() { if (fileChooser == null) { fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home", "."))); //$NON-NLS-1$ //$NON-NLS-2$ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileHidingEnabled(false); fileChooser.setFileFilter(new FileNameExtensionFilter(Messages.getString("GTDFree.FileFilter"), "xml")); //$NON-NLS-1$ //$NON-NLS-2$ }/*from ww w .j av a 2s . c o m*/ return fileChooser; }
From source file:org.jax.haplotype.io.SnpStreamUtil.java
/** * A main for snp data conversion/* w w w . j ava 2 s .co 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.languagetool.gui.Tools.java
/** * Show a file chooser dialog in a specified directory * @param frame Owner frame// w w w.jav a 2s . c o m * @param fileFilter The pattern of files to choose from * @param initialDir The initial directory * @return the selected file * @since 2.6 */ static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir) { return openFileDialog(frame, fileFilter, initialDir, JFileChooser.FILES_ONLY); }
From source file:org.martin.ftp.gui.GUIClient.java
private void btnFileOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileOptionActionPerformed dialogUploadOptions.hide();/*from w ww . j av a 2 s . co m*/ fileChoos.setFileSelectionMode(JFileChooser.FILES_ONLY); int selection = fileChoos.showOpenDialog(formManagement); if (selection == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = fileChoos.getSelectedFiles(); if (selectedFiles != null) { Thread t = new Thread(() -> { try { for (File file : selectedFiles) if (file.isFile()) linker.uploadFile(file, directorioActual); updateTable(); } catch (IOException ex) { Logger.getLogger(GUIClient.class.getName()).log(Level.SEVERE, null, ex); } }); t.start(); threadsUploaders.add(t); } } }