use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class MenuBuildUtils method addChatSelectionMenu.
public static void addChatSelectionMenu(final MenuManager menu_manager, final MenuItem chat_item, String existing_chat, ChatSelectionListener _listener) {
ChatSelectionListener listener = new ChatSelectionDelegator(_listener);
chat_item.setStyle(MenuItem.STYLE_MENU);
chat_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.removeAllChildItems();
MenuItem create_menu = menu_manager.addMenuItem(chat_item, "chat.view.create.chat");
create_menu.setStyle(MenuItem.STYLE_MENU);
BuddyUIUtils.createChat(menu_manager, create_menu, true, new BuddyUIUtils.ChatCreationListener() {
@Override
public void chatCreated(Object target, String name) {
listener.chatSelected(target, name);
}
@Override
public void chatAvailable(Object target, ChatInstance chat) {
listener.chatAvailable(target, chat);
}
});
MenuItem mi = menu_manager.addMenuItem(chat_item, "sep");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
List<ChatInstance> chats = BuddyPluginUtils.getChats();
for (int i = 0; i < 2; i++) {
MenuItem chat_menu = menu_manager.addMenuItem(chat_item, i == 0 ? "label.public" : "label.anon");
chat_menu.setStyle(MenuItem.STYLE_MENU);
String net = i == 0 ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P;
for (ChatInstance chat : chats) {
if (chat.getNetwork() == net) {
mi = menu_manager.addMenuItem(chat_menu, "!" + chat.getKey() + "!");
mi.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
listener.chatSelected(target, chat.getNetAndKey());
listener.chatAvailable(target, chat);
try {
BuddyPluginUtils.getBetaPlugin().showChat(chat);
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
}
}
}
});
}
use of com.biglybt.pif.ui.menus.MenuItemListener in project BiglyBT by BiglySoftware.
the class TagUIUtils method setupSideBarMenus.
public static void setupSideBarMenus(final MenuManager menuManager) {
// show tags in sidebar
{
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "ConfigView.section.style.TagInSidebar");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
boolean b = COConfigurationManager.getBooleanParameter("Library.TagInSideBar");
COConfigurationManager.setParameter("Library.TagInSideBar", !b);
}
});
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(COConfigurationManager.getBooleanParameter("Library.TagInSideBar")));
}
});
}
// show tag groups
{
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "! " + MessageText.getString("ConfigView.section.style.TagGroupsInSidebar") + "!");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
boolean b = COConfigurationManager.getBooleanParameter("Library.TagGroupsInSideBar");
COConfigurationManager.setParameter("Library.TagGroupsInSideBar", !b);
}
});
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(COConfigurationManager.getBooleanParameter("Library.TagGroupsInSideBar")));
menu.setEnabled(COConfigurationManager.getBooleanParameter("Library.TagInSideBar"));
}
});
}
// tag options
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, "label.tags");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
// manual
final TagType manual_tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, manual_tt.getTagTypeName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
final List<Tag> all_tags = manual_tt.getTags();
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
boolean all_visible = true;
boolean all_invisible = true;
boolean has_ut = false;
for (Tag t : all_tags) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
if (t.isVisible()) {
all_invisible = false;
} else {
all_visible = false;
}
TagFeatureProperties props = (TagFeatureProperties) t;
TagProperty prop = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
if (prop != null) {
Boolean b = prop.getBoolean();
if (b != null && b) {
has_ut = true;
}
}
}
com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : all_tags) {
t.setVisible(true);
}
}
});
com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : all_tags) {
t.setVisible(false);
}
}
});
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sepm");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
showAllItem.setEnabled(!all_visible);
hideAllItem.setEnabled(!all_invisible);
List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
for (Object obj : menu_structure) {
List<Tag> bucket_tags = new ArrayList<>();
com.biglybt.pif.ui.menus.MenuItem parent_menu;
if (obj instanceof String) {
parent_menu = menu;
bucket_tags.add(menu_name_map.get((String) obj));
} else {
Object[] entry = (Object[]) obj;
List<String> tag_names = (List<String>) entry[1];
boolean sub_all_visible = true;
boolean sub_some_visible = false;
for (String name : tag_names) {
Tag tag = menu_name_map.get(name);
if (tag.isVisible()) {
sub_some_visible = true;
} else {
sub_all_visible = false;
}
bucket_tags.add(tag);
}
String mod;
if (sub_all_visible) {
mod = " (*)";
} else if (sub_some_visible) {
mod = " (+)";
} else {
mod = "";
}
parent_menu = menuManager.addMenuItem(menu, "!" + (String) entry[0] + mod + "!");
parent_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
}
for (final Tag tag : bucket_tags) {
com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(parent_menu, tag.getTagName(false));
m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
m.setData(Boolean.valueOf(tag.isVisible()));
setMenuIcon(m, tag);
m.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
tag.setVisible(!tag.isVisible());
}
});
}
}
if (!has_ut) {
sepItem = menuManager.addMenuItem(menu, "sepu");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
com.biglybt.pif.ui.menus.MenuItem m = menuManager.addMenuItem(menu, "label.untagged");
m.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
m.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
try {
String tag_name = MessageText.getString("label.untagged");
Tag ut_tag = manual_tt.getTag(tag_name, true);
if (ut_tag == null) {
ut_tag = manual_tt.createTag(tag_name, true);
}
TagFeatureProperties tp = (TagFeatureProperties) ut_tag;
tp.getProperty(TagFeatureProperties.PR_UNTAGGED).setBoolean(true);
} catch (TagException e) {
Debug.out(e);
}
}
});
}
}
});
menuItem = menuManager.addMenuItem(menu, "label.add.tag");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
createManualTag(null);
}
});
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep1");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
// auto
menuItem = menuManager.addMenuItem(menu, "wizard.maketorrent.auto");
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
// autos
List<TagType> tag_types = TagManagerFactory.getTagManager().getTagTypes();
for (final TagType tag_type : tag_types) {
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_CATEGORY) {
continue;
}
if (!tag_type.isTagTypeAuto()) {
continue;
}
if (tag_type.getTags().size() == 0) {
continue;
}
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, tag_type.getTagTypeName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.removeAllChildItems();
final List<Tag> tags = tag_type.getTags();
com.biglybt.pif.ui.menus.MenuItem showAllItem = menuManager.addMenuItem(menu, "label.show.all");
showAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
showAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : tags) {
t.setVisible(true);
}
}
});
com.biglybt.pif.ui.menus.MenuItem hideAllItem = menuManager.addMenuItem(menu, "popup.error.hideall");
hideAllItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
hideAllItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
for (Tag t : tags) {
t.setVisible(false);
}
}
});
boolean all_visible = true;
boolean all_invisible = true;
for (Tag t : tags) {
if (t.isVisible()) {
all_invisible = false;
} else {
all_visible = false;
}
}
showAllItem.setEnabled(!all_visible);
hideAllItem.setEnabled(!all_invisible);
com.biglybt.pif.ui.menus.MenuItem sepItem = menuManager.addMenuItem(menu, "sep2");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
for (final Tag t : tags) {
com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(menu, t.getTagName(false));
menuItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK);
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
t.setVisible(menu.isSelected());
}
});
menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
menu.setData(t.isVisible());
}
});
}
}
});
}
}
});
sepItem = menuManager.addMenuItem(menu, "sep3");
sepItem.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
menuItem = menuManager.addMenuItem(menu, "tag.show.stats");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().showEntryByID(StatsView.VIEW_ID, "TagStatsView");
}
});
menuItem = menuManager.addMenuItem(menu, "tag.show.overview");
menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
}
});
}
});
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
checkTagSharing(true);
}
});
}
Aggregations