// This could occur if the icon has a _hide parameter.
background = figure;
}
while (ports.hasNext()) {
Port port = (Port) ports.next();
Figure portFigure = getController().getFigure(port);
// If there is no figure, then ignore this port. This may
// happen if the port hasn't been rendered yet.
if (portFigure == null) {
continue;
}
Rectangle2D portBounds = portFigure.getShape().getBounds2D();
PortSite site = new PortSite(background, port, number, count,
direction);
number++;
// NOTE: previous expression for port location was:
// 100.0 * number / (count+1)
// But this leads to squished ports with uneven spacing.
// Note that we don't use CanvasUtilities.translateTo because
// we want to only get the bounds of the background of the
// port figure.
double x = site.getX() - portBounds.getCenterX();
double y = site.getY() - portBounds.getCenterY();
portFigure.translate(x, y);
// If the actor contains a variable named "_showRate",
// with value true, then visualize the rate information.
// NOTE: Showing rates only makes sense for IOPorts.
Attribute showRateAttribute = port.getAttribute("_showRate");
if (port instanceof IOPort
&& showRateAttribute instanceof Variable) {
boolean showRate = false;
try {
showRate = ((Variable) showRateAttribute).getToken()
.equals(BooleanToken.TRUE);
} catch (Exception ex) {
// Ignore.
}
if (showRate) {
// Infer the rate. See DFUtilities.
String rateString = "";
Variable rateParameter = null;
if (((IOPort) port).isInput()) {
rateParameter = (Variable) port
.getAttribute("tokenConsumptionRate");
if (rateParameter == null) {
String altName = "_tokenConsumptionRate";
rateParameter = (Variable) port
.getAttribute(altName);
}
} else if (((IOPort) port).isOutput()) {
rateParameter = (Variable) port
.getAttribute("tokenProductionRate");
if (rateParameter == null) {
String altName = "_tokenProductionRate";
rateParameter = (Variable) port
.getAttribute(altName);
}
}
if (rateParameter != null) {
try {
rateString = rateParameter.getToken()
.toString();
} catch (KernelException ex) {
// Ignore.
}
}
LabelFigure labelFigure = _createPortLabelFigure(
rateString, _portLabelFont, x, y, direction);
labelFigure.setFillPaint(Color.BLUE);
figure.add(labelFigure);
}
}
// If the port contains an attribute named "_showName",
// then render the name of the port as well. If the
// attribute is a boolean-valued parameter, then
// show the name only if the value is true.
Attribute showAttribute = port.getAttribute("_showName");
String toShow = null;
if (showAttribute != null) {
boolean show = true;
if (showAttribute instanceof Parameter) {
try {
Token token = ((Parameter) showAttribute)
.getToken();
if (token instanceof BooleanToken) {
show = ((BooleanToken) token).booleanValue();
}
} catch (IllegalActionException e) {
// Ignore. Presence of the attribute will prevail.
}
}
if (show) {
toShow = port.getDisplayName();
}
}
// In addition, if the port contains an attribute
// called "_showInfo", then if that attribute is
// a variable, then its value is shown. Otherwise,
// if it is a Settable, then its expression is shown.
Attribute showInfo = port.getAttribute("_showInfo");
try {
if (showInfo instanceof Variable
&& !((Variable) showInfo).isStringMode()) {
String value = ((Variable) showInfo).getToken()
.toString();