Search in sources :

Example 41 with ParameterListener

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

the class ColumnDateSizer method init.

private void init() {
    final TableContextMenuItem menuShowTime = addContextMenuItem("TableColumn.menu.date_added.time", MENU_STYLE_HEADER);
    menuShowTime.setStyle(TableContextMenuItem.STYLE_CHECK);
    menuShowTime.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(showTime);
        }
    });
    menuShowTime.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            showTime = !showTime;
            setUserData("showTime", new Long(showTime ? 1 : 0));
            maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
            maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
            curFormat = -1;
            recalcWidth(new Date(), null);
            if (curFormat < 0) {
                curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
            }
        }
    });
    configDateFormatListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            tableFormatOverride = COConfigurationManager.getStringParameter("Table.column.dateformat", "");
            if (tableFormatOverride == null) {
                tableFormatOverride = "";
            }
            curFormat = -1;
            if (tableFormatOverride.length() == 0) {
                recalcWidth(new Date(), null);
                if (curFormat < 0) {
                    curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
                }
                menuShowTime.setVisible(true);
            } else {
                invalidateCells();
                menuShowTime.setVisible(false);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Table.column.dateformat", configDateFormatListener);
    cdf = ViewUtils.addCustomDateFormat(this);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ParameterListener(com.biglybt.core.config.ParameterListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Date(java.util.Date)

Example 42 with ParameterListener

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

the class SideBar method skinObjectInitialShow.

// @see SkinView#showSupport(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    super.skinObjectInitialShow(skinObject, params);
    configShowSideBarListener = new ParameterListener() {

        @Override
        public void parameterChanged(String name) {
            boolean visible = COConfigurationManager.getBooleanParameter(name);
            if (visible != isVisible()) {
                flipSideBarVisibility();
            }
        }
    };
    COConfigurationManager.addParameterListener("Show Side Bar", configShowSideBarListener);
    updateSidebarVisibility();
    return null;
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

Example 43 with ParameterListener

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

the class SB_Transfers method setupViewTitleWithCore.

protected void setupViewTitleWithCore(Core _core) {
    synchronized (SB_Transfers.class) {
        if (!first) {
            return;
        }
        first = false;
        core = _core;
        coreCreateTime = core.getCreateTime();
    }
    categoryListener = new CategoryListener() {

        @Override
        public void downloadManagerRemoved(Category cat, DownloadManager removed) {
            RefreshCategorySideBar(cat);
        }

        @Override
        public void downloadManagerAdded(Category cat, DownloadManager manager) {
            RefreshCategorySideBar(cat);
        }
    };
    paramCatInSidebarListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            if (Utils.isAZ2UI()) {
                return;
            }
            Category[] categories = CategoryManager.getCategories();
            if (categories.length == 0) {
                return;
            }
            boolean catInSidebar = COConfigurationManager.getBooleanParameter("Library.CatInSideBar");
            if (catInSidebar) {
                if (categoryManagerListener != null) {
                    return;
                }
                categoryManagerListener = new CategoryManagerListener() {

                    @Override
                    public void categoryRemoved(Category category) {
                        removeCategory(category);
                    }

                    @Override
                    public void categoryChanged(Category category) {
                        RefreshCategorySideBar(category);
                    }

                    @Override
                    public void categoryAdded(Category category) {
                        Category[] categories = CategoryManager.getCategories();
                        if (categories.length == 3) {
                            for (Category cat : categories) {
                                setupCategory(cat);
                            }
                        } else {
                            setupCategory(category);
                        }
                    }
                };
                CategoryManager.addCategoryManagerListener(categoryManagerListener);
                if (categories.length > 2) {
                    for (Category category : categories) {
                        category.addCategoryListener(categoryListener);
                        setupCategory(category);
                    }
                }
            } else {
                if (categoryManagerListener != null) {
                    CategoryManager.removeCategoryManagerListener(categoryManagerListener);
                    categoryManagerListener = null;
                }
                for (Category category : categories) {
                    category.removeCategoryListener(categoryListener);
                    removeCategory(category);
                }
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Library.CatInSideBar", paramCatInSidebarListener);
    tagListener = new TagListener() {

        @Override
        public void taggableAdded(Tag tag, Taggable tagged) {
            refreshTagSideBar(tag);
        }

        @Override
        public void taggableSync(Tag tag) {
            refreshTagSideBar(tag);
        }

        @Override
        public void taggableRemoved(Tag tag, Taggable tagged) {
            refreshTagSideBar(tag);
        }
    };
    paramTagsInSidebarListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean tagInSidebar = COConfigurationManager.getBooleanParameter("Library.TagInSideBar");
            if (tagInSidebar) {
                addTagManagerListeners();
            } else {
                removeTagManagerListeners(true);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Library.TagInSideBar", paramTagsInSidebarListener);
    final GlobalManager gm = core.getGlobalManager();
    dmListener = new DownloadManagerAdapter() {

        @Override
        public void stateChanged(DownloadManager dm, int state) {
            stateChanged(dm, state, statsNoLowNoise);
            stateChanged(dm, state, statsWithLowNoise);
        }

        public void stateChanged(DownloadManager dm, int state, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                updateDMCounts(dm);
                boolean complete = dm.getAssumedComplete();
                Boolean wasErrorStateB = (Boolean) dm.getUserData("wasErrorState");
                boolean wasErrorState = wasErrorStateB != null && wasErrorStateB.booleanValue();
                boolean isErrorState = state == DownloadManager.STATE_ERROR;
                if (isErrorState != wasErrorState) {
                    int rel = isErrorState ? 1 : -1;
                    if (complete) {
                        stats.numErrorComplete += rel;
                    } else {
                        stats.numErrorInComplete += rel;
                    }
                    updateErrorTooltip(gm, stats);
                    dm.setUserData("wasErrorState", Boolean.valueOf(isErrorState));
                }
                refreshAllLibraries();
            }
        }

        @Override
        public void completionChanged(DownloadManager dm, boolean completed) {
            completionChanged(dm, completed, statsNoLowNoise);
            completionChanged(dm, completed, statsWithLowNoise);
        }

        public void completionChanged(DownloadManager dm, boolean completed, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                int dm_state = updateDMCounts(dm);
                if (completed) {
                    stats.numComplete++;
                    stats.numIncomplete--;
                    if (dm_state == DownloadManager.STATE_ERROR) {
                        stats.numErrorComplete++;
                        stats.numErrorInComplete--;
                    }
                    if (dm_state == DownloadManager.STATE_STOPPED) {
                        statsNoLowNoise.numStoppedIncomplete--;
                    }
                } else {
                    stats.numComplete--;
                    stats.numIncomplete++;
                    if (dm_state == DownloadManager.STATE_ERROR) {
                        stats.numErrorComplete--;
                        stats.numErrorInComplete++;
                    }
                    if (dm_state == DownloadManager.STATE_STOPPED) {
                        statsNoLowNoise.numStoppedIncomplete++;
                    }
                }
                recountUnopened();
                updateErrorTooltip(gm, stats);
                refreshAllLibraries();
            }
        }
    };
    gmListener = new GlobalManagerAdapter() {

        @Override
        public void downloadManagerRemoved(DownloadManager dm) {
            downloadManagerRemoved(dm, statsNoLowNoise);
            downloadManagerRemoved(dm, statsWithLowNoise);
        }

        public void downloadManagerRemoved(DownloadManager dm, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            synchronized (statsLock) {
                recountUnopened();
                if (dm.getAssumedComplete()) {
                    stats.numComplete--;
                    Boolean wasDownloadingB = (Boolean) dm.getUserData("wasDownloading");
                    if (wasDownloadingB != null && wasDownloadingB.booleanValue()) {
                        stats.numDownloading--;
                    }
                } else {
                    stats.numIncomplete--;
                    Boolean wasSeedingB = (Boolean) dm.getUserData("wasSeeding");
                    if (wasSeedingB != null && wasSeedingB.booleanValue()) {
                        stats.numSeeding--;
                    }
                }
                Boolean wasStoppedB = (Boolean) dm.getUserData("wasStopped");
                boolean wasStopped = wasStoppedB != null && wasStoppedB.booleanValue();
                if (wasStopped) {
                    if (!dm.getAssumedComplete()) {
                        stats.numStoppedIncomplete--;
                    }
                }
                Boolean wasQueuedB = (Boolean) dm.getUserData("wasQueued");
                boolean wasQueued = wasQueuedB != null && wasQueuedB.booleanValue();
                if (wasQueued) {
                    stats.numQueued--;
                }
                refreshAllLibraries();
            }
            dm.removeListener(dmListener);
        }

        @Override
        public void downloadManagerAdded(DownloadManager dm) {
            dm.addListener(dmListener, false);
            synchronized (statsLock) {
                recountUnopened();
                downloadManagerAdded(dm, statsNoLowNoise);
                downloadManagerAdded(dm, statsWithLowNoise);
                refreshAllLibraries();
            }
        }

        public void downloadManagerAdded(DownloadManager dm, stats stats) {
            if (!stats.includeLowNoise && PlatformTorrentUtils.isAdvancedViewOnly(dm)) {
                return;
            }
            boolean assumed_complete = dm.getAssumedComplete();
            synchronized (statsLock) {
                if (dm.isPersistent() && dm.getTorrent() != null && !assumed_complete) {
                    // ignore borked torrents as their create time is inaccurate
                    stats.newestIncompleteDownloadTime = Math.max(stats.newestIncompleteDownloadTime, dm.getCreationTime());
                }
                int dm_state = dm.getState();
                if (assumed_complete) {
                    stats.numComplete++;
                    if (dm_state == DownloadManager.STATE_SEEDING) {
                        stats.numSeeding++;
                    }
                } else {
                    stats.numIncomplete++;
                    if (dm_state == DownloadManager.STATE_DOWNLOADING) {
                        dm.setUserData("wasDownloading", Boolean.TRUE);
                        stats.numDownloading++;
                    } else {
                        dm.setUserData("wasDownloading", Boolean.FALSE);
                    }
                }
            }
        }
    };
    gm.addListener(gmListener, false);
    resetStats(gm, dmListener, statsWithLowNoise, statsNoLowNoise);
    refreshAllLibraries();
    timerEventPeriodic = SimpleTimer.addPeriodicEvent("header:refresh", 60 * 1000, new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            stats withNoise = new stats();
            stats noNoise = new stats();
            noNoise.includeLowNoise = false;
            withNoise.includeLowNoise = true;
            synchronized (statsLock) {
                resetStats(gm, null, withNoise, noNoise);
                boolean fixed = false;
                if (!withNoise.sameAs(statsWithLowNoise)) {
                    statsWithLowNoise.copyFrom(withNoise);
                    fixed = true;
                }
                if (!noNoise.sameAs(statsNoLowNoise)) {
                    statsNoLowNoise.copyFrom(noNoise);
                    fixed = true;
                }
                if (fixed) {
                    updateErrorTooltip(gm, statsWithLowNoise);
                    updateErrorTooltip(gm, statsNoLowNoise);
                    refreshAllLibraries();
                }
            }
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) CategoryManagerListener(com.biglybt.core.category.CategoryManagerListener) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerAdapter(com.biglybt.core.download.impl.DownloadManagerAdapter) GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerAdapter(com.biglybt.core.global.GlobalManagerAdapter) ParameterListener(com.biglybt.core.config.ParameterListener) CategoryListener(com.biglybt.core.category.CategoryListener)

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