comparison dwtx/draw2d/MidpointLocator.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
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.MidpointLocator;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.draw2d.geometry.Point;
18 import dwtx.draw2d.ConnectionLocator;
19 import dwtx.draw2d.Connection;
20
21 /**
22 * A ConnectionLocator that is used to place figures at the midpoint between two points on
23 * a {@link dwtx.draw2d.Connection}.
24 */
25 public class MidpointLocator
26 : ConnectionLocator
27 {
28
29 private int index;
30
31 /**
32 * Constructs a MidpointLocator with associated Connection <i>c</i> and index <i>i</i>.
33 * The points at index i and i+1 on the connection are used to calculate the midpoint of
34 * the line segment.
35 *
36 * @param c the connection associated with the locator
37 * @param i the point from where the connection's midpoint will be calculated.
38 * @since 2.0
39 */
40 public this(Connection c, int i) {
41 super(c);
42 index = i;
43 }
44
45 /**
46 * Returns this MidpointLocator's index. This integer represents the position of the start
47 * point in this MidpointLocator's associated {@link Connection} from where midpoint
48 * calculation will be made.
49 *
50 * @return the locator's index
51 * @since 2.0
52 */
53
54 protected int getIndex() {
55 return index;
56 }
57
58 /**
59 * Returns the point of reference associated with this locator. This point will be midway
60 * between points at 'index' and 'index' + 1.
61 *
62 * @return the reference point
63 * @since 2.0
64 */
65 protected Point getReferencePoint() {
66 Connection conn = getConnection();
67 Point p = Point.SINGLETON;
68 Point p1 = conn.getPoints().getPoint(getIndex());
69 Point p2 = conn.getPoints().getPoint(getIndex() + 1);
70 conn.translateToAbsolute(p1);
71 conn.translateToAbsolute(p2);
72 p.x = (p2.x - p1.x) / 2 + p1.x;
73 p.y = (p2.y - p1.y) / 2 + p1.y;
74 return p;
75 }
76
77 }