use of org.apache.pivot.io.FileList in project pivot by apache.
the class FileBrowserSheet method setSelectedFiles.
/**
* Sets the selected files.
*
* @param selectedFiles The files to select.
* @return The files that were selected, with duplicates eliminated.
* @throws IllegalArgumentException if the selected files sequence is {@code null}
* or if the sequence is longer than one file and multi-select is not enabled, or
* if any entry is the sequence is {@code null} or whose parent is not the
* current root directory.
*/
public Sequence<File> setSelectedFiles(Sequence<File> selectedFiles) {
Utils.checkNull(selectedFiles, "selectedFiles");
if (mode != Mode.OPEN_MULTIPLE && selectedFiles.getLength() > 1) {
throw new IllegalArgumentException("Multi-select is not enabled.");
}
// Update the selection
Sequence<File> previousSelectedFiles = getSelectedFiles();
FileList fileList = new FileList();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File file = selectedFiles.get(i);
Utils.checkNull(file, "file");
if (!file.isAbsolute()) {
file = new File(rootDirectory, file.getPath());
}
if (!file.getParentFile().equals(rootDirectory)) {
throw new IllegalArgumentException(file.getPath() + " is not a child of the root directory.");
}
fileList.add(file);
}
this.selectedFiles = fileList;
// Notify listeners
fileBrowserSheetListeners.selectedFilesChanged(this, previousSelectedFiles);
return getSelectedFiles();
}
use of org.apache.pivot.io.FileList in project pivot by apache.
the class LocalManifestAdapter method getTransferData.
@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException {
Object transferData = null;
int index = transferDataFlavors.indexOf(dataFlavor);
if (index == -1) {
throw new UnsupportedFlavorException(dataFlavor);
}
if (dataFlavor.equals(DataFlavor.stringFlavor)) {
transferData = localManifest.getText();
} else if (dataFlavor.equals(DataFlavor.imageFlavor)) {
Picture picture = (Picture) localManifest.getImage();
transferData = picture.getBufferedImage();
} else if (dataFlavor.equals(DataFlavor.javaFileListFlavor)) {
FileList fileList = localManifest.getFileList();
transferData = fileList.getList();
} else if (dataFlavor.getMimeType().equals(URI_LIST_MIME_TYPE)) {
FileList fileList = localManifest.getFileList();
StringBuilder buf = new StringBuilder();
for (File file : fileList) {
buf.append(file.toURI().toString()).append("\r\n");
}
transferData = buf.toString();
}
return transferData;
}
Aggregations