1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.connection.tests.actions;
\r
14 import java.awt.Graphics2D;
\r
15 import java.awt.geom.Line2D;
\r
17 import org.simantics.diagram.connection.RouteGraph;
\r
18 import org.simantics.diagram.connection.RouteLineHalf;
\r
19 import org.simantics.diagram.connection.actions.IAction;
\r
20 import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;
\r
22 public class HighlightReconnectPointsAction implements IAction {
\r
24 public static final double DEGENERATED_LINE_LENGTH = 0.8;
\r
25 public static final double CROSS_SIZE = 0.5;
\r
30 public HighlightReconnectPointsAction(RouteGraph rg) {
\r
31 this(rg, CROSS_SIZE);
\r
34 public HighlightReconnectPointsAction(RouteGraph rg, double crossSize) {
\r
36 this.crossSize = crossSize;
\r
40 public void render(Graphics2D g, IRouteGraphRenderer renderer, double mouseX, double mouseY) {
\r
41 renderer.render(g, rg);
\r
42 for(RouteLineHalf lh : rg.getLineHalves()) {
\r
43 if(lh.getLine().getLength() < DEGENERATED_LINE_LENGTH)
\r
45 double x = lh.getLink().getX();
\r
46 double y = lh.getLink().getY();
\r
47 if(lh.getLine().isHorizontal()) {
\r
48 if(lh.getLink() == lh.getLine().getBegin())
\r
54 if(lh.getLink() == lh.getLine().getBegin())
\r
59 g.draw(new Line2D.Double(x-crossSize,y-crossSize,x+crossSize,y+crossSize));
\r
60 g.draw(new Line2D.Double(x-crossSize,y+crossSize,x+crossSize,y-crossSize));
\r