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

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

package org.yaoqiang.graph.shape;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.util.Map;

import org.yaoqiang.bpmn.model.elements.collaboration.Participant;
import org.yaoqiang.graph.model.GraphModel;
import org.yaoqiang.util.Constants;

import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.model.mxICell;
import com.mxgraph.shape.mxBasicShape;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;

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

	public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {
		if (!(((mxICell) state.getCell()).getValue() instanceof Participant)) {
			return;
		}
		Map style = state.getStyle();
		GraphModel model = (GraphModel) state.getView().getGraph().getModel();
		if (model.isInitiatingChoreographyParticipant(state.getCell())) {
			style.put(mxConstants.STYLE_FILLCOLOR, "#E8EEF7");
			style.put(mxConstants.STYLE_GRADIENTCOLOR, "#B8BEC7");
		}
		super.paintShape(canvas, state);

		if (((Participant) model.getValue(state.getCell())).getMultiplicity() > 1) {
			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, Constants.SHAPE_MARKER + "loop_multiple.png");
		}
	}

	public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state) {
		Map style = state.getStyle();
		Rectangle rect = state.getRectangle();
		String position = mxUtils.getString(style, Constants.STYLE_POSITION, "top");
		boolean border = mxUtils.isTrue(style, Constants.STYLE_BORDER, true);
		int x = rect.x;
		int y = rect.y;
		int w = rect.width;
		int h = rect.height;
		int radius = getArcSize(w, h);

		if (border) {
			RoundRectangle2D roundRect = new RoundRectangle2D.Double();
			if (position.equals("top")) {
				roundRect.setRoundRect(x, y, w, h + h / 2, radius, radius);
			} else {
				roundRect.setRoundRect(x, y - h / 2, w, h + h / 2, radius, radius);
			}
			return roundRect;
		} else {
			return rect;
		}
	}

	public int getArcSize(int w, int h) {
		return Constants.RECTANGLE_ARCSIZE;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy