Search in sources :

Example 11 with FileTable

use of com.mucommander.ui.main.table.FileTable in project mucommander by mucommander.

the class FileSelectionDialog method actionPerformed.

// //////////////////////////
// ActionListener methods //
// //////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    FileTable activeTable = mainFrame.getActiveTable();
    // Action coming from the selection dialog
    if ((source == okButton || source == selectionField)) {
        // Save values for next time this dialog is invoked
        caseSensitive = caseSensitiveCheckBox.isSelected();
        includeFolders = includeFoldersCheckBox.isSelected();
        comparison = comparisonComboBox.getSelectedIndex();
        String testString;
        keywordString = selectionField.getText();
        if (comparison != REGEXP) {
            // Remove '*' characters
            testString = keywordString.replace("*", "");
        } else {
            testString = keywordString;
        }
        // Instantiate the main file filter
        FileFilter filter;
        switch(comparison) {
            case CONTAINS:
                filter = new ContainsFilenameFilter(testString, caseSensitive);
                break;
            case STARTS_WITH:
                filter = new StartsWithFilenameFilter(testString, caseSensitive);
                break;
            case ENDS_WIDTH:
                filter = new EndsWithFilenameFilter(testString, caseSensitive);
                break;
            case IS:
                filter = new EqualsFilenameFilter(testString, caseSensitive);
                break;
            case REGEXP:
            default:
                try {
                    filter = new RegexpFilenameFilter(testString, caseSensitive);
                } catch (PatternSyntaxException ex) {
                    // Todo: let the user know the regexp is invalid
                    LOGGER.debug("Invalid regexp", ex);
                    // This filter does match any file
                    filter = new PassThroughFileFilter(false);
                }
                break;
        }
        // If folders are excluded, add a regular file filter and chain it with an AndFileFilter
        if (!includeFolders) {
            filter = new AndFileFilter(new AttributeFileFilter(FileAttribute.FILE), filter);
        }
        // Mark/unmark the files using the filter
        activeTable.getFileTableModel().setFilesMarked(filter, addToSelection);
        // Notify registered listeners that currently marked files have changed on this FileTable
        activeTable.fireMarkedFilesChangedEvent();
        activeTable.repaint();
    }
    dispose();
}
Also used : AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileTable(com.mucommander.ui.main.table.FileTable) EndsWithFilenameFilter(com.mucommander.commons.file.filter.EndsWithFilenameFilter) ContainsFilenameFilter(com.mucommander.commons.file.filter.ContainsFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) StartsWithFilenameFilter(com.mucommander.commons.file.filter.StartsWithFilenameFilter) RegexpFilenameFilter(com.mucommander.commons.file.filter.RegexpFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 12 with FileTable

use of com.mucommander.ui.main.table.FileTable in project mucommander by mucommander.

the class FileJob method run.

// ///////////////////////////
// Runnable implementation //
// ///////////////////////////
/**
 * This method is public as a side-effect of this class implementing <code>Runnable</code>.
 */
public final void run() {
    FileTable activeTable = getMainFrame().getActiveTable();
    // Notify that this job has started
    jobStarted();
    // Loop on all source files, checking that job has not been interrupted
    for (currentFileIndex = 0; currentFileIndex < nbFiles; currentFileIndex++) {
        AbstractFile currentFile = files.elementAt(currentFileIndex);
        // Change current file and advance file index
        nextFile(currentFile);
        // Process current file
        boolean success = processFile(currentFile, null);
        // Stop if job was interrupted
        if (getState() == FileJobState.INTERRUPTED)
            break;
        // and file was processed successfully
        if (autoUnmark && success) {
            // Do not repaint rows individually as it would be too expensive
            activeTable.setFileMarked(currentFile, false, false);
        }
    }
    // without errors, switch to FINISHED state and notify listeners
    if (currentFileIndex == nbFiles && getState() != FileJobState.INTERRUPTED) {
        stop();
        jobCompleted();
        setState(FileJobState.FINISHED);
    }
    // Refresh tables's current folders, based on the job's refresh policy.
    refreshTables();
    JobsManager.getInstance().jobEnded(this);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileTable(com.mucommander.ui.main.table.FileTable)

Example 13 with FileTable

use of com.mucommander.ui.main.table.FileTable in project mucommander by mucommander.

the class MainMenuBar method menuSelected.

// ////////////////////////
// MenuListener methods //
// ////////////////////////
public void menuSelected(MenuEvent e) {
    Object source = e.getSource();
    if (source == viewMenu) {
        FileTable activeTable = mainFrame.getActiveTable();
        // Select the 'sort by' criterion currently in use in the active table
        sortByItems[activeTable.getSortInfo().getCriterion().ordinal()].setSelected(true);
        toggleShowFoldersFirstItem.setSelected(activeTable.getSortInfo().getFoldersFirst());
        toggleShowHiddenFilesItem.setSelected(MuConfigurations.getPreferences().getVariable(MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES));
        toggleTreeItem.setSelected(activeTable.getFolderPanel().isTreeVisible());
        toggleToggleAutoSizeItem.setSelected(mainFrame.isAutoSizeColumnsEnabled());
        toggleUseSinglePanel.setSelected(mainFrame.isSinglePanel());
    /* TODO branch toggleBranchView.setSelected(activeTable.getFolderPanel().isBranchView()); */
    } else if (source == columnsMenu) {
        // Update the selected and enabled state of each column menu item.
        FileTable activeTable = mainFrame.getActiveTable();
        for (Column c : Column.values()) {
            if (// Name column doesn't have a menu item as it cannot be disabled
            c == Column.NAME)
                continue;
            JCheckBoxMenuItem item = toggleColumnItems[c.ordinal()];
            item.setSelected(activeTable.isColumnEnabled(c));
            item.setEnabled(activeTable.isColumnDisplayable(c));
            // Override the action's label to a shorter one
            item.setText(c.getLabel());
        }
    } else if (source == goMenu) {
        // as they might have changed since menu was last selected
        for (int i = goMenu.getItemCount(); i > volumeOffset; i--) goMenu.remove(volumeOffset);
        AbstractFile[] volumes = LocalFile.getVolumes();
        int nbFolders = volumes.length;
        for (int i = 0; i < nbFolders; i++) goMenu.add(new OpenLocationAction(mainFrame, new Hashtable<String, Object>(), volumes[i]));
    } else if (source == bookmarksMenu) {
        // as bookmarks might have changed since menu was last selected
        for (int i = bookmarksMenu.getItemCount(); i > bookmarksOffset; i--) bookmarksMenu.remove(bookmarksOffset);
        // Add bookmarks menu items
        java.util.List<Bookmark> bookmarks = BookmarkManager.getBookmarks();
        int nbBookmarks = bookmarks.size();
        if (nbBookmarks > 0) {
            for (int i = 0; i < nbBookmarks; i++) MenuToolkit.addMenuItem(bookmarksMenu, new OpenLocationAction(mainFrame, new Hashtable<String, Object>(), bookmarks.get(i)), null);
        } else {
            // Show 'No bookmark' as a disabled menu item instead showing nothing
            JMenuItem noBookmarkItem = MenuToolkit.addMenuItem(bookmarksMenu, Translator.get("bookmarks_menu.no_bookmark"), null, null, null);
            noBookmarkItem.setEnabled(false);
        }
    } else if (source == windowMenu) {
        // Select the split orientation currently in use
        if (mainFrame.getSplitPaneOrientation())
            splitVerticallyItem.setSelected(true);
        else
            splitHorizontallyItem.setSelected(true);
        // menu has been deselected.
        for (int i = windowMenu.getItemCount(); i > windowOffset; i--) windowMenu.remove(windowOffset);
        // This WeakHashMap maps menu items to frame instances. It has to be a weakly referenced hash map
        // and not a regular hash map, since it will not (and cannot) be emptied when the menu has been deselected
        // and we really do not want this hash map to prevent the frames to be GCed
        windowMenuFrames = new WeakHashMap<JMenuItem, Frame>();
        // Create a menu item for each of the MainFrame instances, that displays the MainFrame's path
        // and a keyboard accelerator to recall the frame (for the first 10 frames only).
        java.util.List<MainFrame> mainFrames = WindowManager.getMainFrames();
        MainFrame mainFrame;
        JCheckBoxMenuItem checkBoxMenuItem;
        int nbFrames = mainFrames.size();
        for (int i = 0; i < nbFrames; i++) {
            mainFrame = mainFrames.get(i);
            checkBoxMenuItem = new JCheckBoxMenuItem();
            // If frame number is less than 10, use the corresponding action class (accelerator will be displayed in the menu item)
            MuAction recallWindowAction;
            if (i < 10) {
                recallWindowAction = ActionManager.getActionInstance(RECALL_WINDOW_ACTION_IDS[i], this.mainFrame);
            } else // Else use the generic RecallWindowAction
            {
                Hashtable<String, Object> actionProps = new Hashtable<String, Object>();
                // Specify the window number using the dedicated property
                actionProps.put(RecallWindowAction.WINDOW_NUMBER_PROPERTY_KEY, "" + (i + 1));
                recallWindowAction = ActionManager.getActionInstance(new ActionParameters(RecallWindowAction.Descriptor.ACTION_ID, actionProps), this.mainFrame);
            }
            checkBoxMenuItem.setAction(recallWindowAction);
            // Replace the action's label and use the MainFrame's current folder path instead
            checkBoxMenuItem.setText((i + 1) + " " + mainFrame.getActiveTable().getFolderPanel().getCurrentFolder().getAbsolutePath());
            // Use the action's label as a tooltip
            checkBoxMenuItem.setToolTipText(recallWindowAction.getLabel());
            // Check current MainFrame (the one this menu bar belongs to)
            checkBoxMenuItem.setSelected(mainFrame == this.mainFrame);
            windowMenu.add(checkBoxMenuItem);
        }
        // Add 'other' (non-MainFrame) windows : viewer and editor frames, no associated accelerator
        Frame[] frames = Frame.getFrames();
        nbFrames = frames.length;
        Frame frame;
        JMenuItem menuItem;
        boolean firstFrame = true;
        for (int i = 0; i < nbFrames; i++) {
            frame = frames[i];
            // Test if Frame is not hidden (disposed), Frame.getFrames() returns both active and disposed frames
            if (frame.isShowing() && (frame instanceof FileFrame)) {
                // and other frames
                if (firstFrame) {
                    windowMenu.add(new JSeparator());
                    firstFrame = false;
                }
                // Use frame's window title
                menuItem = new JMenuItem(frame.getTitle());
                menuItem.addActionListener(this);
                windowMenu.add(menuItem);
                windowMenuFrames.put(menuItem, frame);
            }
        }
    } else if (source == themesMenu) {
        // Remove all previous theme items, create new ones for each available theme and select the current theme
        themesMenu.removeAll();
        ButtonGroup buttonGroup = new ButtonGroup();
        Iterator<Theme> themes = ThemeManager.availableThemes();
        Theme theme;
        JCheckBoxMenuItem item;
        themesMenu.add(new JMenuItem(new EditCurrentThemeAction()));
        themesMenu.add(new JSeparator());
        while (themes.hasNext()) {
            theme = themes.next();
            item = new JCheckBoxMenuItem(new ChangeCurrentThemeAction(theme));
            buttonGroup.add(item);
            if (ThemeManager.isCurrentTheme(theme))
                item.setSelected(true);
            themesMenu.add(item);
        }
    }
}
Also used : FileFrame(com.mucommander.ui.viewer.FileFrame) MainFrame(com.mucommander.ui.main.MainFrame) Frame(java.awt.Frame) AbstractFile(com.mucommander.commons.file.AbstractFile) FileTable(com.mucommander.ui.main.table.FileTable) MainFrame(com.mucommander.ui.main.MainFrame) JSeparator(javax.swing.JSeparator) Column(com.mucommander.ui.main.table.Column) Iterator(java.util.Iterator) MuAction(com.mucommander.ui.action.MuAction) JMenuItem(javax.swing.JMenuItem) Hashtable(java.util.Hashtable) FileFrame(com.mucommander.ui.viewer.FileFrame) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ActionParameters(com.mucommander.ui.action.ActionParameters) ButtonGroup(javax.swing.ButtonGroup) Theme(com.mucommander.ui.theme.Theme) OpenLocationAction(com.mucommander.ui.action.impl.OpenLocationAction)

Example 14 with FileTable

use of com.mucommander.ui.main.table.FileTable in project mucommander by mucommander.

the class StatusBar method updateSelectedFilesInfo.

/**
 * Updates info about currently selected files ((nb of selected files, combined size), displayed on the left-side of this status bar.
 */
// Making this method synchronized creates a deadlock with FileTable
// public synchronized void updateSelectedFilesInfo() {
public void updateSelectedFilesInfo() {
    // No need to waste precious cycles if status bar is not visible
    if (!isVisible())
        return;
    FileTable currentFileTable = mainFrame.getActiveTable();
    // Currently select file, can be null
    AbstractFile selectedFile = currentFileTable.getSelectedFile(false, true);
    FileTableModel tableModel = currentFileTable.getFileTableModel();
    // Number of marked files, can be 0
    int nbMarkedFiles = tableModel.getNbMarkedFiles();
    // Combined size of marked files, 0 if no file has been marked
    long markedTotalSize = tableModel.getTotalMarkedSize();
    // number of files in folder
    int fileCount = tableModel.getFileCount();
    // Update files info based on marked files if there are some, or currently selected file otherwise
    int nbSelectedFiles;
    if (nbMarkedFiles == 0 && selectedFile != null)
        nbSelectedFiles = 1;
    else
        nbSelectedFiles = nbMarkedFiles;
    String filesInfo;
    if (fileCount == 0) {
        // Set status bar to a space character, not an empty string
        // otherwise it will disappear
        filesInfo = " ";
    } else {
        filesInfo = Translator.get("status_bar.selected_files", "" + nbSelectedFiles, "" + fileCount);
        if (nbMarkedFiles > 0)
            filesInfo += " - " + SizeFormat.format(markedTotalSize, selectedFileSizeFormat);
        if (selectedFile != null)
            filesInfo += " - " + selectedFile.getName();
    }
    // Update label
    setStatusInfo(filesInfo);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileTableModel(com.mucommander.ui.main.table.FileTableModel) FileTable(com.mucommander.ui.main.table.FileTable)

Example 15 with FileTable

use of com.mucommander.ui.main.table.FileTable in project mucommander by mucommander.

the class FocusPreviousAction method performAction.

@Override
public void performAction() {
    Component focusOwner = mainFrame.getFocusOwner();
    // Abort if the focus is not in the MainFrame this action is tied to
    if (focusOwner == null)
        return;
    FolderPanel folderPanel = mainFrame.getActivePanel();
    FileTable fileTable = folderPanel.getFileTable();
    JTextField locationField = folderPanel.getLocationTextField();
    JTree tree = folderPanel.getFoldersTreePanel().getTree();
    // Request focus on the 'previous' component, the cycle order being from right to left, bottom to top.
    Component previousComponent;
    if (focusOwner == fileTable)
        previousComponent = folderPanel.isTreeVisible() ? tree : locationField;
    else if (focusOwner == tree)
        previousComponent = locationField;
    else if (focusOwner == locationField)
        previousComponent = fileTable;
    else
        return;
    FocusRequester.requestFocusInWindow(previousComponent);
}
Also used : JTree(javax.swing.JTree) FileTable(com.mucommander.ui.main.table.FileTable) Component(java.awt.Component) JTextField(javax.swing.JTextField) FolderPanel(com.mucommander.ui.main.FolderPanel)

Aggregations

FileTable (com.mucommander.ui.main.table.FileTable)25 AbstractFile (com.mucommander.commons.file.AbstractFile)10 FileTableModel (com.mucommander.ui.main.table.FileTableModel)8 FolderPanel (com.mucommander.ui.main.FolderPanel)3 MainFrame (com.mucommander.ui.main.MainFrame)2 TablePopupMenu (com.mucommander.ui.main.menu.TablePopupMenu)2 Component (java.awt.Component)2 Rectangle (java.awt.Rectangle)2 JTextField (javax.swing.JTextField)2 JTree (javax.swing.JTree)2 AbstractFilenameFilter (com.mucommander.commons.file.filter.AbstractFilenameFilter)1 AndFileFilter (com.mucommander.commons.file.filter.AndFileFilter)1 AttributeFileFilter (com.mucommander.commons.file.filter.AttributeFileFilter)1 ContainsFilenameFilter (com.mucommander.commons.file.filter.ContainsFilenameFilter)1 EndsWithFilenameFilter (com.mucommander.commons.file.filter.EndsWithFilenameFilter)1 EqualsFilenameFilter (com.mucommander.commons.file.filter.EqualsFilenameFilter)1 ExtensionFilenameFilter (com.mucommander.commons.file.filter.ExtensionFilenameFilter)1 FileFilter (com.mucommander.commons.file.filter.FileFilter)1 FilenameFilter (com.mucommander.commons.file.filter.FilenameFilter)1 PassThroughFileFilter (com.mucommander.commons.file.filter.PassThroughFileFilter)1