source: tmcsimulator-scriptbuilder/branches/ScriptBuilder4/src/scriptbuilder/gui/drawers/EventIconDrawer.java @ 6

Revision 6, 3.9 KB checked in by jdalbey, 9 years ago (diff)

Add original prototype to branch

Line 
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.*;
15
16/**
17 *
18 * @author Greg Eddington <geddingt@calpoly.edu>
19 */
20public class EventIconDrawer
21{
22    private static Map<String, Image> images = null;
23
24    private static Image radioEventImage = null;
25    private static Image paramicsEventImage = null;
26    private static Image cadEventImage = null;
27    private static Image evaluationEventImage = null;
28
29    private static Image getImage(String name)
30    {
31        if (images == null)
32        {
33            try
34            {
35                images = new HashMap<String, Image>();
36                for (ScriptEventType t : ScriptEventType.values())
37                {
38                    images.put(t.IMAGE_NAME, ImageIO.read(Images.getImage(t.IMAGE_NAME + ".png")));
39                }
40            }
41            catch (IOException ex)
42            {
43                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
44            }
45        }
46
47        return images.get(name);
48    }
49
50    private static Image getRadioEventImage()
51    {
52        if (radioEventImage == null)
53        {
54            try
55            {
56                radioEventImage = ImageIO.read(Images.getImage("Radio.png"));
57            }
58            catch (IOException ex)
59            {
60                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
61            }
62        }
63
64        return radioEventImage;
65    }
66
67    private static Image getParamicsEventImage()
68    {
69        if (paramicsEventImage == null)
70        {
71            try
72            {
73                paramicsEventImage = ImageIO.read(Images.getImage("Paramics.png"));
74            }
75            catch (IOException ex)
76            {
77                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
78            }
79        }
80
81        return paramicsEventImage;
82    }
83
84        private static Image getCadEventImage()
85    {
86        if (cadEventImage == null)
87        {
88            try
89            {
90                cadEventImage = ImageIO.read(Images.getImage("CAD.png"));
91            }
92            catch (IOException ex)
93            {
94                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
95            }
96        }
97
98        return cadEventImage;
99    }
100
101    private static Image getEvaluationEventImage()
102    {
103        if (evaluationEventImage == null)
104        {
105            try
106            {
107                evaluationEventImage = ImageIO.read(Images.getImage("Evaluation.png"));
108            }
109            catch (IOException ex)
110            {
111                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
112            }
113        }
114
115        return evaluationEventImage;
116    }
117
118    public static void DrawEventIcon(Graphics2D g2d, ScriptEvent event,
119            int x, int y)
120    {
121        DrawEventIcon(g2d, event.getScriptEventType(), x, y);
122    }
123
124    public static void DrawEventIcon(Graphics2D g2d, ScriptEventType eventType,
125            int x, int y)
126    {
127        g2d.drawImage(getImage(eventType.IMAGE_NAME), x, y, null);
128        /**
129        switch(eventType)
130        {
131            case CHP_RADIO_EVENT:
132                break;
133            case PARAMICS_EVENT:
134                g2d.drawImage(getParamicsEventImage(), x, y, null);
135                break;
136            case CAD_EVENT:
137                g2d.drawImage(getCadEventImage(), x, y, null);
138                break;
139            case CAD_EVAL_EVENT:
140                g2d.drawImage(getEvaluationEventImage(), x, y, null);
141                break;
142        }
143        */
144    }
145}
Note: See TracBrowser for help on using the repository browser.