The Role of Argument Maps in
text2gui
Argument
Maps as a Source of Data
at During Conversion
The first purpose of an argument maps is to allow the user to specify
values that
would be used in a GUI component constructed mainly from resource
bundle data.
For example, consider and application that displays information laid
out in a form. Most of the form can be constructed from static data --
text fields, labels, spaces, etc. This static data can originate from a
resource bundle. However, each text field, checkbox,
etc. needs to be filled in with a dynamic value (name,
address, etc.). But it would be a pain
if the caller of the component converter needed to configure these
components
manually -- after all that is the point of using a component converter.
Also we want to leave it up to definition of the component to display
the value -- the caller of the component converter shouldn't need to
know how the values are displayed. So
the solution is to have the caller put the dynamic information
into an argument map before
passing the map to a component converter -- the component converter
then can take values out of the argument map as
needed. com.taco.data.INoReturnMap
specifies the interface for a basic argument map.
Here's an example of a definition for a text field that takes its text
from the argument map:
# Entry point: textField
textField.dispatchType=jtextfield
# Reference the "initialText" key in the argument map
textField.text=$initialText
textField.editable=false
textField.disabledTextColor=GRAY
The text property of the text field is set to $initialText. The $ prefix means that the value
comes from the argument map. The following name, initialText, is the key in the
argument map that is mapped to the desired value. To create the text
field, we would write something like this:
// Get the bundle
bundle =
ChainedResourceBundleFactory.DEFAULT_INSTANCE.getBundle("MyResourceBundle",
locale);
// Create the argument map.
INoReturnMap argMap = new
NoReturnMapAdapter();
// Put the initial text in the
argument map.
argMap.putNoReturn("initialText",
"Howdy!");
// Create the text field.
JTextField textField =
(JTextField) DispatchingComponentConverter.DEFAULT_INSTANCE.toObject(
bundle, "textField", argMap, null);
After these steps, textField
is set to a text field with the text "Howdy!". Note the type of the
argument map in this case -- NoReturnMapAdapter.
This is the most basic implementation of an argument map, which is not
observable. The putNoReturn()
method does the same thing as Map.put(),
but for efficiency, has no return value.
Whenever a reference to an argument map value like $initialText is found, the
value corresponding to the initialText
key is read from the argument map to use as a property value. This can
be disabled by adding a suffix to the reference as in $initialText:w. The lack of an r after the colon (':') means that the value is
not read from the argument map initially -- the default value is used.