
org.yaoqiang.graph.shape.ConversationNodeShape Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yaoqiang-bpmn-editor Show documentation
Show all versions of yaoqiang-bpmn-editor Show documentation
an Open Source BPMN 2.0 Modeler
package org.yaoqiang.graph.shape;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.Map;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.shape.mxBasicShape;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
/**
* ConversationNodeShape
*
* @author Shi Yaoqiang([email protected])
*/
public class ConversationNodeShape extends mxBasicShape {
public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state) {
Rectangle temp = state.getRectangle();
int x = temp.x;
int y = temp.y;
int w = temp.width;
int h = temp.height;
Polygon hexagon = new Polygon();
hexagon.addPoint(x + (int) (0.25 * w), y);
hexagon.addPoint(x + (int) (0.75 * w), y);
hexagon.addPoint(x + w, y + (int) (0.5 * h));
hexagon.addPoint(x + (int) (0.75 * w), y + h);
hexagon.addPoint(x + (int) (0.25 * w), y + h);
hexagon.addPoint(x, y + (int) (0.5 * h));
return hexagon;
}
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {
super.paintShape(canvas, state);
Map style = state.getStyle();
String image = mxUtils.getString(style, mxConstants.STYLE_IMAGE, "");
if (image != null) {
double scale = canvas.getScale();
double imgWidth = 16 * scale;
double imgHeight = 16 * scale;
Rectangle imageBounds = state.getRectangle();
imageBounds.setRect(imageBounds.getX() + (imageBounds.getWidth() - imgWidth) / 2, imageBounds.getY() + imageBounds.getHeight() - imgHeight,
imgWidth, imgHeight);
canvas.drawImage(imageBounds, canvas.getImageForStyle(style));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy