package event.editor.frame; import event.editor.AudioPanel; import event.editor.CADLogPanel; import event.editor.CCTVPanel; import event.editor.CHPRadioPanel; import event.editor.CMSEvaluationPanel; import event.editor.GenericEvaluationPanel; import event.editor.I_ScriptEventEditorPanel; import event.editor.MaintenanceRadioPanel; import event.editor.ParamicsPanel; import event.editor.TMTRadioPanel; import event.editor.TelephonePanel; import event.editor.TowPanel; import event.editor.UnitPanel; import event.editor.WitnessPanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.EnumMap; import java.util.HashMap; import java.util.Observable; import java.util.Observer; import java.util.TreeMap; import javax.swing.JPanel; import scriptbuilder.structures.ScriptIncident; import scriptbuilder.structures.TimeSlice; import scriptbuilder.structures.events.I_ScriptEvent; /** * * @author Bryan McGuffin */ public class PropertyModel extends Observable implements Observer { PropertyPanels properties = new PropertyPanels(); private EnumMap classMap = new EnumMap(Properties.class); public HashMap eventMap = new HashMap(); public PropertyModel() { classMap.put(Properties.ATMS, GenericEvaluationPanel.class); classMap.put(Properties.ActivityLog, GenericEvaluationPanel.class); classMap.put(Properties.CAD, GenericEvaluationPanel.class); classMap.put(Properties.Facilitator, GenericEvaluationPanel.class); classMap.put(Properties.Radio, GenericEvaluationPanel.class); classMap.put(Properties.MaintenanceRadio, MaintenanceRadioPanel.class); classMap.put(Properties.TMTRadio, TMTRadioPanel.class); classMap.put(Properties.CHPRadio, CHPRadioPanel.class); classMap.put(Properties.Telephone, TelephonePanel.class); classMap.put(Properties.Audio, AudioPanel.class); classMap.put(Properties.CADLog, CADLogPanel.class); classMap.put(Properties.CCTV, CCTVPanel.class); classMap.put(Properties.CMS, CMSEvaluationPanel.class); classMap.put(Properties.Paramics, ParamicsPanel.class); classMap.put(Properties.Tow, TowPanel.class); classMap.put(Properties.Unit, UnitPanel.class); classMap.put(Properties.Witness, WitnessPanel.class); properties.addObserver(this); } public void addEventPanel(Properties property, I_ScriptEvent se) { try { //todo: this is where there are problems with initializing the unit window JPanel panel = (JPanel) classMap.get(property).newInstance(); final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel); if (panel instanceof I_ScriptEventEditorPanel) { eventMap.put(panel, se); ((I_ScriptEventEditorPanel) panel).getEventObject(se); } } catch (Exception e) { System.err.println("Could not create panel of type \"" + property + "\""); } } public void addEventFromDropdown(Properties property, ScriptIncident inc, TimeSlice ts) { try { I_ScriptEvent se = property.getEvent(); inc.addNewEvent(se, ts.getTime()); JPanel panel = (JPanel) classMap.get(property).newInstance(); final PropertyPanel propertyPanel = properties.addPropertyPanel(property, panel); if (panel instanceof I_ScriptEventEditorPanel) { eventMap.put(panel, se); ((I_ScriptEventEditorPanel) panel).getEventObject(se); } } catch (Exception e) { System.err.println("Could not create panel of type \"" + property + "\""); } } public void removeProperty(Properties property) { properties.removeProperty(property); } public void update(Observable o, Object arg) { setChanged(); notifyObservers(arg); } /** * Propagate the window closure. */ public void closePanels() { for(JPanel panel : eventMap.keySet()) { if(panel instanceof I_ScriptEventEditorPanel) { ((I_ScriptEventEditorPanel) panel).uponClose(); } } } /* public Vector getPropertyPanels() { return properties.getProperties(); } */ }