Search in sources :

Example 16 with ParameterListener

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

the class ConfigurationManager method addParameterListener.

public void addParameterListener(String parameter, ParameterListener new_listener) {
    if (parameter == null || new_listener == null) {
        return;
    }
    synchronized (parameterListenerz) {
        ParameterListener[] listeners = parameterListenerz.get(parameter);
        if (listeners == null) {
            parameterListenerz.put(parameter, new ParameterListener[] { new_listener });
        } else {
            ParameterListener[] new_listeners = new ParameterListener[listeners.length + 1];
            if (Constants.IS_CVS_VERSION && listeners.length > 100) {
                Debug.out(parameter);
            }
            int pos;
            if (new_listener instanceof PriorityParameterListener) {
                new_listeners[0] = new_listener;
                pos = 1;
            } else {
                new_listeners[listeners.length] = new_listener;
                pos = 0;
            }
            for (int i = 0; i < listeners.length; i++) {
                ParameterListener existing_listener = listeners[i];
                if (existing_listener == new_listener) {
                    return;
                }
                new_listeners[pos++] = existing_listener;
            }
            if (DEBUG_PARAMETER_LISTENERS) {
                System.out.println(parameter + "->" + new_listeners.length);
            }
            parameterListenerz.put(parameter, new_listeners);
        }
    }
}
Also used : PriorityParameterListener(com.biglybt.core.config.PriorityParameterListener) ParameterListener(com.biglybt.core.config.ParameterListener) PriorityParameterListener(com.biglybt.core.config.PriorityParameterListener)

Example 17 with ParameterListener

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

the class ConfigurationManager method removeParameterListener.

public void removeParameterListener(String parameter, ParameterListener listener) {
    if (parameter == null || listener == null) {
        return;
    }
    synchronized (parameterListenerz) {
        ParameterListener[] listeners = parameterListenerz.get(parameter);
        if (listeners == null) {
            return;
        }
        if (listeners.length == 1) {
            if (listeners[0] == listener) {
                parameterListenerz.remove(parameter);
            }
        } else {
            ParameterListener[] new_listeners = new ParameterListener[listeners.length - 1];
            int pos = 0;
            for (int i = 0; i < listeners.length; i++) {
                ParameterListener existing_listener = listeners[i];
                if (existing_listener != listener) {
                    if (pos == new_listeners.length) {
                        return;
                    }
                    new_listeners[pos++] = existing_listener;
                }
            }
            if (DEBUG_PARAMETER_LISTENERS) {
                System.out.println(parameter + "->" + new_listeners.length);
            }
            parameterListenerz.put(parameter, new_listeners);
        }
    }
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) PriorityParameterListener(com.biglybt.core.config.PriorityParameterListener)

Example 18 with ParameterListener

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

the class FileLogging method initialize.

public void initialize() {
    // Shorten from COConfigurationManager To make code more readable
    final ConfigurationManager config = ConfigurationManager.getInstance();
    boolean overrideLog = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOG) != null;
    for (int i = 0; i < ignoredComponents.length; i++) {
        ignoredComponents[i] = new ArrayList();
    }
    if (!overrideLog) {
        config.addListener(new COConfigurationListener() {

            @Override
            public void configurationSaved() {
                checkLoggingConfig();
            }
        });
    }
    checkLoggingConfig();
    config.addParameterListener(CFG_ENABLELOGTOFILE, new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            FileLogging.this.reloadLogToFileParam();
        }
    });
}
Also used : COConfigurationListener(com.biglybt.core.config.COConfigurationListener) ArrayList(java.util.ArrayList) ParameterListener(com.biglybt.core.config.ParameterListener) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager)

Example 19 with ParameterListener

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

the class LoggerImpl method init.

/**
 * Must be seperate from constructor, because the code may call a Logger.*
 * method, which requires a loggerImpl to be not null.
 */
public void init() {
    // temporarily set to true, to log any errors between now and setting
    // bEnabled properly.
    bEventLoggingEnabled = true;
    // Shorten from COConfigurationManager To make code more readable
    final ConfigurationManager config = ConfigurationManager.getInstance();
    boolean overrideLog = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOG) != null;
    if (overrideLog) {
        bEventLoggingEnabled = true;
    } else {
        bEventLoggingEnabled = config.getBooleanParameter("Logger.Enabled");
        config.addParameterListener("Logger.Enabled", new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                bEventLoggingEnabled = config.getBooleanParameter("Logger.Enabled");
            }
        });
    }
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager)

Example 20 with ParameterListener

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

the class TorrentUtils method getIgnoreSetSupport.

private static synchronized Set<String> getIgnoreSetSupport(boolean force) {
    if (ignore_files_set == null || force) {
        Set<String> new_ignore_set = new HashSet<>();
        String ignore_list = COConfigurationManager.getStringParameter("File.Torrent.IgnoreFiles", TOTorrent.DEFAULT_IGNORE_FILES);
        if (ignore_files_set == null) {
            // first time - add the listener
            COConfigurationManager.addParameterListener("File.Torrent.IgnoreFiles", new ParameterListener() {

                @Override
                public void parameterChanged(String parameterName) {
                    getIgnoreSetSupport(true);
                }
            });
        }
        int pos = 0;
        while (true) {
            int p1 = ignore_list.indexOf(";", pos);
            String bit;
            if (p1 == -1) {
                bit = ignore_list.substring(pos);
            } else {
                bit = ignore_list.substring(pos, p1);
                pos = p1 + 1;
            }
            // use default locale as we're dealing with local file names
            new_ignore_set.add(bit.trim().toLowerCase());
            if (p1 == -1) {
                break;
            }
        }
        ignore_files_set = new_ignore_set;
    }
    return (ignore_files_set);
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener)

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