Search in sources :

Example 6 with ViewTitleInfo

use of com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method setupHeader.

private void setupHeader(MultipleDocumentInterface mdi, final MdiEntry entryHeader) {
    addDefaultDropListener(entryHeader);
    /* and away you go!
		SideBarVitalityImage addDevice = entryHeader.addVitalityImage("image.sidebar.subs.add");

		addDevice.setToolTip("Add Device");

		addDevice.addListener(
			new SideBarVitalityImageListener()
			{
				public void
				sbVitalityImage_clicked(
					int x, int y)
				{
					addNewDevice();
					//new DevicesWizard( DeviceManagerUI.this );
				}
			});
		*/
    // Rollup spinner/warning/info
    entryHeader.setViewTitleInfo(new ViewTitleInfo() {

        private int last_indicator = 0;

        MdiEntryVitalityImage spinner = entryHeader.addVitalityImage(SPINNER_IMAGE_ID);

        MdiEntryVitalityImage warning = entryHeader.addVitalityImage(ALERT_IMAGE_ID);

        MdiEntryVitalityImage info = entryHeader.addVitalityImage(INFO_IMAGE_ID);

        {
            hideIcon(spinner);
            hideIcon(warning);
            hideIcon(info);
        }

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            boolean expanded = entryHeader.isExpanded();
            if (propertyID == TITLE_INDICATOR_TEXT) {
                spinner.setVisible(!expanded && device_manager.isBusy(Device.DT_UNKNOWN));
                if (!expanded) {
                    Device[] devices = device_manager.getDevices();
                    last_indicator = 0;
                    String all_errors = "";
                    String all_infos = "";
                    for (Device device : devices) {
                        String error = device.getError();
                        if (error != null) {
                            all_errors += (all_errors.length() == 0 ? "" : "; ") + error;
                        }
                        String info = device.getInfo();
                        if (info != null) {
                            all_infos += (all_infos.length() == 0 ? "" : "; ") + info;
                        }
                        if (device instanceof DeviceMediaRenderer) {
                            if (SHOW_RENDERER_VITALITY) {
                                DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
                                last_indicator += renderer.getCopyToDevicePending() + renderer.getCopyToFolderPending();
                            }
                        }
                    }
                    if (all_errors.length() > 0) {
                        hideIcon(info);
                        showIcon(warning, all_errors);
                    } else {
                        hideIcon(warning);
                        if (all_infos.length() > 0) {
                            showIcon(info, all_infos);
                        } else {
                            hideIcon(info);
                        }
                    }
                    if (last_indicator > 0) {
                        return (String.valueOf(last_indicator));
                    }
                } else {
                    hideIcon(warning);
                    hideIcon(info);
                }
            } else if (propertyID == TITLE_INDICATOR_COLOR) {
            /*
					if ( last_indicator > 0 ){

						if ( SHOW_VITALITY ){

							return( to_copy_indicator_colors );
						}
					}
					*/
            } else if (propertyID == TITLE_INDICATOR_TEXT_TOOLTIP) {
                return (getHeaderToolTip());
            }
            return null;
        }
    });
    // /////// Turn On
    if (!DISABLED_TRANSCODING) {
        deviceManagerListener = new DeviceManagerListener() {

            @Override
            public void deviceRemoved(Device device) {
            }

            @Override
            public void deviceManagerLoaded() {
                device_manager.removeListener(this);
                if (entryHeader == null || entryHeader.isDisposed()) {
                    return;
                }
                PluginManager pm = CoreFactory.getSingleton().getPluginManager();
                PluginInterface pi;
                pi = pm.getPluginInterfaceByID("vuzexcode");
                if (device_manager.getTranscodeManager().getProviders().length == 0 || pi == null) {
                    // provider plugin not installed yet
                    final MdiEntryVitalityImage turnon = entryHeader.addVitalityImage("image.sidebar.turnon");
                    if (turnon != null) {
                        turnon.addListener(new MdiEntryVitalityImageListener() {

                            @Override
                            public void mdiEntryVitalityImage_clicked(int x, int y) {
                                DevicesFTUX.ensureInstalled(null);
                            }
                        });
                        transcodeManagerListener = new TranscodeManagerListener() {

                            @Override
                            public void providerAdded(TranscodeProvider provider) {
                                // only triggers when vuzexcode is avail
                                turnon.setVisible(false);
                            }

                            @Override
                            public void providerUpdated(TranscodeProvider provider) {
                            }

                            @Override
                            public void providerRemoved(TranscodeProvider provider) {
                            }
                        };
                        device_manager.getTranscodeManager().addListener(transcodeManagerListener);
                    }
                }
            }

            @Override
            public void deviceChanged(Device device) {
            }

            @Override
            public void deviceAttentionRequest(Device device) {
            }

            @Override
            public void deviceAdded(Device device) {
            }
        };
        device_manager.addListener(deviceManagerListener);
    }
    entryHeader.addListener(new MdiCloseListener() {

        @Override
        public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
            if (device_manager != null) {
                device_manager.removeListener(deviceManagerListener);
                if (transcodeManagerListener != null) {
                    device_manager.getTranscodeManager().removeListener(transcodeManagerListener);
                }
            }
        }
    });
    // /////// Menu
    MenuManager menu_manager = ui_manager.getMenuManager();
    createOverallMenu(menu_manager, "sidebar." + SideBar.SIDEBAR_HEADER_DEVICES);
    createOverallMenu(menu_manager, "sidebar." + SideBar.SIDEBAR_SECTION_DEVICES);
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) PluginInterface(com.biglybt.pif.PluginInterface) Point(org.eclipse.swt.graphics.Point) PluginManager(com.biglybt.pif.PluginManager) MenuManager(com.biglybt.pif.ui.menus.MenuManager) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 7 with ViewTitleInfo

use of com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method exportStandAlone.

public Map<String, Object> exportStandAlone() {
    Map<String, Object> result = new HashMap<>();
    result.put("mdi", (this instanceof SideBarEntrySWT) ? "sidebar" : "tabbed");
    String title = null;
    ViewTitleInfo vti = getViewTitleInfo();
    if (vti != null) {
        title = (String) vti.getTitleInfoProperty(ViewTitleInfo.TITLE_TEXT);
    }
    if (title == null || title.length() == 0) {
        title = getFullTitle();
    }
    result.put("title", title);
    result.put("skin_ref", getSkinRef());
    result.put("skin_id", skin.getSkinID());
    result.put("parent_id", getParentID());
    result.put("id", id);
    Object data_source = getDatasourceCore();
    if (data_source == null) {
        data_source = getInitialDataSource();
    }
    if (data_source != null) {
        if (data_source instanceof String) {
            result.put("data_source", data_source);
        } else if (data_source instanceof Integer) {
            List l = new ArrayList();
            l.add("i");
            l.add(((Integer) data_source).longValue());
            result.put("data_source", l);
        } else {
            result.put("data_source", DataSourceResolver.exportDataSource(data_source));
        }
    }
    result.put("control_type", getControlType());
    UISWTViewEventListener listener = getEventListener();
    if (listener instanceof UISWTViewCoreEventListenerEx) {
        CloneConstructor cc = ((UISWTViewCoreEventListenerEx) listener).getCloneConstructor();
        String name = cc.getCloneClass().getName();
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        List<Object> params = cc.getParameters();
        if (params != null) {
            List p_types = new ArrayList<>();
            List p_vals = new ArrayList<>();
            map.put("p_types", p_types);
            map.put("p_vals", p_vals);
            for (Object p : params) {
                if (p instanceof Boolean) {
                    p_types.add("bool");
                    p_vals.add(new Long(((Boolean) p) ? 1 : 0));
                } else if (p instanceof Long) {
                    p_types.add("long");
                    p_vals.add(p);
                } else if (p instanceof String) {
                    p_types.add("string");
                    p_vals.add(p);
                } else {
                    Debug.out("Unsupported param type: " + p);
                }
            }
        }
        result.put("event_listener", map);
    } else if (listener instanceof UISWTViewEventListenerEx) {
        com.biglybt.ui.swt.pif.UISWTViewEventListenerEx.CloneConstructor cc = ((UISWTViewEventListenerEx) listener).getCloneConstructor();
        PluginInterface pi = cc.getPluginInterface();
        Map<String, Object> map = new HashMap<>();
        map.put("plugin_id", pi.getPluginID());
        map.put("plugin_name", pi.getPluginName());
        map.put("ipc_method", cc.getIPCMethod());
        List<Object> params = cc.getIPCParameters();
        if (params != null) {
            List p_types = new ArrayList<>();
            List p_vals = new ArrayList<>();
            map.put("p_types", p_types);
            map.put("p_vals", p_vals);
            for (Object p : params) {
                if (p instanceof Boolean) {
                    p_types.add("bool");
                    p_vals.add(new Long(((Boolean) p) ? 1 : 0));
                } else if (p instanceof Long) {
                    p_types.add("long");
                    p_vals.add(p);
                } else if (p instanceof String) {
                    p_types.add("string");
                    p_vals.add(p);
                } else {
                    Debug.out("Unsupported param type: " + p);
                }
            }
        }
        result.put("event_listener", map);
    }
    return (result);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEventListenerEx(com.biglybt.ui.swt.pif.UISWTViewEventListenerEx) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) List(java.util.List) CloneConstructor(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListenerEx.CloneConstructor) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 8 with ViewTitleInfo

use of com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method setEventListener.

/* (non-Javadoc)
	 * @see com.biglybt.ui.swt.pifimpl.UISWTViewImpl2#setEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener, boolean)
	 */
@Override
public void setEventListener(UISWTViewEventListener _eventListener, boolean doCreate) throws UISWTViewEventCancelledException {
    UISWTViewEventListener eventListener = getEventListener();
    if (eventListener instanceof UIToolBarEnablerBase) {
        removeToolbarEnabler((UIToolBarEnablerBase) eventListener);
    }
    if ((eventListener instanceof ViewTitleInfo) && viewTitleInfo == eventListener) {
        setViewTitleInfo(null);
    }
    if (_eventListener instanceof UISWTViewEventListenerHolder) {
        UISWTViewEventListenerHolder h = (UISWTViewEventListenerHolder) _eventListener;
        UISWTViewEventListener delegatedEventListener = h.getDelegatedEventListener(this);
        if (delegatedEventListener != null) {
            _eventListener = delegatedEventListener;
        }
    }
    if (_eventListener instanceof UIToolBarEnablerBase) {
        addToolbarEnabler((UIToolBarEnablerBase) _eventListener);
    }
    if ((_eventListener instanceof ViewTitleInfo) && viewTitleInfo == null) {
        setViewTitleInfo((ViewTitleInfo) _eventListener);
    }
    if (_eventListener instanceof BasicPluginViewImpl) {
        String existing_id = getImageLeftID();
        if (existing_id == null || "image.sidebar.plugin".equals(existing_id)) {
            setImageLeftID("image.sidebar.logview");
        }
    }
    super.setEventListener(_eventListener, doCreate);
}
Also used : UIToolBarEnablerBase(com.biglybt.pif.ui.toolbar.UIToolBarEnablerBase) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 9 with ViewTitleInfo

use of com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo in project BiglyBT by BiglySoftware.

the class TabbedMDI_Ren method setupTabFolderRenderer.

static void setupTabFolderRenderer(final TabbedMDI mdi, final CTabFolder tabFolder) {
    CTabFolderRenderer renderer = new CTabFolderRenderer(tabFolder) {

        /* (non-Javadoc)
			 * @see org.eclipse.swt.custom.CTabFolderRenderer#computeSize(int, int, org.eclipse.swt.graphics.GC, int, int)
			 */
        @Override
        protected Point computeSize(int part, int state, GC gc, int wHint, int hHint) {
            gc.setAntialias(SWT.ON);
            Point pt = super.computeSize(part, state, gc, wHint, hHint);
            if (tabFolder.isDisposed()) {
                return pt;
            }
            if (part >= 0) {
                TabbedEntry entry = mdi.getEntryFromTabItem(tabFolder.getItem(part));
                if (entry != null) {
                    ViewTitleInfo viewTitleInfo = entry.getViewTitleInfo();
                    if (viewTitleInfo != null) {
                        Object titleRight = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
                        if (titleRight != null) {
                            Point size = gc.textExtent(titleRight.toString(), 0);
                            pt.x += size.x + 10 + 2;
                        }
                    }
                    MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
                    com.biglybt.ui.swt.imageloader.ImageLoader imageLoader = com.biglybt.ui.swt.imageloader.ImageLoader.getInstance();
                    for (MdiEntryVitalityImage mdiEntryVitalityImage : vitalityImages) {
                        if (mdiEntryVitalityImage != null && mdiEntryVitalityImage.isVisible()) {
                            String imageID = mdiEntryVitalityImage.getImageID();
                            Image image = imageLoader.getImage(imageID);
                            if (com.biglybt.ui.swt.imageloader.ImageLoader.isRealImage(image)) {
                                pt.x += image.getBounds().x + 1;
                            }
                        }
                    }
                }
            }
            return pt;
        }

        /* (non-Javadoc)
			 * @see org.eclipse.swt.custom.CTabFolderRenderer#draw(int, int, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC)
			 */
        @Override
        protected void draw(int part, int state, Rectangle bounds, GC parent_gc) {
            try {
                // super.draw(part, state & ~(SWT.FOREGROUND), bounds, gc);
                super.draw(part, state, bounds, parent_gc);
            } catch (Throwable t) {
                Debug.out(t);
            }
            if (part < 0) {
                return;
            }
            try {
                CTabItem item = mdi.getTabFolder().getItem(part);
                TabbedEntry entry = mdi.getEntryFromTabItem(item);
                if (entry == null) {
                    return;
                }
                ViewTitleInfo viewTitleInfo = entry.getViewTitleInfo();
                if (viewTitleInfo != null) {
                    Object titleRight = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
                    if (titleRight != null) {
                        String textIndicator = titleRight.toString();
                        int x1IndicatorOfs = 0;
                        int SIDEBAR_SPACING = 0;
                        int x2 = bounds.x + bounds.width;
                        if (item.getShowClose()) {
                            try {
                                Field fldCloseRect = item.getClass().getDeclaredField("closeRect");
                                fldCloseRect.setAccessible(true);
                                Rectangle closeBounds = (Rectangle) fldCloseRect.get(item);
                                if (closeBounds != null && closeBounds.x > 0) {
                                    x2 = closeBounds.x;
                                }
                            } catch (Exception e) {
                                x2 -= 20;
                            }
                        }
                        // gc.setAntialias(SWT.ON); FAIL ON WINDOWS 7 AT LEAST
                        Point textSize = parent_gc.textExtent(textIndicator);
                        // Point minTextSize = gc.textExtent("99");
                        // if (textSize.x < minTextSize.x + 2) {
                        // textSize.x = minTextSize.x + 2;
                        // }
                        int width = textSize.x + 10;
                        x1IndicatorOfs += width + SIDEBAR_SPACING;
                        int startX = x2 - x1IndicatorOfs;
                        int textOffsetY = 0;
                        int height = textSize.y + 1;
                        int startY = bounds.y + ((bounds.height - height) / 2) + 1;
                        Image image = new Image(parent_gc.getDevice(), width + 1, height + 1);
                        GC gc = new GC(image);
                        gc.setAdvanced(true);
                        gc.setAntialias(SWT.ON);
                        gc.setBackground(mdi.getTabFolder().getBackground());
                        gc.fillRectangle(new Rectangle(0, 0, width + 1, height + 1));
                        // gc.setBackground(((state & SWT.SELECTED) != 0 ) ? item.getParent().getSelectionBackground() : item.getParent().getBackground());
                        // gc.fillRectangle(startX - 5, startY, width + 5, height);
                        // Pattern pattern;
                        // Color color1;
                        // Color color2;
                        // gc.fillRectangle(startX, startY, width, height);
                        Color default_color = ColorCache.getSchemedColor(gc.getDevice(), "#5b6e87");
                        Object color = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
                        if (color instanceof int[]) {
                            gc.setBackground(ColorCache.getColor(gc.getDevice(), (int[]) color));
                        } else {
                            gc.setBackground(default_color);
                        }
                        Color text_color = Colors.white;
                        gc.fillRoundRectangle(0, 0, width, height, textSize.y * 2 / 3, height * 2 / 3);
                        if (color != null) {
                            Color bg = gc.getBackground();
                            int red = bg.getRed();
                            int green = bg.getGreen();
                            int blue = bg.getBlue();
                            double brightness = Math.sqrt(red * red * 0.299 + green * green * 0.587 + blue * blue * 0.114);
                            if (brightness >= 130) {
                                text_color = Colors.black;
                            }
                            gc.setBackground(default_color);
                            gc.drawRoundRectangle(0, 0, width, height, textSize.y * 2 / 3, height * 2 / 3);
                        }
                        gc.setForeground(text_color);
                        GCStringPrinter.printString(gc, textIndicator, new Rectangle(0, 0 + textOffsetY, width, height), true, false, SWT.CENTER);
                        gc.dispose();
                        parent_gc.drawImage(image, startX, startY);
                        image.dispose();
                    }
                }
            } catch (Throwable t) {
                Debug.out(t);
            }
        }
    };
    tabFolder.setRenderer(renderer);
}
Also used : MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage) CTabItem(org.eclipse.swt.custom.CTabItem) Field(java.lang.reflect.Field) CTabFolderRenderer(org.eclipse.swt.custom.CTabFolderRenderer) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 10 with ViewTitleInfo

use of com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo 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();
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) UIManager(com.biglybt.pif.ui.UIManager) UIManagerListener2(com.biglybt.pif.ui.UIManagerListener2) DownloadStub(com.biglybt.pif.download.DownloadStub) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) ShareManagerListener(com.biglybt.pif.sharing.ShareManagerListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInstance(com.biglybt.pif.ui.UIInstance) StatsView(com.biglybt.ui.swt.views.stats.StatsView) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) DownloadStubEvent(com.biglybt.pif.download.DownloadStubEvent) TRHost(com.biglybt.core.tracker.host.TRHost) DownloadHistoryListener(com.biglybt.core.history.DownloadHistoryListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo) AsyncController(com.biglybt.core.util.AsyncController) ShareManager(com.biglybt.pif.sharing.ShareManager) ManagerUtils(com.biglybt.ui.swt.views.utils.ManagerUtils) URL(java.net.URL) DownloadHistoryEvent(com.biglybt.core.history.DownloadHistoryEvent) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) Download(com.biglybt.pif.download.Download) ShareResource(com.biglybt.pif.sharing.ShareResource) InputStream(java.io.InputStream) PluginInterface(com.biglybt.pif.PluginInterface) DownloadStubListener(com.biglybt.pif.download.DownloadStubListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MenuItem(com.biglybt.pif.ui.menus.MenuItem) IOException(java.io.IOException) TRHostListener(com.biglybt.core.tracker.host.TRHostListener) ParameterListener(com.biglybt.core.config.ParameterListener) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView)

Aggregations

ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)16 PluginInterface (com.biglybt.pif.PluginInterface)4 MenuItem (com.biglybt.pif.ui.menus.MenuItem)4 MdiEntry (com.biglybt.ui.mdi.MdiEntry)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)3 MenuManager (com.biglybt.pif.ui.menus.MenuManager)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManager (com.biglybt.core.global.GlobalManager)2 TimerEvent (com.biglybt.core.util.TimerEvent)2 TimerEventPerformer (com.biglybt.core.util.TimerEventPerformer)2 UIManager (com.biglybt.pif.ui.UIManager)2 MdiEntryVitalityImage (com.biglybt.ui.mdi.MdiEntryVitalityImage)2 MdiListener (com.biglybt.ui.mdi.MdiListener)2 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)2 MdiSWTMenuHackListener (com.biglybt.ui.swt.mdi.MdiSWTMenuHackListener)2 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 SideBarEntrySWT (com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2