Search in sources :

Example 1 with MdiListener

use of com.biglybt.ui.mdi.MdiListener 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)

Example 2 with MdiListener

use of com.biglybt.ui.mdi.MdiListener in project BiglyBT by BiglySoftware.

the class SBC_GenericBrowsePage method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    Object creationParams = skinObject.getData("CreationParams");
    browserSkinObject = SWTSkinUtils.findBrowserSO(soMain);
    final MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null) {
        entry = mdi.getEntryBySkinView(this);
        if (entry != null) {
            vitalityImage = entry.addVitalityImage("image.sidebar.vitality.dots");
            vitalityImage.setVisible(false);
            mdi.addListener(new MdiListener() {

                long lastSelect = 0;

                @Override
                public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
                    if (entry == newEntry) {
                        if (entry == oldEntry) {
                            if (lastSelect < SystemTime.getOffsetTime(-1000)) {
                                if (browserSkinObject != null) {
                                    browserSkinObject.restart();
                                }
                            }
                        } else {
                            lastSelect = SystemTime.getCurrentTime();
                        }
                    }
                }

                @Override
                public void mdiDisposed(MultipleDocumentInterface mdi) {
                }
            });
        }
    }
    browserSkinObject.addListener(new SWTSkinObjectListener() {

        @Override
        public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
            if (eventType == EVENT_SHOW) {
                browserSkinObject.removeListener(this);
                browserSkinObject.addListener(new BrowserContext.loadingListener() {

                    @Override
                    public void browserLoadingChanged(boolean loading, String url) {
                        if (vitalityImage != null) {
                            vitalityImage.setVisible(loading);
                        }
                    }
                });
            } else if (eventType == EVENT_DATASOURCE_CHANGED) {
                if (params instanceof String) {
                    browserSkinObject.setURL((String) params);
                }
            }
            return null;
        }
    });
    openURL();
    return null;
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntry(com.biglybt.ui.mdi.MdiEntry) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface)

Example 3 with MdiListener

use of com.biglybt.ui.mdi.MdiListener in project BiglyBT by BiglySoftware.

the class SB_Dashboard method setupMDIEntry.

public MdiEntry setupMDIEntry() {
    ViewTitleInfo title_info = new ViewTitleInfo() {

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            if (propertyID == TITLE_INDICATOR_TEXT) {
                return (String.valueOf(items.size()));
            }
            if (propertyID == TITLE_INDICATOR_TEXT_TOOLTIP) {
                return (null);
            }
            return null;
        }
    };
    mdi_entry = mdi.createEntryFromSkinRef("", MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD, "dashboard", "{sidebar.header.dashboard}", title_info, null, false, null);
    mdi_entry.setImageLeftID("image.sidebar.dashboard");
    MdiEntryVitalityImage cog = mdi_entry.addVitalityImage("image.sidebar.cog");
    cog.setToolTip(MessageText.getString("configure.dashboard"));
    final long[] cog_click_time = { 0 };
    cog.addListener(new MdiEntryVitalityImageListener() {

        @Override
        public void mdiEntryVitalityImage_clicked(int x, int y) {
            synchronized (items) {
                cog_click_time[0] = SystemTime.getMonotonousTime();
                new DBConfigWindow(new ArrayList<DashboardItem>(items));
            }
        }
    });
    cog.setVisible(true);
    mdi.addListener(new MdiListener() {

        @Override
        public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
            if (mdi_entry == newEntry && mdi_entry == oldEntry) {
                SimpleTimer.addEvent("changed", SystemTime.getOffsetTime(250), new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent event) {
                        synchronized (items) {
                            if (SystemTime.getMonotonousTime() - cog_click_time[0] < 250) {
                                return;
                            }
                        }
                        fireChanged();
                    }
                });
            }
        }

        public void mdiDisposed(MultipleDocumentInterface mdi) {
        }
    });
    return (mdi_entry);
}
Also used : MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryVitalityImageListener(com.biglybt.ui.mdi.MdiEntryVitalityImageListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) Point(org.eclipse.swt.graphics.Point) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Aggregations

MdiEntry (com.biglybt.ui.mdi.MdiEntry)3 MdiListener (com.biglybt.ui.mdi.MdiListener)3 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)3 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 ActivitiesListener (com.biglybt.activities.ActivitiesListener)1 TimerEvent (com.biglybt.core.util.TimerEvent)1 TimerEventPerformer (com.biglybt.core.util.TimerEventPerformer)1 PluginInterface (com.biglybt.pif.PluginInterface)1 UIManager (com.biglybt.pif.ui.UIManager)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 MenuManager (com.biglybt.pif.ui.menus.MenuManager)1 MdiEntryCreationListener (com.biglybt.ui.mdi.MdiEntryCreationListener)1 MdiEntryVitalityImage (com.biglybt.ui.mdi.MdiEntryVitalityImage)1 MdiEntryVitalityImageListener (com.biglybt.ui.mdi.MdiEntryVitalityImageListener)1 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)1 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)1 SWTSkinObjectListener (com.biglybt.ui.swt.skin.SWTSkinObjectListener)1