001package jmri.jmrix.can.cbus; 002 003import java.util.Vector; 004 005import jmri.implementation.*; 006import jmri.CommandStation; 007import jmri.ConsistManager.EnableListener; 008 009/** 010 * The CBUS Consist Manager which uses the NmraConsist class for 011 * the consists it builds. This implementation just tracks the 012 * consist via a table of {@link jmri.implementation.DccConsist} objects 013 * that handle the actual operations. 014 * 015 * @author Andrew Crosland Copyright (C) 2022 016 */ 017public class CbusConsistManager extends NmraConsistManager implements EnableListener { 018 019 public CbusConsistManager(CommandStation cs) { 020 super(cs); 021 } 022 023 /** 024 * Can this consist manager be disabled? 025 * 026 * @return true if the manager can be disabled, false otherwise 027 */ 028 @Override 029 public boolean canBeDisabled() { 030 return true; 031 } 032 033 protected static final Vector<EnableListener> enableListeners = new Vector<EnableListener>(); 034 protected boolean _enabled = false; 035 036 /** 037 * Register a listener that is called if this manager is enabled or disabled. 038 * @param listener the listener 039 */ 040 @Override 041 public void registerEnableListener(EnableListener listener) { 042 // add only if not already registered 043 if (listener == null) { 044 throw new java.lang.NullPointerException(); 045 } 046 if (!enableListeners.contains(listener)) { 047 enableListeners.addElement(listener); 048 } 049 } 050 051 /** 052 * Unregister a listener that is called if this manager is enabled or disabled. 053 * @param listener the listener 054 */ 055 @Override 056 public void unregisterEnableListener(EnableListener listener) { 057 if (enableListeners.contains(listener)) { 058 enableListeners.removeElement(listener); 059 } 060 } 061 062 /** 063 * Check if this manager is enabled 064 * @return true if enabled 065 */ 066 @Override 067 public boolean isEnabled() { 068 return _enabled; 069 } 070 071 /** 072 * A listener that listens to whether the manager is enabled or disabled. 073 * 074 * Call each listeners setEnabled() method. 075 * 076 * @param value true to enable 077 */ 078 @Override 079 public void setEnabled(boolean value) { 080 _enabled = value; 081 for (int i = 0; i < enableListeners.size(); i++) { 082 enableListeners.elementAt(i).setEnabled(value); 083 } 084 } 085 086}