All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.draw2d.PolylineShape Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2008, 2010, 2012 IBM Corporation, Gerhardt Informatics Kft. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Alexander Shatalin (Borland) - initial API and implementation
 *     Gerhardt Informatics Kft. - GEFGWT port
 *******************************************************************************/
package org.eclipse.draw2d;

import org.eclipse.draw2d.geometry.Geometry;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * Renders a {@link PointList} as a series of line segments. All points from the
 * {@link PointList} are recognized as a relative points, so you can move/resize
 * this figure normally by calling {@link Figure#setBounds(Rectangle)}.
 * 
 * @since 3.5
 */
public class PolylineShape extends AbstractPointListShape {

	private int tolerance = 2;

	/**
	 * @return true if the distance between specified point and closest segment
	 *         of this PolyLine is less then {@link PolylineShape#tolerance}
	 */
	protected boolean shapeContainsPoint(int x, int y) {
		Point location = getLocation();
		return Geometry.polylineContainsPoint(points, x - location.x, y
				- location.y, tolerance);
	}

	protected void fillShape(Graphics graphics) {
	}

	protected void outlineShape(Graphics graphics) {
		graphics.pushState();
		graphics.translate(getLocation());
		graphics.drawPolyline(points);
		graphics.popState();
	}

	/**
	 * Setting tolerance parameter. This parameter will be used in
	 * {@link PolylineShape#shapeContainsPoint(int, int)}
	 */
	public void setTolerance(int tolerance) {
		this.tolerance = tolerance;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy