+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.connection.tests.actions;\r
+\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Line2D;\r
+\r
+import org.simantics.diagram.connection.RouteGraph;\r
+import org.simantics.diagram.connection.RouteLineHalf;\r
+import org.simantics.diagram.connection.actions.IAction;\r
+import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;\r
+\r
+public class HighlightReconnectPointsAction implements IAction {\r
+\r
+ public static final double DEGENERATED_LINE_LENGTH = 0.8;\r
+ public static final double CROSS_SIZE = 0.5;\r
+\r
+ RouteGraph rg;\r
+ double crossSize;\r
+\r
+ public HighlightReconnectPointsAction(RouteGraph rg) {\r
+ this(rg, CROSS_SIZE);\r
+ }\r
+\r
+ public HighlightReconnectPointsAction(RouteGraph rg, double crossSize) {\r
+ this.rg = rg;\r
+ this.crossSize = crossSize;\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g, IRouteGraphRenderer renderer, double mouseX, double mouseY) {\r
+ renderer.render(g, rg);\r
+ for(RouteLineHalf lh : rg.getLineHalves()) {\r
+ if(lh.getLine().getLength() < DEGENERATED_LINE_LENGTH)\r
+ continue;\r
+ double x = lh.getLink().getX();\r
+ double y = lh.getLink().getY();\r
+ if(lh.getLine().isHorizontal()) {\r
+ if(lh.getLink() == lh.getLine().getBegin())\r
+ x += crossSize*2;\r
+ else\r
+ x -= crossSize*2;\r
+ }\r
+ else {\r
+ if(lh.getLink() == lh.getLine().getBegin())\r
+ y += crossSize*2;\r
+ else\r
+ y -= crossSize*2;\r
+ }\r
+ g.draw(new Line2D.Double(x-crossSize,y-crossSize,x+crossSize,y+crossSize));\r
+ g.draw(new Line2D.Double(x-crossSize,y+crossSize,x+crossSize,y-crossSize));\r
+ }\r
+ }\r
+\r
+}\r