Class AbstractSignalHead

java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.implementation.AbstractSignalHead
All Implemented Interfaces:
VetoableChangeListener, Comparable<NamedBean>, EventListener, PropertyChangeProvider, NamedBean, Signal, SignalHead
Direct Known Subclasses:
DccSignalHead, DefaultSignalHead

public abstract class AbstractSignalHead extends AbstractNamedBean implements SignalHead, VetoableChangeListener
Abstract class providing the basic logic of the SignalHead interface.
  • Field Details

    • mAppearance

      protected int mAppearance
    • mLit

      protected boolean mLit
      By default, signals are lit.
    • mHeld

      protected boolean mHeld
      By default, signals are not held.
  • Constructor Details

  • Method Details

    • getAppearanceName

      @Nonnull public String getAppearanceName(int appearance)
      Get the Appearance Name for a particular Appearance.
      Specified by:
      getAppearanceName in interface SignalHead
      Parameters:
      appearance - id for the Name.
      Returns:
      the Appearance Name, or empty String if unknown.
    • getAppearanceName

      Get the current appearance name.
      Specified by:
      getAppearanceName in interface SignalHead
      Returns:
      Name of the Appearance, e.g. "Dark" or "Flashing Red"
    • getAppearanceKey

      @Nonnull public String getAppearanceKey(int appearance)
      Get the Appearance Key for a particular Appearance.
      Specified by:
      getAppearanceKey in interface SignalHead
      Parameters:
      appearance - id for the key, e.g. SignalHead.GREEN
      Returns:
      the Appearance Key, e.g. "Green" or empty String if unknown. The key can be used as a Bundle String, e.g. Bundle.getMessage(getAppearanceKey(SignalHead.RED))
    • getAppearanceKey

      Get the current Signal Head Appearance Key.
      Specified by:
      getAppearanceKey in interface SignalHead
      Returns:
      Key, or empty String if no valid appearance set.
    • getAppearance

      public int getAppearance()
      Get the Signal Head Appearance. Changes in this value can be listened to using the Appearance property.
      Specified by:
      getAppearance in interface SignalHead
      Returns:
      the appearance, e.g. SignalHead.YELLOW
    • isCleared

      public boolean isCleared()
      Determine whether this signal shows an aspect or appearance that allows travel past it, e.g. it's "been cleared". This might be a yellow or green appearance, or an Approach or Clear aspect
      Specified by:
      isCleared in interface Signal
      Returns:
      true if the signal is showing a clear indication; false otherwise
    • isShowingRestricting

      public boolean isShowingRestricting()
      Determine whether this signal shows an aspect or appearance that allows travel past it only at restricted speed. This might be a flashing red appearance, or a Restricting aspect.
      Specified by:
      isShowingRestricting in interface Signal
      Returns:
      true if the signal is showing a restricting indication; false otherwise
    • isAtStop

      public boolean isAtStop()
      Determine whether this signal shows an aspect or appearance that forbid travel past it. This might be a red appearance, or a Stop aspect. Stop-and-Proceed or Restricting would return false here.
      Specified by:
      isAtStop in interface Signal
      Returns:
      true if the signal is showing a stop indication; false otherwise
    • getLit

      public boolean getLit()
      Default behavior for "lit" parameter is to track value and return it. Get whether the signal is lit or dark. Changes to this value can be listened to using the Lit property.
      Specified by:
      getLit in interface Signal
      Specified by:
      getLit in interface SignalHead
      Returns:
      is lit
    • getHeld

      public boolean getHeld()
      "Held" parameter is just tracked and notified. Get whether the signal is held. Changes to this value can be listened to using the Held property. It controls what mechanisms can control the signal's appearance. The actual semantics are defined by those external mechanisms.
      Specified by:
      getHeld in interface Signal
      Specified by:
      getHeld in interface SignalHead
      Returns:
      is held
    • setState

      public void setState(int s)
      Implement a shorter name for setAppearance.

      This generally shouldn't be used by Java code; use setAppearance instead. The is provided to make Jython script access easier to read.

      Specified by:
      setState in interface NamedBean
      Parameters:
      s - new state
    • getState

      public int getState()
      Implement a shorter name for getAppearance.

      This generally shouldn't be used by Java code; use getAppearance instead. The is provided to make Jython script access easier to read.

      Specified by:
      getState in interface NamedBean
      Returns:
      current state
    • getDefaultValidStates

      public static int[] getDefaultValidStates()
    • getDefaultValidStateNames

      public static String[] getDefaultValidStateNames()
    • getDefaultStateName

      @Nonnull public static String getDefaultStateName(int appearance)
      Get a localized text describing appearance from the corresponding state index.
      Parameters:
      appearance - the index of the appearance
      Returns:
      translated name for appearance
    • getValidStates

      public int[] getValidStates()
      Get an array of appearance indexes valid for the mast type.
      Specified by:
      getValidStates in interface SignalHead
      Returns:
      array of appearance state values available on this mast type
    • getValidStateKeys

      Get an array of non-localized appearance keys valid for the mast type. For GUI application consider using (capitalized) SignalHead.getValidStateNames()
      Specified by:
      getValidStateKeys in interface SignalHead
      Returns:
      array of translated appearance names available on this mast type
    • getValidStateNames

      Get an array of localized appearance descriptions valid for the mast type. For persistance and comparison consider using SignalHead.getValidStateKeys()
      Specified by:
      getValidStateNames in interface SignalHead
      Returns:
      array of translated appearance names
    • describeState

      public String describeState(int state)
      Describe SignalHead state. Does not have to be a valid state for this SignalHead instance hence suitable for state error logging. Can include multiple head states, with exception of DARK, the only state which must exist on its own. Includes the HELD state if present.
      Specified by:
      describeState in interface NamedBean
      Overrides:
      describeState in class AbstractNamedBean
      Parameters:
      state - the state to describe.
      Returns:
      description of state from Bundle.
      See Also:
    • isTurnoutUsed

      public abstract boolean isTurnoutUsed(Turnout t)
      Check if a given turnout is used on this head.
      Parameters:
      t - Turnout object to check
      Returns:
      true if turnout is configured as output or driver of head
    • vetoableChange

      Specified by:
      vetoableChange in interface NamedBean
      Specified by:
      vetoableChange in interface VetoableChangeListener
      Overrides:
      vetoableChange in class AbstractNamedBean
      Throws:
      PropertyVetoException
    • getBeanType

      For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
      Specified by:
      getBeanType in interface NamedBean
      Returns:
      a string of the bean type, eg Turnout, Sensor etc