| 1 | package scriptbuilder.gui.drawers; |
|---|
| 2 | |
|---|
| 3 | import java.awt.Graphics2D; |
|---|
| 4 | import java.awt.Image; |
|---|
| 5 | import java.awt.geom.AffineTransform; |
|---|
| 6 | import java.io.File; |
|---|
| 7 | import java.io.IOException; |
|---|
| 8 | import java.util.logging.Level; |
|---|
| 9 | import java.util.logging.Logger; |
|---|
| 10 | import javax.imageio.ImageIO; |
|---|
| 11 | import scriptbuilder.gui.ScriptBuilderGuiConstants; |
|---|
| 12 | import scriptbuilder.structures.ScriptEvent; |
|---|
| 13 | import scriptbuilder.structures.TimeSlice; |
|---|
| 14 | import scriptbuilder.structures.events.I_ScriptEvent; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * Draws the icons present in one timeslice, in one incident. |
|---|
| 18 | * |
|---|
| 19 | * @author Greg Eddington <geddingt@calpoly.edu> |
|---|
| 20 | * @author Bryan McGuffin |
|---|
| 21 | */ |
|---|
| 22 | public class TimeSliceDrawer |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * The icon which indicates that there are events present in this timeSlice. |
|---|
| 27 | */ |
|---|
| 28 | private static Image sliceEventImage = null; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * The default zoom level. |
|---|
| 32 | */ |
|---|
| 33 | public static int zoom = 20; |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * Get the icon to use whenever events are present in the slice. If we don't |
|---|
| 37 | * already have a copy, harvest it from a file. |
|---|
| 38 | * |
|---|
| 39 | * @return The existing copy of Event.png |
|---|
| 40 | */ |
|---|
| 41 | private static Image getSliceEventImage() |
|---|
| 42 | { |
|---|
| 43 | if (sliceEventImage == null) |
|---|
| 44 | { |
|---|
| 45 | try |
|---|
| 46 | { |
|---|
| 47 | sliceEventImage = ImageIO.read(images.Images.getImage("Event.png")); |
|---|
| 48 | } |
|---|
| 49 | catch (IOException ex) |
|---|
| 50 | { |
|---|
| 51 | Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | return sliceEventImage; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Draw the events in this timeslice. If any exist, draw the slice event |
|---|
| 60 | * image. If the incident isn't collapsed, draw the event icons as well. |
|---|
| 61 | * |
|---|
| 62 | * @param g2d the graphics component |
|---|
| 63 | * @param slice the timeSlice to draw |
|---|
| 64 | * @param collapsed if true, don't draw the event icons |
|---|
| 65 | */ |
|---|
| 66 | public static void DrawTimeSlice(Graphics2D g2d, TimeSlice slice, |
|---|
| 67 | boolean collapsed) |
|---|
| 68 | { |
|---|
| 69 | // If this is an empty slice, return |
|---|
| 70 | if (slice.events.size() == 0) |
|---|
| 71 | { |
|---|
| 72 | return; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | // Draw the slice event icon to show that there are events here |
|---|
| 76 | g2d.drawImage(getSliceEventImage(), slice.getX() |
|---|
| 77 | - ScriptBuilderGuiConstants.EVENT_ICON_WIDTH, |
|---|
| 78 | ScriptBuilderGuiConstants.TIMELINE_EVENT_ICON_MARGIN, null); |
|---|
| 79 | |
|---|
| 80 | // If the incident isn't collapsed, draw the event icons |
|---|
| 81 | if (!collapsed) |
|---|
| 82 | { |
|---|
| 83 | for (int i = 0; i < slice.events.size(); i++) |
|---|
| 84 | { |
|---|
| 85 | if (i >= ScriptBuilderGuiConstants.MAX_NUMBER_OF_SCRIPT_EVENT_ICON) |
|---|
| 86 | { |
|---|
| 87 | break; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | I_ScriptEvent event = slice.events.get(i); |
|---|
| 91 | EventIconDrawer.DrawEventIcon(g2d, event, slice.getX() |
|---|
| 92 | - ScriptBuilderGuiConstants.EVENT_ICON_WIDTH, |
|---|
| 93 | ScriptBuilderGuiConstants.SCRIPT_EVENT_ICON_TOP_MARGIN |
|---|
| 94 | + i * ScriptBuilderGuiConstants.SCRIPT_EVENT_ICON_STEP); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | } |
|---|