Java Code Examples for javax.swing.JFileChooser.getFileSystemView()

The following are Jave code examples for showing how to use getFileSystemView() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rapidminer   File: FileChooserUI.java   Source Code and License Vote up 6 votes
private void doDirectoryChanged(PropertyChangeEvent e) {
	JFileChooser fc = getFileChooser();
	FileSystemView fsv = fc.getFileSystemView();

	clearIconCache();

	File currentDirectory = fc.getCurrentDirectory();
	this.fileList.updatePath(currentDirectory);

	if (currentDirectory != null) {
		this.directoryComboBoxModel.addItem(currentDirectory);
		getNewFolderAction().setEnabled(currentDirectory.canWrite());
		getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
		getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
		getGoHomeAction().setEnabled(!userHomeDirectory.equals(currentDirectory));

		if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
			if (fsv.isFileSystem(currentDirectory)) {
				setFileName(currentDirectory.getPath());
			} else {
				setFileName(null);
			}
			setFileSelected();
		}
	}
}
 
Example 2
Project: rapidminer   File: FileChooserUI.java   Source Code and License Vote up 5 votes
@Override
public void actionPerformed(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", "");

	try {
		if (name != null && !"".equals(name)) {
			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();
}