use of com.mucommander.bonjour.BonjourService 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;
}
Aggregations