Search in sources :

Example 1 with ParameterListener

use of com.biglybt.pif.ui.config.ParameterListener 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)

Example 2 with ParameterListener

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

the class BuddyPlugin method initialize.

@Override
public void initialize(final PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
    az2_handler = new BuddyPluginAZ2(this);
    sec_man = plugin_interface.getUtilities().getSecurityManager();
    logger = plugin_interface.getLogger().getChannel("Friends");
    logger.setDiagnostic();
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    lu.addListener(new LocaleListener() {

        @Override
        public void localeChanged(Locale l) {
            updateLocale(lu);
        }
    });
    updateLocale(lu);
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
    // enabled
    classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
    // nickname
    nick_name_param = config.addStringParameter2("azbuddy.nickname", "azbuddy.nickname", "");
    nick_name_param.setGenerateIntermediateEvents(false);
    nick_name_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            updateNickName(nick_name_param.getValue());
        }
    });
    // online status
    String[] os_values = STATUS_VALUES;
    String[] os_labels = STATUS_STRINGS;
    online_status_param = config.addStringListParameter2("azbuddy.online_status", "azbuddy.online_status", os_values, os_labels, os_values[0]);
    online_status_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            int status = Integer.parseInt(online_status_param.getValue());
            updateOnlineStatus(status);
        }
    });
    // If we add this then use proper message texts in the STATUS_STRINGS
    online_status_param.setVisible(SUPPORT_ONLINE_STATUS);
    // protocol speed
    final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
    protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
    ConnectionManager cman = plugin_interface.getConnectionManager();
    int inbound_limit = protocol_speed.getValue() * 1024;
    inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
    outbound_limiter = cman.createRateLimiter("buddy_down", 0);
    protocol_speed.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
        }
    });
    // chat notifications
    enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
    // default published tags or cats
    cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
    cat_pub.setGenerateIntermediateEvents(false);
    setPublicTagsOrCategories(cat_pub.getValue(), false);
    final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
    final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
    final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
    buddies_lan_local.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            lan_local_peers = buddies_lan_local.getValue();
        }
    });
    lan_local_peers = buddies_lan_local.getValue();
    cat_pub.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setPublicTagsOrCategories(cat_pub.getValue(), false);
        }
    });
    config.createGroup("label.friends", new Parameter[] { classic_enabled_param, nick_name_param, online_status_param, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local });
    // decentralised stuff
    beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
    config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
    // config end
    beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
    final TableContextMenuItem menu_item_itorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "azbuddy.contextmenu");
    final TableContextMenuItem menu_item_ctorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, "azbuddy.contextmenu");
    menu_item_itorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_itorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
    menu_item_ctorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_ctorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
    MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object _target) {
            menu.removeAllChildItems();
            if (!(isClassicEnabled() && isAvailable())) {
                menu.setEnabled(false);
                return;
            }
            final List<Torrent> torrents = new ArrayList<>();
            if (_target instanceof TableRow) {
                addDownload(torrents, (TableRow) _target);
            } else {
                TableRow[] rows = (TableRow[]) _target;
                for (TableRow row : rows) {
                    addDownload(torrents, row);
                }
            }
            if (torrents.size() == 0) {
                menu.setEnabled(false);
            } else {
                List<BuddyPluginBuddy> buddies = getBuddies();
                boolean incomplete = ((TableContextMenuItem) menu).getTableID() == TableManager.TABLE_MYTORRENTS_INCOMPLETE;
                TableContextMenuItem parent = incomplete ? menu_item_itorrents : menu_item_ctorrents;
                for (int i = 0; i < buddies.size(); i++) {
                    final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
                    boolean online = buddy.isOnline(true);
                    TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(parent, "!" + buddy.getName() + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
                    item.addMultiListener(new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            for (Torrent torrent : torrents) {
                                az2_handler.sendAZ2Torrent(torrent, buddy);
                            }
                        }
                    });
                    item.setEnabled(online);
                }
                menu.setEnabled(true);
            }
        }

        protected void addDownload(List<Torrent> torrents, TableRow row) {
            Object obj = row.getDataSource();
            Download download;
            if (obj instanceof Download) {
                download = (Download) obj;
            } else {
                DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                try {
                    download = file.getDownload();
                } catch (DownloadException e) {
                    Debug.printStackTrace(e);
                    return;
                }
            }
            Torrent torrent = download.getTorrent();
            if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                torrents.add(torrent);
            }
        }
    };
    menu_item_itorrents.addFillListener(menu_fill_listener);
    menu_item_ctorrents.addFillListener(menu_fill_listener);
    buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    synchronized (swt_ui_waiters) {
                        swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class, String.class }).newInstance(new Object[] { BuddyPlugin.this, instance, VIEW_ID });
                        for (Runnable r : swt_ui_waiters) {
                            try {
                                r.run();
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                        swt_ui_waiters.clear();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
            setupDisablePrompt(instance);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
                swt_ui.destroy();
                swt_ui = null;
            }
        }
    });
    ParameterListener enabled_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            boolean classic_enabled = classic_enabled_param.getValue();
            nick_name_param.setEnabled(classic_enabled);
            online_status_param.setEnabled(classic_enabled);
            protocol_speed.setEnabled(classic_enabled);
            enable_chat_notifications.setEnabled(classic_enabled);
            cat_pub.setEnabled(classic_enabled);
            tracker_enable.setEnabled(classic_enabled);
            tracker_so_enable.setEnabled(tracker_enable.getValue());
            if (param != null) {
                setClassicEnabledInternal(classic_enabled);
                fireEnabledStateChanged();
            }
        }
    };
    enabled_listener.parameterChanged(null);
    classic_enabled_param.addListener(enabled_listener);
    beta_enabled_param.addListener(enabled_listener);
    tracker_enable.addListener(enabled_listener);
    loadConfig();
    registerMessageHandler();
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                @Override
                public void run() {
                    new AEThread2("BuddyPlugin:init", true) {

                        @Override
                        public void run() {
                            startup();
                            beta_plugin.startup();
                            initialization_complete.set(true);
                        }
                    }.start();
                }
            });
            dt.queue();
        }

        @Override
        public void closedownInitiated() {
            saveConfig(true);
            closedown();
            beta_plugin.closedown();
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) PluginListener(com.biglybt.pif.PluginListener) ConnectionManager(com.biglybt.pif.network.ConnectionManager) DownloadException(com.biglybt.pif.download.DownloadException) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) TableRow(com.biglybt.pif.ui.tables.TableRow) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 3 with ParameterListener

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

the class SearchUI method delayedInit.

private void delayedInit() {
    final MetaSearchManager manager = MetaSearchManagerFactory.getSingleton();
    if (manager == null) {
        return;
    }
    BasicPluginConfigModel configModel = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_ROOT, CONFIG_SECTION_ID);
    // proxy enable
    final BooleanParameter proxy_enable = configModel.addBooleanParameter2("search.proxy.enable", "search.proxy.enable", manager.getProxyRequestsEnabled());
    proxy_enable.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            manager.setProxyRequestsEnabled(proxy_enable.getValue());
        }
    });
    // open rcm on search
    final BooleanParameter paramRCMWindow = configModel.addBooleanParameter2("search.showRCMView", "search.showRCMView", false);
}
Also used : ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MetaSearchManager(com.biglybt.core.metasearch.MetaSearchManager) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Aggregations

ParameterListener (com.biglybt.pif.ui.config.ParameterListener)3 UIInstance (com.biglybt.pif.ui.UIInstance)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 BooleanParameter (com.biglybt.pif.ui.config.BooleanParameter)2 Parameter (com.biglybt.pif.ui.config.Parameter)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)2 MetaSearchManager (com.biglybt.core.metasearch.MetaSearchManager)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1 NetworkAdminPropertyChangeListener (com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener)1 PluginListener (com.biglybt.pif.PluginListener)1 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)1 Download (com.biglybt.pif.download.Download)1 DownloadException (com.biglybt.pif.download.DownloadException)1 ConnectionManager (com.biglybt.pif.network.ConnectionManager)1 Torrent (com.biglybt.pif.torrent.Torrent)1 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)1 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)1 TableRow (com.biglybt.pif.ui.tables.TableRow)1