Search in sources :

Example 61 with AbstractFile

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

the class EAWTHandler method handleOpenFile.

@Override
public void handleOpenFile(ApplicationEvent event) {
    AbstractFile file = FileFactory.getFile(event.getFilename());
    CoreServiceTracker.getCoreService().openFile(file.getAbsolutePath());
    event.setHandled(true);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 62 with AbstractFile

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

the class CredentialsManager method loadCredentials.

/**
 * Tries to load credentials from the credentials file if it exists. Does nothing if it doesn't.
 *
 * @throws Exception if an error occurs while loading the credentials file.
 */
public static void loadCredentials() throws Exception {
    AbstractFile credentialsFile = getCredentialsFile();
    if (credentialsFile.exists()) {
        LOGGER.debug("Found credentials file: " + credentialsFile.getAbsolutePath());
        // Parse the credentials file
        new CredentialsParser().parse(credentialsFile);
        LOGGER.debug("Credentials file loaded.");
    } else
        LOGGER.debug("No credentials file found at " + credentialsFile.getAbsolutePath());
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 63 with AbstractFile

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

the class ResourceLoaderTest method testRootPackageAsFile.

/**
 * Tests <code>ResourceLoader#getRootPackageAsFile</code> methods.
 *
 * @throws IOException should not happen
 */
@Test
public void testRootPackageAsFile() throws IOException {
    AbstractFile rootPackageFile = ResourceLoader.getRootPackageAsFile(getClass());
    assert rootPackageFile != null;
    assert rootPackageFile.exists();
    assert rootPackageFile.isBrowsable();
    AbstractFile thisClassFile = rootPackageFile.getChild("com/mucommander/commons/file/util/ResourceLoaderTest.class");
    assertReadable(thisClassFile);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) Test(org.testng.annotations.Test)

Example 64 with AbstractFile

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

the class CalculateDirectorySizeWorker method calcDirectorySize.

private void calcDirectorySize(AbstractFile path) throws IOException {
    if (isCancelled()) {
        return;
    }
    long tm = System.currentTimeMillis();
    if (tm - lastRefreshTime > REFRESH_RATE_MS) {
        lastRefreshTime = tm;
        publish(size);
    }
    if (path.isSymlink() && path != this.path) {
        return;
    }
    AbstractFile[] childs;
    try {
        childs = path.ls();
    } catch (IOException e) {
        return;
    }
    for (AbstractFile f : childs) {
        if (isCancelled()) {
            return;
        }
        if (f.isDirectory()) {
            calcDirectorySize(f);
        } else if (!f.isSymlink()) {
            size += f.getSize();
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException)

Example 65 with AbstractFile

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

the class FileTable method setCurrentFolder.

/**
 * Changes the current folder to the specified one and refreshes the table to reflect the folder's contents.
 * The current file selection is also updated, with the following behavior:
 * <ul>
 *   <li>If <code>filetoSelect</code> is not <code>null</code>, the specified file becomes the currently selected
 * file, if it can be found in the new current folder. Previously marked files are cleared.</li>
 *   <li>If it is <code>null</code>:
 *     <ul>
 *       <li>if the current folder is the same as the previous one, the currently selected file and marked files
 * remain the same, provided they still exist.</li>
 *       <li>if the new current folder is the parent of the previous one, the previous current folder is selected.</li>
 *       <li>in any other case, the first row is selected, whether it be the parent directory ('..') or the first
 * file of the current folder if it has no parent.</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * <p>
 * This method returns only when the folder has actually been changed and the table refreshed.<br>
 * <b>Important:</b> This method should only be called by {@link FolderPanel} and in any case MUST be synchronized
 * externally to ensure this method is never called concurrently by different threads.
 * </p>
 *
 * @param folder the new current folder
 * @param children children of the specified folder
 * @param fileToSelect the file to select, <code>null</code> for the default selection.
 */
public void setCurrentFolder(AbstractFile folder, AbstractFile[] children, AbstractFile fileToSelect) {
    overlayTable.setOverlayVisible(!folder.exists());
    // Stop quick search in case it was being used before folder change
    quickSearch.stop();
    AbstractFile currentFolder = folderPanel.getCurrentFolder();
    // If we're refreshing the current folder, save the current selection and marked files
    // in order to restore them properly.
    FileSet markedFiles = null;
    if (currentFolder != null && folder.equalsCanonical(currentFolder)) {
        markedFiles = tableModel.getMarkedFiles();
        if (fileToSelect == null)
            fileToSelect = getSelectedFile();
    } else // If we're navigating to the current folder's parent, we select the current folder.
    if (fileToSelect == null) {
        if (tableModel.hasParentFolder() && folder.equals(tableModel.getParentFolder()))
            fileToSelect = currentFolder;
    }
    // Changes the current folder in the swing thread to make sure that repaints cannot
    // happen in the middle of the operation - this is used to prevent flickering, badly
    // refreshed frames and such unpleasant graphical artifacts.
    Runnable folderChangeThread = new FolderChangeThread(folder, children, markedFiles, fileToSelect);
    // due to AWT thread synchronization issues.
    synchronized (folderChangeThread) {
        SwingUtilities.invokeLater(folderChangeThread);
        while (true) {
            try {
                // FolderChangeThread will call notify when done
                folderChangeThread.wait();
                break;
            } catch (InterruptedException e) {
            // will keep looping
            }
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileSet(com.mucommander.commons.file.util.FileSet)

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