Search in sources :

Example 31 with MenuItem

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);
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) PluginManager(com.biglybt.pif.PluginManager) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 32 with MenuItem

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();
        }
    });
}
Also used : ActivitiesListener(com.biglybt.activities.ActivitiesListener) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryCreationListener(com.biglybt.ui.mdi.MdiEntryCreationListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) ArrayList(java.util.ArrayList) List(java.util.List) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Aggregations

MenuItem (com.biglybt.pif.ui.menus.MenuItem)32 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)19 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)11 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)9 UIFunctions (com.biglybt.ui.UIFunctions)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 Download (com.biglybt.pif.download.Download)7 UIManager (com.biglybt.pif.ui.UIManager)7 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)7 List (java.util.List)7 UIInstance (com.biglybt.pif.ui.UIInstance)6 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)6 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)5 URL (java.net.URL)5 DownloadManager (com.biglybt.core.download.DownloadManager)4 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)4 UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)4