Search in sources :

Example 36 with ParameterListener

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

the class UPnPMappingManager method addConfigPort.

protected void addConfigPort(String name_resource, boolean tcp, final String enabler_param_name, final String int_param_name) {
    boolean enabled = COConfigurationManager.getBooleanParameter(enabler_param_name);
    final UPnPMapping mapping = addConfigPort(name_resource, tcp, enabled, int_param_name);
    mapping.addListener(new UPnPMappingListener() {

        @Override
        public void mappingChanged(UPnPMapping mapping) {
            COConfigurationManager.setParameter(int_param_name, mapping.getPort());
        }

        @Override
        public void mappingDestroyed(UPnPMapping mapping) {
        }
    });
    addConfigListener(enabler_param_name, new ParameterListener() {

        @Override
        public void parameterChanged(String name) {
            mapping.setEnabled(COConfigurationManager.getBooleanParameter(enabler_param_name));
        }
    });
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

Example 37 with ParameterListener

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

the class UPnPMappingManager method addConfigPortX.

protected void addConfigPortX(final String name_resource, final boolean tcp, final String enabler_param_name, final String string_param_name) {
    final List config_mappings = new ArrayList();
    ParameterListener l1 = new ParameterListener() {

        @Override
        public void parameterChanged(String name) {
            boolean enabled = COConfigurationManager.getBooleanParameter(enabler_param_name);
            List ports = stringToPorts(COConfigurationManager.getStringParameter(string_param_name));
            for (int i = 0; i < ports.size(); i++) {
                int port = ((Integer) ports.get(i)).intValue();
                if (config_mappings.size() <= i) {
                    UPnPMapping mapping = addMapping(name_resource, tcp, port, enabled);
                    mapping.setEnabled(enabled);
                    config_mappings.add(mapping);
                } else {
                    ((UPnPMapping) config_mappings.get(i)).setPort(port);
                }
            }
            for (int i = ports.size(); i < config_mappings.size(); i++) {
                ((UPnPMapping) config_mappings.get(i)).setEnabled(false);
            }
        }
    };
    addConfigListener(string_param_name, l1);
    ParameterListener l2 = new ParameterListener() {

        @Override
        public void parameterChanged(String name) {
            List ports = stringToPorts(COConfigurationManager.getStringParameter(string_param_name));
            boolean enabled = COConfigurationManager.getBooleanParameter(enabler_param_name);
            for (int i = 0; i < (enabled ? ports.size() : config_mappings.size()); i++) {
                ((UPnPMapping) config_mappings.get(i)).setEnabled(enabled);
            }
        }
    };
    addConfigListener(enabler_param_name, l2);
    l1.parameterChanged(null);
    l2.parameterChanged(null);
}
Also used : ArrayList(java.util.ArrayList) ParameterListener(com.biglybt.core.config.ParameterListener) List(java.util.List) ArrayList(java.util.ArrayList)

Example 38 with ParameterListener

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

the class Legend method createLegendComposite.

public static Composite createLegendComposite(final Composite panel, final Color[] blockColors, final String[] keys, final String[] key_texts, Object layoutData, boolean horizontal, final LegendListener listener) {
    final ConfigurationManager config = ConfigurationManager.getInstance();
    if (blockColors.length != keys.length)
        return null;
    final Color[] defaultColors = new Color[blockColors.length];
    final ParameterListener[] paramListeners = new ParameterListener[keys.length];
    System.arraycopy(blockColors, 0, defaultColors, 0, blockColors.length);
    Composite legend = new Composite(panel, SWT.NONE);
    if (layoutData != null)
        legend.setLayoutData(layoutData);
    RowLayout layout = new RowLayout(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
    layout.wrap = true;
    layout.marginBottom = 0;
    layout.marginTop = 0;
    layout.marginLeft = 0;
    layout.marginRight = 0;
    layout.spacing = 0;
    legend.setLayout(layout);
    RowData data;
    final int[] hover_state = { -1, 0 };
    for (int i = 0; i < blockColors.length; i++) {
        int r = config.getIntParameter(keys[i] + ".red", -1);
        if (r >= 0) {
            int g = config.getIntParameter(keys[i] + ".green");
            int b = config.getIntParameter(keys[i] + ".blue");
            Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
            blockColors[i] = color;
        }
        Composite colorSet = new Composite(legend, SWT.NONE);
        Utils.setLayout(colorSet, new RowLayout(SWT.HORIZONTAL));
        final Canvas cColor = new Canvas(colorSet, SWT.BORDER);
        cColor.setData("Index", new Integer(i));
        Messages.setLanguageTooltip(cColor, "label.click.to.change.tooltip");
        // XXX Use paint instead of setBackgrond, because OSX does translucent
        // crap
        cColor.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                int i = ((Integer) cColor.getData("Index")).intValue();
                e.gc.setBackground(blockColors[i]);
                e.gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
        });
        cColor.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                Integer iIndex = (Integer) cColor.getData("Index");
                if (iIndex == null)
                    return;
                int index = iIndex.intValue();
                if (e.button == 1) {
                    RGB rgb = Utils.showColorDialog(panel, blockColors[index].getRGB());
                    if (rgb != null) {
                        config.setRGBParameter(keys[index], rgb.red, rgb.green, rgb.blue);
                    }
                } else {
                    config.removeRGBParameter(keys[index]);
                }
            }
        });
        final Label lblDesc = new Label(colorSet, SWT.NULL);
        if (key_texts == null) {
            Messages.setLanguageText(lblDesc, keys[i]);
        } else {
            lblDesc.setText(key_texts[i]);
        }
        if (listener != null) {
            Messages.setLanguageTooltip(lblDesc, "label.click.to.showhide.tooltip");
            final int f_i = i;
            lblDesc.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseUp(MouseEvent e) {
                    boolean vis = !config.getBooleanParameter(keys[f_i] + ".vis", true);
                    config.setParameter(keys[f_i] + ".vis", vis);
                    listener.visibilityChange(vis, f_i);
                    lblDesc.setForeground(vis ? Colors.getSystemColor(lblDesc.getDisplay(), SWT.COLOR_BLACK) : Colors.grey);
                }
            });
            boolean vis = config.getBooleanParameter(keys[f_i] + ".vis", true);
            if (!vis) {
                listener.visibilityChange(vis, i);
                lblDesc.setForeground(Colors.grey);
            }
        }
        data = new RowData();
        data.width = 20;
        data.height = lblDesc.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 3;
        cColor.setLayoutData(data);
        // If color changes, update our legend
        config.addParameterListener(keys[i], paramListeners[i] = new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                for (int j = 0; j < keys.length; j++) {
                    if (keys[j].equals(parameterName)) {
                        final int index = j;
                        final int r = config.getIntParameter(keys[j] + ".red", -1);
                        if (r >= 0) {
                            final int g = config.getIntParameter(keys[j] + ".green");
                            final int b = config.getIntParameter(keys[j] + ".blue");
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    if (panel == null || panel.isDisposed())
                                        return;
                                    Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
                                    blockColors[index] = color;
                                    cColor.redraw();
                                }
                            });
                        } else {
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    if (panel == null || panel.isDisposed())
                                        return;
                                    blockColors[index] = defaultColors[index];
                                    cColor.redraw();
                                }
                            });
                        }
                    }
                }
            }
        });
        if (listener != null) {
            final int f_i = i;
            Control[] controls = { colorSet, cColor, lblDesc };
            MouseTrackListener ml = new MouseTrackListener() {

                @Override
                public void mouseEnter(MouseEvent e) {
                    handleHover(listener, true, f_i, hover_state);
                }

                @Override
                public void mouseExit(MouseEvent e) {
                    handleHover(listener, false, f_i, hover_state);
                }

                @Override
                public void mouseHover(MouseEvent e) {
                }
            };
            for (Control c : controls) {
                c.addMouseTrackListener(ml);
            }
        }
    }
    legend.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // We don't want to give them disposed colors
            // Restore defaults in case blockColors is a static or is used
            // afterwards, or if the view wants to dispose of the old colors.
            System.arraycopy(defaultColors, 0, blockColors, 0, blockColors.length);
            for (int i = 0; i < keys.length; i++) config.removeParameterListener(keys[i], paramListeners[i]);
        }
    });
    return legend;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Label(org.eclipse.swt.widgets.Label) RowData(org.eclipse.swt.layout.RowData) Control(org.eclipse.swt.widgets.Control) RowLayout(org.eclipse.swt.layout.RowLayout) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) Canvas(org.eclipse.swt.widgets.Canvas) RGB(org.eclipse.swt.graphics.RGB) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 39 with ParameterListener

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

the class MainWindowImpl method showMainWindow.

private void showMainWindow() {
    configShowDLBasketListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            configureDownloadBasket();
        }
    };
    COConfigurationManager.addAndFireParameterListener("Show Download Basket", configShowDLBasketListener);
    boolean isOSX = com.biglybt.core.util.Constants.isOSX;
    boolean bEnableTray = COConfigurationManager.getBooleanParameter("Enable System Tray");
    boolean bPassworded = COConfigurationManager.getBooleanParameter("Password enabled");
    boolean bStartMinimize = bEnableTray && (bPassworded || COConfigurationManager.getBooleanParameter("Start Minimized"));
    SWTSkinObject soMain = skin.getSkinObject("main");
    if (soMain != null) {
        soMain.getControl().setVisible(true);
    }
    shell.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event event) {
            System.out.println("---------SHOWN AT " + SystemTime.getCurrentTime() + ";" + (SystemTime.getCurrentTime() - Initializer.startTime) + "ms");
            if (statusBar != null) {
                Utils.execSWTThreadLater(10, new Runnable() {

                    @Override
                    public void run() {
                        statusBar.relayout();
                    }
                });
            }
            // bring back and stand-alone shells
            ShellManager.sharedManager().performForShells(new Listener() {

                @Override
                public void handleEvent(Event event) {
                    Shell this_shell = (Shell) event.widget;
                    if (this_shell.getParent() == null && !this_shell.isVisible()) {
                        boolean minimize;
                        synchronized (minimized_on_hide) {
                            minimize = minimized_on_hide.remove(this_shell);
                        }
                        this_shell.setVisible(true);
                        if (minimize) {
                            this_shell.setMinimized(true);
                        } else {
                            this_shell.moveAbove(shell);
                        }
                    }
                }
            });
        }
    });
    if (!bStartMinimize) {
        shell.open();
        if (!isOSX) {
            shell.forceActive();
        }
    }
    if (delayedCore) {
        // max 5 seconds of dispatching.  We don't display.sleep here because
        // we only want to clear the backlog of SWT events, and sleep would
        // add new ones
        Display display = Utils.getDisplay();
        if (display == null) {
            return;
        }
        try {
            long endSWTDispatchOn = SystemTime.getOffsetTime(5000);
            while (SystemTime.getCurrentTime() < endSWTDispatchOn && !display.isDisposed() && display.readAndDispatch()) ;
        } catch (Exception e) {
            Debug.out(e);
        }
        System.out.println("---------DONE DISPATCH AT " + SystemTime.getCurrentTime() + ";" + (SystemTime.getCurrentTime() - Initializer.startTime) + "ms");
        if (display.isDisposed()) {
            return;
        }
    }
    if (bEnableTray) {
        try {
            systemTraySWT = SystemTraySWT.getTray();
        } catch (Throwable e) {
            e.printStackTrace();
            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "Upgrade to SWT3.0M8 or later for system tray support."));
        }
        if (bStartMinimize) {
            minimizeToTray(null);
        } else // Only show the password if not started minimized
        // Correct bug #878227
        {
            if (bPassworded) {
                minimizeToTray(null);
                // invokes password
                setVisible(true);
            }
        }
    }
    if (uiInitializer != null) {
        uiInitializer.initializationComplete();
    }
    boolean run_speed_test = false;
    if (!Utils.isAZ2UI() && !COConfigurationManager.getBooleanParameter("SpeedTest Completed")) {
        if (ConfigurationChecker.isNewInstall()) {
            run_speed_test = true;
        } else if (FeatureAvailability.triggerSpeedTestV1()) {
            long upload_limit = COConfigurationManager.getLongParameter("Max Upload Speed KBs");
            boolean auto_up = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY);
            if (auto_up) {
                if (upload_limit <= 18) {
                    run_speed_test = true;
                }
            } else {
                boolean up_seed_limit = COConfigurationManager.getBooleanParameter("enable.seedingonly.upload.rate");
                if (upload_limit == 0 && !up_seed_limit) {
                    run_speed_test = true;
                }
            }
        }
    }
    if (run_speed_test) {
        SpeedTestSelector.runMLABTest(new AERunnable() {

            @Override
            public void runSupport() {
                WelcomeView.setWaitLoadingURL(false);
            }
        });
    } else {
        WelcomeView.setWaitLoadingURL(false);
    }
    if (Utils.isAZ2UI()) {
        if (!COConfigurationManager.getBooleanParameter("Wizard Completed")) {
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    new ConfigureWizard(false, ConfigureWizard.WIZARD_MODE_FULL);
                }
            });
        }
        checkForWhatsNewWindow();
    }
    AssociationChecker.checkAssociations();
    // Donation stuff
    Map<?, ?> map = VersionCheckClient.getSingleton().getMostRecentVersionCheckData();
    DonationWindow.setInitialAskHours(MapUtils.getMapInt(map, "donations.askhrs", DonationWindow.getInitialAskHours()));
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            core.triggerLifeCycleComponentCreated(uiFunctions);
        }
    });
    System.out.println("---------READY AT " + SystemTime.getCurrentTime() + ";" + (SystemTime.getCurrentTime() - Initializer.startTime) + "ms");
    isReady = true;
// SESecurityManagerImpl.getSingleton().exitVM(0);
}
Also used : MdiEntryLogIdListener(com.biglybt.ui.mdi.MdiEntryLogIdListener) ParameterListener(com.biglybt.core.config.ParameterListener) MdiListener(com.biglybt.ui.mdi.MdiListener) NavigationHelper.navigationListener(com.biglybt.util.NavigationHelper.navigationListener) GlobalManagerListener(com.biglybt.core.global.GlobalManagerListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ConfigureWizard(com.biglybt.ui.swt.config.wizard.ConfigureWizard) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) CoreRunningListener(com.biglybt.core.CoreRunningListener) ParameterListener(com.biglybt.core.config.ParameterListener) Core(com.biglybt.core.Core)

Example 40 with ParameterListener

use of com.biglybt.core.config.ParameterListener 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

ParameterListener (com.biglybt.core.config.ParameterListener)43 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 PriorityParameterListener (com.biglybt.core.config.PriorityParameterListener)4 LogEvent (com.biglybt.core.logging.LogEvent)4 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)4 ArrayList (java.util.ArrayList)4 Core (com.biglybt.core.Core)3 ConfigurationManager (com.biglybt.core.config.impl.ConfigurationManager)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 AERunnable (com.biglybt.core.util.AERunnable)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 DelayedTask (com.biglybt.pif.utils.DelayedTask)2