Search in sources :

Example 1 with UISWTStatusEntry

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

the class BuddyPluginView method checkBetaInit.

private void checkBetaInit() {
    if (plugin.isBetaEnabled() && plugin.getBeta().isAvailable()) {
        synchronized (this) {
            if (beta_init_done) {
                return;
            }
            beta_init_done = true;
        }
        MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
        MenuItem chat_item = menu_manager.addMenuItem(MenuManager.MENU_DOWNLOAD_CONTEXT, "label.chat");
        chat_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        chat_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        final MenuItem mi_chat = MenuBuildUtils.addChatMenu(menu_manager, chat_item, new MenuBuildUtils.ChatKeyResolver() {

            @Override
            public String getChatKey(Object object) {
                return (BuddyPluginUtils.getChatKey((Download) object));
            }
        });
        addBetaSubviews(true);
        beta_status = ui_instance.createStatusEntry();
        beta_status.setImageEnabled(true);
        beta_status.setVisible(true);
        updateIdleTT(false);
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                bs_chat_gray = imageLoader.getImage("dchat_gray");
                bs_chat_gray_text = imageLoader.getImage("dchat_gray_text");
                bs_chat_green = imageLoader.getImage("dchat_green");
                bs_chat_red = imageLoader.getImage("dchat_red");
                setBetaStatus(bs_chat_gray);
                mi_chat.setGraphic(ui_instance.createGraphic(bs_chat_gray));
            }
        });
        beta_status.setListener(new UISWTStatusEntryListener() {

            @Override
            public void entryClicked(UISWTStatusEntry entry) {
                Set<ChatInstance> current_instances = menu_latest_instances;
                for (ChatInstance chat : current_instances) {
                    if (chat.getMessageOutstanding()) {
                        try {
                            openChat(chat.getClone());
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        });
        periodicEventMsgCheck = SimpleTimer.addPeriodicEvent("msgcheck", 30 * 1000, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                List<ChatInstance> chats = plugin.getBeta().getChats();
                synchronized (pending_msg_map) {
                    for (ChatInstance chat : chats) {
                        if (chat.isInvisible()) {
                            continue;
                        }
                        if (!chat_uis.containsKey(chat)) {
                            if (chat.isFavourite() || chat.isAutoNotify() || chat.isInteresting()) {
                                if (!chat.isStatistics()) {
                                    ChatMessage last_msg = chat.getLastMessageRequiringAttention();
                                    if (last_msg != null) {
                                        ChatMessage last_handled = (ChatMessage) chat.getUserData(CHAT_LM_KEY);
                                        long last_msg_time = last_msg.getTimeStamp();
                                        if (last_handled == null || last_msg_time > last_handled.getTimeStamp()) {
                                            chat.setUserData(CHAT_LM_KEY, last_msg);
                                            betaMessagePending(chat, null, last_msg);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    updateIdleTT(false);
                }
            }
        });
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) ChatMessage(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 2 with UISWTStatusEntry

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

the class PMSWTImpl method initialise.

@Override
public void initialise(final PluginInterface pi, final BooleanParameter icon_enable) {
    final NetworkAdmin na = NetworkAdmin.getSingleton();
    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

        @Override
        public void propertyChanged(String property) {
            if (property == NetworkAdmin.PR_NETWORK_INTERFACES) {
                updateLocalAddresses(na);
            }
        }
    });
    updateLocalAddresses(na);
    pi.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uiUpdaterListener = new UIUpdaterListener() {

                        @Override
                        public void updateComplete(int count) {
                            last_update_count = count;
                            updateStatus(true);
                        }
                    };
                    uif.getUIUpdater().addListener(uiUpdaterListener);
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        icon_idle = imageLoader.getImage("pair_sb_idle");
                        icon_green = imageLoader.getImage("pair_sb_green");
                        icon_red = imageLoader.getImage("pair_sb_red");
                        UISWTInstance ui_instance = (UISWTInstance) instance;
                        status = ui_instance.createStatusEntry();
                        last_tooltip_text = MessageText.getString("pairing.ui.icon.tip");
                        status.setTooltipText(last_tooltip_text);
                        status.setImageEnabled(true);
                        status.setImage(icon_idle);
                        last_image = icon_idle;
                        boolean is_visible = icon_enable.getValue();
                        status.setVisible(is_visible);
                        if (is_visible) {
                            updateStatus(false);
                        }
                        final MenuItem mi_show = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "pairing.ui.icon.show");
                        mi_show.setStyle(MenuItem.STYLE_CHECK);
                        mi_show.setData(Boolean.valueOf(is_visible));
                        mi_show.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                icon_enable.setValue(false);
                            }
                        });
                        iconEnableListener = new ParameterListener() {

                            @Override
                            public void parameterChanged(Parameter param) {
                                boolean is_visible = icon_enable.getValue();
                                status.setVisible(is_visible);
                                mi_show.setData(Boolean.valueOf(is_visible));
                                if (is_visible) {
                                    updateStatus(false);
                                }
                            }
                        };
                        icon_enable.addListener(iconEnableListener);
                        MenuItem mi_pairing = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.pairing");
                        mi_pairing.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif == null) {
                                    Debug.out("UIFunctions not available, can't open remote pairing window");
                                } else {
                                    uif.openRemotePairingWindow();
                                }
                            }
                        });
                        MenuItem mi_sep = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "");
                        mi_sep.setStyle(MenuItem.STYLE_SEPARATOR);
                        MenuItem mi_options = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.view.configuration");
                        mi_options.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        });
                        UISWTStatusEntryListener click_listener = new UISWTStatusEntryListener() {

                            @Override
                            public void entryClicked(UISWTStatusEntry entry) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        };
                        status.setListener(click_listener);
                    }
                });
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null && uiUpdaterListener != null) {
                    uif.getUIUpdater().removeListener(uiUpdaterListener);
                    uiUpdaterListener = null;
                }
                if (status != null) {
                    // menu items get destroyed with this call
                    status.destroy();
                    status = null;
                }
                if (icon_enable != null && iconEnableListener != null) {
                    icon_enable.removeListener(iconEnableListener);
                    iconEnableListener = null;
                }
            }
        }
    });
}
Also used : UIUpdaterListener(com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) UIFunctions(com.biglybt.ui.UIFunctions) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) UIInstance(com.biglybt.pif.ui.UIInstance)

Aggregations

MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)2 UISWTStatusEntry (com.biglybt.ui.swt.pif.UISWTStatusEntry)2 UISWTStatusEntryListener (com.biglybt.ui.swt.pif.UISWTStatusEntryListener)2 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1 NetworkAdminPropertyChangeListener (com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 BooleanParameter (com.biglybt.pif.ui.config.BooleanParameter)1 Parameter (com.biglybt.pif.ui.config.Parameter)1 ParameterListener (com.biglybt.pif.ui.config.ParameterListener)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 MenuManager (com.biglybt.pif.ui.menus.MenuManager)1 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)1 ChatMessage (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage)1 UIFunctions (com.biglybt.ui.UIFunctions)1 UIUpdaterListener (com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener)1 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)1 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)1 HashSet (java.util.HashSet)1