//_isRed = true;
test.send(0, new IntToken(hops + 1));
//Call fireAt to set the color back to white after the delay time.
Director director = getDirector();
double delayTime = ((DoubleToken) delay.getToken())
.doubleValue();
Time time = director.getModelTime().add(delayTime);
director.fireAt(this, time);
} else if (getName().equals(routeTo) || (hops == 0)) {
// Change the color of the icon to green.
_circle2.fillColor.setToken("{0.0, 1.0, 0.0, 1.0}");
CompositeEntity container = (CompositeEntity) getContainer();
Entity destNode = container.getEntity(destination);
Locatable destLocation = (Locatable) destNode.getAttribute(
"_location", Locatable.class);
Locatable myLocation = (Locatable) this.getAttribute(
"_location", Locatable.class);
if ((destLocation == null) || (myLocation == null)) {
throw new IllegalActionException(
"Cannot determine location for node "
+ destNode.getName() + ".");
}
Iterator nodes = _connectedNodes.iterator();
double minDistance = _distanceBetween(destLocation, myLocation);
String to = " ";
boolean multi = ((BooleanToken) doublePath.getToken())
.booleanValue();
double nextMinDistance = _distanceBetween(destLocation,
myLocation);
String to2 = " ";
while (nodes.hasNext()) {
Entity node = (Entity) nodes.next();
Locatable location = (Locatable) node.getAttribute(
"_location", Locatable.class);
if (location == null) {
throw new IllegalActionException(
"Cannot determine location for node "
+ node.getName() + ".");
}
double d = _distanceBetween(destLocation, location);
if (multi) {
if (d < minDistance) {
nextMinDistance = minDistance;
to2 = to;
minDistance = d;
to = node.getName();
} else if (d < nextMinDistance) {
nextMinDistance = d;
to2 = node.getName();
}
} else {
if (d < minDistance) {
minDistance = d;
to = node.getName();
}
}
}
// Request refiring after a certain amount of time specified
// by the <i>delay<i> parameter.
Director director = getDirector();
Token[] values = { new DoubleToken(data),
new StringToken(destination), new StringToken(to),
new IntToken(hops + 1) };
double delayTime = ((DoubleToken) delay.getToken())
.doubleValue();
Time time = director.getModelTime().add(delayTime);
if (_receptions == null) {
_receptions = new HashMap();
}
Double timeDouble = Double.valueOf(time.getDoubleValue());
String[] labels = { "data", "destination", "routeTo", "hops" };
RecordToken result = new RecordToken(labels, values);
_receptions.put(timeDouble, result);
director.fireAt(this, time);
if (multi) {
Token[] values2 = { new DoubleToken(data),
new StringToken(destination), new StringToken(to2),
new IntToken(hops + 1) };
if (_receptions == null) {
_receptions = new HashMap();
}
RecordToken result2 = new RecordToken(labels, values2);
_receptions.put(timeDouble, result2);
director.fireAt(this, time.add(delayTime));
}
//output.send(0, result);
}
} else {