
eu.webtoolkit.jwt.WPolygonArea Maven / Gradle / Ivy
Show all versions of jwt Show documentation
/*
* Copyright (C) 2009 Emweb bvba, Leuven, Belgium.
*
* See the LICENSE file for terms of use.
*/
package eu.webtoolkit.jwt;
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.lang.ref.*;
import java.util.concurrent.locks.ReentrantLock;
import javax.servlet.http.*;
import javax.servlet.*;
import eu.webtoolkit.jwt.*;
import eu.webtoolkit.jwt.chart.*;
import eu.webtoolkit.jwt.utils.*;
import eu.webtoolkit.jwt.servlet.*;
/**
* An interactive area in a widget, specified by a polygon.
*
*
* The area may be added to a {@link WImage} or {@link WPaintedWidget} to
* provide interactivity on a polygon area of the image. The polygon is
* specified in pixel coordinates, and uses an even-odd winding rule (overlaps
* create holes).
*
* The polygon area corresponds to the HTML
* <area shape="poly">
tag.
*
*
* @see WImage#addArea(WAbstractArea area)
* @see WPaintedWidget#addArea(WAbstractArea area)
* @see WCircleArea
* @see WRectArea
*/
public class WPolygonArea extends WAbstractArea {
/**
* Creates an empty polygon.
*
* Defines an empty polygon.
*/
public WPolygonArea() {
super();
this.points_ = new ArrayList();
}
/**
* Creates a polygon area with given vertices.
*
* The polygon is defined with vertices corresponding to points
* . The polygon is closed by connecting the last point with the first
* point.
*/
public WPolygonArea(List points) {
super();
this.points_ = points;
}
/**
* Adds a point.
*/
public void addPoint(int x, int y) {
this.points_.add(new WPoint(x, y));
}
/**
* Adds a point.
*/
public void addPoint(double x, double y) {
this.points_.add(new WPoint((int) x, (int) y));
}
/**
* Adds a point.
*/
public void addPoint(WPoint point) {
this.points_.add(point);
}
/**
* Adds a point.
*/
public void addPoint(WPointF point) {
this.points_.add(new WPoint((int) point.getX(), (int) point.getY()));
}
/**
* Sets the polygon vertices.
*
* The polygon is defined with vertices corresponding to points
* . The polygon is closed by connecting the last point with the first
* point.
*/
public void setPoints(List points) {
this.points_ = points;
}
/**
* Returns the polygon vertices.
*
*
* @see WPolygonArea#setPoints(List points)
*/
public List getPoints() {
return this.points_;
}
private List points_;
void updateDom(DomElement element, boolean all) {
element.setAttribute("shape", "poly");
StringWriter coords = new StringWriter();
for (int i = 0; i < this.points_.size(); ++i) {
if (i != 0) {
coords.append(',');
}
coords.append(String.valueOf(this.points_.get(i).getX())).append(
',').append(String.valueOf(this.points_.get(i).getY()));
}
element.setAttribute("coords", coords.toString());
super.updateDom(element, all);
}
}