package ch.psi.plot.jfree;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import org.jfree.ui.Drawable;

/**
 * Class that draws an cross as annotation.
 *
 * This is an implementation of the {@link Drawable} interface, to illustrate
 * the use of the {@link org.jfree.chart.annotations.XYDrawableAnnotation}
 * class.
 */
public class CrossAnnotation implements Drawable {

    private final Color color;

    /**
     * Creates a new instance.
     */
    public CrossAnnotation(Color color) {
        this.color = color;
    }

    /**
     * Draws cross
     *
     * @param g2 the graphics device.
     * @param area the area in which to draw.
     */
    public void draw(Graphics2D g2, Rectangle2D area) {

        // Draw red cross
        g2.setPaint(color);
        g2.setStroke(new BasicStroke(2)); // Stroke width = 2
        Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
        Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY());
        g2.draw(line1);
        g2.draw(line2);
    }
}
