Search in sources :

Example 1 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class AddBookmarkDialog method actionPerformed.

// /////////////////////////
// ActionListener method //
// /////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == addButton) {
        // Starts by disposing the dialog
        dispose();
        // Add bookmark and write bookmarks file to disk
        BookmarkManager.addBookmark(new Bookmark(nameField.getText(), locationField.getText()));
        try {
            BookmarkManager.writeBookmarks(false);
        }// We should probably pop an error dialog here.
         catch (Exception e2) {
        }
    } else if (source == cancelButton) {
        dispose();
    }
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Example 2 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class DrivePopupButton method getPopupMenu.

// //////////////////////////////
// PopupButton implementation //
// //////////////////////////////
@Override
public JPopupMenu getPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();
    // Update the list of volumes in case new ones were mounted
    volumes = getDisplayableVolumes();
    // Add volumes
    int nbVolumes = volumes.length;
    final MainFrame mainFrame = folderPanel.getMainFrame();
    // Provides mnemonics and ensures uniqueness
    MnemonicHelper mnemonicHelper = new MnemonicHelper();
    JMenuItem item;
    MuAction action;
    String volumeName;
    boolean useExtendedDriveNames = fileSystemView != null;
    ArrayList<JMenuItem> itemsV = new ArrayList<JMenuItem>();
    for (int i = 0; i < nbVolumes; i++) {
        action = new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), volumes[i]);
        volumeName = volumes[i].getName();
        // volume's path, to disambiguate
        for (int j = 0; j < nbVolumes; j++) {
            if (j != i && volumes[j].getName().equalsIgnoreCase(volumeName)) {
                action.setLabel(volumes[i].getAbsolutePath());
                break;
            }
        }
        item = popupMenu.add(action);
        setMnemonic(item, mnemonicHelper);
        // Set icon from cache
        Icon icon = iconCache.get(volumes[i]);
        if (icon != null) {
            item.setIcon(icon);
        }
        if (useExtendedDriveNames) {
            // Use the last known value (if any) while we update it in a separate thread
            String previousExtendedName = extendedNameCache.get(volumes[i]);
            if (previousExtendedName != null)
                item.setText(previousExtendedName);
        }
        // JMenu offers no way to retrieve a particular JMenuItem, so we have to keep them
        itemsV.add(item);
    }
    new RefreshDriveNamesAndIcons(popupMenu, itemsV).start();
    popupMenu.add(new JSeparator());
    // Add boookmarks
    java.util.List<Bookmark> bookmarks = BookmarkManager.getBookmarks();
    if (!bookmarks.isEmpty()) {
        for (Bookmark bookmark : bookmarks) {
            item = popupMenu.add(new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), bookmark));
            setMnemonic(item, mnemonicHelper);
        }
    } else {
        // No bookmark : add a disabled menu item saying there is no bookmark
        popupMenu.add(Translator.get("bookmarks_menu.no_bookmark")).setEnabled(false);
    }
    popupMenu.add(new JSeparator());
    // Add 'Network shares' shortcut
    if (FileFactory.isRegisteredProtocol(FileProtocols.SMB)) {
        action = new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), new Bookmark(Translator.get("drive_popup.network_shares"), "smb:///"));
        action.setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.NETWORK_ICON_NAME));
        setMnemonic(popupMenu.add(action), mnemonicHelper);
    }
    // Add Bonjour services menu
    setMnemonic(popupMenu.add(new BonjourMenu() {

        @Override
        public MuAction getMenuItemAction(BonjourService bs) {
            return new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), bs);
        }
    }), mnemonicHelper);
    popupMenu.add(new JSeparator());
    // Add 'connect to server' shortcuts
    schemaToPanelProvider.values().stream().sorted(Comparator.comparing(ProtocolPanelProvider::priority)).map(this::toServerConnectAction).map(popupMenu::add).forEach(menuItem -> setMnemonic(menuItem, mnemonicHelper));
    return popupMenu;
}
Also used : Hashtable(java.util.Hashtable) ProtocolPanelProvider(com.mucommander.protocol.ui.ProtocolPanelProvider) ArrayList(java.util.ArrayList) MnemonicHelper(com.mucommander.commons.util.ui.helper.MnemonicHelper) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) Bookmark(com.mucommander.bookmark.Bookmark) BonjourService(com.mucommander.bonjour.BonjourService) MuAction(com.mucommander.ui.action.MuAction) BonjourMenu(com.mucommander.bonjour.BonjourMenu) Icon(javax.swing.Icon) JMenuItem(javax.swing.JMenuItem)

Example 3 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class DrivePopupButton method updateButton.

/**
 * Updates the button's label and icon to reflect the current folder and match one of the current volumes: <
 * <ul>
 * <li>If the specified folder corresponds to a bookmark, the bookmark's name will be displayed
 * <li>If the specified folder corresponds to a local file, the enclosing volume's name will be displayed
 * <li>If the specified folder corresponds to a remote file, the protocol's name will be displayed
 * </ul>
 * The button's icon will be the current folder's one.
 */
private void updateButton() {
    AbstractFile currentFolder = folderPanel.getCurrentFolder();
    String currentPath = currentFolder.getAbsolutePath();
    FileURL currentURL = currentFolder.getURL();
    // First try to find a bookmark matching the specified folder
    for (Bookmark bookmark : BookmarkManager.getBookmarks()) {
        if (currentPath.equals(bookmark.getLocation())) {
            // Note: if several bookmarks match current folder, the first one will be used
            setText(bookmark.getName());
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.BOOKMARK_ICON_NAME));
            return;
        }
    }
    // If no bookmark matched current folder
    String protocol = currentURL.getScheme();
    switch(protocol) {
        // Local file, use volume's name
        case LocalFile.SCHEMA:
            String newLabel = null;
            // display 'SMB' which is the underlying protocol
            if (OsFamily.WINDOWS.isCurrent() && !FileURL.LOCALHOST.equals(currentURL.getHost())) {
                newLabel = "SMB";
            } else {
                if (OsFamily.WINDOWS.isCurrent())
                    currentPath = currentFolder.getAbsolutePath(false).toLowerCase();
                else
                    currentPath = currentFolder.getCanonicalPath(false).toLowerCase();
                int bestLength = -1;
                int bestIndex = 0;
                String temp;
                int len;
                for (int i = 0; i < volumes.length; i++) {
                    if (OsFamily.WINDOWS.isCurrent())
                        temp = volumes[i].getAbsolutePath(false).toLowerCase();
                    else
                        temp = volumes[i].getCanonicalPath(false).toLowerCase();
                    len = temp.length();
                    if (currentPath.startsWith(temp) && len > bestLength) {
                        bestIndex = i;
                        bestLength = len;
                    }
                }
                newLabel = volumes[bestIndex].getName();
            // Not used because the call to FileSystemView is slow
            // if(fileSystemView!=null)
            // newToolTip = getWindowsExtendedDriveName(volumes[bestIndex]);
            }
            setText(newLabel);
            setIcon(FileIcons.getFileIcon(currentFolder));
            break;
        case BookmarkProtocolProvider.BOOKMARK:
            String currentFolderName = currentFolder.getName();
            setText(currentFolderName.isEmpty() ? Translator.get("bookmarks_menu") : currentFolderName);
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.BOOKMARKS_ICON_NAME));
            break;
        case SearchFile.SCHEMA:
            setText(Translator.get("find"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.FIND_RESULT_ICON_NAME));
            break;
        case "gdrive":
            setText(Translator.get("gdrive"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.GOOGLE_DRIVE_ICON_NAME));
            break;
        case "dropbox":
            setText(Translator.get("dropbox"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.DROPBOX_ICON_NAME));
            break;
        default:
            // Remote file, use the protocol's name
            setText(protocol.toUpperCase());
            setIcon(FileIcons.getFileIcon(currentFolder));
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) Bookmark(com.mucommander.bookmark.Bookmark)

Example 4 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class CustomFileIconProvider method getFileIcon.

// ///////////////////////////////////
// FileIconProvider implementation //
// ///////////////////////////////////
public Icon getFileIcon(AbstractFile file, Dimension preferredResolution) {
    // Call init, if not done already
    if (!initialized)
        init();
    // If file is a symlink, get the linked file's icon and paint a semi-transparent symbolic icon on top of it
    boolean isSymlink = file.isSymlink();
    if (isSymlink)
        file = file.getCanonicalFile();
    if (BookmarkManager.isBookmark(file.getURL())) {
        for (Bookmark bookmark : BookmarkManager.getBookmarks()) {
            if (file.getName().equals(bookmark.getName())) {
                // Note: if several bookmarks match current folder, the first one will be used
                file = FileFactory.getFile(bookmark.getLocation());
                break;
            }
        }
    }
    if (file == null)
        return IconManager.getIcon(IconManager.FILE_ICON_SET, DISCONNECTED_ICON_NAME);
    ImageIcon icon;
    // Retrieve the file's extension, null if the file has no extension
    String fileExtension = file.getExtension();
    if (!file.exists()) {
        icon = IconManager.getIcon(IconManager.FILE_ICON_SET, DISCONNECTED_ICON_NAME);
    } else // Special icon for the root of remote (non-local) locations
    if (!LocalFile.SCHEMA.equals(file.getURL().getScheme()) && file.isRoot()) {
        icon = IconManager.getIcon(IconManager.FILE_ICON_SET, NETWORK_ICON_NAME);
    } else // If file is a directory, use folder icon. One exception is made for 'app' extension under MAC OS
    if (file.isDirectory()) {
        // Mac OS X application are directories with the .app extension and have a dedicated icon
        if (fileExtension != null && fileExtension.equals("app"))
            icon = IconManager.getIcon(IconManager.FILE_ICON_SET, MAC_OS_APP_ICON_NAME);
        else
            // Default folder icon
            icon = IconManager.getIcon(IconManager.FILE_ICON_SET, FOLDER_ICON_NAME);
    } else // If the file is browsable (supported archive or other), use an icon symbolizing an archive
    if (file.isBrowsable()) {
        icon = IconManager.getIcon(IconManager.FILE_ICON_SET, ARCHIVE_ICON_NAME);
    } else // Regular file icon
    {
        // Determine if the file's extension has an associated icon
        if (fileExtension == null)
            // File has no extension, use default file icon
            icon = IconManager.getIcon(IconManager.FILE_ICON_SET, FILE_ICON_NAME);
        else {
            // Compare extension against lower-cased extensions
            String iconName = extensionMap.get(fileExtension.toLowerCase());
            if (// No icon associated to extension, use default file icon
            iconName == null)
                icon = IconManager.getIcon(IconManager.FILE_ICON_SET, FILE_ICON_NAME);
            else {
                // Retrieves the cached (or freshly loaded if not in cache already) ImageIcon instance corresponding to the icon's name
                icon = IconManager.getIcon(IconManager.FILE_ICON_SET, iconName);
                // Returned IconImage should never be null, but if it is (icon file missing), return default file icon
                if (icon == null)
                    return IconManager.getIcon(IconManager.FILE_ICON_SET, FILE_ICON_NAME);
            }
        }
    }
    // If file is a symlink, paint a semi-transparent symbolic icon over the linked file's icon
    if (isSymlink)
        return getSymlinkIcon(icon);
    return icon;
}
Also used : ImageIcon(javax.swing.ImageIcon) Bookmark(com.mucommander.bookmark.Bookmark)

Example 5 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class BookmarkFile method copyRemotelyTo.

// - Bookmark duplication --------------------------------------------------
// -------------------------------------------------------------------------
/**
 * Tries to copy the bookmark to the specified destination.
 * <p>
 * If the specified destination is an instance of <code>BookmarkFile</code>,
 * this will duplicate the bookmark. Otherwise, this method will fail.
 * </p>
 * @param  destination           where to copy the bookmark to.
 * @throws FileTransferException if the specified destination is not an instance of <code>BookmarkFile</code>.
 */
@Override
public void copyRemotelyTo(AbstractFile destination) throws IOException {
    // Makes sure we're working with a bookmark.
    destination = destination.getTopAncestor();
    if (!(destination instanceof BookmarkFile))
        throw new IOException();
    // Copies this bookmark to the specified destination.
    BookmarkManager.addBookmark(new Bookmark(destination.getName(), bookmark.getLocation()));
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Aggregations

Bookmark (com.mucommander.bookmark.Bookmark)10 AbstractFile (com.mucommander.commons.file.AbstractFile)2 BonjourMenu (com.mucommander.bonjour.BonjourMenu)1 BonjourService (com.mucommander.bonjour.BonjourService)1 FileURL (com.mucommander.commons.file.FileURL)1 MnemonicHelper (com.mucommander.commons.util.ui.helper.MnemonicHelper)1 ProtocolPanelProvider (com.mucommander.protocol.ui.ProtocolPanelProvider)1 MuAction (com.mucommander.ui.action.MuAction)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1