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

Revision 130, 3.6 KB checked in by bmcguffin, 9 years ago (diff)

Changed implementation of save function for event editor panels. Instead of updating their model objects whenever the enter key is pressed, panels are now notified when the window is closed and update their information then.

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.events.I_ScriptEvent;
26
27/**
28 *
29 * @author Bryan McGuffin
30 */
31public class PropertyModel extends Observable implements Observer
32{
33
34    PropertyPanels properties = new PropertyPanels();
35
36    private EnumMap<Properties, Class> classMap
37            = new EnumMap<Properties, Class>(Properties.class);
38   
39    public HashMap<JPanel, I_ScriptEvent> eventMap = new HashMap<JPanel, I_ScriptEvent>();
40
41    public PropertyModel()
42    {
43        classMap.put(Properties.ATMS, GenericEvaluationPanel.class);
44        classMap.put(Properties.ActivityLog, GenericEvaluationPanel.class);
45        classMap.put(Properties.CAD, GenericEvaluationPanel.class);
46        classMap.put(Properties.Facilitator, GenericEvaluationPanel.class);
47        classMap.put(Properties.Radio, GenericEvaluationPanel.class);
48
49        classMap.put(Properties.MaintenanceRadio, MaintenanceRadioPanel.class);
50        classMap.put(Properties.TMTRadio, TMTRadioPanel.class);
51        classMap.put(Properties.CHPRadio, CHPRadioPanel.class);
52        classMap.put(Properties.Telephone, TelephonePanel.class);
53
54        classMap.put(Properties.Audio, AudioPanel.class);
55        classMap.put(Properties.CADLog, CADLogPanel.class);
56        classMap.put(Properties.CCTV, CCTVPanel.class);
57        classMap.put(Properties.CMS, CMSEvaluationPanel.class);
58        classMap.put(Properties.Paramics, ParamicsPanel.class);
59        classMap.put(Properties.Tow, TowPanel.class);
60        classMap.put(Properties.Unit, UnitPanel.class);
61        classMap.put(Properties.Witness, WitnessPanel.class);
62
63        properties.addObserver(this);
64    }
65
66    public void addEventPanel(Properties property, I_ScriptEvent se)
67    {
68        try
69        {
70            JPanel panel = (JPanel) classMap.get(property).newInstance();
71
72            final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel);
73            if (panel instanceof I_ScriptEventEditorPanel)
74            {
75                eventMap.put(panel, se);
76                ((I_ScriptEventEditorPanel) panel).getEventObject(se);
77            }
78        }
79        catch (Exception e)
80        {
81            System.err.println("Could not create panel of type \"" + property + "\"");
82        }
83    }
84
85    public void removeProperty(Properties property)
86    {
87        properties.removeProperty(property);
88    }
89
90    public void update(Observable o, Object arg)
91    {
92        setChanged();
93        notifyObservers(arg);
94    }
95   
96    /**
97     * Propagate the window closure.
98     */
99    public void closePanels()
100    {
101        for(JPanel panel : eventMap.keySet())
102        {
103            if(panel instanceof I_ScriptEventEditorPanel)
104            {
105                ((I_ScriptEventEditorPanel) panel).uponClose();
106            }
107        }
108    }
109
110    /*
111     public Vector<PropertyPanel> getPropertyPanels()
112     {
113     return properties.getProperties();
114     }
115     */
116}
Note: See TracBrowser for help on using the repository browser.