Mercurial > projects > dwt2
comparison org.eclipse.draw2d/src/org/eclipse/draw2d/BendpointConnectionRouter.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | dbfb303e8fb0 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.draw2d.BendpointConnectionRouter; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.draw2d.geometry.Point; | |
18 import org.eclipse.draw2d.geometry.PointList; | |
19 import org.eclipse.draw2d.geometry.PrecisionPoint; | |
20 import org.eclipse.draw2d.AbstractRouter; | |
21 import org.eclipse.draw2d.Connection; | |
22 import org.eclipse.draw2d.Bendpoint; | |
23 | |
24 /** | |
25 * Routes {@link Connection}s through a <code>List</code> of {@link Bendpoint Bendpoints}. | |
26 */ | |
27 public class BendpointConnectionRouter | |
28 : AbstractRouter | |
29 { | |
30 | |
31 private Map constraints; | |
32 | |
33 private static PrecisionPoint A_POINT_; | |
34 private static PrecisionPoint A_POINT(){ | |
35 if( A_POINT_ is null ){ | |
36 synchronized( BendpointConnectionRouter.classinfo ){ | |
37 if( A_POINT_ is null ){ | |
38 A_POINT_ = new PrecisionPoint(); | |
39 } | |
40 } | |
41 } | |
42 return A_POINT_; | |
43 } | |
44 | |
45 public this(){ | |
46 constraints = new HashMap(11); | |
47 } | |
48 | |
49 /** | |
50 * Gets the constraint for the given {@link Connection}. | |
51 * | |
52 * @param connection The connection whose constraint we are retrieving | |
53 * @return The constraint | |
54 */ | |
55 public Object getConstraint(Connection connection) { | |
56 return constraints.get(cast(Object)connection); | |
57 } | |
58 | |
59 /** | |
60 * Removes the given connection from the map of constraints. | |
61 * | |
62 * @param connection The connection to remove | |
63 */ | |
64 public void remove(Connection connection) { | |
65 constraints.remove(cast(Object)connection); | |
66 } | |
67 | |
68 /** | |
69 * Routes the {@link Connection}. Expects the constraint to be a List | |
70 * of {@link org.eclipse.draw2d.Bendpoint Bendpoints}. | |
71 * | |
72 * @param conn The connection to route | |
73 */ | |
74 public void route(Connection conn) { | |
75 PointList points = conn.getPoints(); | |
76 points.removeAllPoints(); | |
77 | |
78 List bendpoints = cast(List)getConstraint(conn); | |
79 if (bendpoints is null) | |
80 bendpoints = Collections.EMPTY_LIST; | |
81 | |
82 Point ref1, ref2; | |
83 | |
84 if (bendpoints.isEmpty()) { | |
85 ref1 = conn.getTargetAnchor().getReferencePoint(); | |
86 ref2 = conn.getSourceAnchor().getReferencePoint(); | |
87 } else { | |
88 ref1 = new Point((cast(Bendpoint)bendpoints.get(0)).getLocation()); | |
89 conn.translateToAbsolute(ref1); | |
90 ref2 = new Point((cast(Bendpoint)bendpoints.get(bendpoints.size() - 1)).getLocation()); | |
91 conn.translateToAbsolute(ref2); | |
92 } | |
93 | |
94 A_POINT.setLocation(conn.getSourceAnchor().getLocation(ref1)); | |
95 conn.translateToRelative(A_POINT); | |
96 points.addPoint(A_POINT); | |
97 | |
98 for (int i = 0; i < bendpoints.size(); i++) { | |
99 Bendpoint bp = cast(Bendpoint)bendpoints.get(i); | |
100 points.addPoint(bp.getLocation()); | |
101 } | |
102 | |
103 A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2)); | |
104 conn.translateToRelative(A_POINT); | |
105 points.addPoint(A_POINT); | |
106 conn.setPoints(points); | |
107 } | |
108 | |
109 /** | |
110 * Sets the constraint for the given {@link Connection}. | |
111 * | |
112 * @param connection The connection whose constraint we are setting | |
113 * @param constraint The constraint | |
114 */ | |
115 public void setConstraint(Connection connection, Object constraint) { | |
116 constraints.put(cast(Object)connection, constraint); | |
117 } | |
118 | |
119 } |