Class Layout

  • All Implemented Interfaces:
    java.beans.VetoableChangeListener, java.util.EventListener

    public class Layout
    extends java.lang.Object
    implements java.beans.VetoableChangeListener
    Define the content of a Layout record.

    The fast clock, scale and metric values affect the scale mile / scale km. When these are changed, the stop times for all of the trains have to be re-calculated. Depending on the schedule limits, this can result in calculation errors. When this occurs, exceptions occur which trigger rolling back the changes.

    • Constructor Detail

      • Layout

        public Layout()
        Create a new layout with default values.
      • Layout

        public Layout​(int layoutId,
                      java.lang.String layoutName,
                      Scale scale,
                      int fastClock,
                      int throttles,
                      boolean metric)
    • Method Detail

      • getCopy

        public Layout getCopy()
        Make a copy of the layout.
        Returns:
        a new layout instance.
      • setScaleMK

        public void setScaleMK()
        Calculate the length of a scale mile or scale kilometer. The values are adjusted for scale and fast clock ratio. The resulting value is the real feet or meters. The final step is to re-calculate the train times.
        Throws:
        java.lang.IllegalArgumentException - The calculate can throw an exception which will get re-thrown.
      • setLayoutName

        public void setLayoutName​(java.lang.String newName)
      • setFastClock

        public void setFastClock​(int newClock)
        Set a new fast clock speed, update smile/skm.
        Parameters:
        newClock - The value to be used.
        Throws:
        java.lang.IllegalArgumentException - (CLOCK_LT_1) if the value is less than 1. will also re-throw a recalc error.
      • setThrottles

        public void setThrottles​(int newThrottles)
        Set the new value for throttles.
        Parameters:
        newThrottles - The new throttle count.
        Throws:
        java.lang.IllegalArgumentException - (THROTTLES_USED, THROTTLES_LT_0) when the new count is less than train references or a negative number was passed.
      • setMetric

        public void setMetric​(boolean newMetric)
        Set metric flag, update smile/skm.
        Parameters:
        newMetric - True for metric units.
        Throws:
        java.lang.IllegalArgumentException - if there was a recalc error.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • vetoableChange

        public void vetoableChange​(java.beans.PropertyChangeEvent evt)
                            throws java.beans.PropertyVetoException
        Listen for ratio changes to my current scale. Verify that the new ratio is neither too small nor too large. Too large can cause train times to move outside of the schedule window. If the new ratio is invalid, the change will be vetoed.
        Specified by:
        vetoableChange in interface java.beans.VetoableChangeListener
        Parameters:
        evt - The scale ratio property change event.
        Throws:
        java.beans.PropertyVetoException - The message will depend on the actual error.