Search in sources :

Example 36 with AbstractFile

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

the class CalculateChecksumDialog method actionPerformed.

// /////////////////////////////////
// ActionListener implementation //
// /////////////////////////////////
public void actionPerformed(ActionEvent e) {
    // Start by disposing this dialog
    dispose();
    if (e.getSource() == okButton) {
        try {
            MessageDigest digest = getSelectedMessageDigest();
            String algorithm = digest.getAlgorithm();
            AbstractFile checksumFile;
            if (specificLocationRadioButton.isSelected()) {
                // User-defined checksum file
                String enteredPath = specificLocationTextField.getText();
                PathUtils.ResolvedDestination resolvedDest = PathUtils.resolveDestination(enteredPath, mainFrame.getActivePanel().getCurrentFolder());
                // The path entered doesn't correspond to any existing folder
                if (resolvedDest == null) {
                    showErrorDialog(Translator.get("invalid_path", enteredPath));
                    return;
                }
                if (resolvedDest.getDestinationType() == DestinationType.EXISTING_FOLDER)
                    checksumFile = resolvedDest.getDestinationFile().getDirectChild(getChecksumFilename(algorithm));
                else
                    checksumFile = resolvedDest.getDestinationFile();
            } else {
                // Temporary file
                checksumFile = FileFactory.getTemporaryFile(getChecksumFilename(algorithm), true);
            }
            // Save the algorithm that was used for the next time this dialog is invoked
            lastUsedAlgorithm = algorithm;
            // Start processing files
            ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("properties_dialog.calculating"));
            CalculateChecksumJob job = new CalculateChecksumJob(progressDialog, mainFrame, files, checksumFile, digest);
            progressDialog.start(job);
        } catch (IOException ex) {
            // Note: FileFactory.getTemporaryFile() should never throw an IOException
            showErrorDialog(Translator.get("invalid_path", specificLocationTextField.getText()));
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) CalculateChecksumJob(com.mucommander.job.impl.CalculateChecksumJob) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) PathUtils(com.mucommander.commons.file.util.PathUtils)

Example 37 with AbstractFile

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

the class CombineFilesDialog method searchParts.

/**
 * Searches for parts of a file.
 *
 * @param part1 first part of a file
 */
private void searchParts(AbstractFile part1) {
    AbstractFile parent = part1.getParent();
    if (parent == null) {
        return;
    }
    String ext = part1.getExtension();
    int firstIndex;
    try {
        firstIndex = Integer.parseInt(ext);
    } catch (NumberFormatException e) {
        return;
    }
    AndFileFilter filter = new AndFileFilter(new StartsWithFilenameFilter(part1.getNameWithoutExtension(), false), new AttributeFileFilter(FileAttribute.FILE), new EqualsFilenameFilter(part1.getName(), false, true));
    try {
        AbstractFile[] otherParts = parent.ls(filter);
        for (AbstractFile otherPart : otherParts) {
            String ext2 = otherPart.getExtension();
            try {
                int partIdx = Integer.parseInt(ext2);
                if (partIdx > firstIndex)
                    files.add(otherPart);
            } catch (NumberFormatException e) {
            // nothing
            }
        }
    } catch (IOException e) {
        LOGGER.debug("Caught exception", e);
    }
    setFiles(files);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) StartsWithFilenameFilter(com.mucommander.commons.file.filter.StartsWithFilenameFilter) IOException(java.io.IOException)

Example 38 with AbstractFile

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

the class FileDragSourceListener method dragGestureRecognized.

// /**
// * Creates a custom DragGestureEvent instance re-using the information contained in the given DragGestureEvent, but
// * overridding the actions with the specified actions bitwise mask.
// * When used with <code>DragSource.startDrag</code>, this allows to start a drag operation with a different source
// * action set from the one specified in the <code>DragGestureRecognizer</code>, based on the current state and
// * contents of the FolderPanel.
// */
// private DragGestureEvent createCustomDragGestureEvent(DragGestureEvent originalDGE, int actions) {
// Vector eventList = new Vector();
// Iterator eventIterator = originalDGE.iterator();
// 
// while(eventIterator.hasNext())
// eventList.add(eventIterator.next());
// 
// DragGestureRecognizer dragGestureRecognizer = originalDGE.getSourceAsDragGestureRecognizer();
// dragGestureRecognizer.setSourceActions(actions);
// 
// return new DragGestureEvent(dragGestureRecognizer,
// actions,
// originalDGE.getDragOrigin(),
// eventList);
// }
// ///////////////////////////////
// DragGestureListener methods //
// ///////////////////////////////
public void dragGestureRecognized(DragGestureEvent event) {
    if (folderPanel.getMainFrame().getNoEventsMode())
        return;
    FileTable fileTable = folderPanel.getFileTable();
    FileTableModel tableModel = fileTable.getFileTableModel();
    // Return (do not initiate drag) if mouse button2 or button3 was used
    if ((event.getTriggerEvent().getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0)
        return;
    // Do not use that to retrieve the current selected file as it is inaccurate: the selection could have changed since the
    // the mouse was clicked.
    // AbstractFile selectedFile = fileTable.getSelectedFile(false);
    // // Return if selected file is null (could happen if '..' is selected)
    // if(selectedFile==null)
    // return;
    // Find out which row was clicked
    int clickedRow = fileTable.rowAtPoint(event.getDragOrigin());
    // Return (do not initiate drag) if the selected file is the parent folder '..'
    if (clickedRow == -1 || fileTable.isParentFolder(clickedRow))
        return;
    // Retrieve the file corresponding to the clicked row
    AbstractFile selectedFile = tableModel.getFileAtRow(clickedRow);
    // Find out which files are to be dragged, based on the selected file and currenlty marked files.
    // If there are some files marked, drag marked files only if the selected file is one of the marked files.
    // In any other case, only drag the selected file.
    FileSet markedFiles;
    FileSet draggedFiles;
    if (tableModel.getNbMarkedFiles() > 0 && (markedFiles = fileTable.getSelectedFiles()).contains(selectedFile)) {
        draggedFiles = markedFiles;
    } else {
        draggedFiles = new FileSet(folderPanel.getCurrentFolder(), selectedFile);
    }
    // Set initial DnDContext information
    DnDContext.setDragInitiatedByMucommander(true);
    DnDContext.setDragInitiator(folderPanel);
    DnDContext.setDragGestureModifiersEx(event.getTriggerEvent().getModifiersEx());
    // Start dragging
    DragSource.getDefaultDragSource().startDrag(event, null, new TransferableFileSet(draggedFiles), this);
// DragSource.getDefaultDragSource().startDrag(createCustomDragGestureEvent(event, DnDConstants.ACTION_MOVE), null, new TransferableFileSet(draggedFiles), this);
}
Also used : FileTableModel(com.mucommander.ui.main.table.FileTableModel) AbstractFile(com.mucommander.commons.file.AbstractFile) FileSet(com.mucommander.commons.file.util.FileSet) FileTable(com.mucommander.ui.main.table.FileTable)

Example 39 with AbstractFile

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

the class AppearancePanel method importLookAndFeelLibrary.

/**
 * Tries to import the specified library in the extensions folder.
 * <p>
 * If there is already a file with the same name in the extensions folder,
 * this method will ask the user for confirmation before overwriting it.
 * </p>
 *
 * @param library library to import in the extensions folder.
 * @return <code>true</code> if the library was imported, <code>false</code> if the user cancelled the operation.
 * @throws IOException if an I/O error occurred while importing the library
 */
private boolean importLookAndFeelLibrary(AbstractFile library) throws IOException {
    // Tries to import the file, but if a version of it is already present in the extensions folder,
    // asks the user for confirmation.
    AbstractFile destFile = ExtensionManager.getExtensionsFile(library.getName());
    int collision = FileCollisionChecker.checkForCollision(library, destFile);
    if (collision != FileCollisionChecker.NO_COLLISION) {
        // Do not offer the multiple files mode options such as 'skip' and 'apply to all'
        DialogAction action = new FileCollisionDialog(parent, parent, collision, library, destFile, false, false).getActionValue();
        // User chose to overwrite the file
        if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
        // Simply continue and file will be overwritten
        } else if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_OLDER) {
            // Overwrite if the source is more recent than the destination
            if (library.getDate() <= destFile.getDate()) {
                return false;
            }
        // Simply continue and file will be overwritten
        } else if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_SIZE_DIFFERS) {
            // Overwrite if the source and target file size differs
            if (library.getSize() == destFile.getSize()) {
                return false;
            }
        // Simply continue and file will be overwritten
        } else // User chose to cancel or closed the dialog
        {
            return false;
        }
    }
    return ExtensionManager.importLibrary(library, true);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileCollisionDialog(com.mucommander.ui.dialog.file.FileCollisionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction)

Example 40 with AbstractFile

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

the class AppearancePanel method importTheme.

/**
 * Imports a new theme in muCommander.
 */
private void importTheme() {
    // Used to select the theme to import.
    JFileChooser chooser;
    // Path to the theme to import.
    AbstractFile file;
    // Initialises the file chooser.
    chooser = createFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new ExtensionFileFilter("xml", Translator.get("prefs_dialog.xml_file")));
    chooser.setDialogTitle(Translator.get("prefs_dialog.import_theme"));
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    if (chooser.showDialog(parent, Translator.get("prefs_dialog.import")) == JFileChooser.APPROVE_OPTION) {
        // Makes sure the file actually exists - JFileChooser apparently doesn't enforce that properly in all look&feels.
        file = FileFactory.getFile(chooser.getSelectedFile().getAbsolutePath());
        lastSelectedFolder = file.getParent();
        if (!file.exists()) {
            InformationDialog.showErrorDialog(this, Translator.get("this_file_does_not_exist", file.getName()));
            return;
        }
        // Imports the theme and makes sure it appears in the combobox.
        try {
            insertTheme(ThemeManager.importTheme((java.io.File) file.getUnderlyingFileObject()));
        }// Notifies the user that something went wrong.
         catch (Exception ex) {
            InformationDialog.showErrorDialog(this, Translator.get("prefs_dialog.error_in_import", file.getName()));
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) JFileChooser(javax.swing.JFileChooser) AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException)

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