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

Revision 89, 3.2 KB checked in by bmcguffin, 9 years ago (diff)

Added dropdown menu item to ScriptBuilderFrame?: "Delete Incident". When clicked, user may select an existing incident to delete. Program will prompt user to confirm the deletion, then remove the incident from the script and refresh the display.

Added button to individual event editor window: "Remove this event". When clicked, the currently displayed event will be removed from the timeslice it is in. The display will be refreshed accordingly. NOTE: This still has some bugs, namely that the last remaining event in a timeslice fails to be deleted.

Restructured Interface ScriptEventEditorPanel? to include a removeAssociatedEvent method, which calls a new method in I_ScriptEvent called removeThis, which causes the event to be removed from its timeslice.

Editor.Java previously contained several classes and enums, none of which were set to private scope. Moved these extra classes to their own files to decrease clutter in Editor.java and increase readability of all files.

Line 
1package event.editor;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.ActionListener;
5import java.util.EnumMap;
6import java.util.Observable;
7import java.util.Observer;
8import javax.swing.JPanel;
9import scriptbuilder.structures.events.I_ScriptEvent;
10
11/**
12 *
13 * @author Bryan McGuffin
14 */
15public class PropertyModel extends Observable implements Observer
16{
17
18    PropertyPanels properties = new PropertyPanels();
19
20    private EnumMap<Properties, Class> classMap
21            = new EnumMap<Properties, Class>(Properties.class);
22
23    public PropertyModel()
24    {
25        classMap.put(Properties.ATMS, GenericEvaluationPanel.class);
26        classMap.put(Properties.ActivityLog, GenericEvaluationPanel.class);
27        classMap.put(Properties.CAD, GenericEvaluationPanel.class);
28        classMap.put(Properties.Facilitator, GenericEvaluationPanel.class);
29        classMap.put(Properties.Radio, GenericEvaluationPanel.class);
30
31        classMap.put(Properties.MaintenanceRadio, MaintenanceRadioPanel.class);
32        classMap.put(Properties.TMTRadio, TMTRadioPanel.class);
33        classMap.put(Properties.CHPRadio, CHPRadioPanel.class);
34        classMap.put(Properties.Telephone, TelephonePanel.class);
35
36        classMap.put(Properties.Audio, AudioPanel.class);
37        classMap.put(Properties.CADLog, CADLogPanel.class);
38        classMap.put(Properties.CCTV, CCTVPanel.class);
39        classMap.put(Properties.CMS, CMSEvaluationPanel.class);
40        classMap.put(Properties.Paramics, ParamicsPanel.class);
41        classMap.put(Properties.Tow, TowPanel.class);
42        classMap.put(Properties.Unit, UnitPanel.class);
43        classMap.put(Properties.Witness, WitnessPanel.class);
44
45        properties.addObserver(this);
46    }
47
48    public void addProperty(Properties property, I_ScriptEvent se)
49    {
50        try
51        {
52            JPanel panel = (JPanel) classMap.get(property).newInstance();
53
54            final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel);
55            if (panel instanceof ScriptEventEditorPanel)
56            {
57                ((ScriptEventEditorPanel) panel).getEventObject(se);
58            }
59            if (property.getType() == PropertyTypes.Multiple)
60            {
61
62                if (panel instanceof RemoveablePanel)
63                {
64                    ((RemoveablePanel) panel).setRemoveListener(new ActionListener()
65                    {
66                        public void actionPerformed(ActionEvent evt)
67                        {
68                            properties.removeProperty(propertyPanel);
69                        }
70                    });
71                }
72                else
73                {
74                    throw new RuntimeException("Property was multiple but panel was not removeable");
75                }
76            }
77        }
78        catch (Exception e)
79        {
80            System.err.println("Could not create panel of type \"" + property + "\"");
81        }
82    }
83
84    public void removeProperty(Properties property)
85    {
86        properties.removeProperty(property);
87    }
88
89    public void update(Observable o, Object arg)
90    {
91        setChanged();
92        notifyObservers(arg);
93    }
94
95    /*
96     public Vector<PropertyPanel> getPropertyPanels()
97     {
98     return properties.getProperties();
99     }
100     */
101}
Note: See TracBrowser for help on using the repository browser.