1 22 package info.monitorenter.gui.chart.rangepolicies; 23 24 import info.monitorenter.gui.chart.Chart2D; 25 import info.monitorenter.gui.chart.IRangePolicy; 26 import info.monitorenter.util.Range; 27 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeSupport ; 30 31 import javax.swing.event.SwingPropertyChangeSupport ; 32 33 81 public abstract class ARangePolicy implements IRangePolicy { 82 89 public static final String PROPERTY_RANGE_MAX = "rangepolicy.rangemax"; 90 91 99 public static final String PROPERTY_RANGE = "rangepolicy.range"; 100 101 108 public static final String PROPERTY_RANGE_MIN = "rangepolicy.rangemin"; 109 110 115 116 protected PropertyChangeSupport m_propertyChangeSupport = new SwingPropertyChangeSupport (this); 117 118 124 private Range m_range; 125 126 131 public ARangePolicy() { 132 this.m_range = Range.RANGE_UNBOUNDED; 133 } 134 135 143 public ARangePolicy(final Range range) { 144 this.m_range = range; 145 } 146 147 158 public final void addPropertyChangeListener(final String propertyName, 159 final PropertyChangeListener listener) { 160 this.m_propertyChangeSupport.addPropertyChangeListener(propertyName, listener); 161 } 162 163 178 protected final void firePropertyChange(final String property, final Object oldvalue, 179 final Object newvalue) { 180 if (Chart2D.DEBUG_THREADING) { 181 System.out.println("AbstractRangePolicy.firePropertyChange (" + property + "), 0 locks"); 182 } 183 this.m_propertyChangeSupport.firePropertyChange(property, oldvalue, newvalue); 184 } 185 186 189 public PropertyChangeListener [] getPropertyChangeListeners(final String property) { 190 return this.m_propertyChangeSupport.getPropertyChangeListeners(property); 191 } 192 193 202 public final Range getRange() { 203 return this.m_range; 204 } 205 206 209 public void removePropertyChangeListener(final PropertyChangeListener listener) { 210 this.m_propertyChangeSupport.removePropertyChangeListener(listener); 211 } 212 213 217 public void removePropertyChangeListener(final String property, 218 final PropertyChangeListener listener) { 219 this.m_propertyChangeSupport.removePropertyChangeListener(property, listener); 220 } 221 222 232 public void setRange(final Range range) { 233 double oldMin = this.m_range.getMin(); 234 double oldMax = this.m_range.getMax(); 235 Range oldRange = this.m_range; 236 boolean minchanged = range.getMin() != oldMin; 237 boolean maxchanged = range.getMax() != oldMax; 238 this.m_range = range; 239 if (minchanged && maxchanged) { 240 this.firePropertyChange(ARangePolicy.PROPERTY_RANGE, oldRange, this.m_range); 241 } else if (minchanged) { 242 this.firePropertyChange(ARangePolicy.PROPERTY_RANGE_MIN, new Double (oldMin), new Double (range 243 .getMin())); 244 } else if (maxchanged) { 245 this.firePropertyChange(ARangePolicy.PROPERTY_RANGE_MAX, new Double (oldMax), new Double (range 246 .getMax())); 247 } 248 249 } 250 251 } 252 | Popular Tags |