Search in sources :

Example 6 with FileList

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();
}
Also used : FileList(org.apache.pivot.io.FileList) File(java.io.File)

Example 7 with FileList

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;
}
Also used : FileList(org.apache.pivot.io.FileList) Picture(org.apache.pivot.wtk.media.Picture) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) File(java.io.File)

Aggregations

FileList (org.apache.pivot.io.FileList)7 File (java.io.File)6 IOException (java.io.IOException)4 DropAction (org.apache.pivot.wtk.DropAction)4 FileInputStream (java.io.FileInputStream)2 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 Component (org.apache.pivot.wtk.Component)2 DropTarget (org.apache.pivot.wtk.DropTarget)2 Manifest (org.apache.pivot.wtk.Manifest)2 PushButton (org.apache.pivot.wtk.PushButton)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Sequence (org.apache.pivot.collections.Sequence)1 JSONSerializer (org.apache.pivot.json.JSONSerializer)1 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)1 DragSource (org.apache.pivot.wtk.DragSource)1 Keyboard (org.apache.pivot.wtk.Keyboard)1 ListView (org.apache.pivot.wtk.ListView)1 LocalManifest (org.apache.pivot.wtk.LocalManifest)1