Mercurial > projects > dwt2
comparison org.eclipse.draw2d/src/org/eclipse/draw2d/RelativeBendpoint.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 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2008 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.RelativeBendpoint; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.draw2d.geometry.Dimension; | |
18 import org.eclipse.draw2d.geometry.Point; | |
19 import org.eclipse.draw2d.geometry.PrecisionPoint; | |
20 import org.eclipse.draw2d.Bendpoint; | |
21 import org.eclipse.draw2d.Connection; | |
22 | |
23 /** | |
24 * RelativeBendpoint is a Bendpoint that calculates its location based on its distance | |
25 * from the start and end points of the {@link Connection}, as well as its weight. See | |
26 * {@link #setWeight(float)} for a description of what behavior different weights will | |
27 * provide. | |
28 */ | |
29 public class RelativeBendpoint | |
30 : Bendpoint | |
31 { | |
32 | |
33 private Connection connection; | |
34 private float weight = 0.5f; | |
35 private Dimension d1, d2; | |
36 | |
37 /** | |
38 * Constructs a new RelativeBendpoint. | |
39 * | |
40 * @since 2.0 | |
41 */ | |
42 public this() { } | |
43 | |
44 /** | |
45 * Constructs a new RelativeBendpoint and associates it with the given Connection. | |
46 * @param conn The Connection this Bendpoint is associated with | |
47 * @since 2.0 | |
48 */ | |
49 public this(Connection conn) { | |
50 setConnection(conn); | |
51 } | |
52 | |
53 /** | |
54 * Returns the Connection this Bendpoint is associated with. | |
55 * @return The Connection this Bendpoint is associated with | |
56 * @since 2.0 | |
57 */ | |
58 protected Connection getConnection() { | |
59 return connection; | |
60 } | |
61 | |
62 /** | |
63 * Calculates and returns this Bendpoint's new location. | |
64 * @return This Bendpoint's new location | |
65 * @since 2.0 | |
66 */ | |
67 public Point getLocation() { | |
68 PrecisionPoint a1 = new PrecisionPoint(getConnection().getSourceAnchor().getReferencePoint()); | |
69 PrecisionPoint a2 = new PrecisionPoint(getConnection().getTargetAnchor().getReferencePoint()); | |
70 | |
71 getConnection().translateToRelative(a1); | |
72 getConnection().translateToRelative(a2); | |
73 | |
74 return new PrecisionPoint((a1.preciseX() + d1.preciseWidth()) | |
75 * (1f - weight) + weight * (a2.preciseX() + d2.preciseWidth()), | |
76 (a1.preciseY() + d1.preciseHeight()) * (1f - weight) + weight | |
77 * (a2.preciseY() + d2.preciseHeight())); | |
78 } | |
79 | |
80 /** | |
81 * Sets the Connection this bendpoint should be associated with. | |
82 * @param conn The Connection this bendpoint should be associated with | |
83 * @since 2.0 | |
84 */ | |
85 public void setConnection(Connection conn) { | |
86 connection = conn; | |
87 } | |
88 | |
89 /** | |
90 * Sets the Dimensions representing the X and Y distances this Bendpoint is from the start | |
91 * and end points of the Connection. These Dimensions are generally set once and are used | |
92 * in calculating the Bendpoint's location. | |
93 * @param dim1 The X and Y distances this Bendpoint is from the start of the Connection | |
94 * @param dim2 The X and Y distances this Bendpoint is from the end of the Connection | |
95 * @since 2.0 | |
96 */ | |
97 public void setRelativeDimensions(Dimension dim1, Dimension dim2) { | |
98 d1 = dim1; | |
99 d2 = dim2; | |
100 } | |
101 | |
102 /** | |
103 * Sets the weight this Bendpoint should use to calculate its location. The weight should | |
104 * be between 0.0 and 1.0. A weight of 0.0 will cause the Bendpoint to follow the start | |
105 * point, while a weight of 1.0 will cause the Bendpoint to follow the end point. A weight | |
106 * of 0.5 (the default) will cause the Bendpoint to maintain its original aspect ratio | |
107 * between the start and end points. | |
108 * @param w The weight | |
109 * @since 2.0 | |
110 */ | |
111 public void setWeight(float w) { | |
112 weight = w; | |
113 } | |
114 | |
115 } |