FileDocCategorySizeDatePackage
ConfigParameterAdapter.javaAPI DocAzureus 3.0.3.46371Tue Jul 10 00:06:00 BST 2007org.gudy.azureus2.ui.swt.config

ConfigParameterAdapter

public class ConfigParameterAdapter extends org.gudy.azureus2.ui.swt.config.generic.GenericParameterAdapter

Fields Summary
private static final int
CHANGINGCOUNT_BREAKER
private Parameter
owner
private int
changingCount
private boolean
changedExternally
Constructors Summary
protected ConfigParameterAdapter(Parameter _owner, String configID)


	      
		owner = _owner;

		COConfigurationManager.addParameterListener(configID,
				new ParameterListener() {
					public void parameterChanged(String parameterName) {
						try {
  						if (owner.isDisposed()) {
  							COConfigurationManager.removeParameterListener(parameterName, this);
  							return;
  						}
  
  						informChanged(true);
  						
  						Object valueObject = owner.getValueObject();
  
  						if (valueObject instanceof Boolean) {
  							boolean b = COConfigurationManager.getBooleanParameter(parameterName);
  							owner.setValue(new Boolean(b));
  						} else if (valueObject instanceof Integer) {
  							int i = COConfigurationManager.getIntParameter(parameterName);
  							owner.setValue(new Integer(i));
  						} else if (valueObject instanceof String) {
  							String s = COConfigurationManager.getStringParameter(parameterName);
  							owner.setValue(s);
  						}
						} catch (Exception e) {
							Debug.out("parameterChanged trigger from ConfigParamAdapter "
									+ configID, e);
						}
					}
				});
	
Methods Summary
public booleangetBooleanValue(java.lang.String key)

		return (COConfigurationManager.getBooleanParameter(key));
	
public booleangetBooleanValue(java.lang.String key, boolean def)

		return (COConfigurationManager.getBooleanParameter(key, def));
	
public intgetIntValue(java.lang.String key)

		return (COConfigurationManager.getIntParameter(key));
	
public intgetIntValue(java.lang.String key, int def)

		return (COConfigurationManager.getIntParameter(key, def));
	
public voidinformChanged(boolean internally)

		if (owner.change_listeners != null) {
			for (int i = 0; i < owner.change_listeners.size(); i++) {
				try {
					((ParameterChangeListener) owner.change_listeners.get(i)).parameterChanged(
							owner, internally);
				} catch (Exception e) {
					Debug.out(e);
				}
			}
		}
	
public voidinformChanging(int toValue)

		if (owner.change_listeners != null) {
			for (int i = 0; i < owner.change_listeners.size(); i++) {
				try {
					ParameterChangeListener l = (ParameterChangeListener) owner.change_listeners.get(i);
					l.intParameterChanging(owner, toValue);
				} catch (Exception e) {
					Debug.out(e);
				}
			}
		}
	
public voidinformChanging(boolean toValue)

		if (owner.change_listeners != null) {
			for (int i = 0; i < owner.change_listeners.size(); i++) {
				try {
					ParameterChangeListener l = (ParameterChangeListener) owner.change_listeners.get(i);
					l.booleanParameterChanging(owner, toValue);
				} catch (Exception e) {
					Debug.out(e);
				}
			}
		}
	
public voidinformChanging(java.lang.String toValue)

		if (owner.change_listeners != null) {
			for (int i = 0; i < owner.change_listeners.size(); i++) {
				try {
					ParameterChangeListener l = (ParameterChangeListener) owner.change_listeners.get(i);
					l.stringParameterChanging(owner, toValue);
				} catch (Exception e) {
					Debug.out(e);
				}
			}
		}
	
public voidinformChanging(double toValue)

		if (owner.change_listeners != null) {
			for (int i = 0; i < owner.change_listeners.size(); i++) {
				try {
					ParameterChangeListener l = (ParameterChangeListener) owner.change_listeners.get(i);
					l.floatParameterChanging(owner, toValue);
				} catch (Exception e) {
					Debug.out(e);
				}
			}
		}
	
public booleanresetIntDefault(java.lang.String key)

		if (COConfigurationManager.doesParameterDefaultExist(key)) {
			COConfigurationManager.removeParameter(key);
			return (true);
		}

		return (false);
	
public voidsetBooleanValue(java.lang.String key, boolean value)

		if (changingCount == 0) {
			changedExternally = false;
		}

		changingCount++;
		try {
			if (getBooleanValue(key) == value) {
				changedExternally = true;
				return;
			}

			if (changingCount > CHANGINGCOUNT_BREAKER) {
				Debug.out("Preventing StackOverflow on setting " + key + " to " + value
						+ " (was " + getBooleanValue(key) + ") via "
						+ Debug.getCompressedStackTrace());
				changingCount = 1;
			} else {
				informChanging(value);

				if (!changedExternally) {
					COConfigurationManager.setParameter(key, value);
					changedExternally = true;
				}
			}

		} finally {
			changingCount--;
		}
	
public voidsetIntValue(java.lang.String key, int value)

		if (changingCount == 0) {
			changedExternally = false;
		}
		changingCount++;
		try {
			if (getIntValue(key) == value) {
				changedExternally = true;
				return;
			}

			if (changingCount > CHANGINGCOUNT_BREAKER) {
				Debug.out("Preventing StackOverflow on setting " + key + " to " + value
						+ " (was " + getIntValue(key) + ") via "
						+ Debug.getCompressedStackTrace());
				changingCount = 1;
			} else {
				informChanging(value);

				if (!changedExternally) {
					COConfigurationManager.setParameter(key, value);
					changedExternally = true;
				}
			}

		} finally {
			changingCount--;
		}