|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.visuals.UnitsBox
public class UnitsBox
A UnitsBox object is a visual component for entering a measurement value as a number, in one of a set of units. One of the units is a preferred unit i.e. has a scale of 1.0) and the other units are scaled in relation to that preferred unit. For example, this field may be used to enter a distance; the units may be
millimeter centimeter inch foot meter 0.001 0.01 0.02541 0.304878 1.0In this case, meter is the preferred unit. Or for measuring time, the units may be
millisecond second minute hour day 0.001 1.0 60.0 3600.0 86400.0and the preferred units is second.
The units and their scaling factors are supplied via a AssociationListInterface; the keys are the unit labels (which are typically strings but may be any object) and the values are java.lang.Number objects containing the units. The toString() value of the keys are used in the combo box drop down list unless a display transform is supplied to convert the keys to strings.
The visual component consists of a text entry field, a spin button for incrementing/decrementing the doubleData, and a combo box which shows the current units. Changing the units will scale the number in the text field, but it does not change the UnitsBox doubleData property.
The UnitsBox presents two main properties.
Field Summary | |
---|---|
protected Choice |
choice
|
static java.lang.String |
RB_KEY
|
protected SpinBox |
spinBox
|
Constructor Summary | |
---|---|
UnitsBox()
Default constructor |
Method Summary | |
---|---|
void |
attachModel(com.sas.ModelInterface model)
Attaches the specified model to this view. |
void |
contentsChanged(com.sas.collection.ContentsChangedEvent event)
handle a change in the units association list. |
protected void |
createComponents()
Create the components of the composite object. |
double |
getCurrentScale()
Return the amount by which the number is scaled The number in the text field is scaled by this much (determined by the current units) to calculate the doubleData property. |
java.lang.Object |
getCurrentUnits()
Deprecated. use getDisplayedUnit() |
static int |
getDefaultHeight()
|
static int |
getDefaultWidth()
|
java.lang.Object |
getDisplayedUnit()
Return the current units |
double |
getDoubleData()
Return the numeric value of the UnitsBox object. |
double |
getEquivalent(java.lang.String unit)
Deprecated. use getMagnitude (Object unit) |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
|
double |
getMagnitude()
Return the numeric value of the UnitsBox object. |
double |
getMagnitude(java.lang.Object unit)
Get the magnitude in the given unit. |
double |
getMaximumMagnitude()
Return the value of the maximumMagnitude property. |
double |
getMinimumMagnitude()
Return the value of the minimumMagnitude property. |
java.lang.Object |
getPreferredUnits()
Deprecated. use getUnit() |
java.util.Vector |
getRequiredInterfaces()
Returns the required interfaces Vector for this component. |
java.lang.String |
getText()
Get the text value of the object |
boolean |
getTextScaled()
Deprecated. This property has been removed. |
java.lang.Object |
getUnit()
Return the preferred unit of UnitsBox |
java.lang.String |
getUnitName()
Return the preferred unit of UnitsBox |
com.sas.collection.AssociationListInterface |
getUnits()
return the units association list. |
com.sas.util.transforms.TransformInterface |
getUnitsDisplayTransform()
return the units display transform |
protected void |
hookupComponents()
Hookup the components by establishing event listener lists, etc. |
void |
initialize()
Initialize the component. |
protected void |
layoutComponents()
Lays out the components in a layout manager. |
static com.sas.collection.AssociationListInterface |
makeTimeUnits()
Deprecated. Use com.sas.measures.Time.makeUnitsAssociationList() |
protected Choice |
newChoice()
Factory method for creating the choice Override this in subclasses if you want to use a different choice object |
protected SpinBox |
newSpinBox()
|
void |
pickBestUnits()
Change the units to one whose scale is closest to the value. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Handle a property change event from one of the components. |
void |
setColumns(int nCols)
Set the number of columns in the textField of the UnitsBox. |
void |
setCurrentUnits(java.lang.Object unit)
Deprecated. use setDisplayedUnit(Object) |
static void |
setDefaultHeight(int newDefaultHeight)
|
void |
setDefaultValues()
Set default values. |
static void |
setDefaultWidth(int newDefaultWidth)
|
void |
setDisplayedUnit(int i)
Set the current units |
void |
setDisplayedUnit(java.lang.Object unit)
Set the current units. |
void |
setDoubleData(double d)
Set the numeric value of the UnitsBox object. |
void |
setEnabled(boolean e)
setEnabled() is the set accessor method for the Enabled attribute. |
void |
setErrorHandler(ErrorHandlerInterface errorHandler)
Set the errorHandler for the validator of the text in the textField of the SpinBox. |
void |
setForeground(java.awt.Color color)
Overrides setForeground in java.awt.Component. |
void |
setMagnitude(double d)
Set the value of the UnitsBox, in perferred units. |
void |
setMaximumMagnitude(double newMaximumMagnitude)
Set the maximumMagnitude property. |
void |
setMinimumMagnitude(double newMinimumMagnitude)
Set the minimumMagnitude property. |
void |
setText(java.lang.String text)
Set the text attribute. |
void |
setTextScaled(boolean textScaled)
Deprecated. This property has been removed. To get unscaled behavior, simply provide an association list with all values equal to 1.0 |
void |
setUnits(com.sas.collection.AssociationListInterface newUnits)
Set the units used to control the object. |
void |
setUnitsDisplayTransform(com.sas.util.transforms.TransformInterface unitsDisplayTransform)
Set the units display transform. |
void |
setValidator(ValidationInterface validator)
Set the validator for the text in the textField of the SpinBox. |
java.lang.String |
toString()
Get the text value of the object |
protected static java.lang.String |
toString(double d)
format a double as a string, stripping trailing ".0" |
protected void |
updateMagnitude()
Update the magnitude based on changes in the doubleData on the spinBox. |
protected void |
updateText()
Change the text after the units or double data have changed, while preserving the doubleData. |
protected void |
updateUnits()
update the object after the units collection has changed. |
static void |
validateUnits(com.sas.collection.AssociationListInterface unitList)
Check that the units list is valid and throw an exception if not. |
Methods inherited from class com.sas.awt.Panel |
---|
remove, remove, removeAll |
Methods inherited from interface com.sas.awt.ContainerInterface |
---|
getComponents, getLayout, invalidate, setLayout, validate |
Field Detail |
---|
public static final java.lang.String RB_KEY
protected Choice choice
protected SpinBox spinBox
Constructor Detail |
---|
public UnitsBox()
Method Detail |
---|
public static int getDefaultWidth()
public static void setDefaultWidth(int newDefaultWidth)
public static int getDefaultHeight()
public static void setDefaultHeight(int newDefaultHeight)
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
public java.util.Vector getRequiredInterfaces()
getRequiredInterfaces
in interface com.sas.ViewInterface
getRequiredInterfaces
in class PanelVisualComponent
ViewInterface.getRequiredInterfaces()
public void setDefaultValues()
setDefaultValues
in interface ContainerInterface
setDefaultValues
in interface VisualInterface
setDefaultValues
in interface com.sas.ComponentInterface
setDefaultValues
in class CompositePanel
ContainerInterface.setDefaultValues()
public void setEnabled(boolean e)
VisualInterface
setEnabled
in interface VisualInterface
setEnabled
in class PanelVisualComponent
e
- Whether the component should be enabled.VisualInterface.setEnabled(boolean)
public void setForeground(java.awt.Color color)
setForeground
in class java.awt.Component
color
- the new color for the foregroundpublic void setUnits(com.sas.collection.AssociationListInterface newUnits)
newUnits
- an association list that maps
a unit value (the keys in the association list; keys may be any object)
to a scale factor for each unit. The values in the association
list must be java.lang.Number objects; at least one of them
must have the value 1.0; it is referred to as the preferred
unit and all other units are scaled from the preferred unit.protected void hookupComponents()
public void setTextScaled(boolean textScaled)
textScaled
- true to scale the text, not the numeric value;
false to preserve the visible text and scale the number.public boolean getTextScaled()
public void attachModel(com.sas.ModelInterface model)
ViewInterface
attachModel
in interface com.sas.ViewInterface
attachModel
in class PanelVisualComponent
model
- Model to attach toViewInterface.attachModel(com.sas.ModelInterface)
protected void updateUnits()
public com.sas.collection.AssociationListInterface getUnits()
public void contentsChanged(com.sas.collection.ContentsChangedEvent event)
contentsChanged
in interface com.sas.collection.ContentsChangedListener
event
- a contents change event from the units
association list.public static void validateUnits(com.sas.collection.AssociationListInterface unitList)
java.lang.IllegalArgumentException
- if the units contains values but one or more
values is not a java.lang.Number, or if none == 1.0public java.lang.String getText()
getText
in interface com.sas.lang.StringDataInterface
public java.lang.String toString()
toString
in class java.awt.Component
protected static java.lang.String toString(double d)
d
- a double
public void setText(java.lang.String text)
setText
in interface com.sas.lang.StringDataInterface
text
- must consist of a number, one or more spaces, and a string
which matches one of the units toString values,
Examples of valid input are "1.5 hours" or "0.001 meters" or
"3e8 m/s"public void setCurrentUnits(java.lang.Object unit)
unit
- must be one of the keys in the units association listsetDisplayedUnit(Object)
public final java.lang.Object getCurrentUnits()
getDisplayedUnit()
public void setDisplayedUnit(java.lang.Object unit)
unit
- must be one of the keys in the units association listpublic java.lang.Object getDisplayedUnit()
public final java.lang.Object getPreferredUnits()
public java.lang.Object getUnit()
getUnit
in interface com.sas.measures.MeasureInterface
public java.lang.String getUnitName()
getUnitName
in interface com.sas.measures.MeasureInterface
public final double getEquivalent(java.lang.String unit)
public double getMagnitude(java.lang.Object unit)
getMagnitude
in interface com.sas.measures.MeasureInterface
unit
- the unit to scale the magnitude to
return the scaled magnitudepublic double getCurrentScale()
public void setDisplayedUnit(int i)
i
- is an index in the units association list.
java.lang.IndexOutOfBoundsException
- if i is less than 0 or >= units.count()public void pickBestUnits()
public void setColumns(int nCols)
public void setMaximumMagnitude(double newMaximumMagnitude)
newMaximumMagnitude
- the new value for the maximumMagnitude property.public double getMaximumMagnitude()
public void setMinimumMagnitude(double newMinimumMagnitude)
newMinimumMagnitude
- the new value for the minimumMagnitude property.public double getMinimumMagnitude()
protected void updateMagnitude()
public final double getDoubleData()
getDoubleData
in interface com.sas.lang.DoubleDataInterface
getMagnitude(java.lang.Object)
public double getMagnitude()
getMagnitude
in interface com.sas.measures.MeasureInterface
public final void setDoubleData(double d)
setDoubleData
in interface com.sas.lang.DoubleDataInterface
d
- the new numeric value.setMagnitude(double)
public void setMagnitude(double d)
d
- the new value of the UnitsBox.
This is the number of preferred units.
For example, if the preferred units is "meters"
then calling setDoubleData will change the
number of meters. For example, setDoubleData(10300.0)
will set the UnitsBox at 10,300 meters.
If the current (display) units is "kilometers", then
the text field will be set to "10.3" and the text
property will become "10.3 kilometers".
If d < getMinimumMagnitude() or d > getMaximumMagnitude() it is adjusted to be in the valid range defined by those bounds.
protected void updateText()
public void initialize()
initialize
in interface com.sas.ComponentInterface
initialize
in class PanelVisualComponent
ComponentInterface.initialize()
protected Choice newChoice()
protected SpinBox newSpinBox()
protected void createComponents()
protected void layoutComponents()
public void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
propertyChange
in class PanelVisualComponent
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)
public com.sas.util.transforms.TransformInterface getUnitsDisplayTransform()
public void setUnitsDisplayTransform(com.sas.util.transforms.TransformInterface unitsDisplayTransform)
unitsDisplayTransform
- the transform object which this UnitsBox object uses to
to convert the unit values (the keys in the units association list)
into displayable strings in the combo box. If null, then
unit.toString() is used.public void setValidator(ValidationInterface validator)
setValidator
in interface ValidatorInterface
setValidator
in class PanelContainerComponent
public void setErrorHandler(ErrorHandlerInterface errorHandler)
setErrorHandler
in interface ValidatorInterface
setErrorHandler
in class PanelContainerComponent
public static com.sas.collection.AssociationListInterface makeTimeUnits()
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |