source: tmcsimulator-scriptbuilder/trunk/src/event/editor/frame/PropertyModel.java @ 145

Revision 145, 4.5 KB checked in by sdanthin, 6 years ago (diff)

Move from Git to Svn (LARGE COMMIT)

Line 
1package event.editor.frame;
2
3import event.editor.AudioPanel;
4import event.editor.CADLogPanel;
5import event.editor.CCTVPanel;
6import event.editor.CHPRadioPanel;
7import event.editor.CMSEvaluationPanel;
8import event.editor.GenericEvaluationPanel;
9import event.editor.I_ScriptEventEditorPanel;
10import event.editor.MaintenanceRadioPanel;
11import event.editor.ParamicsPanel;
12import event.editor.TMTRadioPanel;
13import event.editor.TelephonePanel;
14import event.editor.TowPanel;
15import event.editor.UnitPanel;
16import event.editor.WitnessPanel;
17import java.awt.event.ActionEvent;
18import java.awt.event.ActionListener;
19import java.util.EnumMap;
20import java.util.HashMap;
21import java.util.Observable;
22import java.util.Observer;
23import java.util.TreeMap;
24import javax.swing.JPanel;
25import scriptbuilder.structures.ScriptIncident;
26import scriptbuilder.structures.TimeSlice;
27import scriptbuilder.structures.events.I_ScriptEvent;
28
29/**
30 *
31 * @author Bryan McGuffin
32 */
33public class PropertyModel extends Observable implements Observer
34{
35
36    PropertyPanels properties = new PropertyPanels();
37
38    private EnumMap<Properties, Class> classMap
39            = new EnumMap<Properties, Class>(Properties.class);
40   
41    public HashMap<JPanel, I_ScriptEvent> eventMap = new HashMap<JPanel, I_ScriptEvent>();
42
43    public PropertyModel()
44    {
45        classMap.put(Properties.ATMS, GenericEvaluationPanel.class);
46        classMap.put(Properties.ActivityLog, GenericEvaluationPanel.class);
47        classMap.put(Properties.CAD, GenericEvaluationPanel.class);
48        classMap.put(Properties.Facilitator, GenericEvaluationPanel.class);
49        classMap.put(Properties.Radio, GenericEvaluationPanel.class);
50
51        classMap.put(Properties.MaintenanceRadio, MaintenanceRadioPanel.class);
52        classMap.put(Properties.TMTRadio, TMTRadioPanel.class);
53        classMap.put(Properties.CHPRadio, CHPRadioPanel.class);
54        classMap.put(Properties.Telephone, TelephonePanel.class);
55
56        classMap.put(Properties.Audio, AudioPanel.class);
57        classMap.put(Properties.CADLog, CADLogPanel.class);
58        classMap.put(Properties.CCTV, CCTVPanel.class);
59        classMap.put(Properties.CMS, CMSEvaluationPanel.class);
60        classMap.put(Properties.Paramics, ParamicsPanel.class);
61        classMap.put(Properties.Tow, TowPanel.class);
62        classMap.put(Properties.Unit, UnitPanel.class);
63        classMap.put(Properties.Witness, WitnessPanel.class);
64
65        properties.addObserver(this);
66    }
67
68    public void addEventPanel(Properties property, I_ScriptEvent se)
69    {
70        try
71        {
72            //todo: this is where there are problems with initializing the unit window
73            JPanel panel = (JPanel) classMap.get(property).newInstance();
74
75            final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel);
76            if (panel instanceof I_ScriptEventEditorPanel)
77            {
78                eventMap.put(panel, se);
79                ((I_ScriptEventEditorPanel) panel).getEventObject(se);
80            }
81        }
82        catch (Exception e)
83        {
84            System.err.println("Could not create panel of type \"" + property + "\"");
85        }           
86    }
87   
88    public void addEventFromDropdown(Properties property, ScriptIncident inc, TimeSlice ts)
89    {
90        try
91        {
92            I_ScriptEvent se = property.getEvent();
93           
94            inc.addNewEvent(se, ts.getTime());
95           
96            JPanel panel = (JPanel) classMap.get(property).newInstance();
97
98            final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel);
99            if (panel instanceof I_ScriptEventEditorPanel)
100            {
101                eventMap.put(panel, se);
102                ((I_ScriptEventEditorPanel) panel).getEventObject(se);
103            }
104        }
105        catch (Exception e)
106        {
107            System.err.println("Could not create panel of type \"" + property + "\"");
108        }
109    }
110
111    public void removeProperty(Properties property)
112    {
113        properties.removeProperty(property);
114    }
115
116    public void update(Observable o, Object arg)
117    {
118        setChanged();
119        notifyObservers(arg);
120    }
121   
122    /**
123     * Propagate the window closure.
124     */
125    public void closePanels()
126    {
127        for(JPanel panel : eventMap.keySet())
128        {
129            if(panel instanceof I_ScriptEventEditorPanel)
130            {
131                ((I_ScriptEventEditorPanel) panel).uponClose();
132            }
133        }
134    }
135
136    /*
137     public Vector<PropertyPanel> getPropertyPanels()
138     {
139     return properties.getProperties();
140     }
141     */
142}
Note: See TracBrowser for help on using the repository browser.