// //polygon2.lineTo(5, 9);
// polygon2.closePath();
// paintedList.add(new PaintedPath(polygon2, (float) 1.0, Color.black));
// figure = new PaintedFigure(paintedList);
figure = new BasicFigure(polygon, new Color(0, 0, 0, 0),
(float) 0.0);
} else {
figure = new BasicFigure(polygon, fill, (float) 1.5);
}
if (!(port instanceof IOPort)) {
direction = SwingConstants.NORTH;
} else {
IOPort ioport = (IOPort) port;
if (ioport.isInput() && ioport.isOutput()) {
direction = SwingConstants.NORTH;
} else if (ioport.isInput()) {
direction = SwingConstants.EAST;
} else if (ioport.isOutput()) {
direction = SwingConstants.WEST;
} else {
// should never happen
direction = SwingConstants.NORTH;
}
}
double normal = CanvasUtilities.getNormal(direction);
String name = port.getName();
Rectangle2D backBounds = figure.getBounds();
figure = 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() {
return _portTooltip(port);
}
};
if ((name != null) && !name.equals("")
&& !(port instanceof ParameterPort)) {
LabelFigure label = new LabelFigure(name, _labelFont, 1.0,
SwingConstants.SOUTH_WEST);
// Shift the label slightly right so it doesn't
// collide with ports.
label.translateTo(backBounds.getX(), backBounds.getY());
((CompositeFigure) figure).add(label);
}
if (port instanceof IOPort) {
// Create a diagonal connector for multiports, if necessary.
IOPort ioPort = (IOPort) port;
if (ioPort.isMultiport()) {
int numberOfLinks = ioPort.insideRelationList().size();
if (numberOfLinks > 1) {
// The diagonal is necessary.
// Line depends on the orientation.
double startX;
// The diagonal is necessary.
// Line depends on the orientation.
double startY;
// The diagonal is necessary.
// Line depends on the orientation.
double endX;
// The diagonal is necessary.
// 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 * IOPortController.MULTIPORT_CONNECTION_SPACING);
endY = startY
+ (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
} else if (direction == SwingConstants.WEST) {
startX = x;
startY = y + (height / 2);
endX = startX
- (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
endY = startY
- (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
} else if (direction == SwingConstants.NORTH) {
startX = x + (width / 2);
startY = y;
endX = startX
- (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
endY = startY
- (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
} else {
startX = x + (width / 2);
startY = y + height;
endX = startX
+ (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
endY = startY
+ (extent * IOPortController.MULTIPORT_CONNECTION_SPACING);
}
Line2D line = new Line2D.Double(startX, startY,
endX, endY);
Figure lineFigure = new BasicFigure(line, fill,
(float) 2.0);
((CompositeFigure) figure).add(lineFigure);
}
}
figure = new PortTerminal(ioPort, figure, normal, true);
} else {
Site tsite = new PerimeterSite(figure, 0);
tsite.setNormal(normal);
tsite = new FixedNormalSite(tsite);
figure = new TerminalFigure(figure, tsite) {
// Override this because the tooltip may
// change over time. I.e., the port may
// change from being an input or output, etc.
public String getToolTipText() {
return _portTooltip(port);
}
};
}
// Have to do this as well or awt will not render a tooltip.
figure.setToolTipText(port.getName());
} else {
polygon.moveTo(0, 0);
polygon.lineTo(0, 10);
polygon.lineTo(12, 0);
polygon.lineTo(0, -10);
polygon.closePath();
figure = new BasicFigure(polygon, Color.black);
figure.setToolTipText("Unknown port");
}
return figure;
}