/** Render a link.
*/
public class LinkRenderer implements EdgeRenderer {
/** Render a visual representation of the given edge. */
public Connector render(Object edge, Site tailSite, Site headSite) {
ArcConnector c = new ArcConnector(tailSite, headSite);
Arrowhead arrowhead = new Arrowhead();
c.setHeadEnd(arrowhead);
c.setLineWidth((float) 2.0);
c.setUserObject(edge);
Arc arc = (Arc) edge;
Transition transition = (Transition) arc.getRelation();
// When first dragging out a transition, the relation
// may still be null.
if (transition != null) {
// Use a larger, unfilled arrowhead for a reset transition.
try {
if (((BooleanToken) transition.reset.getToken())
.booleanValue()) {
arrowhead.setFilled(false);
}
} catch (IllegalActionException e) {
// Ignore erroneous parameter value.
}
if (transition.isPreemptive()) {
Blob blob = new Blob(0, 0, 0, Blob.BLOB_CIRCLE, 4.0,
Color.red);
blob.setFilled(true);
c.setTailEnd(blob);
}
if (transition.isNondeterministic()) {
c.setStrokePaint(Color.RED);
}
c.setToolTipText(transition.getName());
String labelStr = transition.getLabel();
try {
double exitAngle = ((DoubleToken) (transition.exitAngle
.getToken())).doubleValue();
// If the angle is too large, then truncate it to
// a reasonable value.
double maximum = 99.0 * Math.PI;
if (exitAngle > maximum) {
exitAngle = maximum;
} else if (exitAngle < -maximum) {
exitAngle = -maximum;
}
// If the angle is zero, then the arc does not get
// drawn. So we restrict it so that it can't quite
// go to zero.
double minimum = Math.PI / 999.0;
if ((exitAngle < minimum) && (exitAngle > -minimum)) {
if (exitAngle > 0.0) {
exitAngle = minimum;
} else {
exitAngle = -minimum;
}
}
c.setAngle(exitAngle);
// Set the gamma angle
double gamma = ((DoubleToken) (transition.gamma.getToken()))
.doubleValue();
c.setGamma(gamma);
} catch (IllegalActionException ex) {
// Ignore, accepting the default.
// This exception should not occur.
}
if (!labelStr.equals("")) {
// FIXME: get label position modifier, if any.
LabelFigure label = new LabelFigure(labelStr, _labelFont);
label.setFillPaint(Color.black);
c.setLabelFigure(label);
}
}
return c;
}