Package jmri
Class Scale
- All Implemented Interfaces:
BeanInterface,PropertyChangeFirer,PropertyChangeProvider,VetoableChangeProvider
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.
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
-
Field Summary
Fields inherited from class jmri.beans.ConstrainedBean
vetoableChangeSupportFields inherited from class jmri.beans.Bean
propertyChangeSupport -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet the Scale FactorGet the Name of the Scale.doubleGet the Scale Ratio.Get the UserName of the Scale.voidsetScaleRatio(double newRatio) Set the new scale ratio and calculate the scale factor.voidsetUserName(String newName) Set the user name for the current scale.toString()Return a String representation of the Scale.Methods inherited from class jmri.beans.ConstrainedBean
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getIndexedPropertyOrNull, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener, setIndexedProperty, setPropertyMethods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty
-
Constructor Details
-
Scale
public Scale() -
Scale
-
-
Method Details
-
getScaleName
Get the Name of the Scale.- Returns:
- the Scale name.
-
getUserName
Get the UserName of the Scale.- Returns:
- the UserName.
-
getScaleRatio
Get the Scale Ratio.- Returns:
- e.g. 87.1
-
getScaleFactor
Get the Scale Factor- Returns:
- e.g. 1 divided by 87.1
-
setUserName
public void setUserName(@Nonnull String newName) throws IllegalArgumentException, 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:
IllegalArgumentException- The supplied name is a duplicate.PropertyVetoException- The user name change was vetoed.
-
setScaleRatio
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:
IllegalArgumentException- The new ratio is less than 1.PropertyVetoException- The ratio change was vetoed.
-
toString
Return a String representation of the Scale.
-