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

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

package org.yaoqiang.graph.shape;

import java.awt.AlphaComposite;
import java.awt.Rectangle;

import org.yaoqiang.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;

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

	public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {

		Rectangle tmp = state.getRectangle();

		int x = tmp.x;
		int y = tmp.y;
		int w = tmp.width;
		int h = tmp.height;
		int radius = getArcSize(w, h);
		float opacity = mxUtils.getFloat(state.getStyle(), mxConstants.STYLE_OPACITY, 0);

		if (canvas.getGraphics().hitClip(x, y, w, h)) {

			// Paints the background
			if (configureGraphics(canvas, state, true)) {
				canvas.getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity / 100));
				canvas.getGraphics().fillRoundRect(x, y, w, h, radius, radius);
			}

			// Paints the foreground
			if (configureGraphics(canvas, state, false)) {
				canvas.getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
				canvas.getGraphics().drawRoundRect(x, y, w, h, radius, radius);
			}
		}
	}

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy