
org.yaoqiang.graph.shape.ConversationLinkShape 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.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.shape.mxBasicShape;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
/**
* ConversationLinkShape
*
* @author Shi Yaoqiang([email protected])
*/
public class ConversationLinkShape extends mxBasicShape {
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {
if (state.getAbsolutePointCount() > 1 && configureGraphics(canvas, state, false)) {
List pts = new ArrayList(state.getAbsolutePoints());
Map style = state.getStyle();
paintPolyline(canvas, pts, style);
}
}
protected void paintPolyline(mxGraphics2DCanvas canvas, List points, Map style) {
boolean rounded = isRounded(style) && canvas.getScale() > mxConstants.MIN_SCALE_FOR_ROUNDED_LINES;
canvas.paintPolyline(points.toArray(new mxPoint[points.size()]), rounded);
double scale = canvas.getScale() * 3;
List pointsB = new ArrayList();
mxPoint[] p = points.toArray(new mxPoint[points.size()]);
double a = p[0].getX() - p[p.length - 1].getX();
double b = p[0].getY() - p[p.length - 1].getY();
if ((int) p[0].getX() == (int) p[1].getX()) {
pointsB.add(new mxPoint(p[0].getX() - scale, p[0].getY()));
if (a * b < 0) {
pointsB.add(new mxPoint(p[1].getX() - scale, p[1].getY() - scale));
if (p.length == 3) {
pointsB.add(new mxPoint(p[2].getX(), p[2].getY() - scale));
} else {
pointsB.add(new mxPoint(p[2].getX() - scale, p[2].getY() - scale));
}
}
} else {
pointsB.add(new mxPoint(p[0].getX(), p[0].getY() + scale));
if (a * b < 0) {
pointsB.add(new mxPoint(p[1].getX() + scale, p[1].getY() + scale));
if (p.length == 3) {
pointsB.add(new mxPoint(p[2].getX() + scale, p[2].getY()));
} else {
pointsB.add(new mxPoint(p[2].getX() + scale, p[2].getY() + scale));
}
}
}
if (a * b > 0) {
pointsB.add(new mxPoint(p[1].getX() - scale, p[1].getY() + scale));
if (p.length == 3) {
if ((int) p[0].getX() == (int) p[1].getX()) {
pointsB.add(new mxPoint(p[2].getX(), p[2].getY() + scale));
} else {
pointsB.add(new mxPoint(p[2].getX() - scale, p[2].getY()));
}
} else {
pointsB.add(new mxPoint(p[2].getX() - scale, p[2].getY() + scale));
}
}
if (p.length != 3 || (int)a == 0 || (int)b == 0) {
if ((int) p[p.length - 2].getX() == (int) p[p.length - 1].getX()) {
pointsB.add(new mxPoint(p[p.length - 1].getX() - scale, p[p.length - 1].getY()));
} else if ((int) p[p.length - 2].getY() == (int) p[p.length - 1].getY()) {
pointsB.add(new mxPoint(p[p.length - 1].getX(), p[p.length - 1].getY() + scale));
}
}
canvas.paintPolyline(pointsB.toArray(new mxPoint[pointsB.size()]), rounded);
}
public boolean isRounded(Map style) {
return mxUtils.isTrue(style, mxConstants.STYLE_ROUNDED, false);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy