com.sas.awt
Class Choice

com.sas.awt.Choice
All Implemented Interfaces:
VisualInterface, com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.collection.ContentsChangedListener, com.sas.ComponentInterface, com.sas.lang.StringDataInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, com.sas.PublicClonable, com.sas.ViewDefaultModelInterface, com.sas.ViewInterface, MultipleValueEventSourceInterface, ResizeToFitInterface, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.accessibility.Accessible

public class Choice
implements com.sas.collection.ContentsChangedListener, com.sas.lang.StringDataInterface, com.sas.PublicClonable, ResizeToFitInterface, com.sas.ViewDefaultModelInterface

Choice is a component that maintains a dropdown list of items for selection.

Creation:

  1. Create a choice

    Choice choice1 = new Choice();
    choice1.initialize();


Default Size:
Required Interfaces:
Choice requires a model that implements com.sas.collection.StaticOrderedCollectionInterface. A default model is automatically created and attached to the choice when the Choice is initially constructed.

Events:
The Choice sends out an ItemEvent when an item is selected in the dropdown list.

Notes:

See Also:
Serialized Form

Field Summary
static java.lang.String RB_KEY
           
 
Constructor Summary
Choice()
          Default constructor
 
Method Summary
 void add(java.lang.Object item)
          Adds an item to the end of the list if the attached model supports addition of items.
 void add(java.lang.Object[] items)
          Adds items to the end of the list if the attached model supports addition of items.
 void add(java.lang.String item)
          Adds an item to the end of the list if the attached model supports addition of items.
 void addItems(java.util.Enumeration items)
          Adds items to the end of the list if the attached model supports addition of items.
 void addNotify()
          Notifies the component that it has been added to a container and that the peer should be created.
 void attachModel(com.sas.ModelInterface model)
          Attaches a model to the component.
 java.lang.Object clone()
          Clones the component
 java.awt.Dimension computePreferredSize()
          Returns the preferred size of the component
 void contentsChanged(com.sas.collection.ContentsChangedEvent evt)
          Called when the contents of the Model have changed.
 void detachModel(com.sas.ModelInterface model)
          Detaches the current model and attaches the default model if the model is set to null
static int getDefaultHeight()
          Returns the default height for instances of this class
static int getDefaultWidth()
          Returns the default width for instances of this class
 com.sas.util.transforms.TransformInterface getDisplayTransform()
          Returns the display transform.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns the ExtendedBeanInfo for this class.
 java.lang.String[] getInitialItems()
          Returns the initial items (an empty string array is returned if there are no initial items)
 com.sas.util.transforms.TransformInterface getInputTransform()
          Returns the InputTransform
 java.lang.String[] getItems()
          Returns the items in the model (an empty string array is returned is there are no items)
 com.sas.util.transforms.TransformInterface getOutputTransform()
          Returns the OutputTransform
 java.util.Vector getRequiredInterfaces()
          Returns the required interfaces Vector for this component.
 java.lang.Object[] getSelectedObjects()
          Returns the selected object This method is overriden in order to actually contain an object within the object array(AWT returns an object array containing a string item)
 java.lang.String getText()
          Returns the selected item.
 void insert(java.lang.Object item, int index)
          Adds an item at the specified location if the attached model supports addition of items.
 void insert(java.lang.String item, int index)
          Adds an item at the specified location if the attached model supports addition of items.
 boolean isDefaultModelAttached()
          Returns whether the default model is attached.
 boolean isResizeToFit()
          Returns the value of the resizeToFit property The resizeToFit property determines whether to change the size of the component when either the text or font changes.
protected  void processItemEvent(java.awt.event.ItemEvent e)
          Processes item events occurring on this component.Subclasses should always call super so that events are delivered to any ItemListeners.
 void refresh()
          Clear current items and add items obtained from the attached model
 void refresh(com.sas.ModelInterface model)
          Clear current items and add items obtained from the attached model
 void remove(int position)
          Removes the item at the specified position if the attached model supports removal of items.
 void remove(java.lang.Object item)
          Removes the first occurrence of item if the attached model supports removal of items.
 void remove(java.lang.String item)
          Removes the first occurrence of item if the attached model supports removal of items.
 void removeAll()
          Removes all items if the attached model supports removal of items.
 void select(int index)
          Selects the item corresponding to the specified index
 void select(java.lang.String str)
          Selects the item corresponding to the specified string.
static void setDefaultHeight(int newDefaultHeight)
          Sets the default height of the component.
 void setDefaultValues()
          Sets the initial values to the default values.
static void setDefaultWidth(int newDefaultWidth)
          Sets the default width of the component.
 void setDisplayTransform(com.sas.util.transforms.TransformInterface transform)
          Sets the display transform.
 void setFont(java.awt.Font font)
          Sets the font to be used by the component for displaying text.
 void setInitialItems(java.lang.String[] items)
          Sets the initialItems on the Choice.
 void setInputTransform(com.sas.util.transforms.TransformInterface transform)
          Sets the input Transform.
 void setItems(java.lang.Object[] items)
          Sets the items if the attached model supports addition of items
 void setItems(java.lang.String[] items)
          Sets the items
 void setOutputTransform(com.sas.util.transforms.TransformInterface transform)
          Sets the output Transform.
 void setResizeToFit(boolean resizeToFit)
          Sets the value of the resizeToFit property.
 void setSelectedIndex(int index)
          Selects the item corresponding to the specified index
 void setSelectedItem(java.lang.Object text)
          Sets the selected item to the specified object.
 void setSelectedItem(java.lang.String text)
          Sets the selected item to the specified string.
 void setText(java.lang.String text)
          Sets the selected item.
 
Methods inherited from class com.sas.awt.ChoiceVisualComponent
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachView, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getBackgroundColor, getBorder, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getFont, getForegroundColor, getHeight, getHorizontalPosition, getLinkInfo, getMinimumSize, getModelInterface, getPreferredSize, getPrePainter, getVerticalPosition, getViewInterfaceSupportInfo, getVisualInterfaceSupportInfo, getWidth, initialize, initializeComponent, isDesignTime, isEnabled, isFocus, isLinked, isTransparent, isVisible, paint, propertyChange, queryLinks, queryLinks, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setBackgroundColor, setBorder, setBounds, setComponentDescription, setComponentSupportInfo, setEnabled, setFocus, setForegroundColor, setHeight, setHorizontalPosition, setLinkInfo, setModelInterface, setPreferredSize, setPrePainter, setRequiredInterfaces, setTransparent, setVerticalPosition, setViewInterfaceSupportInfo, setVisible, setVisualInterfaceSupportInfo, setWidth, superGetFont, superGetMinimumSize, superGetPreferredSize, superIsEnabled, superIsVisible, superPaint, superSetBounds, superSetEnabled, superSetFont, superSetVisible, superUpdate, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, update, validateObject
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values
Constructor Detail

Choice

public Choice()
Default constructor

Method Detail

getDefaultWidth

public static int getDefaultWidth()
Returns the default width for instances of this class

Returns:
the default width in pixels
See Also:
setDefaultWidth(int)

setDefaultWidth

public static void setDefaultWidth(int newDefaultWidth)
Sets the default width of the component. The default width will be used by webAF when creating this component.

Parameters:
newDefaultWidth - the new default width in pixels
See Also:
getDefaultWidth()

getDefaultHeight

public static int getDefaultHeight()
Returns the default height for instances of this class

Returns:
the default height in pixels
See Also:
setDefaultHeight(int)

setDefaultHeight

public static void setDefaultHeight(int newDefaultHeight)
Sets the default height of the component. The default height will be used by webAF when creating this component.

Parameters:
newDefaultHeight - the new default height in pixels
See Also:
getDefaultHeight()

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns the ExtendedBeanInfo for this class.

Returns:
ExtendedBeanInfo for this class

add

public void add(java.lang.String item)
Adds an item to the end of the list if the attached model supports addition of items.

Overrides:
add in class java.awt.Choice
Parameters:
item - item to be added

add

public void add(java.lang.Object[] items)
Adds items to the end of the list if the attached model supports addition of items.

Parameters:
items - items to be added

addItems

public void addItems(java.util.Enumeration items)
Adds items to the end of the list if the attached model supports addition of items.

Parameters:
items - items to be added

add

public void add(java.lang.Object item)
Adds an item to the end of the list if the attached model supports addition of items.

Parameters:
item - item to be added

addNotify

public void addNotify()
Notifies the component that it has been added to a container and that the peer should be created.

Overrides:
addNotify in class java.awt.Choice

attachModel

public void attachModel(com.sas.ModelInterface model)
Attaches a model to the component. Listens for PropertyChangeEvents from the model.

Specified by:
attachModel in interface com.sas.ViewInterface
Overrides:
attachModel in class ChoiceVisualComponent
Parameters:
model - model to attach
See Also:
ViewInterface.attachModel(com.sas.ModelInterface)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the component

Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class ChoiceVisualComponent
Returns:
new instance of the Choice
Throws:
java.lang.CloneNotSupportedException - if the model attached to the component being cloned will not allow the clone to attach.

computePreferredSize

public java.awt.Dimension computePreferredSize()
Returns the preferred size of the component

Specified by:
computePreferredSize in interface VisualInterface
Overrides:
computePreferredSize in class ChoiceVisualComponent
Returns:
preferred size
See Also:
VisualInterface.computePreferredSize()

contentsChanged

public void contentsChanged(com.sas.collection.ContentsChangedEvent evt)
Called when the contents of the Model have changed.

Specified by:
contentsChanged in interface com.sas.collection.ContentsChangedListener
Parameters:
evt - ContentsChangedEvent from the Model

detachModel

public void detachModel(com.sas.ModelInterface model)
Detaches the current model and attaches the default model if the model is set to null

Specified by:
detachModel in interface com.sas.ViewInterface
Overrides:
detachModel in class ChoiceVisualComponent
Parameters:
model - Model to detach
See Also:
ViewInterface.detachModel(com.sas.ModelInterface)

getDisplayTransform

public com.sas.util.transforms.TransformInterface getDisplayTransform()
Returns the display transform.

Returns:
the display transform
See Also:
setDisplayTransform(com.sas.util.transforms.TransformInterface)

getInitialItems

public java.lang.String[] getInitialItems()
Returns the initial items (an empty string array is returned if there are no initial items)

Returns:
initial items
See Also:
setInitialItems(java.lang.String[])

getInputTransform

public com.sas.util.transforms.TransformInterface getInputTransform()
Returns the InputTransform

Returns:
inputTransform
See Also:
setInputTransform(com.sas.util.transforms.TransformInterface)

getItems

public java.lang.String[] getItems()
Returns the items in the model (an empty string array is returned is there are no items)

Returns:
items in the model

getOutputTransform

public com.sas.util.transforms.TransformInterface getOutputTransform()
Returns the OutputTransform

Returns:
outputTransform
See Also:
setOutputTransform(com.sas.util.transforms.TransformInterface)

getRequiredInterfaces

public java.util.Vector getRequiredInterfaces()
Returns the required interfaces Vector for this component.

Specified by:
getRequiredInterfaces in interface com.sas.ViewInterface
Overrides:
getRequiredInterfaces in class ChoiceVisualComponent
Returns:
the required interfaces Vector for this component.
See Also:
ViewInterface.getRequiredInterfaces()

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Returns the selected object This method is overriden in order to actually contain an object within the object array(AWT returns an object array containing a string item)

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Overrides:
getSelectedObjects in class java.awt.Choice
Returns:
object array of one item that contains the object selected

getText

public java.lang.String getText()
Returns the selected item.

Specified by:
getText in interface com.sas.lang.StringDataInterface
Returns:
selected Item
See Also:
setText(java.lang.String)

insert

public void insert(java.lang.Object item,
                   int index)
Adds an item at the specified location if the attached model supports addition of items.

Parameters:
item - item to be added
index - location for adding the item

insert

public void insert(java.lang.String item,
                   int index)
Adds an item at the specified location if the attached model supports addition of items.

Overrides:
insert in class java.awt.Choice
Parameters:
item - item to be added
index - location for adding the item

isDefaultModelAttached

public boolean isDefaultModelAttached()
Returns whether the default model is attached.

Specified by:
isDefaultModelAttached in interface com.sas.ViewDefaultModelInterface
Returns:
whether the default model is attached.

isResizeToFit

public boolean isResizeToFit()
Returns the value of the resizeToFit property The resizeToFit property determines whether to change the size of the component when either the text or font changes.

Specified by:
isResizeToFit in interface ResizeToFitInterface
Returns:
value of the resizeToFit property
See Also:
setResizeToFit(boolean)

processItemEvent

protected void processItemEvent(java.awt.event.ItemEvent e)
Processes item events occurring on this component.Subclasses should always call super so that events are delivered to any ItemListeners.

Overrides:
processItemEvent in class java.awt.Choice
Parameters:
e - event to be handled

refresh

public void refresh()
Clear current items and add items obtained from the attached model


refresh

public void refresh(com.sas.ModelInterface model)
Clear current items and add items obtained from the attached model

Specified by:
refresh in interface com.sas.ViewInterface
Overrides:
refresh in class ChoiceVisualComponent
Parameters:
model - attached model
See Also:
ViewInterface.refresh(com.sas.ModelInterface)

remove

public void remove(int position)
Removes the item at the specified position if the attached model supports removal of items.

Overrides:
remove in class java.awt.Choice
Parameters:
position - the index of the item to remove

remove

public void remove(java.lang.Object item)
Removes the first occurrence of item if the attached model supports removal of items.

Parameters:
item - item to be removed
Throws:
java.lang.IllegalArgumentException - if item is not found in the component

remove

public void remove(java.lang.String item)
Removes the first occurrence of item if the attached model supports removal of items.

Overrides:
remove in class java.awt.Choice
Parameters:
item - item to be removed
Throws:
java.lang.IllegalArgumentException - if item is not found in the component

removeAll

public void removeAll()
Removes all items if the attached model supports removal of items.

Overrides:
removeAll in class java.awt.Choice

select

public void select(int index)
Selects the item corresponding to the specified index

Overrides:
select in class java.awt.Choice
Parameters:
index - the selected item position

select

public void select(java.lang.String str)
Selects the item corresponding to the specified string.

Overrides:
select in class java.awt.Choice
Parameters:
str - the specified string

setDefaultValues

public void setDefaultValues()
Sets the initial values to the default values. This method is called by the Component constructors. The setDefaultValues method of each class is responsible for setting its own initial values.

Specified by:
setDefaultValues in interface VisualInterface
Specified by:
setDefaultValues in interface com.sas.ComponentInterface
Overrides:
setDefaultValues in class ChoiceVisualComponent
See Also:
ComponentInterface.setDefaultValues()

setDisplayTransform

public void setDisplayTransform(com.sas.util.transforms.TransformInterface transform)
Sets the display transform. The display transform is used to transform the data prior to it being displayed.

Parameters:
transform - the new value for the displayTransform property
See Also:
getDisplayTransform()

setFont

public void setFont(java.awt.Font font)
Sets the font to be used by the component for displaying text.

Specified by:
setFont in interface VisualInterface
Overrides:
setFont in class ChoiceVisualComponent
Parameters:
font - the font to be used by the component for displaying text.
See Also:
Component.setFont(java.awt.Font), ChoiceVisualComponent.getFont()

setInitialItems

public void setInitialItems(java.lang.String[] items)
Sets the initialItems on the Choice. This sets the items on the defaultModel and will attach the defaultModel if it is not already attached. The items will all be transformed using the inputTransform before being added to the model.

Parameters:
items - items to add to the defaultModel
See Also:
getInitialItems()

setInputTransform

public void setInputTransform(com.sas.util.transforms.TransformInterface transform)
Sets the input Transform. The inputTransform is used to transform the input to methods of the Choice to the objects that are in the model.

Parameters:
the - new value for the inputTransform property
See Also:
getInputTransform()

setItems

public void setItems(java.lang.Object[] items)
Sets the items if the attached model supports addition of items

Parameters:
items - an array of elements

setItems

public void setItems(java.lang.String[] items)
Sets the items

Parameters:
items - an array of elements

setOutputTransform

public void setOutputTransform(com.sas.util.transforms.TransformInterface transform)
Sets the output Transform. The outputTransform is used to transform the output from methods of the Choice from the objects that are in the model.

Parameters:
transform - the new value for the outputTransform property
See Also:
getOutputTransform()

setResizeToFit

public void setResizeToFit(boolean resizeToFit)
Sets the value of the resizeToFit property. The resizeToFit property determines whether to change the size of the component when either the text or font changes. The resizeToFit property determines whether to change the size of the component when either the text or font changes. If the component is managed by a layout manager that uses preferred sizes, the component will behave as if the resizeToFit property has been set to true regardless of the actual value of the resizeToFit property.

Specified by:
setResizeToFit in interface ResizeToFitInterface
Parameters:
resizeToFit - boolean value
See Also:
isResizeToFit()

setSelectedIndex

public void setSelectedIndex(int index)
Selects the item corresponding to the specified index

Parameters:
index - the selected item position

setSelectedItem

public void setSelectedItem(java.lang.Object text)
Sets the selected item to the specified object. If more than one item matches the specified object, the one with the smallest index is selected.

Parameters:
text - the string to select

setSelectedItem

public void setSelectedItem(java.lang.String text)
Sets the selected item to the specified string. If more than one item matches the specified string, the one with the smallest index is selected.

Parameters:
text - the string to select

setText

public void setText(java.lang.String text)
Sets the selected item. This method is an alias for setSelectedItem(String).

Specified by:
setText in interface com.sas.lang.StringDataInterface
Parameters:
text - selected item
See Also:
getText()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.