AffineTransform transform = AffineTransform.getRotateInstance(Math
.toRadians(rotation));
shape = ShapeUtilities.transformModify(shape, transform);
// Create a figure with a tooltip.
Figure figure = new BasicFigure(shape, fill, (float) 1.5) {
// Override this because we want to show the type.
// It doesn't work to set it once because the type
// has not been resolved, and anyway, it may
// change. NOTE: This is copied below.
public String getToolTipText() {
String tipText = port.getName();
String displayName = port.getDisplayName();
if (!tipText.equals(displayName)) {
tipText = displayName + " (" + tipText + ")";
}
StringAttribute _explAttr = (StringAttribute) (port
.getAttribute("_explanation"));
if (_explAttr != null) {
tipText = _explAttr.getExpression();
} else if (port instanceof Typeable) {
try {
tipText = tipText + ", type:"
+ ((Typeable) port).getType();
} catch (IllegalActionException ex) {
// System.out.println("Tooltip failed: " + ex);
}
}
return tipText;
}
};
// Have to do this also, or the AWT doesn't display any
// tooltip at all.
String tipText = port.getName();
String displayName = port.getDisplayName();
if (!tipText.equals(displayName)) {
tipText = displayName + " (" + tipText + ")";
}
figure.setToolTipText(tipText);
double normal = CanvasUtilities.getNormal(direction);
if (port instanceof IOPort) {
// Create a diagonal connector for multiports, if necessary.
IOPort ioPort = (IOPort) port;
if (ioPort.isMultiport()) {
int numberOfLinks = ioPort.linkedRelationList().size();
if (numberOfLinks > 1) {
// The diagonal is necessary.
CompositeFigure compositeFigure = new CompositeFigure(
figure) {
// Override this because we want to show the type.
// It doesn't work to set it once because the type
// has not been resolved, and anyway, it may
// change. NOTE: This is copied from above.
public String getToolTipText() {
String tipText = port.getName();
String displayName = port.getDisplayName();
if (!tipText.equals(displayName)) {
tipText = displayName + " (" + tipText
+ ")";
}
StringAttribute _explAttr = (StringAttribute) (port
.getAttribute("_explanation"));
if (_explAttr != null) {
tipText = _explAttr.getExpression();
} else if (port instanceof Typeable) {
try {
tipText = tipText + ", type:"
+ ((Typeable) port).getType();
} catch (IllegalActionException ex) {
// System.out.println("Tooltip failed: " + ex);
}
}
return tipText;
}
};
// Line depends on the orientation.
double startX;
// Line depends on the orientation.
double startY;
// Line depends on the orientation.
double endX;
// Line depends on the orientation.
double endY;
Rectangle2D bounds = figure.getShape().getBounds2D();
double x = bounds.getX();
double y = bounds.getY();
double width = bounds.getWidth();
double height = bounds.getHeight();
int extent = numberOfLinks - 1;
if (direction == SwingConstants.EAST) {
startX = x + width;
startY = y + (height / 2);
endX = startX
+ (extent * MULTIPORT_CONNECTION_SPACING);
endY = startY
+ (extent * MULTIPORT_CONNECTION_SPACING);
} else if (direction == SwingConstants.WEST) {
startX = x;
startY = y + (height / 2);
endX = startX
- (extent * MULTIPORT_CONNECTION_SPACING);
endY = startY
- (extent * MULTIPORT_CONNECTION_SPACING);
} else if (direction == SwingConstants.NORTH) {
startX = x + (width / 2);
startY = y;
endX = startX
- (extent * MULTIPORT_CONNECTION_SPACING);
endY = startY
- (extent * MULTIPORT_CONNECTION_SPACING);
} else {
startX = x + (width / 2);
startY = y + height;
endX = startX
+ (extent * MULTIPORT_CONNECTION_SPACING);
endY = startY
+ (extent * MULTIPORT_CONNECTION_SPACING);
}
Line2D line = new Line2D.Double(startX, startY, endX,
endY);
Figure lineFigure = new BasicFigure(line, fill,
(float) 2.0);
compositeFigure.add(lineFigure);
figure = compositeFigure;
}
}