Package jmri

Class Scale

  • All Implemented Interfaces:
    BeanInterface, PropertyChangeFirer, PropertyChangeProvider, VetoableChangeProvider

    public class Scale
    extends ConstrainedBean
    Define the characteristics of a layout scale. A scale has four properties.
    • Name - A fixed string, such N or HO.
    • User name - An alternate name that can be changed. It defaults to the scale name.
    • Ratio - The ratio for the scale, such as 160 for N scale.
    • Factor - A derived value created by dividing 1 by the scale ratio.
    In addition to the standard scales, there is custom entry. Custom settings are retained in a local copy of ScaleData.xml.

    Methods are provided to set/get the user name and the scale ratio. The scale factor is generated from the scale ratio and is read only, as is the scale name.

    While changing the ratio and user names of the standard scales is not prohibited, doing so is not recommended due to potential conflicts with other applications.

    Changes to user names and ratios send a vetoableChange event. Interested applications can add a vetoableChange listener in order to be notified when an event occurs. If the listener determines that the change cannot occur, it can throw a PropertyVetoException.

    See Scale Manager for manager details.

    Since:
    4.13.6
    • Constructor Detail

      • Scale

        public Scale​(@Nonnull
                     java.lang.String name,
                     double ratio,
                     java.lang.String userName)
    • Method Detail

      • getScaleName

        public java.lang.String getScaleName()
        Get the Name of the Scale.
        Returns:
        the Scale name.
      • getUserName

        public java.lang.String getUserName()
        Get the UserName of the Scale.
        Returns:
        the UserName.
      • getScaleRatio

        public double getScaleRatio()
        Get the Scale Ratio.
        Returns:
        e.g. 87.1
      • getScaleFactor

        public double getScaleFactor()
        Get the Scale Factor
        Returns:
        e.g. 1 divided by 87.1
      • setUserName

        public void setUserName​(@Nonnull
                                java.lang.String newName)
                         throws java.lang.IllegalArgumentException,
                                java.beans.PropertyVetoException
        Set the user name for the current scale. Registered listeners can veto the change.
        Parameters:
        newName - The name to be applied if unique.
        Throws:
        java.lang.IllegalArgumentException - The supplied name is a duplicate.
        java.beans.PropertyVetoException - The user name change was vetoed.
      • setScaleRatio

        public void setScaleRatio​(double newRatio)
                           throws java.lang.IllegalArgumentException,
                                  java.beans.PropertyVetoException
        Set the new scale ratio and calculate the scale factor. Registered listeners can veto the change.
        Parameters:
        newRatio - A double value containing the ratio.
        Throws:
        java.lang.IllegalArgumentException - The new ratio is less than 1.
        java.beans.PropertyVetoException - The ratio change was vetoed.
      • toString

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