/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javafx.scene.media;

import javafx.event.Event;
import javafx.event.EventTarget;
import javafx.event.EventType;

import com.sun.javafx.beans.annotations.NoBuilder;

/**
 * An {@link Event} representing the occurrence of an error in handling media.
 */
@NoBuilder
public class MediaErrorEvent extends Event {
    /**
     * The only valid event type for the <code>MediaErrorEvent</code>.
     */
    public static final EventType<MediaErrorEvent> MEDIA_ERROR = new EventType<MediaErrorEvent>("Media Error Event");

    /**
     * The {@link MediaException} which provoked this error event.
     */
    private MediaException error;

    /**
     * Construct a new <code>MediaErrorEvent</code> with the specified event
     * source, target and error.
     *
     * @param source the event source which sent the event
     * @param target the event target to associate with the event
     * @param error the error which provoked the event
     * @throws <code>IllegalArgumentException</code> if <code>error</code> is
     * <code>null</code>.
     */
    MediaErrorEvent(Object source, EventTarget target, MediaException error) {
        super(source, target, MEDIA_ERROR);

        if(error == null) {
            throw new IllegalArgumentException("error == null!");
        }

        this.error = error;
    }

    /**
     * Retrieve the error associated with this event.
     *
     * @return The <code>MediaException</code>
     */
    public MediaException getMediaError() {
        return error;
    }

    /**
     * Retrieve a <code>String</code> representation of the event.
     */
    @Override
    public String toString() {
        return super.toString() + ": source " + getSource() +
                "; target " + getTarget() + "; error " + error;
    }
}
