package cn.dongjak.table2bean.ui.event;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public final class SettingChangeEventManager {
	private static Collection<SettingChangeListener> listeners;

	/**
	 * Ìí¼ÓÊÂ¼þ
	 * 
	 * @param listener
	 *            DoorListener
	 */
	public static void addSettingChangeListener(SettingChangeListener listener) {
		if (listeners == null) {
			listeners = new HashSet<SettingChangeListener>();
		}
		listeners.add(listener);
	}

	/**
	 * ÒÆ³ýÊÂ¼þ
	 * 
	 * @param listener
	 *            DoorListener
	 */
	public static void removeSettingChangeListener(
			SettingChangeListener listener) {
		if (listeners == null)
			return;
		listeners.remove(listener);
	}

	/**
	 * ´¥·¢ÉèÖÃ¸ü¸ÄÊÂ¼þ
	 */
	public static void fireSettingChange(Object source, String settingType) {
		if (listeners == null)
			return;
		SettingChangeEvent event = new SettingChangeEvent(source, settingType);
		notifyListeners(event);
	}

	/**
	 * Í¨ÖªËùÓÐµÄDoorListener
	 */
	private static void notifyListeners(SettingChangeEvent event) {
		Iterator<SettingChangeListener> iter = listeners.iterator();
		while (iter.hasNext())
			iter.next().settingChange(event);
	}

}
