Java Code Examples for javax.swing.JFileChooser#isMultiSelectionEnabled()

The following examples show how to use javax.swing.JFileChooser#isMultiSelectionEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFileChooserJavaElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean marathon_select(String value) {
    JFileChooser fc = (JFileChooser) component;
    if (value.equals("")) {
        fc.cancelSelection();
        return true;
    }
    if (fc.isMultiSelectionEnabled()) {
        fc.setSelectedFiles(ChooserHelper.decode(value));
        fc.approveSelection();
        return true;
    }
    fc.setSelectedFile(ChooserHelper.decodeFile(value));
    fc.approveSelection();
    return true;
}
 
Example 2
Source File: RFileChooser.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void recordApproveSelection(JFileChooser fc) {
    if (fc.isMultiSelectionEnabled()) {
        File[] fs = fc.getSelectedFiles();
        recorder.recordSelect(this, ChooserHelper.encode(fs));
    } else {
        File file = fc.getSelectedFile();
        recorder.recordSelect(this, ChooserHelper.encode(file));
    }
}
 
Example 3
Source File: FileChooserUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void loggedActionPerformed(ActionEvent e) {
	if (UIManager.getBoolean("FileChooser.readOnly")) {
		return;
	}
	JFileChooser fc = getFileChooser();
	File currentDirectory = fc.getCurrentDirectory();
	FileSystemView fsv = fc.getFileSystemView();
	File newFolder = null;

	String name = SwingTools.showInputDialog("file_chooser.new_folder", "");

	// abort if cancelled or user entered nothing
	if (name == null || name.isEmpty()) {
		return;
	}

	try {
		newFolder = fsv.createNewFolder(currentDirectory);
		if (newFolder.renameTo(fsv.createFileObject(fsv.getParentDirectory(newFolder), name))) {
			newFolder = fsv.createFileObject(fsv.getParentDirectory(newFolder), name);
		} else {
			SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.rename", name);
		}
	} catch (IOException exc) {
		SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.create", name);
		return;
	} catch (Exception exp) {
		// do nothing
	}

	if (fc.isMultiSelectionEnabled()) {
		fc.setSelectedFiles(new File[] { newFolder });
	} else {
		fc.setSelectedFile(newFolder);
	}

	fc.rescanCurrentDirectory();
}
 
Example 4
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static File[] showOpenFolderDialog( final Component parent, final String title, final boolean multiselection,
        final File initialPath ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setMultiSelectionEnabled(multiselection);
            fc.setCurrentDirectory(initialPath);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            if (fc.isMultiSelectionEnabled()) {
                File[] selectedFiles = fc.getSelectedFiles();
                this.returnValue = selectedFiles;
            } else {
                File selectedFile = fc.getSelectedFile();
                if (selectedFile != null && selectedFile.exists())
                    PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
                this.returnValue = new File[]{selectedFile};
            }

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File[]) runnable.getReturnValue();
}
 
Example 5
Source File: Preferences.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
void grab(JFileChooser jfc)  {
     location = jfc.getLocation();
     if(jfc.isMultiSelectionEnabled())
selection = jfc.getSelectedFiles();
     else
selection = new File[] {jfc.getSelectedFile()};
   }
 
Example 6
Source File: J2SEVolumeCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setAcceptAllFileFilterUsed(false);
    if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_CLASSPATH)) {
        chooser.setMultiSelectionEnabled (true);
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenClasses"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Classpath"),new String[] {"ZIP","JAR"}));   //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectCP"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectCP").charAt(0));
    }
    else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_JAVADOC)) {
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenJavadoc"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Javadoc"),new String[] {"ZIP","JAR"}));     //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectJD"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectJD").charAt(0));
    }
    else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_SRC)) {
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenSources"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Sources"),new String[] {"ZIP","JAR"}));     //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectSRC"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectSRC").charAt(0));
    }
    if (lastFolder != null) {
        chooser.setCurrentDirectory (lastFolder);
    }
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            lastFolder = chooser.getCurrentDirectory();
            if (chooser.isMultiSelectionEnabled()) {
                addFiles (chooser.getSelectedFiles());
            }
            else {
                final File selectedFile = chooser.getSelectedFile();                    
                addFiles (new File[] {selectedFile});
            }
        } catch (MalformedURLException mue) {
            Exceptions.printStackTrace(mue);
        }
    }
}
 
Example 7
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static File[] showOpenFilesDialog( final Component parent, final String title, final boolean multiselection,
        final File initialPath, final FileFilter filter ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fc.setMultiSelectionEnabled(multiselection);
            fc.setCurrentDirectory(initialPath);
            if (filter != null)
                fc.setFileFilter(filter);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            if (fc.isMultiSelectionEnabled()) {
                File[] selectedFiles = fc.getSelectedFiles();
                this.returnValue = selectedFiles;
            } else {
                File selectedFile = fc.getSelectedFile();
                if (selectedFile != null && selectedFile.exists())
                    PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
                this.returnValue = new File[]{selectedFile};
            }

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File[]) runnable.getReturnValue();
}