Search in sources :

Example 1 with UISWTViewEventListenerHolder

use of com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder in project BiglyBT by BiglySoftware.

the class TabbedMDI method createEntryFromEventListener.

@Override
public MdiEntry createEntryFromEventListener(String parentEntryID, String parentViewID, UISWTViewEventListener l, String id, boolean closeable, Object datasource, String preferredAfterID) {
    if (isEntryClosedByUser(id)) {
        return null;
    }
    MdiEntry oldEntry = getEntry(id);
    if (oldEntry != null) {
        return oldEntry;
    }
    TabbedEntry entry = new TabbedEntry(this, skin, id, parentViewID);
    if (datasource == null && l instanceof UISWTViewEventListenerHolder) {
        datasource = ((UISWTViewEventListenerHolder) l).getInitialDataSource();
    }
    try {
        // hack - seteventlistener will create view it needs to have item available now, not a little later
        addItem(entry);
        entry.setEventListener(l, true);
    } catch (UISWTViewEventCancelledException e) {
        entry.close(true);
        removeItem(entry, false);
        return null;
    }
    entry.setDatasource(datasource);
    entry.setPreferredAfterID(preferredAfterID);
    setupNewEntry(entry, id, -1, closeable);
    addMenus(entry, id);
    if (l instanceof IViewAlwaysInitialize) {
        entry.build();
    }
    return entry;
}
Also used : UISWTViewEventCancelledException(com.biglybt.ui.swt.pifimpl.UISWTViewEventCancelledException) MdiEntry(com.biglybt.ui.mdi.MdiEntry) IViewAlwaysInitialize(com.biglybt.ui.swt.views.IViewAlwaysInitialize) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder)

Example 2 with UISWTViewEventListenerHolder

use of com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder in project BiglyBT by BiglySoftware.

the class SubscriptionManagerUI method setupSideBar.

protected void setupSideBar(final UISWTInstance swt_ui) {
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi == null) {
        return;
    }
    mdiEntryOverview = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, new UISWTViewEventListenerHolder(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, SubscriptionsView.class, null, null), MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, false, null, null);
    if (mdiEntryOverview == null) {
        return;
    }
    mdiEntryOverview.setDefaultExpanded(true);
    synchronized (this) {
        if (sidebar_setup_done) {
            return;
        }
        sidebar_setup_done = true;
    }
    mdiEntryOverview.setImageLeftID("image.sidebar.subscriptions");
    setupHeader(mdi, mdiEntryOverview);
    String parentID = "sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS;
    MenuManager menu_manager = ui_manager.getMenuManager();
    MenuItem mi = menu_manager.addMenuItem(parentID, "menu.update.all.now");
    mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    mi.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
            SubscriptionScheduler sched = subs_man.getScheduler();
            Subscription[] subs = subs_man.getSubscriptions(true);
            for (Subscription sub : subs) {
                if (!sub.isSearchTemplate()) {
                    if (sub.getHistory().isEnabled()) {
                        try {
                            sched.downloadAsync(sub, true);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        }
    });
    mi = menu_manager.addMenuItem(parentID, "sep1");
    mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    mi.setStyle(MenuItem.STYLE_SEPARATOR);
    mi = menu_manager.addMenuItem(parentID, "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) {
                uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, CONFIG_SECTION_ID);
            }
        }
    });
}
Also used : MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) UIFunctions(com.biglybt.ui.UIFunctions) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 3 with UISWTViewEventListenerHolder

use of com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder in project BiglyBT by BiglySoftware.

the class SubscriptionManagerUI method createSubscriptionMdiEntry.

private MdiEntry createSubscriptionMdiEntry(final Subscription subs) {
    if (!subs.isSubscribed()) {
        return null;
    }
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi == null) {
        return (null);
    }
    String parent_name = subs.getParent();
    if (parent_name != null && parent_name.length() == 0) {
        parent_name = null;
    }
    final String key = getKey(subs);
    String subs_name = subs.getName();
    TreeMap<String, String> name_map = new TreeMap<String, String>(new FormattersImpl().getAlphanumericComparator(true));
    name_map.put(subs_name, key);
    MdiEntry[] existing = mdi.getEntries();
    for (MdiEntry e : existing) {
        String id = e.getId();
        if (id.startsWith("Subscription_")) {
            Object ds = e.getDatasource();
            if (ds instanceof Subscription) {
                String sp = ((Subscription) ds).getParent();
                if (sp != null && sp.length() == 0) {
                    sp = null;
                }
                if (sp == parent_name || (sp != null && parent_name != null && sp.equals(parent_name))) {
                    name_map.put(e.getTitle(), id);
                }
            }
        }
    }
    String prev_id = null;
    for (String this_id : name_map.values()) {
        if (this_id == key) {
            break;
        }
        prev_id = this_id;
    }
    if (prev_id == null && name_map.size() > 1) {
        Iterator<String> it = name_map.values().iterator();
        it.next();
        prev_id = "~" + it.next();
    }
    MdiEntry entry;
    if (parent_name == null || parent_name.length() == 0) {
        entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, new UISWTViewEventListenerHolder(key, SubscriptionView.class, subs, null), key, true, subs, prev_id);
    } else {
        MdiEntry parent_entry;
        synchronized (parent_views) {
            parent_entry = parent_views.get(parent_name);
            if (parent_entry == null) {
                SubsParentView parent = new SubsParentView(parent_name);
                String parent_key = getParentKey(parent_name);
                String parent_prev_id = null;
                parent_views.put(parent_name, parent_entry);
                String parent_prev = null;
                for (String pn : parent_views.keySet()) {
                    if (pn == parent_name) {
                        break;
                    }
                    parent_prev = pn;
                }
                boolean is_before;
                if (parent_prev == null && parent_views.size() > 1) {
                    Iterator<String> it = parent_views.keySet().iterator();
                    it.next();
                    parent_prev = it.next();
                    is_before = true;
                } else {
                    is_before = false;
                }
                if (parent_prev != null) {
                    parent_prev_id = getParentKey(parent_prev);
                    if (is_before) {
                        parent_prev_id = "~" + parent_prev_id;
                    }
                }
                parent_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, parent_key, null, parent_name, parent, null, false, parent_prev_id);
            }
        }
        entry = mdi.createEntryFromEventListener(parent_entry.getId(), new UISWTViewEventListenerHolder(key, SubscriptionView.class, subs, null), key, true, subs, prev_id);
    }
    // This sets up the entry (menu, etc)
    SubscriptionMDIEntry entryInfo = new SubscriptionMDIEntry(subs, entry);
    subs.setUserData(SUB_ENTRYINFO_KEY, entryInfo);
    entry.addListener(new MdiCloseListener() {

        @Override
        public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
            subs.setUserData(SUB_ENTRYINFO_KEY, null);
        }
    });
    return entry;
}
Also used : UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) FormattersImpl(com.biglybt.pifimpl.local.utils.FormattersImpl) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)

Example 4 with UISWTViewEventListenerHolder

use of com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder in project BiglyBT by BiglySoftware.

the class SBC_ChatOverview method createChatMdiEntry.

private static MdiEntry createChatMdiEntry(final ChatInstance chat) {
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi == null) {
        return (null);
    }
    try {
        String key = "Chat_" + chat.getNetwork() + ":" + Base32.encode(chat.getKey().getBytes("UTF-8"));
        MdiEntry existing = mdi.getEntry(key);
        if (existing != null) {
            chat.destroy();
            return (existing);
        }
        BuddyPluginBeta bp = BuddyPluginUtils.getBetaPlugin();
        TreeMap<ChatInstance, String> name_map = new TreeMap<>(new Comparator<ChatInstance>() {

            @Override
            public int compare(ChatInstance o1, ChatInstance o2) {
                return (o1.getName().compareTo(o2.getName()));
            }
        });
        name_map.put(chat, key);
        List<ChatInstance> all_chats = bp.getChats();
        for (ChatInstance c : all_chats) {
            try {
                String k = "Chat_" + c.getNetwork() + ":" + Base32.encode(c.getKey().getBytes("UTF-8"));
                if (mdi.getEntry(k) != null) {
                    name_map.put(c, k);
                }
            } catch (Throwable e) {
            }
        }
        String prev_id = null;
        for (String this_id : name_map.values()) {
            if (this_id == key) {
                break;
            }
            prev_id = this_id;
        }
        if (prev_id == null && name_map.size() > 1) {
            Iterator<String> it = name_map.values().iterator();
            it.next();
            prev_id = "~" + it.next();
        }
        MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, new UISWTViewEventListenerHolder(key, ChatView.class, chat, null), key, true, chat, prev_id);
        ChatMDIEntry entry_info = new ChatMDIEntry(chat, entry);
        chat.setUserData(MDI_KEY, entry_info);
        entry.addListener(new MdiCloseListener() {

            @Override
            public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                chat.setUserData(MDI_KEY, null);
            }
        });
        return (entry);
    } catch (Throwable e) {
        Debug.out(e);
        return (null);
    }
}
Also used : TreeMap(java.util.TreeMap) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) MdiCloseListener(com.biglybt.ui.mdi.MdiCloseListener)

Example 5 with UISWTViewEventListenerHolder

use of com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder in project BiglyBT by BiglySoftware.

the class PeersGraphicView method initialize.

protected void initialize(Composite composite) {
    display = composite.getDisplay();
    panel = new Canvas(composite, SWT.NO_BACKGROUND);
    panel.addListener(SWT.MouseHover, new Listener() {

        @Override
        public void handleEvent(Event event) {
            int x = event.x;
            int y = event.y;
            String tt = "";
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        if (dm_data.length > 1) {
                            tt = manager.getDisplayName() + "\r\n";
                        }
                        tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
                        break;
                    } else {
                        PEPeer target = null;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                break;
                            }
                        }
                        if (target != null) {
                            PEPeerStats stats = target.getStats();
                            String[] details = PeerUtils.getCountryDetails(target);
                            String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
                            /*
							if ( dm_map.size() > 1 ){

								tt = manager.getDisplayName() + "\r\n";
							}
							*/
                            tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
                            break;
                        }
                    }
                }
            }
            panel.setToolTipText(tt);
        }
    });
    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent event) {
            if (event.button == 3) {
                int x = event.x;
                int y = event.y;
                PEPeer target = null;
                DownloadManager target_manager = null;
                synchronized (dm_data_lock) {
                    for (ManagerData data : dm_data) {
                        DownloadManager manager = data.manager;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                target_manager = manager;
                                break;
                            }
                        }
                        if (target != null) {
                            break;
                        }
                    }
                }
                if (target == null) {
                    return;
                }
                Menu menu = panel.getMenu();
                if (menu != null && !menu.isDisposed()) {
                    menu.dispose();
                }
                menu = new Menu(panel);
                PeersViewBase.fillMenu(menu, target, target_manager);
                final Point cursorLocation = Display.getCurrent().getCursorLocation();
                menu.setLocation(cursorLocation.x, cursorLocation.y);
                menu.setVisible(true);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            int x = event.x;
            int y = event.y;
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                        if (uiFunctions != null) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
                        }
                    } else {
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                PEPeer target = entry.getKey();
                                try {
                                    String dm_id = "DMDetails_" + Base32.encode(manager.getTorrent().getHash());
                                    MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(dm_id);
                                    if (mdi_entry != null) {
                                        mdi_entry.setDatasource(new Object[] { manager, target });
                                    }
                                    Composite comp = panel.getParent();
                                    while (comp != null) {
                                        if (comp instanceof CTabFolder) {
                                            CTabFolder tf = (CTabFolder) comp;
                                            CTabItem[] items = tf.getItems();
                                            for (CTabItem item : items) {
                                                UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
                                                UISWTViewEventListener listener = view.getEventListener();
                                                if (listener instanceof UISWTViewEventListenerHolder) {
                                                    listener = ((UISWTViewEventListenerHolder) listener).getDelegatedEventListener(view);
                                                }
                                                if (listener instanceof PeersView) {
                                                    tf.setSelection(item);
                                                    Event ev = new Event();
                                                    ev.item = item;
                                                    // manual setSelection doesn't file selection event - derp
                                                    tf.notifyListeners(SWT.Selection, ev);
                                                    ((PeersView) listener).selectPeer(target);
                                                    return;
                                                }
                                            }
                                        }
                                        comp = comp.getParent();
                                    }
                                } catch (Throwable e) {
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    });
    // without this we get a transient blank when mousing in and out of the tab folder on OSX :(
    panel.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            doRefresh();
        }
    });
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) Listener(org.eclipse.swt.widgets.Listener) DownloadManagerPeerListener(com.biglybt.core.download.DownloadManagerPeerListener) CTabFolder(org.eclipse.swt.custom.CTabFolder) PEPeerStats(com.biglybt.core.peer.PEPeerStats) DownloadManager(com.biglybt.core.download.DownloadManager) CTabItem(org.eclipse.swt.custom.CTabItem) MdiEntry(com.biglybt.ui.mdi.MdiEntry) UIFunctions(com.biglybt.ui.UIFunctions) MdiEntry(com.biglybt.ui.mdi.MdiEntry) Menu(org.eclipse.swt.widgets.Menu) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEventListenerHolder(com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Aggregations

UISWTViewEventListenerHolder (com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder)6 MdiEntry (com.biglybt.ui.mdi.MdiEntry)3 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)3 UIFunctions (com.biglybt.ui.UIFunctions)2 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)2 UISWTViewCore (com.biglybt.ui.swt.pifimpl.UISWTViewCore)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerPeerListener (com.biglybt.core.download.DownloadManagerPeerListener)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerStats (com.biglybt.core.peer.PEPeerStats)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 MenuManager (com.biglybt.pif.ui.menus.MenuManager)1 FormattersImpl (com.biglybt.pifimpl.local.utils.FormattersImpl)1 BuddyPluginBeta (com.biglybt.plugin.net.buddy.BuddyPluginBeta)1 MdiCloseListener (com.biglybt.ui.mdi.MdiCloseListener)1 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)1 UISWTInstanceImpl (com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)1 SWTViewListener (com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener)1