use of com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener 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;
}
}
}
});
}
Aggregations