⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgmodeldigester.java

📁 一个java写的business process management系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				int x = flowletBind.getLabel().getX();
				int y = flowletBind.getLabel().getY();
				drawLabel(svgGenerator, desc.trim(), x, y, Color.BLACK);
			} else
				drawLabel(svgGenerator, flowletBind.getLabel());
			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestJoinFlowlet(net.orthanc.flow4j.model.bind.JoinFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestJoinFlowlet(
		JoinFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			int w = FigureConsts.DIMENSION_FIGURE_JOIN.width;
			int h = FigureConsts.DIMENSION_FIGURE_JOIN.height;
			Rectangle rect = new Rectangle(w, h);
			rect.translate(flowletBind.getX(), flowletBind.getY());
			adjustCanvasSize(getBottomRight(rect));

			List points = new ArrayList();

			int delta = 5;
			points.add(new Point(rect.x + rect.width / 2 - delta, rect.y));
			points.add(
				new Point(
					rect.x + rect.width / 2 - delta,
					rect.y + rect.height / 2 - delta));
			points.add(new Point(rect.x, rect.y + rect.height / 2 - delta));
			points.add(new Point(rect.x, rect.y + rect.height / 2 + delta));
			points.add(
				new Point(
					rect.x + rect.width / 2 - delta,
					rect.y + rect.height / 2 + delta));
			points.add(
				new Point(rect.x + rect.width / 2 - delta, rect.y + rect.height));
			points.add(
				new Point(rect.x + rect.width / 2 + delta, rect.y + rect.height));
			points.add(
				new Point(
					rect.x + rect.width / 2 + delta,
					rect.y + rect.height / 2 + delta));
			points.add(
				new Point(rect.x + rect.width, rect.y + rect.height / 2 + delta));
			points.add(
				new Point(rect.x + rect.width, rect.y + rect.height / 2 - delta));
			points.add(
				new Point(
					rect.x + rect.width / 2 + delta,
					rect.y + rect.height / 2 - delta));
			points.add(new Point(rect.x + rect.width / 2 + delta, rect.y));

			paintFlowletFigure(svgGenerator, points);
			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestCallFlowlet(net.orthanc.flow4j.model.bind.CallFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestCallFlowlet(
		CallFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			int w = FigureConsts.DIMENSION_FIGURE_CALL.width;
			int h = FigureConsts.DIMENSION_FIGURE_CALL.height;
			Rectangle rect = new Rectangle(w, h);
			rect.translate(flowletBind.getX(), flowletBind.getY());
			adjustCanvasSize(getBottomRight(rect));

			List points = new ArrayList();
			int x = rect.x;
			int y = rect.y;
			points.add(new Point(x, y));
			points.add(new Point(x, y + 11));
			points.add(new Point(x + 36, y + 11));
			points.add(new Point(x + 36, y + rect.height - 20));
			points.add(new Point(x + 14, y + rect.height - 20));
			points.add(new Point(x + 14, y + rect.height - 28));
			points.add(new Point(x, y + rect.height - 14));
			points.add(new Point(x + 14, y + rect.height));
			points.add(new Point(x + 14, y + rect.height - 9));
			points.add(new Point(x + rect.width, y + rect.height - 9));
			points.add(new Point(x + rect.width, y));

			paintFlowletFigure(svgGenerator, points);
			drawLabel(svgGenerator, flowletBind.getLabel());
			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}


	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestJumpFlowlet(net.orthanc.flow4j.model.bind.JumpFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestJumpFlowlet(
		JumpFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			int w = FigureConsts.DIMENSION_FIGURE_JUMP.width;
			int h = FigureConsts.DIMENSION_FIGURE_JUMP.height;
			Rectangle rect = new Rectangle(w, h);
			rect.translate(flowletBind.getX(), flowletBind.getY());
			adjustCanvasSize(getBottomRight(rect));

			List points = new ArrayList();
			int vm = rect.height / 2;
			int v1 = 18;
			int v2 = 7;
			int h1 = 30;
			int x = rect.x;
			int y = rect.y;
			points.add(new Point(x + h1, y + vm - v1));
			points.add(new Point(x + h1, y + vm - v2));
			points.add(new Point(x, y + vm - v2));
			points.add(new Point(x, y + vm + v2));
			points.add(new Point(x + h1, y + vm + v2));
			points.add(new Point(x + h1, y + vm + v1));
			points.add(new Point(x + rect.width, y + vm));

			paintFlowletFigure(svgGenerator, points);
			drawLabel(svgGenerator, flowletBind.getLabel());
			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestTemplateFlowlet(net.orthanc.flow4j.model.bind.TemplateFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestTemplateFlowlet(
		TemplateFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			int width = FigureConsts.DIMENSION_FIGURE_TEMPLATE.width;
			int height = FigureConsts.DIMENSION_FIGURE_TEMPLATE.height;
			Rectangle rect = new Rectangle(width, height);
			rect.translate(flowletBind.getX(), flowletBind.getY());
			adjustCanvasSize(getBottomRight(rect));

			List points = new ArrayList();
			int corner = 10;
			int h = 5;
			points.add(new Point(rect.x + h, rect.y));
			points.add(new Point(rect.x + h, rect.y + rect.height));
			points.add(new Point(rect.x + rect.width - h, rect.y + rect.height));
			points.add(new Point(rect.x + rect.width - h, rect.y + corner));
			points.add(new Point(rect.x + rect.width - h - corner, rect.y));
			points.add(
				new Point(rect.x + rect.width - h - corner, rect.y + corner));
			points.add(new Point(rect.x + rect.width - h, rect.y + corner));
			points.add(new Point(rect.x + rect.width - h - corner, rect.y));

			paintFlowletFigure(svgGenerator, points);

			String desc = flowletBind.getDescription();
			if (desc != null && desc.trim().length() != 0) {
				int x = flowletBind.getLabel().getX();
				int y = flowletBind.getLabel().getY();
				drawLabel(svgGenerator, desc.trim(), x, y, Color.BLACK);
			} else
				drawLabel(svgGenerator, flowletBind.getLabel());

			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}
	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestEndFlowlet(net.orthanc.flow4j.model.bind.EndFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestEndFlowlet(
		EndFlowletBind flowletBind,
		FlowModelBind flowModelBind) {
			int w = FigureConsts.DIMENSION_FIGURE_END.width;
			int h = FigureConsts.DIMENSION_FIGURE_END.height;
			Rectangle rect = new Rectangle(w, h);
			rect.translate(flowletBind.getX(), flowletBind.getY());
			adjustCanvasSize(getBottomRight(rect));

			List points = new ArrayList();
			points.add(new Point(rect.x + rect.width / 3, rect.y));
			points.add(
				new Point(rect.x + rect.width / 3, rect.y + rect.height * 2 / 3));
			points.add(new Point(rect.x, rect.y + rect.height * 2 / 3));
			points.add(new Point(getBottomLeft(rect)));
			points.add(new Point(getBottomRight(rect)));
			points.add(
				new Point(rect.x + rect.width, rect.y + rect.height * 2 / 3));
			points.add(
				new Point(
					rect.x + rect.width * 2 / 3,
					rect.y + rect.height * 2 / 3));
			points.add(new Point(rect.x + rect.width * 2 / 3, rect.y));

			paintFlowletFigure(svgGenerator, points);
			flowletIdToFlowletBindMapping.put(flowletBind.getId(flowModelBind), flowletBind);
	}


	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestTransition(net.orthanc.flow4j.model.bind.TransitionBind, net.orthanc.flow4j.model.bind.IFlowletBind, net.orthanc.flow4j.model.bind.IFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestTransition(
		TransitionBind transitionBind,
		IFlowletBind sourceFlowletBind,
		IFlowletBind targetFlowletBind,
		FlowModelBind flowModelBind) {
			drawTransitionPolyLine(transitionBind);
	}

	/* (non-Javadoc)
	 * @see net.orthanc.flow4j.model.AbstractModelDigester#digestBooleanTransition(net.orthanc.flow4j.model.bind.BooleanTransitionBind, net.orthanc.flow4j.model.bind.IFlowletBind, net.orthanc.flow4j.model.bind.IFlowletBind, net.orthanc.flow4j.model.bind.FlowModelBind)
	 */
	protected void digestBooleanTransition(
		BooleanTransitionBind transitionBind,
		IFlowletBind sourceFlowletBind,
		IFlowletBind targetFlowletBind,
		FlowModelBind flowModelBind) {
			List transitionPoints = drawTransitionPolyLine(transitionBind);
			Point p0 = (Point) transitionPoints.get(0);
			Point p1 = (Point) transitionPoints.get(1);

			drawBooleanTransitionLabel(
				svgGenerator,
				new net.orthanc.flow4j.base.Point(p0.x, p0.y),
				new net.orthanc.flow4j.base.Point(p1.x, p1.y),
				new Boolean(transitionBind.getValue()).toString(),
				(IFlowletBind) flowletIdToFlowletBindMapping.get(
					transitionBind.getSourceId()));
	}

	/*
	 * 
	 * @param g
	 * @param startPoint
	 * @param endPoint
	 * @param text
	 */
	private void drawBooleanTransitionLabel(
		SVGGraphics2D g,
		net.orthanc.flow4j.base.Point startPoint,
		net.orthanc.flow4j.base.Point endPoint,
		String text,
		IFlowletBind decisionFlowletBind) {
		net.orthanc.flow4j.base.Point decisionFlowletTL =
			new net.orthanc.flow4j.base.Point(
				decisionFlowletBind.getX(),
				decisionFlowletBind.getY());
		net.orthanc.flow4j.base.Point decisionFlowletCenter =
			new net.orthanc.flow4j.base.Point(
				decisionFlowletTL.x
					+ FigureConsts.DIMENSION_FIGURE_DECISION.width / 2,
				decisionFlowletTL.y
					+ FigureConsts.DIMENSION_FIGURE_DECISION.height / 2);
		int quadrant =
			calculateConnectionLocation(
				startPoint,
				decisionFlowletTL,
				decisionFlowletCenter);

		boolean transpose = (quadrant == 1 || quadrant == 3);
		if (transpose) {
			startPoint = startPoint.getTransposed();
			endPoint = endPoint.getTransposed();
		}

		int cos = (quadrant == 3 || quadrant == 4) ? -1 : 1;

		double tan =
			(endPoint.x == startPoint.x)
				? 1.0
				: (double) (endPoint.y - startPoint.y)
					/ (double) (endPoint.x - startPoint.x);
		if (tan > 1)
			tan = 1.0;
		else if (tan < -1)
			tan = -1;

		net.orthanc.flow4j.base.Dimension size =
			new net.orthanc.flow4j.base.Dimension(
				g.getFontMetrics().stringWidth(text),
				g.getFontMetrics().getHeight());
		if (transpose)
			size = size.getTransposed();
		int width = size.width;
		int height = size.height;
		int uDist = 10;
		int vDist = 10;

		net.orthanc.flow4j.base.Point labelPoint =
			new net.orthanc.flow4j.base.Point(
				(int) (startPoint.x + uDist * cos + width * ((cos - 1) / 2)),
				(int) (startPoint.y + cos * uDist * tan + vDist));
		if (transpose)
			labelPoint = labelPoint.getTransposed();

		drawLabel(g, text, labelPoint.x, labelPoint.y, Color.BLACK);
	}

	/*
	 * Returns an integer representing the side of the passed Rectangle that a point lies on.
	 *  1 == Top
	 *  2 == Right 
	 *  3 == Bottom 
	 *  4 == Left
	 *  
	 * @param loc The point that is to be located
	 * @param topLeft top left of the parent figure
	 * @param center center of the parent figure
	 */
	private int calculateConnectionLocation(
		net.orthanc.flow4j.base.Point loc,
		net.orthanc.flow4j.base.Point topLeft,
		net.orthanc.flow4j.base.Point center) {
		double m1, m2 = 0;
		m1 = (double) (topLeft.y - center.y) / (double) (topLeft.x - center.x);

		if (loc.x - center.x != 0)
			m2 = (double) (loc.y - center.y) / (double) (loc.x - center.x);

		if (loc.x == center.x) {
			// Case where m2 is vertical
			if (loc.y < center.y)
				return 3;
			else
				return 1;
		} else if (Math.abs(m2) <= Math.abs(m1)) {
			// Connection start point along left or right side
			if (loc.x < center.x)
				return 4;
			else
				return 2;
		} else {
			// Connection start point along top or bottom
			if (loc.y < center.y)
				return 3;
			else
				return 1;
		}
	}

	/*
	 * Draws the transition's plyLine and returns the polyLine's
	 * points.
	 * @param transitionBind
	 * @return the polyLine's points.
	 */
	private List drawTransitionPolyLine(TransitionBind transitionBind) {
		AbstractTransitionFlowletBind source =
			transitionBind.getSourceFlowlet();
		AbstractTransitionFlowletBind target =
			transitionBind.getTargetFlowlet();

		String sourceFlowletRef = source.getType() + "_" + source.getIndex();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -