package scriptbuilder.gui.drawers;

import java.awt.Graphics2D;
import scriptbuilder.gui.ScriptBuilderGuiConstants;
import scriptbuilder.structures.ScriptIncident;
import scriptbuilder.structures.TimeSlice;

/**
 * Draws the graphics for one entire incident.
 *
 * @author Greg Eddington <geddingt@calpoly.edu>
 * @author Bryan McGuffin
 */
public class IncidentTimelineDrawer
{

    /**
     * Draw the incident line. Then, utilize TimeSliceDrawer to draw the
     * timeslices.
     *
     * @param g2d the graphics component
     * @param incident the incident to be drawn
     * @param collapsed if true, time slice events won't be drawn
     */
    public static void DrawIncidentTimeline(Graphics2D g2d,
            ScriptIncident incident, boolean collapsed)
    {
        // Draw the timeline
        g2d.setColor(incident.color);
        g2d.fillRect(incident.offset / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK,
                ScriptBuilderGuiConstants.TIMELINE_TOP_MARGIN,
                incident.length / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION
                * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK,
                ScriptBuilderGuiConstants.TIMELINE_HEIGHT);

        // Draw each time slice
        for (TimeSlice slice : incident.getSlices())
        {
            TimeSliceDrawer.DrawTimeSlice(g2d, slice, collapsed);
        }
    }
}
