001/* 002 * @author Gregory J. Bedlek Copyright (C) 2018, 2019 003 */ 004package jmri.jmrit.ctc; 005 006import java.beans.PropertyChangeListener; 007import java.beans.PropertyChangeSupport; 008 009/** 010 * This object ONLY maintains ONE property: _mRequestedDirection. Ergo no need 011 * to call "addPropertyChangeListener" form with the "propertyName" variant. 012 */ 013public class RequestedDirectionObserved { 014 private int _mRequestedDirection; 015 private final PropertyChangeSupport _mPropertyChangeSupport = new PropertyChangeSupport(this); 016 private final static String PROPERTY = "RequestedDirection"; // NOI18N NEVER pass "null" for propertyName, there is a bug relating to this (for safety!) 017 018 public RequestedDirectionObserved() { _mRequestedDirection = CTCConstants.OUTOFCORRESPONDENCE; } // Obviously nothing could have registered with us YET! 019 public void addPropertyChangeListener(PropertyChangeListener pcl) { _mPropertyChangeSupport.addPropertyChangeListener(pcl); } 020 public void removePropertyChangeListener(PropertyChangeListener pcl) { _mPropertyChangeSupport.removePropertyChangeListener(pcl); } 021 public void setRequestedDirection(int newRequestedDirection) { 022 _mRequestedDirection = newRequestedDirection; // In case user directly asks us instead of using the following values: 023 _mPropertyChangeSupport.firePropertyChange(PROPERTY, this._mRequestedDirection, newRequestedDirection); // Per documentation: NO event fired if NO change in value! 024 } 025 public int getRequestedDirection() { return _mRequestedDirection; } 026}