iconTextLayout = getVertexTextLayout(g2d, iconText, 0.8);
iconTextWidth = (int) iconTextLayout.getBounds().getWidth();
}
/* right corner text */
final ColorText rightCornerText = getRightCornerText((Vertex) v, getRunMode());
TextLayout rightCornerTextLayout = null;
if (rightCornerText != null && !"".equals(rightCornerText.getSubtext())) {
rightCornerTextLayout = getVertexTextLayout(g2d, rightCornerText.getSubtext(), 0.8);
final int rightCornerTextWidth = (int) rightCornerTextLayout.getBounds().getWidth();
if (iconTextWidth + rightCornerTextWidth + 10 > shapeWidth) {
shapeWidth = iconTextWidth + rightCornerTextWidth + 10;
}
}
/* subtext */
final ColorText[] colorTexts = getSubtexts((Vertex) v, getRunMode());
TextLayout[] subtextLayouts = null;
if (colorTexts != null) {
subtextLayouts = new TextLayout[colorTexts.length];
int i = 0;
for (final ColorText colorText : colorTexts) {
subtextLayouts[i] = getVertexTextLayout(g2d, colorText.getSubtext(), 0.8);
final int subtextWidth = (int) subtextLayouts[i].getBounds().getWidth();
if (subtextWidth + 10 > shapeWidth) {
shapeWidth = subtextWidth + 10;
}
i++;
}
if (i > 1) {
shapeHeight += (i - 1) << 3;
}
shapeHeight += 3;
}
final int oldShapeWidth = getVertexWidth((Vertex) v);
final int oldShapeHeight = getVertexHeight((Vertex) v);
if (isRunModeTestAnimation()) {
if (oldShapeWidth > shapeWidth) {
shapeWidth = oldShapeWidth;
}
if (oldShapeHeight > shapeHeight) {
shapeHeight = oldShapeHeight;
}
}
final boolean widthChanged = Math.abs(oldShapeWidth - shapeWidth) > 5;
final boolean heightChanged = Math.abs(oldShapeHeight - shapeHeight) > 1;
if (widthChanged || heightChanged) {
somethingChanged();
/* move it, so that left side has the same position, if it is
* resized */
final Point2D pos = layout.transform((Vertex) v);
if (pos != null) {
double x = pos.getX();
double y = pos.getY();
if (widthChanged) {
setVertexWidth((Vertex) v, shapeWidth);
x -= (oldShapeWidth - getVertexWidth((Vertex) v)) / 2;
}
if (heightChanged) {
setVertexHeight((Vertex) v, shapeHeight);
y -= (oldShapeHeight - getVertexHeight((Vertex) v)) / 2;
}
pos.setLocation(x, y);
application.invokeLater(new Runnable() {
@Override
public void run() {
scale();
}
});
}
}
/* shape */
super.paintShapeForVertex(rc, v, shape);
Point2D loc = layout.transform((Vertex) v);
loc = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, loc);
final double x = loc.getX() - getVertexWidth((Vertex) v) / 2;
final double height = getDefaultVertexHeight((Vertex) v);
final double y = loc.getY() - getVertexHeight((Vertex) v) / 2;
drawInside((Vertex) v, g2d, x, y, shape);
/* icon */
if (icons != null) {
for (final ImageIcon icon : icons) {
icon.setDescription("");
g2d.drawImage(icon.getImage(),
(int) (x + 4),
(int) (y + height / 2 - icon.getIconHeight() / 2),
null);
}
}
/* texts are drawn from left down corner. */
if (mainTextLayout != null) {
final int textW = (int) mainTextLayout.getBounds().getWidth();
final int textH = (int) mainTextLayout.getBounds().getHeight();
drawVertexText(g2d,
mainTextLayout,
x + shapeWidth / 2 - textW / 2, /* middle */
y + height / 2 + textH / 2,
new Color(0, 0, 0),
255);
}
if (iconTextLayout != null) {
drawVertexText(g2d, iconTextLayout, x + 4, y + 11, new Color(0, 0, 0), 255);
}
if (rightCornerTextLayout != null) {
drawVertexText(g2d,
rightCornerTextLayout,
x + shapeWidth - rightCornerTextLayout.getBounds().getWidth() - 4,
y + 11,
rightCornerText.getTextColor(),
255);
}
if (subtextLayouts != null) {
int i = 0;
for (final TextLayout l : subtextLayouts) {
int alpha = 255;
final ColorText colorText = colorTexts[i];
if (" ".equals(colorText.getSubtext().substring(0, 1))) {
alpha = 128;
}
final Color color = colorText.getColor();
if (color != null) {
final Paint p =
new GradientPaint((float) x + shapeWidth / 2,
(float) y,
getVertexFillSecondaryColor((Vertex) v),
(float) x + shapeWidth / 2,
(float) y + shapeHeight,
color,
false);
g2d.setPaint(p);
g2d.fillRect((int) x + 4, (int) (y + height - 3 + 8 * (i - 1)), shapeWidth - 8, 9);
}
final Color textColor = colorText.getTextColor();
drawVertexText(g2d, l, x + 4, y + height - 4 + 8 * i, textColor, alpha);
i++;
}
}