
org.yaoqiang.graph.shape.EventShape 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.Rectangle;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.util.Map;
import org.yaoqiang.graph.util.Constants;
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;
/**
* EventShape
*
* @author Shi Yaoqiang([email protected])
*/
public class EventShape extends mxBasicShape {
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {
super.paintShape(canvas, state);
Rectangle rect = state.getRectangle();
Map style = state.getStyle();
// Paint Image
double scale = canvas.getScale();
int imgWidth = (int) (mxUtils.getInt(style, mxConstants.STYLE_IMAGE_WIDTH, mxConstants.DEFAULT_IMAGESIZE) * scale);
int imgHeight = (int) (mxUtils.getInt(style, mxConstants.STYLE_IMAGE_HEIGHT, mxConstants.DEFAULT_IMAGESIZE) * scale);
Rectangle imageBounds = state.getRectangle();
imageBounds.setRect(imageBounds.getX() + (imageBounds.getWidth() - imgWidth) / 2, imageBounds.getY() + (imageBounds.getHeight() - imgHeight) / 2,
imgWidth, imgHeight);
canvas.drawImage(imageBounds, canvas.getImageForStyle(style));
String type = mxUtils.getString(style, Constants.STYLE_TYPE, "");
if (type.equals(Constants.EVENT_STYLE_INTERMEDIATE)) {
int inset = (int) Math.round((mxUtils.getFloat(style, mxConstants.STYLE_STROKEWIDTH, 1) + 3) * canvas.getScale());
int x = rect.x + inset;
int y = rect.y + inset;
int w = rect.width - 2 * inset;
int h = rect.height - 2 * inset;
canvas.getGraphics().drawOval(x, y, w, h);
}
}
public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state) {
Rectangle rect = state.getRectangle();
return new Ellipse2D.Float(rect.x, rect.y, rect.width, rect.height);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy