Search in sources :

Example 1 with BonjourMenu

use of com.mucommander.bonjour.BonjourMenu 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)

Aggregations

BonjourMenu (com.mucommander.bonjour.BonjourMenu)1 BonjourService (com.mucommander.bonjour.BonjourService)1 Bookmark (com.mucommander.bookmark.Bookmark)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 Icon (javax.swing.Icon)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1