Search in sources :

Example 31 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class UNCFile method ls.

@Override
public AbstractFile[] ls(FilenameFilter filenameFilter) throws IOException {
    File[] files = file.listFiles(filenameFilter == null ? null : new UNCFilenameFilter(filenameFilter));
    if (files == null)
        throw new IOException();
    int nbFiles = files.length;
    AbstractFile[] children = new AbstractFile[nbFiles];
    for (int i = 0; i < nbFiles; i++) {
        File file = files[i];
        // Clone the FileURL of this file and set the child's path, this is more efficient than creating a new
        // FileURL instance from scratch.
        FileURL childURL = (FileURL) fileURL.clone();
        childURL.setPath(addTrailingSeparator(fileURL.getPath()) + file.getName());
        // Retrieves an AbstractFile (LocalFile or AbstractArchiveFile) instance that's potentially already in
        // the cache, reuse this file as the file's parent, and the already-created java.io.File instance.
        children[i] = FileFactory.getFile(childURL, this, Collections.singletonMap("createdFile", file));
    }
    return children;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) ProtocolFile(com.mucommander.commons.file.protocol.ProtocolFile) File(java.io.File) AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 32 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class LocalFileIconProvider method getFileIcon.

// ///////////////////////////////////
// FileIconProvider implementation //
// ///////////////////////////////////
public Icon getFileIcon(AbstractFile originalFile, Dimension preferredResolution) {
    // Specified file is a LocalFile or a ProxyFile proxying a LocalFile (e.g. an archive file): let's simply get
    // the icon using #getLocalFileIcon(LocalFile)
    AbstractFile topFile = originalFile.getTopAncestor();
    Icon icon;
    if (topFile instanceof LocalFile) {
        icon = getLocalFileIcon((LocalFile) topFile, originalFile, preferredResolution);
    } else // File is a remote file: create a temporary local file (or directory) with the same extension to grab the icon
    // and then delete the file. This operation is I/O bound and thus expensive, so an LRU is used to cache
    // frequently-accessed file extensions.
    {
        // Create the temporary, local file
        LocalFile tempFile = createTempLocalFile(topFile);
        if (tempFile == null) {
            // No temp file, no icon!
            return null;
        }
        // Get the file icon
        icon = getLocalFileIcon(tempFile, originalFile, preferredResolution);
        // Delete the temporary file
        try {
            tempFile.delete();
        } catch (IOException e) {
        // Not much to do
        }
    }
    return icon;
}
Also used : LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException)

Example 33 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class AbstractArchiveFile method getArchiveEntryFile.

/**
 * Creates and returns an AbstractFile that corresponds to the given entry path within the archive.
 * The requested entry may or may not exist in the archive, the {@link #exists()} method of the returned entry file
 * can be used to find this out. However, if the requested entry does not exist in the archive and is
 * not located at the top level (i.e. is located in a subfolder), its parent folder must exist in the archive or
 * else an <code>IOException</code> will be thrown.
 *
 * <p>Important note: the given path's separator character must be '/' and the path must be relative to the
 * archive's root, i.e. not start with a leading '/', otherwise the entry will not be found.</p>
 *
 * @param entryPath path to an entry within this archive
 * @return an AbstractFile that corresponds to the given entry path
 * @throws IOException if neither the entry nor its parent exist within the archive
 * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the
 * underlying file protocol.
 */
public AbstractFile getArchiveEntryFile(String entryPath) throws IOException, UnsupportedFileOperationException {
    DefaultMutableTreeNode entryNode = getArchiveEntryNode(entryPath);
    if (entryNode == null) {
        int depth = ArchiveEntry.getDepth(entryPath);
        AbstractFile parentFile;
        if (depth == 1)
            parentFile = this;
        else {
            String parentPath = entryPath;
            if (parentPath.endsWith("/"))
                parentPath = parentPath.substring(0, parentPath.length() - 1);
            parentPath = parentPath.substring(0, parentPath.lastIndexOf('/'));
            parentFile = getArchiveEntryFile(parentPath);
            if (// neither the entry nor the parent exist
            parentFile == null)
                throw new IOException();
        }
        return getArchiveEntryFile(new ArchiveEntry(entryPath, false, 0, 0, false), parentFile);
    }
    return getArchiveEntryFile(entryNode);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IOException(java.io.IOException)

Example 34 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class AbstractCopyDialog method computeInitialPath.

// ////////////////////////////////////////////////////
// TransferDestinationDialog partial implementation //
// ////////////////////////////////////////////////////
@Override
protected PathFieldContent computeInitialPath(FileSet files) {
    // Text to display in the destination field.
    String fieldText;
    // Index of the first selected character in the destination field.
    int startPosition;
    // Index of the last selected character in the destination field.
    int endPosition;
    int nbFiles = files.size();
    // Fill text field with absolute path, and if there is only one file,
    // append file's name
    fieldText = mainFrame.getInactivePanel().getCurrentFolder().getAbsolutePath(true);
    // (otherwise folder would be copied into the destination folder)
    if (nbFiles == 1) {
        AbstractFile file = files.elementAt(0);
        AbstractFile destFile;
        startPosition = fieldText.length();
        if (!(file.isDirectory() && (destFile = FileFactory.getFile(fieldText + file.getName())) != null && destFile.exists() && destFile.isDirectory())) {
            return selectDestinationFilename(file, fieldText + file.getName(), startPosition);
        } else
            endPosition = fieldText.length();
    } else {
        endPosition = fieldText.length();
        startPosition = 0;
    }
    return new PathFieldContent(fieldText, startPosition, endPosition);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 35 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class BatchRenameDialog method generateNewNames.

/**
 * Generates new names for all files.
 */
private void generateNewNames() {
    compilePattern(edtFileNameMask.getText());
    for (int i = 0; i < files.size(); i++) {
        if (Boolean.FALSE.equals(blockNames.get(i))) {
            AbstractFile file = files.get(i);
            String newName = generateNewName(file);
            newNames.set(i, newName);
        }
    }
    checkForDuplicates();
    tableModel.fireTableChanged(new TableModelEvent(tableModel, 0, newNames.size(), 1, TableModelEvent.UPDATE));
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) TableModelEvent(javax.swing.event.TableModelEvent)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)150 IOException (java.io.IOException)49 FileURL (com.mucommander.commons.file.FileURL)19 FileSet (com.mucommander.commons.file.util.FileSet)11 FileTable (com.mucommander.ui.main.table.FileTable)11 DialogAction (com.mucommander.ui.dialog.DialogAction)10 File (java.io.File)9 List (java.util.List)8 MainFrame (com.mucommander.ui.main.MainFrame)6 InputStream (java.io.InputStream)6 Vector (java.util.Vector)6 AbstractArchiveEntryFile (com.mucommander.commons.file.archive.AbstractArchiveEntryFile)5 ProtocolFile (com.mucommander.commons.file.protocol.ProtocolFile)5 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)5 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)5 FolderPanel (com.mucommander.ui.main.FolderPanel)5 FileTableModel (com.mucommander.ui.main.table.FileTableModel)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)4