Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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
 *******************************************************************************/
11
package org.eclipse.gef.handles;
12

    
13
import org.eclipse.draw2d.IFigure;
14
import org.eclipse.draw2d.Locator;
15
import org.eclipse.draw2d.geometry.Insets;
16
import org.eclipse.draw2d.geometry.PrecisionRectangle;
17
import org.eclipse.draw2d.geometry.Rectangle;
18

    
19
/**
20
 * A Locator used to place {@link MoveHandle}s. By default, a MoveHandle's
21
 * bounds are equal to its owner figure's bounds, expanded by the handle's
22
 * {@link Insets}.
23
 */
24
public class MoveHandleLocator implements Locator {
25

    
26
	private IFigure reference;
27

    
28
	/**
29
	 * Creates a new MoveHandleLocator and sets its reference figure to
30
	 * <code>ref</code>. The reference figure should be the handle's owner
31
	 * figure.
32
	 * 
33
	 * @param ref
34
	 *            the handle's owner
35
	 */
36
	public MoveHandleLocator(IFigure ref) {
37
		setReference(ref);
38
	}
39

    
40
	/**
41
	 * Returns the reference figure for this locator.
42
	 * 
43
	 * @return the handle's owner
44
	 */
45
	protected IFigure getReference() {
46
		return reference;
47
	}
48

    
49
	/**
50
	 * Sets the handle's bounds to that of its owner figure's bounds, expanded
51
	 * by the handle's Insets.
52
	 * 
53
	 * @param target
54
	 *            The IFigure to relocate
55
	 */
56
	public void relocate(IFigure target) {
57
		Insets insets = target.getInsets();
58
		Rectangle bounds;
59
		if (getReference() instanceof HandleBounds)
60
			bounds = ((HandleBounds) getReference()).getHandleBounds();
61
		else
62
			bounds = getReference().getBounds();
63
		bounds = new PrecisionRectangle(bounds.getResized(-1, -1));
64
		getReference().translateToAbsolute(bounds);
65
		target.translateToRelative(bounds);
66
		bounds.translate(-insets.left, -insets.top);
67
		bounds.resize(insets.getWidth() + 1, insets.getHeight() + 1);
68
		target.setBounds(bounds);
69
	}
70

    
71
	/**
72
	 * Sets the reference figure.
73
	 * 
74
	 * @param follow
75
	 *            the reference figure, should be the handle's owner figure
76
	 */
77
	public void setReference(IFigure follow) {
78
		this.reference = follow;
79
	}
80

    
81
}
(12-12/19)