/*

 ============================================================================
                   The Apache Software License, Version 1.1
 ============================================================================

 Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.

 Redistribution and use in source and binary forms, with or without modifica-
 tion, are permitted provided that the following conditions are met:

 1. Redistributions of  source code must  retain the above copyright  notice,
    this list of conditions and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

 3. The end-user documentation included with the redistribution, if any, must
    include  the following  acknowledgment:  "This product includes  software
    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
    Alternately, this  acknowledgment may  appear in the software itself,  if
    and wherever such third-party acknowledgments normally appear.

 4. The names "Batik" and  "Apache Software Foundation" must  not  be
    used to  endorse or promote  products derived from  this software without
    prior written permission. For written permission, please contact
    apache@apache.org.

 5. Products  derived from this software may not  be called "Apache", nor may
    "Apache" appear  in their name,  without prior written permission  of the
    Apache Software Foundation.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
 APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
 DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
 OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
 ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
 (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 This software  consists of voluntary contributions made  by many individuals
 on  behalf of the Apache Software  Foundation. For more  information on the
 Apache Software Foundation, please see <http://www.apache.org/>.

*/

package org.apache.batik.gvt.event;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;

import org.apache.batik.gvt.GraphicsNode;

/**
 * An event which indicates that a mouse action occurred in a graphics node.
 *
 * @author <a href="cjolif@ilog.fr>Christophe Jolif</a>
 * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
 * @version $Id: GraphicsNodeMouseEvent.java,v 1.9 2003/08/08 11:39:15 vhardy Exp $
 */
public class GraphicsNodeMouseEvent extends GraphicsNodeInputEvent {

    /**
     * The first number in the range of ids used for mouse events.
     */
    static final int MOUSE_FIRST = 500;

    /**
     * The id for the "mouseClicked" event. This MouseEvent occurs when a mouse
     * button is pressed and released.
     */
    public static final int MOUSE_CLICKED = MOUSE_FIRST;

    /**
     * The id for the "mousePressed" event. This MouseEvent occurs when a mouse
     * button is pushed down.
     */
    public static final int MOUSE_PRESSED = MOUSE_FIRST + 1;

    /**
     * The id for the "mouseReleased" event. This MouseEvent occurs when a mouse
     * button is let up.
     */
    public static final int MOUSE_RELEASED = MOUSE_FIRST + 2;

    /**
     * The id for the "mouseMoved" event. This MouseMotionEvent occurs
     * when the mouse position changes.
     */
    public static final int MOUSE_MOVED = MOUSE_FIRST + 3;

    /**
     * The id for the "mouseEntered" event. This MouseEvent occurs
     * when the mouse cursor enters a graphics node's area.
     */
    public static final int MOUSE_ENTERED = MOUSE_FIRST + 4;

    /**
     * The id for the "mouseExited" event. This MouseEvent occurs when
     * the mouse cursor leaves a graphics node's area.
     */
    public static final int MOUSE_EXITED = MOUSE_FIRST + 5;

    /**
     * The id for the "mouseDragged" event. This MouseEvent
     * occurs when the mouse position changes while the "drag"
     * modifier is active (for example, the shift key).
     */
    public static final int MOUSE_DRAGGED = MOUSE_FIRST + 6;

    /**
     * The graphics node mouse events x coordinate.
     * The x value is relative to the graphics node that fired the event.
     */
    float x;

    /**
     * The graphics node mouse events y coordinate.
     * The y value is relative to the graphics node that fired the event.
     */
    float y;

    int clientX;

    int clientY;

    int screenX;

    int screenY;

    /**
     * Indicates the number of quick consecutive clicks of a mouse button.
     */
    int clickCount;

    /**
     * Additional information. For a MOUSE_EXITED, this will contain the
     * destination node, for a MOUSE_ENTERED the last node and for
     * a MOUSE_DRAGGED the node under the mouse pointer.
     */
    GraphicsNode relatedNode = null;

    /**
     * Constructs a new graphics node mouse event.
     * @param source the graphics node where the event originated
     * @param id the id of this event
     * @param when the time the event occurred
     * @param modifiers the modifier keys down while event occurred
     * @param x,&nbsp;y the mouse coordinates
     * @param screenX,&nbsp;screenY the mouse coordinates relative to the screen
     * @param clickCount the number of clicks
     * @param relatedNode the related node
     * @see #getRelatedNode
     */
    public GraphicsNodeMouseEvent(GraphicsNode source, int id,
                                  long when, int modifiers,
                                  float x, float y, 
                                  int clientX, int clientY,
                                  int screenX, int screenY, 
                                  int clickCount,
                                  GraphicsNode relatedNode) {
        super(source, id, when, modifiers);
        this.x = x;
        this.y = y;
        this.clientX = clientX;
        this.clientY = clientY;
        this.screenX = screenX;
        this.screenY = screenY;
        this.clickCount = clickCount;
        this.relatedNode = relatedNode;
    }

    /**
     * Constructs a new graphics node mouse event from an AWT MouseEvent.
     * @param source the source where the event originated
     * @param evt the AWT mouse event which is the source of this
     *            GraphicsNodeEvent
     */
    public GraphicsNodeMouseEvent(GraphicsNode source, MouseEvent evt) {
        super(source, evt);
        this.x = evt.getX();
        this.y = evt.getY();
        this.clickCount = evt.getClickCount();
    }

    /**
     * Returns the horizontal x position of the event relative to the
     * source graphics node.
     * @return x a float indicating horizontal position relative to the node
     */
    public float getX() {
        return x;
    }

    /**
     * Returns the vertical y position of the event relative to the source node.
     * @return y a float indicating vertical position relative to the node
     */
    public float getY() {
        return y;
    }

    /**
     * Returns the horizontal x position of the event relative to the
     * source graphics node.
     * @return x a float indicating horizontal position relative to the node
     */
    public float getClientX() {
        return clientX;
    }

    /**
     * Returns the vertical y position of the event relative to the source node.
     * @return y a float indicating vertical position relative to the node
     */
    public float getClientY() {
        return clientY;
    }

    /**
     * Returns the horizontal x position of the event relative to the
     * screen.
     * @return x a float indicating horizontal position relative to the screen
     */
    public int getScreenX() {
        return screenX;
    }

    /**
     * Returns the vertical y position of the event relative to the screen.
     * @return y a float indicating vertical position relative to the screen
     */
    public int getScreenY() {
        return screenY;
    }

    /**
     * Returns the (x, y) position of the event relative to the screen.
     * @return a Point object containing the x and y coordinates
     */
    public Point getScreenPoint() {
        return new Point(screenX, screenY);
    }

    /**
     * Returns the (x, y) position of the event relative to the screen.
     * @return a Point object containing the x and y coordinates
     */
    public Point getClientPoint() {
        return new Point(clientX, clientY);
    }

    /**
     * Returns the (x, y) position of the event relative to the source node.
     * @return a Point object containing the x and y coordinates
     */
    public Point2D getPoint2D() {
        return new Point2D.Float(x, y);
    }

    /**
     * Returns the number of mouse clicks associated with this event.
     * @return integer value for the number of clicks
     */
    public int getClickCount() {
        return clickCount;
    }

    /**
     * Returns the related node for this <code>GraphicsNodeMouseEvent</code>.
     * For a <code>MOUSE_ENTERED</code> event it is the previous node target,
     * for a <code>MOUSE_EXITED</code> event it is the next node target and
     * for a <code>MOUSE_DRAGGED</code> event it is the node under the mouse
     * pointer. Otherwise the value is <code>null</code>.
     */
    public GraphicsNode getRelatedNode() {
        return relatedNode;
    }
}
