]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.connection/tests/org/simantics/diagram/connection/tests/actions/HighlightReconnectPointsAction.java
dc9d7352bfe337962606c49a7eda542ca60ce66a
[simantics/platform.git] / bundles / org.simantics.diagram.connection / tests / org / simantics / diagram / connection / tests / actions / HighlightReconnectPointsAction.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.connection.tests.actions;
13
14 import java.awt.Graphics2D;
15 import java.awt.geom.Line2D;
16
17 import org.simantics.diagram.connection.RouteGraph;
18 import org.simantics.diagram.connection.RouteLineHalf;
19 import org.simantics.diagram.connection.actions.IAction;
20 import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;
21
22 public class HighlightReconnectPointsAction implements IAction {
23
24     public static final double DEGENERATED_LINE_LENGTH = 0.8;
25     public static final double CROSS_SIZE = 0.5;
26
27     RouteGraph rg;
28     double crossSize;
29
30     public HighlightReconnectPointsAction(RouteGraph rg) {
31         this(rg, CROSS_SIZE);
32     }
33
34     public HighlightReconnectPointsAction(RouteGraph rg, double crossSize) {
35         this.rg = rg;
36         this.crossSize = crossSize;
37     }
38
39     @Override
40     public void render(Graphics2D g, IRouteGraphRenderer renderer, double mouseX, double mouseY) {
41         renderer.render(g, rg);
42         for(RouteLineHalf lh : rg.getLineHalves()) {
43             if(lh.getLine().getLength() < DEGENERATED_LINE_LENGTH)
44                 continue;
45             double x = lh.getLink().getX();
46             double y = lh.getLink().getY();
47             if(lh.getLine().isHorizontal()) {
48                 if(lh.getLink() == lh.getLine().getBegin())
49                     x += crossSize*2;
50                 else
51                     x -= crossSize*2;
52             }
53             else {
54                 if(lh.getLink() == lh.getLine().getBegin())
55                     y += crossSize*2;
56                 else
57                     y -= crossSize*2;
58             }
59             g.draw(new Line2D.Double(x-crossSize,y-crossSize,x+crossSize,y+crossSize));
60             g.draw(new Line2D.Double(x-crossSize,y+crossSize,x+crossSize,y-crossSize));
61         }
62     }
63
64 }