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;
}
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;
}
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);
}
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);
}
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));
}
Aggregations