All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yaoqiang.graph.shape.ConnectorShape Maven / Gradle / Ivy

There is a newer version: 2.2.18
Show newest version
package org.yaoqiang.graph.shape;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.yaoqiang.graph.model.GraphModel;

import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.shape.mxConnectorShape;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;

/**
 * ConnectorShape
 * 
 * @author Shi Yaoqiang([email protected])
 */
public class ConnectorShape extends mxConnectorShape {

	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();

			GraphModel model = (GraphModel) state.getView().getGraph().getModel();
			if (model.isConditionalSequenceFlow(state.getCell()) && !model.isGateway(model.getTerminal(state.getCell(), true))) {
				style.put(mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 15);
				style.put(mxConstants.STYLE_STARTARROW, "open_diamond");
			} else if (model.isDefaultSequenceFlow(state.getCell())) {
				style.put(mxConstants.STYLE_STARTARROW, "slash");
			}
			// Paints the markers and updates the points
			// Switch off any dash pattern for markers
			boolean dashed = mxUtils.isTrue(style, mxConstants.STYLE_DASHED);
			Object dashedValue = style.get(mxConstants.STYLE_DASHED);

			if (dashed) {
				style.remove(mxConstants.STYLE_DASHED);
				canvas.getGraphics().setStroke(canvas.createStroke(style));
			}

			translatePoint(pts, 0, paintMarker(canvas, state, true));
			translatePoint(pts, pts.size() - 1, paintMarker(canvas, state, false));

			if (dashed) {
				style.put(mxConstants.STYLE_DASHED, dashedValue);
				canvas.getGraphics().setStroke(canvas.createStroke(style));
			}

			paintPolyline(canvas, pts, state.getStyle());
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy