Package jmri
Class Scale
- java.lang.Object
-
- 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.
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
vetoableChangeSupport
-
Fields inherited from class jmri.beans.Bean
propertyChangeSupport
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getScaleFactor()
Get the Scale Factorjava.lang.String
getScaleName()
Get the Name of the Scale.double
getScaleRatio()
Get the Scale Ratio.java.lang.String
getUserName()
Get the UserName of the Scale.void
setScaleRatio(double newRatio)
Set the new scale ratio and calculate the scale factor.void
setUserName(java.lang.String newName)
Set the user name for the current scale.java.lang.String
toString()
-
Methods inherited from class jmri.beans.ConstrainedBean
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getIndexedPropertyOrNull, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener, setIndexedProperty, setProperty
-
Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty
-
-
-
-
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 classjava.lang.Object
-
-