Package com.mucommander.commons.file

Examples of com.mucommander.commons.file.AbstractFile


     *                     <code>false</code> if a library of the same name already exists and
     *                     <code>force</code> is set to <code>false</code>.
     * @throws IOException if an I/O error occurs.
     */
    public static boolean importLibrary(AbstractFile file, boolean force) throws IOException {
        AbstractFile dest;

        // If the file is already in the extensions or classpath,
        // there's nothing to do.
        if(isAvailable(file))
            return true;

        // If the destination file already exists, either delete it
        // if force is set to true or just return false.
        dest = getExtensionsFile(file.getName());
        if(dest.exists()) {
            if(!force)
                return false;
            dest.delete();
        }

        // Copies the library and adds it to the extensions classpath.
        file.copyTo(dest);
        addToClassPath(dest);
View Full Code Here


    //  - 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(FileProtocols.FILE)) {
      AbstractFile folder = FileFactory.getFile(folderURL);
      if (folder.isDirectory() && (folder instanceof LocalFile) && !((LocalFile)folder.getRoot()).guessRemovableDrive()) {
        this.lastRecallableFolder = folder.getAbsolutePath();
        LOGGER.trace("lastRecallableFolder= "+lastRecallableFolder);
      }
    }
  }
View Full Code Here

            return false;

        if(recurseOnDirectories && file.isDirectory()) {
            do {    // Loop for retries
                try {
                    AbstractFile children[] = file.ls();
                    int nbChildren = children.length;

                    for(int i=0; i<nbChildren && getState()!=INTERRUPTED; i++) {
                        // Notify job that we're starting to process this file (needed for recursive calls to processFile)
                        nextFile(children[i]);
View Full Code Here

     * @see                #getPreferencesFolder()
     * @see                #setPreferencesFolder(File)
     * @see                #setPreferencesFolder(AbstractFile)
     */
    public static void setPreferencesFolder(String path) throws IOException {
        AbstractFile folder;

        if((folder = FileFactory.getFile(path)) == null)
            setPreferencesFolder(new File(path));
        else
            setPreferencesFolder(folder);
View Full Code Here

     * Sets the path to the configuration file.
     * @param  path                  path to the file that should be used for configuration storage.
     * @throws FileNotFoundException if the specified file is not a valid file.
     */
    private synchronized void setConfigurationFile(String path) throws FileNotFoundException {
        AbstractFile file;

        if((file = FileFactory.getFile(path)) == null)
            setConfigurationFile(new File(path));
        else
            setConfigurationFile(file);
View Full Code Here

            setPrototypeCellValue(files.elementAt(0));

        if(preloadFileAttributes) {
            filenames = new String[nbFiles];
            icons = new Icon[nbFiles];
            AbstractFile file;
            for(int i=0; i<nbFiles; i++) {
                file = files.elementAt(i);
                filenames[i] = file.getName();
                icons[i] = file.getIcon();
            }

            this.fileAttributesPreloaded = true;
        }

        // Use a custom ListModel
        setModel(new AbstractListModel() {
            public int getSize() {
                return files.size();
            }

            public Object getElementAt(int index) {
                return files.elementAt(index);
            }
        });

        customFont = new JLabel().getFont();
        customFont = customFont.deriveFont(customFont.getStyle(), customFont.getSize()-2);

        // Use a custom ListCellRenderer
        setCellRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                label.setFont(customFont);

                if(FileList.this.fileAttributesPreloaded) {
                    label.setText(filenames[index]);
                    label.setIcon(icons[index]);
                }
                else {
                    AbstractFile file = (AbstractFile)value;
                    label.setText(file.getName());
                    label.setIcon(file.getIcon());
                }

                return label;
            }
        });
View Full Code Here

        // Stop if interrupted
        if(getState()==INTERRUPTED)
            return false;
   
        // Destination folder
        AbstractFile destFolder = recurseParams==null?baseDestFolder:(AbstractFile)recurseParams;
   
        // Is current file in base folder ?
        boolean isFileInBaseFolder = files.indexOf(file)!=-1;

        // Determine filename in destination
        String destFileName;
        if(isFileInBaseFolder && newName!=null)
            destFileName = newName;
         else
            destFileName = file.getName();

        // Create destination AbstractFile instance
        AbstractFile destFile = createDestinationFile(destFolder, destFileName);
        if (destFile == null)
            return false;
        currentDestFile = destFile;

        // Do nothing if file is a symlink (skip file and return)
        if(file.isSymlink())
            return true;

        destFile = checkForCollision(file, destFolder, destFile, false);
        if (destFile == null)
            return false;

        // Copy directory recursively
        if(file.isDirectory()) {
            // Create the folder in the destination folder if it doesn't exist
            if(!(destFile.exists() && destFile.isDirectory())) {
                // Loop for retry
                do {
                    try {
                        destFile.mkdir();
                    }
                    catch(IOException e) {
                        // Unable to create folder
                        int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_create_folder", destFileName));
                        // Retry loops
                        if(ret==RETRY_ACTION)
                            continue;
                        // Cancel or close dialog return false
                        return false;
                        // Skip continues
                    }
                    break;
                } while(true);
            }
     
            // and copy each file in this folder recursively
            do {    // Loop for retry
                try {
                    // for each file in folder...
                    AbstractFile subFiles[] = file.ls();
//filesDiscovered(subFiles);
                    for(int i=0; i<subFiles.length && getState()!=INTERRUPTED; i++) {
                        // Notify job that we're starting to process this file (needed for recursive calls to processFile)
                        nextFile(subFiles[i]);
                        processFile(subFiles[i], destFile);
View Full Code Here

    // TransferDestinationDialog implementation //
    //////////////////////////////////////////////

    @Override
    protected PathFieldContent computeInitialPath(FileSet files) {
        AbstractFile file = files.elementAt(0);

        //    AbstractFile activeFolder = mainFrame.getActiveTable().getCurrentFolder();
        AbstractFile unactiveFolder = mainFrame.getInactivePanel().getCurrentFolder();
        // Fill text field with current folder's absolute path and file name
        return new PathFieldContent(unactiveFolder.getAbsolutePath(true)+file.getName());
    }
View Full Code Here

        // This is one of those cases where a null value actually has a proper meaning.
        if(path == null)
            return getHomeFolder().getURL();

        // Tries the specified path as-is.
        AbstractFile file;
        CredentialsMapping newCredentialsMapping;

        while(true) {
            try {
                file = FileFactory.getFile(path, true);
                if(!file.exists())
                    file = null;
                break;
            }
            // If an AuthException occurred, gets login credential from the user.
            catch(Exception e) {
                if(e instanceof AuthException) {
                    // Prompts the user for a login and password.
                    AuthException authException = (AuthException)e;
                    FileURL url = authException.getURL();
                    AuthDialog authDialog = new AuthDialog(WindowManager.getCurrentMainFrame(), url, true, authException.getMessage());
                    authDialog.showDialog();
                    newCredentialsMapping = authDialog.getCredentialsMapping();
                    if(newCredentialsMapping !=null) {
                        // Use the provided credentials
                        CredentialsManager.authenticate(url, newCredentialsMapping);
                        path = url.toString(true);
                    }
                    // If the user cancels, we fall back to the default path.
                    else {
                        return getHomeFolder().getURL();
                    }
                }
                else {
                    file = null;
                    break;
                }
            }
        }

        // If the specified path does not work out,
        if(file == null)
            // Tries the specified path as a relative path.
            if((file = FileFactory.getFile(new File(path).getAbsolutePath())) == null || !file.exists())
                // Defaults to home.
                return getHomeFolder().getURL();

        // If the specified path is a non-browsable, uses its parent.
        if(!file.isBrowsable())
            // This is just playing things safe, as I doubt there might ever be a case of
            // a file without a parent directory.
            if((file = file.getParent()) == null)
                return getHomeFolder().getURL();

        return file.getURL();
    }
View Full Code Here

    public void performAction() {
        FileTable fileTable = mainFrame.getActiveTable();
        FileTableModel tableModel = fileTable.getFileTableModel();

        // Starts at 1 if current folder is not root so that '..' is not marked
        AbstractFile file;
        int nbRows = tableModel.getRowCount();
        for(int i=tableModel.getFirstMarkableRow(); i<nbRows; i++) {
            file = tableModel.getFileAtRow(i);
            if(!file.isDirectory())
                tableModel.setRowMarked(i, !tableModel.isRowMarked(i));
        }
        fileTable.repaint();

        // Notify registered listeners that currently marked files have changed on the FileTable
View Full Code Here

TOP

Related Classes of com.mucommander.commons.file.AbstractFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.