use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.
the class TabbedMDI method addMenus.
private void addMenus(TabbedEntry entry, String id) {
PluginManager pm = CoreFactory.getSingleton().getPluginManager();
PluginInterface pi = pm.getDefaultPluginInterface();
UIManager uim = pi.getUIManager();
MenuManager menuManager = uim.getMenuManager();
{
if (!Utils.isAZ2UI()) {
MenuItem menuParentItem = menuManager.addMenuItem(id + "._end_", "menu.add.to");
menuParentItem.setStyle(MenuItem.STYLE_MENU);
menuParentItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuParentItem.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
// pick up the right target - due to the confusion of multiple tab instances registering
// the same menu entries the original registerer may well not be the one that should receive the event,
// rather the one specified in the event is
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
}
menu.setVisible(target.canBuildStandAlone());
}
});
MenuItem menuItemDashBoard = menuManager.addMenuItem(menuParentItem, "label.dashboard");
menuItemDashBoard.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
} else if (data instanceof TabbedEntry) {
target = (TabbedEntry) data;
}
MainMDISetup.getSb_dashboard().addItem(target);
}
});
MenuItem menuItemSidebar = menuManager.addMenuItem(menuParentItem, "label.sidebar");
menuItemSidebar.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
} else if (data instanceof TabbedEntry) {
target = (TabbedEntry) data;
}
MainMDISetup.getSb_dashboard().addItemToSidebar(target);
}
});
}
}
{
MenuItem menuParentItem = menuManager.addMenuItem(id + "._end_", "label.pop.out");
menuParentItem.setStyle(MenuItem.STYLE_MENU);
menuParentItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuParentItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
}
menu.setVisible(target.canBuildStandAlone());
}
});
MenuItem menuItemIndependent = menuManager.addMenuItem(menuParentItem, "menu.independent");
MenuItem menuItemOnTop = menuManager.addMenuItem(menuParentItem, "menu.on.top");
com.biglybt.pif.ui.menus.MenuItemListener listener = new com.biglybt.pif.ui.menus.MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
TabbedEntry target = entry;
if (data instanceof Object[]) {
Object[] odata = (Object[]) data;
if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
target = (TabbedEntry) odata[0];
}
} else if (data instanceof TabbedEntry) {
target = (TabbedEntry) data;
}
popoutEntry(target, menu == menuItemOnTop);
}
};
menuItemIndependent.addListener(listener);
menuItemOnTop.addListener(listener);
}
}
use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.
the class SBC_ActivityTableView method setupSidebarEntry.
public static void setupSidebarEntry(final MultipleDocumentInterface mdi) {
// Put TitleInfo in another class
final ViewTitleInfo titleInfoActivityView = new ViewTitleInfo() {
boolean had_unviewed = false;
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
int num_unread = 0;
int num_unviewed = 0;
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
if (!entry.isRead()) {
num_unread++;
}
if (!entry.getViewed()) {
num_unviewed++;
}
}
if (num_unread == 0) {
num_unviewed = 0;
}
boolean has_unviewed = num_unviewed > 0;
if (has_unviewed != had_unviewed) {
if (has_unviewed) {
MdiEntry parent = mdi.getEntry(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE);
if (parent != null && !parent.isExpanded()) {
parent.setExpanded(true);
}
}
had_unviewed = has_unviewed;
}
if (num_unviewed > 0) {
return (String.valueOf(num_unviewed) + (num_unread == 0 ? "" : (":" + num_unread)));
} else if (num_unread > 0) {
return (String.valueOf(num_unread));
}
return null;
} else if (propertyID == TITLE_IMAGEID) {
return "image.sidebar.activity";
} else if (propertyID == TITLE_INDICATOR_COLOR) {
boolean has_unread = false;
boolean has_unviewed = false;
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
if (!entry.isRead()) {
has_unread = true;
}
if (!entry.getViewed()) {
has_unviewed = true;
}
}
if (has_unread && has_unviewed) {
return (COLOR_UNVIEWED_ENTRIES);
}
}
return null;
}
};
activitiesListener = new ActivitiesListener() {
@Override
public void vuzeNewsEntryChanged(ActivitiesEntry entry) {
refresh();
}
@Override
public void vuzeNewsEntriesRemoved(ActivitiesEntry[] entries) {
refresh();
}
@Override
public void vuzeNewsEntriesAdded(ActivitiesEntry[] entries) {
refresh();
}
private void refresh() {
ViewTitleInfoManager.refreshTitleInfo(titleInfoActivityView);
if (mdi_entry != null) {
mdi_entry.redraw();
}
}
};
ActivitiesManager.addListener(activitiesListener);
MdiEntryCreationListener creationListener = new MdiEntryCreationListener() {
@Override
public MdiEntry createMDiEntry(String id) {
mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE, MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "activity", "{sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES + "}", titleInfoActivityView, null, false, null);
return (mdi_entry);
}
};
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, creationListener);
mdi.registerEntry("activities", creationListener);
PluginInterface pi = PluginInitializer.getDefaultInterface();
UIManager uim = pi.getUIManager();
MenuManager menuManager = uim.getMenuManager();
final MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "v3.activity.button.readall");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
entry.setRead(true);
}
}
});
mdi.addListener(new MdiListener() {
@Override
public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
}
@Override
public void mdiDisposed(MultipleDocumentInterface mdi) {
if (activitiesListener != null) {
ActivitiesManager.removeListener(activitiesListener);
activitiesListener = null;
}
menuItem.remove();
}
});
}
Aggregations