annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module org.eclipse.draw2d.RelativeBendpoint;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 import java.lang.all;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 import org.eclipse.draw2d.geometry.Dimension;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import org.eclipse.draw2d.geometry.Point;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import org.eclipse.draw2d.geometry.PrecisionPoint;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import org.eclipse.draw2d.Bendpoint;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import org.eclipse.draw2d.Connection;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 * RelativeBendpoint is a Bendpoint that calculates its location based on its distance
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 * from the start and end points of the {@link Connection}, as well as its weight. See
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 * {@link #setWeight(float)} for a description of what behavior different weights will
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 * provide.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 public class RelativeBendpoint
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 : Bendpoint
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 private Connection connection;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 private float weight = 0.5f;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 private Dimension d1, d2;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 * Constructs a new RelativeBendpoint.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 *
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 public this() { }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 * Constructs a new RelativeBendpoint and associates it with the given Connection.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 * @param conn The Connection this Bendpoint is associated with
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 public this(Connection conn) {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 setConnection(conn);
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * Returns the Connection this Bendpoint is associated with.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 * @return The Connection this Bendpoint is associated with
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 protected Connection getConnection() {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 return connection;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 * Calculates and returns this Bendpoint's new location.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 * @return This Bendpoint's new location
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 public Point getLocation() {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 PrecisionPoint a1 = new PrecisionPoint(getConnection().getSourceAnchor().getReferencePoint());
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 PrecisionPoint a2 = new PrecisionPoint(getConnection().getTargetAnchor().getReferencePoint());
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 getConnection().translateToRelative(a1);
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 getConnection().translateToRelative(a2);
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 return new PrecisionPoint((a1.preciseX() + d1.preciseWidth())
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 * (1f - weight) + weight * (a2.preciseX() + d2.preciseWidth()),
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 (a1.preciseY() + d1.preciseHeight()) * (1f - weight) + weight
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 * (a2.preciseY() + d2.preciseHeight()));
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 * Sets the Connection this bendpoint should be associated with.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 * @param conn The Connection this bendpoint should be associated with
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 public void setConnection(Connection conn) {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 connection = conn;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 * Sets the Dimensions representing the X and Y distances this Bendpoint is from the start
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 * and end points of the Connection. These Dimensions are generally set once and are used
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 * in calculating the Bendpoint's location.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 * @param dim1 The X and Y distances this Bendpoint is from the start of the Connection
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 * @param dim2 The X and Y distances this Bendpoint is from the end of the Connection
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 public void setRelativeDimensions(Dimension dim1, Dimension dim2) {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 d1 = dim1;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 d2 = dim2;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 /**
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 * Sets the weight this Bendpoint should use to calculate its location. The weight should
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 * be between 0.0 and 1.0. A weight of 0.0 will cause the Bendpoint to follow the start
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 * point, while a weight of 1.0 will cause the Bendpoint to follow the end point. A weight
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 * of 0.5 (the default) will cause the Bendpoint to maintain its original aspect ratio
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 * between the start and end points.
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 * @param w The weight
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 * @since 2.0
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 */
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 public void setWeight(float w) {
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 weight = w;
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 }
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114
bc29606a740c Added dwt-addons in original directory structure of eclipse.org
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
115 }