1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2008, 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
|
* Alexander Shatalin (Borland) - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.draw2d;
|
12
|
|
13
|
import org.eclipse.draw2d.geometry.Geometry;
|
14
|
import org.eclipse.draw2d.geometry.Point;
|
15
|
import org.eclipse.draw2d.geometry.PointList;
|
16
|
import org.eclipse.draw2d.geometry.Rectangle;
|
17
|
|
18
|
/**
|
19
|
* Renders a {@link PointList} as a series of line segments. All points from the
|
20
|
* {@link PointList} are recognized as a relative points, so you can move/resize
|
21
|
* this figure normally by calling {@link Figure#setBounds(Rectangle)}.
|
22
|
*
|
23
|
* @since 3.5
|
24
|
*/
|
25
|
public class PolylineShape extends AbstractPointListShape {
|
26
|
|
27
|
private int tolerance = 2;
|
28
|
|
29
|
/**
|
30
|
* @return true if the distance between specified point and closest segment
|
31
|
* of this PolyLine is less then {@link PolylineShape#tolerance}
|
32
|
*/
|
33
|
protected boolean shapeContainsPoint(int x, int y) {
|
34
|
Point location = getLocation();
|
35
|
return Geometry.polylineContainsPoint(points, x - location.x, y
|
36
|
- location.y, tolerance);
|
37
|
}
|
38
|
|
39
|
protected void fillShape(Graphics graphics) {
|
40
|
}
|
41
|
|
42
|
protected void outlineShape(Graphics graphics) {
|
43
|
graphics.pushState();
|
44
|
graphics.translate(getLocation());
|
45
|
graphics.drawPolyline(points);
|
46
|
graphics.popState();
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Setting tolerance parameter. This parameter will be used in
|
51
|
* {@link PolylineShape#shapeContainsPoint(int, int)}
|
52
|
*/
|
53
|
public void setTolerance(int tolerance) {
|
54
|
this.tolerance = tolerance;
|
55
|
}
|
56
|
|
57
|
}
|