Search in sources :

Example 16 with UIInstance

use of com.biglybt.pif.ui.UIInstance in project BiglyBT by BiglySoftware.

the class NetStatusPlugin method initialize.

@Override
public void initialize(final PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    logger = plugin_interface.getLogger().getChannel("NetStatus");
    logger.setDiagnostic();
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
    logging_detailed = config.addBooleanParameter2("plugin.aznetstatus.logfull", "plugin.aznetstatus.logfull", false);
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    swt_ui = (NetStatusPluginViewInterface) Class.forName("com.biglybt.plugin.net.netstatus.swt.NetStatusPluginView").getConstructor(new Class[] { NetStatusPlugin.class, UIInstance.class, String.class }).newInstance(new Object[] { NetStatusPlugin.this, instance, VIEW_ID });
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
                swt_ui.detach(instance);
                swt_ui = null;
            }
        }
    });
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            new AEThread2("NetstatusPlugin:init", true) {

                @Override
                public void run() {
                    try {
                        protocol_tester = new NetStatusProtocolTester(NetStatusPlugin.this, plugin_interface);
                        if (test_button != null) {
                            test_button.setEnabled(true);
                        }
                    } finally {
                        protocol_tester_sem.releaseForever();
                    }
                }
            }.start();
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance) AEThread2(com.biglybt.core.util.AEThread2) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) PluginListener(com.biglybt.pif.PluginListener)

Example 17 with UIInstance

use of com.biglybt.pif.ui.UIInstance in project BiglyBT by BiglySoftware.

the class MainMDISetup method setupSideBar.

public static void setupSideBar(final MultipleDocumentInterfaceSWT mdi, final MdiListener l) {
    if (Utils.isAZ2UI()) {
        setupSidebarClassic(mdi);
    } else {
        setupSidebarVuzeUI(mdi);
    }
    SBC_TorrentDetailsView.TorrentDetailMdiEntry.register(mdi);
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    pi.getUIManager().addUIListener(new UIManagerListener2() {

        @Override
        public void UIDetached(UIInstance instance) {
        }

        @Override
        public void UIAttached(UIInstance instance) {
        }

        @Override
        public void UIAttachedComplete(UIInstance instance) {
            PluginInitializer.getDefaultInterface().getUIManager().removeUIListener(this);
            MdiEntry currentEntry = mdi.getCurrentEntry();
            if (currentEntry != null) {
                // User or another plugin selected an entry
                return;
            }
            final String CFG_STARTTAB = "v3.StartTab";
            final String CFG_STARTTAB_DS = "v3.StartTab.ds";
            String startTab;
            String datasource = null;
            boolean showWelcome = false;
            if (showWelcome) {
                startTab = SideBar.SIDEBAR_SECTION_WELCOME;
            } else {
                if (!COConfigurationManager.hasParameter(CFG_STARTTAB, true)) {
                    COConfigurationManager.setParameter(CFG_STARTTAB, SideBar.SIDEBAR_SECTION_LIBRARY);
                }
                startTab = COConfigurationManager.getStringParameter(CFG_STARTTAB);
                datasource = COConfigurationManager.getStringParameter(CFG_STARTTAB_DS, null);
            }
            if (!mdi.loadEntryByID(startTab, true, false, datasource)) {
                mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
            }
            if (l != null) {
                mdi.addListener(l);
            }
        }
    });
    configBetaEnabledListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean enabled = COConfigurationManager.getBooleanParameter("Beta Programme Enabled");
            if (enabled) {
                boolean closed = COConfigurationManager.getBooleanParameter("Beta Programme Sidebar Closed");
                if (!closed) {
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_BETAPROGRAM, false);
                }
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Beta Programme Enabled", configBetaEnabledListener);
    mdi.registerEntry(StatsView.VIEW_ID, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, new StatsView(), id, true, null, null);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPEERS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, new PeersSuperView(), id, true, null, null);
            entry.setImageLeftID("image.sidebar.allpeers");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LOGGER, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, new LoggerView(), id, true, null, null);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "tagsview", "{tags.view.heading}", null, null, true, null);
            entry.setImageLeftID("image.sidebar.tag-overview");
            entry.setDefaultExpanded(true);
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, id, "tagdiscoveryview", "{mdi.entry.tagdiscovery}", null, null, true, null);
            entry.setImageLeftID("image.sidebar.tag-overview");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    BuddyPluginBeta bp = BuddyPluginUtils.getBetaPlugin();
                    if (bp == null) {
                        return (null);
                    }
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = 0;
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                num++;
                            }
                        }
                        if (num > 0) {
                            return (String.valueOf(num));
                        } else {
                            return (null);
                        }
                    } else if (propertyID == TITLE_INDICATOR_COLOR) {
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                if (chat.hasUnseenMessageWithNick()) {
                                    return (SBC_ChatOverview.COLOR_MESSAGE_WITH_NICK);
                                }
                            }
                        }
                    }
                    return null;
                }
            };
            MdiEntry mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, "chatsview", "{mdi.entry.chatsoverview}", title_info, null, true, null);
            mdi_entry.setImageLeftID("image.sidebar.chat-overview");
            final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:chatup", 5 * 1000, new TimerEventPerformer() {

                private String last_text;

                private int[] last_colour;

                @Override
                public void perform(TimerEvent event) {
                    String text = (String) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
                    int[] colour = (int[]) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
                    boolean changed = text != last_text && (text == null || last_text == null || !text.equals(last_text));
                    if (!changed) {
                        changed = colour != last_colour && (colour == null || last_colour == null || !Arrays.equals(colour, last_colour));
                    }
                    if (changed) {
                        last_text = text;
                        last_colour = colour;
                        mdi_entry.redraw();
                    }
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                }
            });
            mdi_entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    timer.cancel();
                }
            });
            return mdi_entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final com.biglybt.pif.download.DownloadManager download_manager = PluginInitializer.getDefaultInterface().getDownloadManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = download_manager.getDownloadStubCount();
                        return (String.valueOf(num));
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, "archivedlsview", "{mdi.entry.archiveddownloadsview}", title_info, null, true, null);
            entry.setImageLeftID("image.sidebar.archive");
            final DownloadStubListener stub_listener = new DownloadStubListener() {

                @Override
                public void downloadStubEventOccurred(DownloadStubEvent event) {
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                }
            };
            download_manager.addDownloadStubListener(stub_listener, false);
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    download_manager.removeDownloadStubListener(stub_listener);
                }
            });
            entry.addListener(new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object data) {
                    if (data instanceof String) {
                        String str = (String) data;
                        if (str.startsWith("DownloadManager\n")) {
                            String[] bits = str.split("\n");
                            com.biglybt.pif.download.DownloadManager dm = PluginInitializer.getDefaultInterface().getDownloadManager();
                            List<Download> downloads = new ArrayList<>();
                            boolean failed = false;
                            for (int i = 1; i < bits.length; i++) {
                                byte[] hash = Base32.decode(bits[i]);
                                try {
                                    Download download = dm.getDownload(hash);
                                    if (download.canStubbify()) {
                                        downloads.add(download);
                                    } else {
                                        failed = true;
                                    }
                                } catch (Throwable e) {
                                }
                            }
                            final boolean f_failed = failed;
                            ManagerUtils.moveToArchive(downloads, new ManagerUtils.ArchiveCallback() {

                                boolean error = f_failed;

                                @Override
                                public void failed(DownloadStub original, Throwable e) {
                                    error = true;
                                }

                                @Override
                                public void completed() {
                                    if (error) {
                                        String title = MessageText.getString("archive.failed.title");
                                        String text = MessageText.getString("archive.failed.text");
                                        MessageBoxShell prompter = new MessageBoxShell(title, text, new String[] { MessageText.getString("Button.ok") }, 0);
                                        prompter.setAutoCloseInMS(0);
                                        prompter.open(null);
                                    }
                                }
                            });
                        }
                        return (true);
                    }
                    return false;
                }
            });
            return entry;
        }
    });
    // download history
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final DownloadHistoryManager history_manager = (DownloadHistoryManager) CoreFactory.getSingleton().getGlobalManager().getDownloadHistoryManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        if (history_manager == null) {
                            return (null);
                        } else if (history_manager.isEnabled()) {
                            int num = history_manager.getHistoryCount();
                            return (String.valueOf(num));
                        } else {
                            return (MessageText.getString("label.disabled"));
                        }
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, "downloadhistoryview", "{mdi.entry.downloadhistoryview}", title_info, null, true, null);
            entry.setImageLeftID("image.sidebar.logview");
            if (history_manager != null) {
                final DownloadHistoryListener history_listener = new DownloadHistoryListener() {

                    @Override
                    public void downloadHistoryEventOccurred(DownloadHistoryEvent event) {
                        ViewTitleInfoManager.refreshTitleInfo(title_info);
                    }
                };
                history_manager.addListener(history_listener, false);
                entry.addListener(new MdiCloseListener() {

                    @Override
                    public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                        history_manager.removeListener(history_listener);
                    }
                });
            }
            return entry;
        }
    });
    // torrent options
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, TorrentOptionsView.class, MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, true, null, null);
            entry.setImageLeftID("image.sidebar.torrentoptions");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MySharesView.class, MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, true, null, null);
            entry.setImageLeftID("image.sidebar.myshares");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, MyTrackerView.class, MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, true, null, null);
            entry.setImageLeftID("image.sidebar.mytracker");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, ClientStatsView.class, MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, true, null, null);
            entry.setImageLeftID("image.sidebar.clientstats");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, new MdiEntryCreationListener2() {

        @Override
        public MdiEntry createMDiEntry(MultipleDocumentInterface mdi, String id, Object datasource, Map<?, ?> params) {
            String section = (datasource instanceof String) ? ((String) datasource) : null;
            boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
            if (uiClassic || COConfigurationManager.getBooleanParameter("Show Options In Side Bar")) {
                MdiEntry entry = ((MultipleDocumentInterfaceSWT) mdi).createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, ConfigView.class, MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, true, null, null);
                entry.setImageLeftID("image.sidebar.config");
                return entry;
            }
            ConfigShell.getInstance().open(section);
            return null;
        }
    });
    try {
        if (!COConfigurationManager.getBooleanParameter("my.shares.view.auto.open.done", false)) {
            final ShareManager share_manager = pi.getShareManager();
            if (share_manager.getShares().length > 0) {
            // stop showing this by default
            // mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES);
            } else {
                shareManagerListener = new ShareManagerListener() {

                    boolean done = false;

                    @Override
                    public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
                    }

                    @Override
                    public void resourceDeleted(ShareResource resource) {
                    }

                    @Override
                    public void resourceAdded(ShareResource resource) {
                        if (done) {
                            return;
                        }
                        done = true;
                        share_manager.removeListener(this);
                        COConfigurationManager.setParameter("my.shares.view.auto.open.done", true);
                        mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, false);
                    }

                    @Override
                    public void reportProgress(int percent_complete) {
                    }

                    @Override
                    public void reportCurrentTask(String task_description) {
                    }
                };
                share_manager.addListener(shareManagerListener);
            }
        }
    } catch (Throwable t) {
    }
    try {
        if (!COConfigurationManager.getBooleanParameter("my.tracker.view.auto.open.done", false)) {
            // Load Tracker View on first host of file
            TRHost trackerHost = CoreFactory.getSingleton().getTrackerHost();
            trackerHostListener = new TRHostListener() {

                boolean done = false;

                @Override
                public void torrentRemoved(TRHostTorrent t) {
                }

                @Override
                public void torrentChanged(TRHostTorrent t) {
                }

                @Override
                public void torrentAdded(TRHostTorrent t) {
                    if (done) {
                        return;
                    }
                    done = true;
                    trackerHost.removeListener(this);
                    COConfigurationManager.setParameter("my.tracker.view.auto.open.done", true);
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, false);
                }

                @Override
                public boolean handleExternalRequest(InetSocketAddress client_address, String user, String url, URL absolute_url, String header, InputStream is, OutputStream os, AsyncController async) throws IOException {
                    return false;
                }
            };
            trackerHost.addListener(trackerHostListener);
        }
    } catch (Throwable t) {
    }
    UIManager uim = pi.getUIManager();
    if (uim != null) {
        MenuItem menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tags.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tag.discovery.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "chats.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "archivedlsview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "downloadhistoryview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY);
            }
        });
    }
// System.out.println("Activate sidebar " + startTab + " took "
// + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) UIManager(com.biglybt.pif.ui.UIManager) UIManagerListener2(com.biglybt.pif.ui.UIManagerListener2) DownloadStub(com.biglybt.pif.download.DownloadStub) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) ShareManagerListener(com.biglybt.pif.sharing.ShareManagerListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInstance(com.biglybt.pif.ui.UIInstance) StatsView(com.biglybt.ui.swt.views.stats.StatsView) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) DownloadStubEvent(com.biglybt.pif.download.DownloadStubEvent) TRHost(com.biglybt.core.tracker.host.TRHost) DownloadHistoryListener(com.biglybt.core.history.DownloadHistoryListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo) AsyncController(com.biglybt.core.util.AsyncController) ShareManager(com.biglybt.pif.sharing.ShareManager) ManagerUtils(com.biglybt.ui.swt.views.utils.ManagerUtils) URL(java.net.URL) DownloadHistoryEvent(com.biglybt.core.history.DownloadHistoryEvent) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) Download(com.biglybt.pif.download.Download) ShareResource(com.biglybt.pif.sharing.ShareResource) InputStream(java.io.InputStream) PluginInterface(com.biglybt.pif.PluginInterface) DownloadStubListener(com.biglybt.pif.download.DownloadStubListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MenuItem(com.biglybt.pif.ui.menus.MenuItem) IOException(java.io.IOException) TRHostListener(com.biglybt.core.tracker.host.TRHostListener) ParameterListener(com.biglybt.core.config.ParameterListener) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView)

Example 18 with UIInstance

use of com.biglybt.pif.ui.UIInstance in project BiglyBT by BiglySoftware.

the class SBC_ArchivedDownloadsView method registerPluginViews.

private void registerPluginViews(final UISWTInstance pluginUI) {
    if (registeredCoreSubViews) {
        return;
    }
    pluginUI.addView(TABLE_NAME, "ArchivedFilesView", ArchivedFilesView.class, null);
    registeredCoreSubViews = true;
    final UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
    uiManager.addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(UIInstance instance) {
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (!(instance instanceof UISWTInstance)) {
                return;
            }
            registeredCoreSubViews = false;
            pluginUI.removeViews(TABLE_NAME, "ArchivedFilesView");
            uiManager.removeUIListener(this);
        }
    });
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 19 with UIInstance

use of com.biglybt.pif.ui.UIInstance in project BiglyBT by BiglySoftware.

the class SBC_LibraryView method skinObjectInitialShow.

// @see SkinView#showSupport(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(final SWTSkinObject skinObject, Object params) {
    selectedContentListener = new SelectedContentListener() {

        @Override
        public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewId) {
            selection_count = currentContent.length;
            long total_size = 0;
            long total_done = 0;
            ArrayList<DownloadManager> dms = new ArrayList<>(currentContent.length);
            for (ISelectedContent sc : currentContent) {
                DownloadManager dm = sc.getDownloadManager();
                if (dm != null) {
                    dms.add(dm);
                    int file_index = sc.getFileIndex();
                    if (file_index == -1) {
                        DiskManagerFileInfo[] file_infos = dm.getDiskManagerFileInfoSet().getFiles();
                        for (DiskManagerFileInfo file_info : file_infos) {
                            if (!file_info.isSkipped()) {
                                total_size += file_info.getLength();
                                total_done += file_info.getDownloaded();
                            }
                        }
                    } else {
                        DiskManagerFileInfo file_info = dm.getDiskManagerFileInfoSet().getFiles()[file_index];
                        if (!file_info.isSkipped()) {
                            total_size += file_info.getLength();
                            total_done += file_info.getDownloaded();
                        }
                    }
                }
            }
            selection_size = total_size;
            selection_done = total_done;
            selection_dms = dms.toArray(new DownloadManager[dms.size()]);
            SB_Transfers transfers = MainMDISetup.getSb_transfers();
            if (transfers != null) {
                transfers.triggerCountRefreshListeners();
            }
        }
    };
    SelectedContentManager.addCurrentlySelectedContentListener(selectedContentListener);
    soWait = null;
    try {
        soWait = getSkinObject("library-wait");
        soWaitProgress = getSkinObject("library-wait-progress");
        soWaitTask = (SWTSkinObjectText) getSkinObject("library-wait-task");
        if (soWaitProgress != null) {
            soWaitProgress.getControl().addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    assert e != null;
                    Control c = (Control) e.widget;
                    Point size = c.getSize();
                    e.gc.setBackground(ColorCache.getColor(e.display, "#23a7df"));
                    int breakX = size.x * waitProgress / 100;
                    e.gc.fillRectangle(0, 0, breakX, size.y);
                    e.gc.setBackground(ColorCache.getColor(e.display, "#cccccc"));
                    e.gc.fillRectangle(breakX, 0, size.x - breakX, size.y);
                }
            });
        }
        soLibraryInfo = (SWTSkinObjectText) getSkinObject("library-info");
        if (soLibraryInfo != null) {
            MainMDISetup.getSb_transfers().addCountRefreshListener(new SB_Transfers.countRefreshListener() {

                final Map<Composite, ExtraInfoProvider> extra_info_map = new HashMap<>();

                {
                    soLibraryInfo.getControl().getParent().setData("ViewUtils:ViewTitleExtraInfo", new ViewUtils.ViewTitleExtraInfo() {

                        @Override
                        public void update(Composite reporter, int count, int active) {
                            ExtraInfoProvider provider = getProvider(reporter);
                            if (provider == null) {
                                return;
                            }
                            if (provider.value != count || provider.active != active) {
                                provider.value = count;
                                provider.active = active;
                                if (viewMode == provider.view_mode && provider.enabled) {
                                    MainMDISetup.getSb_transfers().triggerCountRefreshListeners();
                                }
                            }
                        }

                        @Override
                        public void setEnabled(Composite reporter, boolean enabled) {
                            ExtraInfoProvider provider = getProvider(reporter);
                            if (provider == null) {
                                return;
                            }
                            if (provider.enabled != enabled) {
                                provider.enabled = enabled;
                                if (viewMode == provider.view_mode) {
                                    MainMDISetup.getSb_transfers().triggerCountRefreshListeners();
                                }
                            }
                        }

                        private ExtraInfoProvider getProvider(Composite reporter) {
                            synchronized (extra_info_map) {
                                ExtraInfoProvider provider = extra_info_map.get(reporter);
                                if (provider != null) {
                                    return (provider);
                                }
                                Composite temp = reporter;
                                while (temp != null) {
                                    Integer vm = (Integer) temp.getData("SBC_LibraryView:ViewMode");
                                    if (vm != null) {
                                        provider = new ExtraInfoProvider(vm);
                                        extra_info_map.put(reporter, provider);
                                        return (provider);
                                    }
                                    temp = temp.getParent();
                                }
                                Debug.out("No view mode found for " + reporter);
                                return (null);
                            }
                        }
                    });
                }

                // @see SBC_LibraryView.countRefreshListener#countRefreshed(SBC_LibraryView.stats, SBC_LibraryView.stats)
                @Override
                public void countRefreshed(SB_Transfers.stats statsWithLowNoise, SB_Transfers.stats statsNoLowNoise) {
                    SB_Transfers.stats stats = viewMode == MODE_SMALLTABLE ? statsWithLowNoise : statsNoLowNoise;
                    String s;
                    if (torrentFilterMode == TORRENTS_ALL || (datasource instanceof Tag)) {
                        if (datasource instanceof Category) {
                            Category cat = (Category) datasource;
                            String id = "library.category.header";
                            s = MessageText.getString(id, new String[] { (cat.getType() != Category.TYPE_USER) ? MessageText.getString(cat.getName()) : cat.getName() });
                        } else if (datasource instanceof Tag) {
                            Tag tag = (Tag) datasource;
                            String id = "library.tag.header";
                            s = MessageText.getString(id, new String[] { tag.getTagName(true) });
                            String desc = tag.getDescription();
                            if (desc != null) {
                                s += " - " + desc;
                            }
                        } else {
                            String id = "library.all.header";
                            if (stats.numComplete + stats.numIncomplete != 1) {
                                id += ".p";
                            }
                            s = MessageText.getString(id, new String[] { String.valueOf(stats.numComplete + stats.numIncomplete), String.valueOf(stats.numSeeding + stats.numDownloading) });
                            if (stats.numQueued > 0) {
                                s += ", " + MessageText.getString("label.num_queued", new String[] { String.valueOf(stats.numQueued) });
                            }
                        }
                    } else if (torrentFilterMode == TORRENTS_INCOMPLETE) {
                        String id = "library.incomplete.header";
                        if (stats.numDownloading != 1) {
                            id += ".p";
                        }
                        int numWaiting = Math.max(stats.numIncomplete - stats.numDownloading, 0);
                        s = MessageText.getString(id, new String[] { String.valueOf(stats.numDownloading), String.valueOf(numWaiting) });
                    } else if (torrentFilterMode == TORRENTS_UNOPENED || torrentFilterMode == TORRENTS_COMPLETE) {
                        // complete filtering currently uses same display text as unopened
                        String id = "library.unopened.header";
                        if (stats.numUnOpened != 1) {
                            id += ".p";
                        }
                        s = MessageText.getString(id, new String[] { String.valueOf(stats.numUnOpened) });
                    } else {
                        s = "";
                    }
                    synchronized (extra_info_map) {
                        int filter_total = 0;
                        int filter_active = 0;
                        boolean filter_enabled = false;
                        for (ExtraInfoProvider provider : extra_info_map.values()) {
                            if (viewMode == provider.view_mode) {
                                if (provider.enabled) {
                                    filter_enabled = true;
                                    filter_total += provider.value;
                                    filter_active += provider.active;
                                }
                            }
                        }
                        if (filter_enabled) {
                            String extra = MessageText.getString("filter.header.matches2", new String[] { String.valueOf(filter_total), String.valueOf(filter_active) });
                            s += " " + extra;
                        }
                    }
                    SB_Transfers transfers = MainMDISetup.getSb_transfers();
                    if (selection_count > 1) {
                        s += ", " + MessageText.getString("label.num_selected", new String[] { String.valueOf(selection_count) });
                        String size_str = null;
                        String rate_str = null;
                        if (selection_size > 0) {
                            if (selection_size == selection_done) {
                                size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_size);
                            } else {
                                size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_done) + "/" + DisplayFormatters.formatByteCountToKiBEtc(selection_size);
                            }
                        }
                        DownloadManager[] dms = selection_dms;
                        if (transfers.header_show_rates && dms.length > 1) {
                            long total_data_up = 0;
                            long total_prot_up = 0;
                            long total_data_down = 0;
                            long total_prot_down = 0;
                            for (DownloadManager dm : dms) {
                                DownloadManagerStats dm_stats = dm.getStats();
                                total_prot_up += dm_stats.getProtocolSendRate();
                                total_data_up += dm_stats.getDataSendRate();
                                total_prot_down += dm_stats.getProtocolReceiveRate();
                                total_data_down += dm_stats.getDataReceiveRate();
                            }
                            rate_str = MessageText.getString("ConfigView.download.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_down, total_prot_down) + " " + MessageText.getString("ConfigView.upload.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_up, total_prot_up);
                        }
                        if (size_str != null || rate_str != null) {
                            String temp;
                            if (size_str == null) {
                                temp = rate_str;
                            } else if (rate_str == null) {
                                temp = size_str;
                            } else {
                                temp = size_str + "; " + rate_str;
                            }
                            s += " (" + temp + ")";
                        }
                    }
                    if (transfers.header_show_uptime && transfers.totalStats != null) {
                        long up_secs = (transfers.totalStats.getSessionUpTime() / 60) * 60;
                        String op;
                        if (up_secs < 60) {
                            up_secs = 60;
                            op = "<";
                        } else {
                            op = " ";
                        }
                        String up_str = TimeFormatter.format2(up_secs, false);
                        if (s.equals("")) {
                            Debug.out("eh");
                        }
                        s += "; " + MessageText.getString("label.uptime_coarse", new String[] { op, up_str });
                    }
                    soLibraryInfo.setText(s);
                }

                class ExtraInfoProvider {

                    int view_mode;

                    boolean enabled;

                    int value;

                    int active;

                    private ExtraInfoProvider(int vm) {
                        view_mode = vm;
                    }
                }
            });
        }
    } catch (Exception ignored) {
    }
    // Core core = CoreFactory.getSingleton();
    if (!CoreFactory.isCoreRunning()) {
        if (soWait != null) {
            soWait.setVisible(true);
        // soWait.getControl().getParent().getParent().getParent().layout(true, true);
        }
        final Initializer initializer = Initializer.getLastInitializer();
        if (initializer != null) {
            initializer.addListener(new InitializerListener() {

                @Override
                public void reportPercent(final int percent) {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (soWaitProgress != null && !soWaitProgress.isDisposed()) {
                                waitProgress = percent;
                                soWaitProgress.getControl().redraw();
                                soWaitProgress.getControl().update();
                            }
                        }
                    });
                    if (percent > 100) {
                        initializer.removeListener(this);
                    }
                }

                @Override
                public void reportCurrentTask(String currentTask) {
                    if (soWaitTask != null && !soWaitTask.isDisposed()) {
                        soWaitTask.setText(currentTask);
                    }
                }
            });
        }
    }
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            PluginInterface pi = PluginInitializer.getDefaultInterface();
            final UIManager uim = pi.getUIManager();
            uim.addUIListener(new UIManagerListener() {

                @Override
                public void UIDetached(UIInstance instance) {
                }

                @Override
                public void UIAttached(UIInstance instance) {
                    if (instance instanceof UISWTInstance) {
                        uim.removeUIListener(this);
                        Utils.execSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                if (soWait != null) {
                                    soWait.setVisible(false);
                                }
                                if (!skinObject.isDisposed()) {
                                    setupView(core, skinObject);
                                }
                            }
                        });
                    }
                }
            });
        }
    });
    return null;
}
Also used : Category(com.biglybt.core.category.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) Control(org.eclipse.swt.widgets.Control) CoreRunningListener(com.biglybt.core.CoreRunningListener) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) UIInstance(com.biglybt.pif.ui.UIInstance) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) PluginInterface(com.biglybt.pif.PluginInterface) SelectedContentListener(com.biglybt.ui.selectedcontent.SelectedContentListener) InitializerListener(com.biglybt.ui.InitializerListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) PluginInitializer(com.biglybt.pifimpl.local.PluginInitializer) Initializer(com.biglybt.ui.swt.Initializer) Tag(com.biglybt.core.tag.Tag) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener)

Aggregations

UIInstance (com.biglybt.pif.ui.UIInstance)19 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)18 UIManager (com.biglybt.pif.ui.UIManager)14 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 DownloadManager (com.biglybt.core.download.DownloadManager)4 PluginListener (com.biglybt.pif.PluginListener)4 Download (com.biglybt.pif.download.Download)4 MenuItem (com.biglybt.pif.ui.menus.MenuItem)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)4 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)4 Tag (com.biglybt.core.tag.Tag)2 PluginInterface (com.biglybt.pif.PluginInterface)2 DownloadException (com.biglybt.pif.download.DownloadException)2 ParameterListener (com.biglybt.pif.ui.config.ParameterListener)2 BuddyPluginBeta (com.biglybt.plugin.net.buddy.BuddyPluginBeta)2 ArrayList (java.util.ArrayList)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 Category (com.biglybt.core.category.Category)1 ParameterListener (com.biglybt.core.config.ParameterListener)1