* @param name The name of the entry that has changed.
*/
public void changed(final String name) {
// Check if the entry that changed is in the mapping.
if (_attributes.containsKey(name)) {
final Settable attribute = (Settable) (_attributes.get(name));
if (attribute == null) {
// No associated attribute.
return;
}
ChangeRequest request;
if (attribute instanceof PasswordAttribute) {
// Passwords have to be handled specially because the password
// is not represented in a string.
request = new ChangeRequest(this, name) {
protected void _execute() throws IllegalActionException {
char[] password = getCharArrayValue(name);
((PasswordAttribute) attribute).setPassword(password);
attribute.validate();
Iterator derived = ((PasswordAttribute) attribute)
.getDerivedList().iterator();
while (derived.hasNext()) {
PasswordAttribute derivedPassword = (PasswordAttribute) derived
.next();
derivedPassword.setPassword(password);
}
}
};
} else if (attribute instanceof NamedObj) {
// NOTE: We must use a MoMLChangeRequest so that changes
// propagate to any objects that have been instantiating
// using this one as a class. This is only an issue if
// attribute is a NamedObj.
NamedObj castAttribute = (NamedObj) attribute;
String stringValue = getStringValue(name);
// If the attribute is a DoubleRangeParameter, then we
// have to translate the integer value returned by the
// JSlider into a double.
if (attribute instanceof DoubleRangeParameter) {
try {
int newValue = Integer.parseInt(stringValue);
int precision = ((IntToken) ((DoubleRangeParameter) attribute).precision
.getToken()).intValue();
double max = ((DoubleToken) ((DoubleRangeParameter) attribute).max
.getToken()).doubleValue();
double min = ((DoubleToken) ((DoubleRangeParameter) attribute).min
.getToken()).doubleValue();
double newValueAsDouble = min
+ (((max - min) * newValue) / precision);
stringValue = "" + newValueAsDouble;
} catch (IllegalActionException e) {
throw new InternalErrorException(e);
}
}
// The context for the MoML should be the first container
// above this attribute in the hierarchy that defers its
// MoML definition, or the immediate parent if there is none.
NamedObj parent = castAttribute.getContainer();
String moml = "<property name=\"" + castAttribute.getName()
+ "\" value=\""
+ StringUtilities.escapeForXML(stringValue) + "\"/>";
request = new MoMLChangeRequest(this, // originator
parent, // context
moml, // MoML code
null) { // base
protected void _execute() throws Exception {
synchronized (PtolemyQuery.this) {
try {
_ignoreChangeNotifications = true;
super._execute();
} finally {
_ignoreChangeNotifications = false;
}
}
}
};
} else {
// If the attribute is not a NamedObj, then we
// set its value directly.
request = new ChangeRequest(this, name) {
protected void _execute() throws IllegalActionException {
attribute.setExpression(getStringValue(name));
attribute.validate();
/* NOTE: Earlier version:
// Here, we need to handle instances of Variable
// specially. This is too bad...
if (attribute instanceof Variable) {