1 18 package org.columba.core.scripting.config; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.columba.core.config.DefaultItem; 25 import org.columba.core.xml.XmlElement; 26 27 30 public class Options 31 extends DefaultItem 32 { 33 34 public static final int DEFAULT_POOLING_INTERVAL = 5, INTERVAL_TIME_UNIT = 1000; 36 static final String POLLING_INTERVAL_KEY = "poll_interval", POLLING_ENABLED_KEY = "polling_enabled"; 37 38 private static final String POLLING_INTERVAL_PATH = "/" + POLLING_INTERVAL_KEY, POLLING_ENABLED_PATH = "/" + POLLING_ENABLED_KEY; 39 40 private List observers = new ArrayList (); 41 42 public Options(XmlElement aRoot) 43 { 44 super(aRoot); 45 } 46 47 public int getPollInterval() 48 { 49 return getIntegerWithDefault(POLLING_INTERVAL_PATH, null, DEFAULT_POOLING_INTERVAL); 51 } 52 53 public boolean isPollingEnabled() 54 { 55 return getBooleanWithDefault(POLLING_ENABLED_PATH, null, true); 57 } 58 59 public void setPollInterval(int interval) 60 { 61 int old = getPollInterval(); 62 63 setInteger(POLLING_INTERVAL_PATH, null, interval); 64 65 if (old != interval) 66 { 67 for (Iterator it = observers.iterator(); it.hasNext();) 68 ((OptionsObserver) it.next()).pollingIntervalChanged(interval); 69 } 70 71 } 72 73 public void setPollingEnabled(boolean poll) 74 { 75 boolean old = isPollingEnabled(); 76 setBoolean(POLLING_ENABLED_PATH, null, poll); 77 if (old != poll) 78 { 79 for (Iterator it = observers.iterator(); it.hasNext();) 80 ((OptionsObserver) it.next()).pollingStateChanged(poll); 81 } 82 } 83 84 public void addObserver(OptionsObserver observer) 85 { 86 if (!observers.contains(observer)) observers.add(observer); 87 } 88 89 public void removeObserver(OptionsObserver observer) 90 { 91 observers.remove(observer); 92 } 93 94 void setDefaultData() 95 { 96 setPollInterval(DEFAULT_POOLING_INTERVAL); 97 setPollingEnabled(true); 98 } 99 100 public int getInternalPollingInterval() 101 { 102 return getPollInterval() * INTERVAL_TIME_UNIT; 103 } 104 } 105 | Popular Tags |