Warning: Can't use blame annotator:
svn blame failed on trunk/src/scriptbuilder/gui/drawers/EventIconDrawer.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/drawers/EventIconDrawer.java @ 7

Revision 7, 4.7 KB checked in by bmcguffin, 9 years ago (diff)

Renamed Interfaces in structures.events package from "*Interface" to "I_*"

RevLine 
1package scriptbuilder.gui.drawers;
2
3import java.awt.Graphics2D;
4import java.awt.Image;
5import java.io.File;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9import java.util.logging.Level;
10import java.util.logging.Logger;
11import javax.imageio.ImageIO;
12import scriptbuilder.structures.ScriptEvent;
13import scriptbuilder.structures.ScriptEvent.ScriptEventType;
14import images.*;
15import scriptbuilder.structures.events.I_ScriptEvent;
16
17/**
18 * Draws the icon for one event. Maintains a map of all previously used images
19 * for faster lookup.
20 *
21 * @author Greg Eddington <geddingt@calpoly.edu>
22 * @author Bryan McGuffin
23 */
24public class EventIconDrawer
25{
26
27    /**
28     * Mapping of all previously used icon images. Keys: The string name of the
29     * image. Values: The image object.
30     */
31    private static Map<String, Image> images = null;
32
33    private static Image radioEventImage = null;
34    private static Image paramicsEventImage = null;
35    private static Image cadEventImage = null;
36    private static Image evaluationEventImage = null;
37
38    /**
39     * Get the image icon which corresponds to the given name. If the image map
40     * hasn't been initialized, do so and give it a copy of each image.
41     *
42     * @param name Name of the image to find
43     * @return Image object corresponding to that name
44     */
45    private static Image getImage(String name)
46    {
47        if (images == null)
48        {
49            try
50            {
51                images = new HashMap<String, Image>();
52                for (ScriptEventType t : ScriptEventType.values())
53                {
54                    images.put(t.IMAGE_NAME, ImageIO.read(Images.getImage(t.IMAGE_NAME + ".png")));
55                }
56            }
57            catch (IOException ex)
58            {
59                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
60            }
61        }
62
63        return images.get(name);
64    }
65
66    private static Image getRadioEventImage()
67    {
68        if (radioEventImage == null)
69        {
70            try
71            {
72                radioEventImage = ImageIO.read(Images.getImage("Radio.png"));
73            }
74            catch (IOException ex)
75            {
76                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
77            }
78        }
79
80        return radioEventImage;
81    }
82
83    private static Image getParamicsEventImage()
84    {
85        if (paramicsEventImage == null)
86        {
87            try
88            {
89                paramicsEventImage = ImageIO.read(Images.getImage("Paramics.png"));
90            }
91            catch (IOException ex)
92            {
93                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
94            }
95        }
96
97        return paramicsEventImage;
98    }
99
100    private static Image getCadEventImage()
101    {
102        if (cadEventImage == null)
103        {
104            try
105            {
106                cadEventImage = ImageIO.read(Images.getImage("CAD.png"));
107            }
108            catch (IOException ex)
109            {
110                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
111            }
112        }
113
114        return cadEventImage;
115    }
116
117    private static Image getEvaluationEventImage()
118    {
119        if (evaluationEventImage == null)
120        {
121            try
122            {
123                evaluationEventImage = ImageIO.read(Images.getImage("Evaluation.png"));
124            }
125            catch (IOException ex)
126            {
127                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
128            }
129        }
130
131        return evaluationEventImage;
132    }
133
134    /**
135     * Given an event, draw its icon.
136     *
137     * @see DrawEventIcon(Graphics2D g2d, ScriptEventType eventType, int x, int
138     * y)
139     */
140    public static void DrawEventIcon(Graphics2D g2d, I_ScriptEvent event,
141            int x, int y)
142    {
143        DrawEventIcon(g2d, event.getScriptEventType(), x, y);
144    }
145
146    /**
147     * Given an event type, draw the icon relevant to that type.
148     *
149     * @param g2d the graphics component
150     * @param eventType The type of event to draw
151     * @param x X position of the icon
152     * @param y Y position of the icon
153     */
154    public static void DrawEventIcon(Graphics2D g2d, ScriptEventType eventType,
155            int x, int y)
156    {
157        g2d.drawImage(getImage(eventType.IMAGE_NAME), x, y, null);
158        /**
159         * switch(eventType) { case CHP_RADIO_EVENT: break; case PARAMICS_EVENT:
160         * g2d.drawImage(getParamicsEventImage(), x, y, null); break; case
161         * CAD_EVENT: g2d.drawImage(getCadEventImage(), x, y, null); break; case
162         * CAD_EVAL_EVENT: g2d.drawImage(getEvaluationEventImage(), x, y, null);
163         * break; }
164         */
165    }
166}
Note: See TracBrowser for help on using the repository browser.