Mercurial > projects > dwt-addons
comparison dwtx/draw2d/ConnectionRouter.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children | 1082a0fc2bb8 |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
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 dwtx.draw2d.ConnectionRouter; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.draw2d.geometry.Point; | |
18 import dwtx.draw2d.geometry.PointList; | |
19 import dwtx.draw2d.AnchorListener; | |
20 import dwtx.draw2d.AbstractRouter; | |
21 import dwtx.draw2d.Connection; | |
22 | |
23 /** | |
24 * Routes a {@link Connection}, possibly using a constraint. | |
25 */ | |
26 public interface ConnectionRouter { | |
27 | |
28 /** | |
29 * Returns the constraint for the Connection. | |
30 * @param connection The connection | |
31 * @return The constraint | |
32 */ | |
33 Object getConstraint(Connection connection); | |
34 | |
35 /** | |
36 * Invalidates the given Connection. | |
37 * @param connection The connection to be invalidated | |
38 */ | |
39 void invalidate(Connection connection); | |
40 | |
41 /** | |
42 * Routes the Connection. | |
43 * @param connection The Connection to route | |
44 */ | |
45 void route(Connection connection); | |
46 | |
47 /** | |
48 * Removes the Connection from this router. | |
49 * @param connection The Connection to remove | |
50 */ | |
51 void remove(Connection connection); | |
52 | |
53 /** | |
54 * Maps the given constraint to the given Connection. | |
55 * @param connection The Connection | |
56 * @param constraint The constraint | |
57 */ | |
58 void setConstraint(Connection connection, Object constraint); | |
59 | |
60 | |
61 } | |
62 /** | |
63 * Routes Connections directly from the source anchor to the target anchor with no | |
64 * bendpoints in between. | |
65 */ | |
66 class NullConnectionRouter | |
67 : AbstractRouter | |
68 { | |
69 | |
70 /** | |
71 * Constructs a new NullConnectionRouter. | |
72 */ | |
73 this() { } | |
74 | |
75 /** | |
76 * Routes the given Connection directly between the source and target anchors. | |
77 * @param conn the connection to be routed | |
78 */ | |
79 public void route(Connection conn) { | |
80 PointList points = conn.getPoints(); | |
81 points.removeAllPoints(); | |
82 Point p; | |
83 conn.translateToRelative(p = getStartPoint(conn)); | |
84 points.addPoint(p); | |
85 conn.translateToRelative(p = getEndPoint(conn)); | |
86 points.addPoint(p); | |
87 conn.setPoints(points); | |
88 } | |
89 } | |
90 | |
91 /** | |
92 * The default router for Connections. | |
93 */ | |
94 public static const ConnectionRouter ConnectionRouter_NULL; | |
95 | |
96 static this(){ | |
97 ConnectionRouter_NULL = new NullConnectionRouter(); | |
98 } | |
99 |