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.geometry.Rectangle;
|
15
|
|
16
|
/**
|
17
|
* Similar to {@link org.eclipse.draw2d.RelativeLocator}, but adds support for
|
18
|
* the {@link org.eclipse.gef.handles.HandleBounds} interface. If the reference
|
19
|
* figure implements <code>HandleBounds</code>, then
|
20
|
* {@link HandleBounds#getHandleBounds()} will be used as the reference box. If
|
21
|
* not, the behavior is the same as that of the superclass.
|
22
|
*
|
23
|
* @author hudsonr
|
24
|
*/
|
25
|
public class RelativeHandleLocator extends org.eclipse.draw2d.RelativeLocator {
|
26
|
|
27
|
/**
|
28
|
* Constructs a new locator using the given reference figure and location.
|
29
|
*
|
30
|
* @param reference
|
31
|
* the reference figure
|
32
|
* @param location
|
33
|
* one of NORTH, NORTH_EAST, etc.
|
34
|
*/
|
35
|
public RelativeHandleLocator(IFigure reference, int location) {
|
36
|
super(reference, location);
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Overridden to check for reference figures implementing the
|
41
|
* <code>HandleBounds</code> interface.
|
42
|
*
|
43
|
* @see org.eclipse.draw2d.RelativeLocator#getReferenceBox()
|
44
|
*/
|
45
|
protected Rectangle getReferenceBox() {
|
46
|
IFigure f = getReferenceFigure();
|
47
|
if (f instanceof HandleBounds)
|
48
|
return ((HandleBounds) f).getHandleBounds();
|
49
|
return super.getReferenceBox();
|
50
|
}
|
51
|
|
52
|
}
|