use of com.biglybt.pif.ui.menus.MenuItem 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();
}
use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.
the class MenuItemImpl method getItem.
@Override
public MenuItem getItem(String key) {
if (this.style != MenuItem.STYLE_MENU) {
return null;
}
java.util.Iterator itr = this.children.iterator();
MenuItem result = null;
while (itr.hasNext()) {
result = (MenuItem) itr.next();
if (key.equals(result.getResourceKey())) {
return result;
}
}
return null;
}
use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.
the class MainMDISetup method setupSideBar.
public static void setupSideBar(final MultipleDocumentInterfaceSWT mdi) {
mdi.setDefaultEntryID(SideBar.SIDEBAR_SECTION_LIBRARY);
if (Utils.isAZ2UI()) {
setupSidebarClassic(mdi);
} else {
setupSidebarVuzeUI(mdi);
}
SBC_TorrentDetailsView.TorrentDetailMdiEntry.register(mdi);
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);
// Note: We don't use ViewManagerSWT because it adds a menu item, and we
// manually do that for StatsView and others
// ViewManagerSWT vi = ViewManagerSWT.getInstance();
// vi.registerView(VIEW_MAIN,
// new UISWTViewBuilderCore(StatsView.VIEW_ID, null, StatsView.class)
// .setParentEntryID(SIDEBAR_HEADER_PLUGINS));
mdi.registerEntry(StatsView.VIEW_ID, id -> {
MdiEntry entry = mdi.createEntry(new UISWTViewBuilderCore(id, null, StatsView.class).setParentEntryID(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS), true);
entry.setImageLeftID("image.sidebar.stats2");
return (entry);
});
mdi.registerEntry(SIDEBAR_SECTION_ALLPEERS, id -> {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, PeersSuperView.class);
builder.setParentEntryID(SIDEBAR_HEADER_TRANSFERS);
builder.setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, SIDEBAR_SECTION_ALLPEERS));
MdiEntry entry = mdi.createEntry(builder, true);
PeerControlScheduler scheduler = PeerControlSchedulerFactory.getSingleton(0);
ViewTitleInfo title_info = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
int[] counts = scheduler.getPeerCount();
return (counts[0] + " | " + counts[1]);
}
return (null);
}
};
entry.setViewTitleInfo(title_info);
entry.setImageLeftID("image.sidebar.allpeers");
final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:allpeers", 1 * 1000, new TimerEventPerformer() {
private int last_count1 = -1;
private int last_count2 = -1;
@Override
public void perform(TimerEvent event) {
int[] counts = scheduler.getPeerCount();
int c1 = counts[0];
int c2 = counts[1];
if (c1 != last_count1 || c2 != last_count2) {
last_count1 = c1;
last_count2 = c2;
entry.redraw();
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
}
});
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
timer.cancel();
}
});
return (entry);
});
mdi.registerEntry(SIDEBAR_SECTION_ALLPIECES, id -> {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, PiecesSuperView.class);
builder.setParentEntryID(SIDEBAR_HEADER_TRANSFERS);
builder.setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, SIDEBAR_SECTION_ALLPIECES));
MdiEntrySWT entry = mdi.createEntry(builder, true);
PeerControlScheduler scheduler = PeerControlSchedulerFactory.getSingleton(0);
ViewTitleInfo title_info = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
int[] counts = scheduler.getPieceCount();
UISWTViewEventListener listener = entry.getEventListener();
if (listener instanceof PiecesViewBase) {
int count = ((PiecesViewBase) listener).getUploadingPieceCount();
if (count >= 0) {
counts[1] = count;
}
}
return (counts[0] + " | " + counts[1]);
}
return (null);
}
};
entry.setViewTitleInfo(title_info);
entry.setImageLeftID("image.sidebar.allpieces");
final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:allpieces", 1 * 1000, new TimerEventPerformer() {
private int last_count1 = -1;
private int last_count2 = -1;
@Override
public void perform(TimerEvent event) {
int[] counts = scheduler.getPieceCount();
UISWTViewEventListener listener = entry.getEventListener();
if (listener instanceof PiecesViewBase) {
int count = ((PiecesViewBase) listener).getUploadingPieceCount();
if (count >= 0) {
counts[1] = count;
}
}
int c1 = counts[0];
int c2 = counts[1];
if (c1 != last_count1 || c2 != last_count2) {
last_count1 = c1;
last_count2 = c2;
entry.redraw();
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
}
});
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
timer.cancel();
}
});
return (entry);
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LOGGER, id -> {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, LoggerView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS);
return mdi.createEntry(builder, true);
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, new MdiEntryCreationListener() {
@Override
public MdiEntry createMDiEntry(String id) {
MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, id, "tagsview", "{tags.view.heading}", null, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_TAGS));
entry.setImageLeftID("image.sidebar.tag-overview");
entry.setDefaultExpanded(true);
TagManager tm = TagManagerFactory.getTagManager();
ViewTitleInfo2 title_info = new ViewTitleInfo2() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
int num = 0;
for (TagType tt : tm.getTagTypes()) {
num += tt.getTagCount();
}
return (String.valueOf(num));
}
return (null);
}
public void titleInfoLinked(MultipleDocumentInterface mdi, MdiEntry mdiEntry) {
}
public MdiEntry getLinkedMdiEntry() {
return (entry);
}
};
entry.setViewTitleInfo(title_info);
TagTypeListener ttl = new TagTypeListener() {
public void tagTypeChanged(TagType tag_type) {
}
public void tagEventOccurred(TagEvent event) {
int type = event.getEventType();
if (type == TagEvent.ET_TAG_ADDED || type == TagEvent.ET_TAG_REMOVED) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
}
}
};
TagManagerListener tml = new TagManagerListener() {
public void tagTypeAdded(TagManager manager, TagType tag_type) {
tag_type.addTagTypeListener(ttl, false);
}
public void tagTypeRemoved(TagManager manager, TagType tag_type) {
}
};
tm.addTagManagerListener(tml, true);
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
tm.removeTagManagerListener(tml);
for (TagType tt : tm.getTagTypes()) {
tt.removeTagTypeListener(ttl);
}
}
});
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, MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS);
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(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, "archivedlsview", "{mdi.entry.archiveddownloadsview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS));
entry.setImageLeftID("image.sidebar.archive");
final DownloadStubListener stub_listener = new DownloadStubListener() {
@Override
public void downloadStubEventOccurred(DownloadStubEvent event) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
};
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(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, "downloadhistoryview", "{mdi.entry.downloadhistoryview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY));
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;
}
});
// all trackers
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS, new MdiEntryCreationListener() {
@Override
public MdiEntry createMDiEntry(String id) {
AllTrackers all_trackers = AllTrackersManager.getAllTrackers();
final ViewTitleInfo title_info = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
return (String.valueOf(all_trackers.getTrackerCount()));
}
return null;
}
};
MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS, "alltrackersview", "{mdi.entry.alltrackersview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS));
entry.setImageLeftID("image.sidebar.alltrackers");
AllTrackersListener at_listener = new AllTrackersListener() {
@Override
public void trackerEventOccurred(AllTrackersEvent event) {
int type = event.getEventType();
if (type == AllTrackersEvent.ET_TRACKER_ADDED || type == AllTrackersEvent.ET_TRACKER_REMOVED) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
}
}
};
all_trackers.addListener(at_listener, false);
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
all_trackers.removeListener(at_listener);
}
});
return entry;
}
});
// torrent options
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, id -> {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, TorrentOptionsView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
MdiEntry entry = mdi.createEntry(builder, true);
entry.setImageLeftID("image.sidebar.torrentoptions");
return entry;
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, id -> {
final ShareManager sm;
{
ShareManager temp;
try {
temp = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getShareManager();
} catch (Throwable e) {
temp = null;
}
sm = temp;
}
ViewTitleInfo title_info = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
return (sm == null ? null : String.valueOf(sm.getShareCount()));
}
return null;
}
};
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, MySharesView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
MdiEntry entry = mdi.createEntry(builder, true);
entry.setViewTitleInfo(title_info);
entry.setImageLeftID("image.sidebar.myshares");
if (sm != null) {
shareManagerListener2 = new ShareManagerListener() {
public void resourceAdded(ShareResource resource) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
}
public void resourceDeleted(ShareResource resource) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
public void reportProgress(int percent_complete) {
}
public void reportCurrentTask(String task_description) {
}
};
sm.addListener(shareManagerListener2);
}
return entry;
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, id -> {
TRHost trackerHost = CoreFactory.getSingleton().getTrackerHost();
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, MyTrackerView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
MdiEntry entry = mdi.createEntry(builder, true);
entry.setImageLeftID("image.sidebar.mytracker");
ViewTitleInfo title_info = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
return (String.valueOf(trackerHost.getTorrentCount()));
}
return null;
}
};
entry.setViewTitleInfo(title_info);
trackerHostListener2 = new TRHostListener() {
@Override
public void torrentRemoved(TRHostTorrent t) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
@Override
public void torrentChanged(TRHostTorrent t) {
}
@Override
public void torrentAdded(TRHostTorrent t) {
ViewTitleInfoManager.refreshTitleInfo(title_info);
entry.redraw();
}
@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(trackerHostListener2);
return entry;
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, id -> {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, ClientStatsView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS);
MdiEntry entry = mdi.createEntry(builder, true);
entry.setImageLeftID("image.sidebar.clientstats");
return entry;
});
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, (mdi1, id, datasource, params) -> {
String section = (datasource instanceof String) ? ((String) datasource) : null;
if (Utils.isAZ2UI() || COConfigurationManager.getBooleanParameter("Show Options In Side Bar")) {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, ConfigView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS).setInitialDatasource(section);
MdiEntry entry = mdi.createEntry(builder, true);
entry.setImageLeftID("image.sidebar.cog");
return entry;
}
ConfigShell.getInstance().open(section);
return null;
});
PluginInterface pi = PluginInitializer.getDefaultInterface();
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);
}
});
menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "alltrackersview.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_ALL_TRACKERS);
}
});
menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "MainWindow.menu.view.allpeers");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPEERS);
}
});
menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "MainWindow.menu.view.allpieces");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPIECES);
}
});
menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "diskops.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_DISK_OPS);
}
});
}
// System.out.println("Activate sidebar " + startTab + " took "
// + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
}
use of com.biglybt.pif.ui.menus.MenuItem 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);
logger = plugin_interface.getLogger().getChannel("Friends");
logger.setDiagnostic();
plugin_networks = new BuddyPluginNetwork[] { new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_PUBLIC), new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_I2P) };
final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
Properties l10n_constants = new Properties();
l10n_constants.put("azbuddy.classic.link.url", Wiki.FRIENDS);
l10n_constants.put("azbuddy.dchat.link.url", Wiki.DECENTRALIZED_CHAT);
l10n_constants.put("azbuddy.profile.info.url", Wiki.FRIENDS_PUBLIC_PROFILE);
lu.integrateLocalisedMessageBundle(l10n_constants);
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);
ParameterTabFolder network_tab = config.createTabFolder();
ParameterGroup network_anon_item = null;
for (int i = 0; i < 2; i++) {
boolean is_pub_tab = i == 0;
String suffix = is_pub_tab ? "" : ".anon";
// nickname
StringParameter nick_param = config.addStringParameter2("azbuddy.nickname" + suffix, "azbuddy.nickname", "");
nick_param.setGenerateIntermediateEvents(false);
nick_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateNickName(is_pub_tab, nick_param.getValue());
}
});
// online status
String[] os_values = STATUS_VALUES;
String[] os_labels = STATUS_STRINGS;
StringListParameter os_param = config.addStringListParameter2("azbuddy.online_status" + suffix, "azbuddy.online_status", os_values, os_labels, os_values[0]);
os_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateOnlineStatus(is_pub_tab, Integer.parseInt(os_param.getValue()));
}
});
// If we add this then use proper message texts in the STATUS_STRINGS
os_param.setVisible(SUPPORT_ONLINE_STATUS);
StringParameter profile_param = config.addStringParameter2("azbuddy.profile.info" + suffix, "", "");
profile_param.setLabelText("<a href=\"" + MessageText.getString("azbuddy.profile.info.url") + "\">" + MessageText.getString("azbuddy.profile.info") + "</a>");
profile_param.setMultiLine(5);
profile_param.setGenerateIntermediateEvents(false);
profile_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateProfiles();
}
});
ParameterGroup profile_group = config.createGroup(is_pub_tab ? "azbuddy.public.profile" : "azbuddy.anon.profile", new Parameter[] { profile_param });
ParameterGroup network_item = config.createGroup(is_pub_tab ? "label.public" : "label.anon", new Parameter[] { nick_param, os_param, profile_group });
if (is_pub_tab) {
nick_name_public_param = nick_param;
online_status_public_param = os_param;
profile_public_param = profile_param;
} else {
nick_name_anon_param = nick_param;
online_status_anon_param = os_param;
profile_anon_param = profile_param;
network_anon_item = network_item;
}
network_tab.addTab(network_item);
}
updateProfiles();
// 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);
// nasty hack but the existing text has a \t prefix that causes UI weirdness but I don't want to change it and
// end up with missing translations...
tracker_so_enable.setLabelText(MessageText.getString("azbuddy.tracker.seeding.only.enabled").trim());
tracker_so_enable.setIndent(1, true);
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();
final BooleanParameter buddies_fp_enable = config.addBooleanParameter2("azbuddy.tracker.fp.enable", "azbuddy.tracker.fp.enable", true);
buddies_fp_enable.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
fp_enable = buddies_fp_enable.getValue();
}
});
fp_enable = buddies_fp_enable.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, network_tab, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local, buddies_fp_enable });
// 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.addLabelParameter2("azbuddy.dchat.more.settings");
// config end
beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
for (String table_id : TableManager.TABLE_MYTORRENTS_ALL) {
TableContextMenuItem menu_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table_id, "azbuddy.contextmenu");
menu_item.setStyle(TableContextMenuItem.STYLE_MENU);
menu_item.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();
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(menu_item, "!" + (buddy.getName() + (buddy.isPublicNetwork() ? "" : (" (" + MessageText.getString("label.anon.medium") + ")"))) + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (Torrent torrent : torrents) {
buddy.getPluginNetwork().getAZ2Handler().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.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 }).newInstance(new Object[] { BuddyPlugin.this, instance });
for (Runnable r : swt_ui_waiters) {
try {
r.run();
} catch (Throwable e) {
Debug.out(e);
}
}
swt_ui_waiters.clear();
}
} catch (Throwable e) {
Debug.out(e);
}
}
setupDisablePrompt(instance);
}
@Override
public void UIDetached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
swt_ui.destroy();
swt_ui = null;
}
}
});
final ParameterGroup f_network_anon_item = network_anon_item;
ParameterListener enabled_listener = new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
boolean classic_enabled = classic_enabled_param.getValue();
nick_name_public_param.setEnabled(classic_enabled);
online_status_public_param.setEnabled(classic_enabled);
nick_name_anon_param.setEnabled(classic_enabled);
online_status_anon_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(classic_enabled && tracker_enable.getValue());
buddies_lan_local.setEnabled(classic_enabled);
buddies_fp_enable.setEnabled(classic_enabled);
network_tab.setEnabled(classic_enabled);
f_network_anon_item.setEnabled(classic_enabled && I2PHelpers.isI2PInstalled());
if (param != null) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.setClassicEnabledInternal(classic_enabled);
}
fireEnabledStateChanged();
}
}
};
classic_enabled_param.addListener(enabled_listener);
beta_enabled_param.addListener(enabled_listener);
tracker_enable.addListener(enabled_listener);
for (BuddyPluginNetwork pn : plugin_networks) {
pn.loadConfig();
pn.registerMessageHandler();
}
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
enabled_listener.parameterChanged(null);
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() {
// meh, moved this to core listener below as we need to closedown before
// i2p plugin so connections aren't torn down before we can tidily close
}
@Override
public void closedownComplete() {
}
});
CoreFactory.getSingleton().addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public boolean syncInvokeRequired() {
return (true);
}
@Override
public void stopping(Core core) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.saveConfig(true);
pn.closedown();
}
beta_plugin.closedown();
}
});
}
use of com.biglybt.pif.ui.menus.MenuItem in project BiglyBT by BiglySoftware.
the class BaseMDI method fillMenu.
public void fillMenu(Menu menu, final MdiEntry entry, String menuID) {
com.biglybt.pif.ui.menus.MenuItem[] menu_items;
menu_items = MenuItemManager.getInstance().getAllAsArray(menuID);
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
if (entry != null) {
menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getViewID());
if (menu_items.length == 0) {
if (entry instanceof UISWTView) {
PluginInterface pi = ((UISWTView) entry).getPluginInterface();
if (pi != null) {
final List<String> relevant_sections = new ArrayList<>();
List<ConfigSectionHolder> sections = ConfigSectionRepository.getInstance().getHolderList();
for (ConfigSectionHolder cs : sections) {
if (pi == cs.getPluginInterface()) {
relevant_sections.add(cs.getConfigSectionID());
}
}
if (relevant_sections.size() > 0) {
MenuItem mi = pi.getUIManager().getMenuManager().addMenuItem(getMenuIdPrefix() + entry.getViewID(), "MainWindow.menu.view.configuration");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
for (String s : relevant_sections) {
uif.getMDI().showEntryByID(SIDEBAR_SECTION_CONFIG, s);
}
}
}
});
menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getViewID());
}
}
}
}
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
MdiSWTMenuHackListener[] menuHackListeners = getMenuHackListeners();
for (MdiSWTMenuHackListener l : menuHackListeners) {
try {
l.menuWillBeShown(entry, menu);
} catch (Exception e) {
Debug.out(e);
}
}
if (currentEntry instanceof BaseMdiEntry) {
menuHackListeners = ((BaseMdiEntry) entry).getMenuHackListeners();
for (MdiSWTMenuHackListener l : menuHackListeners) {
try {
l.menuWillBeShown(entry, menu);
} catch (Exception e) {
Debug.out(e);
}
}
}
}
menu_items = MenuItemManager.getInstance().getAllAsArray(menuID + "._end_");
if (menu_items.length > 0) {
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
}
}
Aggregations