Search in sources :

Example 1 with LocalFile

use of com.mucommander.commons.file.protocol.local.LocalFile 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 2 with LocalFile

use of com.mucommander.commons.file.protocol.local.LocalFile in project mucommander by mucommander.

the class LocalLocationHistory method tryToAddToHistory.

/**
 * Adds the specified folder to history. The folder won't be added if the previous folder is the same.
 *
 * <p>This method is called by FolderPanel each time a folder is changed.
 */
public void tryToAddToHistory(FileURL folderURL) {
    // Do not add folder to history if new current folder is the same as previous folder
    if (historyIndex < 0 || !folderURL.equals(history.get(historyIndex), false, false))
        addToHistory(folderURL);
    // Save last recallable folder on startup, only if :
    // - it is a directory on a local filesytem
    // - it doesn't look like a removable media drive (cd/dvd/floppy), especially in order to prevent
    // Java from triggering that dreaded 'Drive not ready' popup.
    LOGGER.trace("folder=" + folderURL);
    if (folderURL.getScheme().equals(LocalFile.SCHEMA)) {
        AbstractFile folder = FileFactory.getFile(folderURL);
        if (folder.isDirectory() && (folder instanceof LocalFile) && !((LocalFile) folder.getRoot()).guessRemovableDrive()) {
            this.lastRecallableFolder = folder.getAbsolutePath();
            LOGGER.trace("lastRecallableFolder= " + lastRecallableFolder);
        }
    }
}
Also used : LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 3 with LocalFile

use of com.mucommander.commons.file.protocol.local.LocalFile in project mucommander by mucommander.

the class LocalFileTest method testRootDriveMethods.

/**
 * Tests methods related to root drives (e.g. C:\).
 */
@Test
public void testRootDriveMethods() {
    // The following test simply assert that the method doesn't produce an uncaught exception.
    LocalFile.hasRootDrives();
    LocalFile localFile = (LocalFile) tempFile.getAncestor(LocalFile.class);
    localFile.guessRemovableDrive();
}
Also used : LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) AbstractFileTest(com.mucommander.commons.file.AbstractFileTest) Test(org.testng.annotations.Test)

Example 4 with LocalFile

use of com.mucommander.commons.file.protocol.local.LocalFile in project mucommander by mucommander.

the class SwingFileIconProviderImpl method getLocalFileIcon.

/**
 * <i>Implementation note:</i> only one resolution is available (usually 16x16) and blindly returned, the
 * <code>preferredResolution</code> argument is simply ignored.
 */
@Override
public Icon getLocalFileIcon(LocalFile localFile, AbstractFile originalFile, Dimension preferredResolution) {
    // Initialize the Swing object the first time this method is called
    checkInit();
    // Retrieve the icon using the Swing provider component
    Icon icon = getSwingIcon((java.io.File) localFile.getUnderlyingFileObject());
    // 
    if ((!(originalFile.getTopAncestor() instanceof LocalFile)) && originalFile.isSymlink()) {
        icon = getSymlinkIcon(icon);
    }
    return icon;
}
Also used : LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon)

Aggregations

LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)4 AbstractFile (com.mucommander.commons.file.AbstractFile)2 AbstractFileTest (com.mucommander.commons.file.AbstractFileTest)1 IOException (java.io.IOException)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 Test (org.testng.annotations.Test)1