/******************************************************************* Copyright (c) 2001-2007 Apprisant Technologies Inc. All rights reserved. Apprisant Technologies permits non-exclusive royalty free use, copying and modification of this demo program source code for the purposes of evaluating the Apprisant Toolkit or building applications that use it. This software and documentation is provided "AS IS". APPRISANT TECHNOLOGIES DISCLAIMS ANY REPRESENTATIONS AND WARRANTIES, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY AND FITNESS OF THIS PRODUCT FOR ANY PARTICULAR PURPOSE. APPRISANT TECHNOLOGIES SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY ANY PARTY, INCLUDING LOST PROFITS, ARISING FROM THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ITS DERIVATIONS. ********************************************************************/ package camp; import java.io.*; import java.util.*; import apprisant.diagram.*; import apprisant.diagram.data.*; import apprisant.diagram.event.*; import apprisant.diagram.env.*; import camp.Site.Hookup; // enum class /* Data model for the Camp demo. Represents the data as two data sets, one for each reservation date. Data objects are Site instances. */ public class CampData implements DataModel, Serializable { private DataModelSupport support = new DataModelSupport(this); private Diagram diagram; private transient Map jul3Data = new LinkedHashMap(); private transient Map jul10Data = new LinkedHashMap(); private transient Map currentData; // set to one of the above public CampData() { makeData(); currentData = jul3Data; } /* Called by the diagram's setDataModel method. */ public void setDiagram (Diagram diagram) { this.diagram = diagram; } public Diagram getDiagram() { return diagram; } public void addAGDataListener (AGDataListener listener) { support.addAGDataListener(listener); } public void removeAGDataListener (AGDataListener listener) { support.removeAGDataListener(listener); } public AGDataListener[] getAGDataListeners() { return support.getAGDataListeners(); } /* DataModel interface methods. */ public String getName() { return "CampData"; } public Collection keySet() { return currentData.keySet(); } public Site getDataObject (Object key) { return currentData.get(key); } /* Methods for the date radio buttons. The new data objects replace the ones currently attached to the display elements. */ public void setJul3Data() { currentData = jul3Data; support.fireAddAll(); } public void setJul10Data() { currentData = jul10Data; support.fireAddAll(); } /* Methods for the Reserve and Cancel buttons. The second pair requires the data model's diagram property to be set. */ public void reserve (Set keys) { for (Object key : keys) { getDataObject(key).reserve(); } support.fireUpdate(keys, false); } public void cancel (Set keys) { for (Object key : keys) { getDataObject(key).cancel(); } support.fireUpdate(keys, false); } public void reserveSelected() { Set keys = diagram.getSelectionModel().getSelection(); reserve(keys); } public void cancelSelected() { Set keys = diagram.getSelectionModel().getSelection(); cancel(keys); } void makeData() { jul3Data.put("A1", new Site("A1", Hookup.ELECTRIC, 40, false)); jul3Data.put("A2", new Site("A2", Hookup.ELECTRIC, 20, false)); jul3Data.put("A3", new Site("A3", Hookup.ELECTRIC, 20, true)); jul3Data.put("A4", new Site("A4", Hookup.NONE, 20, true)); jul3Data.put("A5", new Site("A5", Hookup.NONE, 50, false)); jul3Data.put("A6", new Site("A6", Hookup.NONE, 20, true)); jul3Data.put("A7", new Site("A7", Hookup.NONE, 40, true)); jul3Data.put("A8", new Site("A8", Hookup.NONE, 20, false)); jul3Data.put("A9", new Site("A9", Hookup.NONE, 50, false)); jul3Data.put("A10", new Site("A10", Hookup.NONE, 40, true)); jul3Data.put("A11", new Site("A11", Hookup.NONE, 20, false)); jul3Data.put("A12", new Site("A12", Hookup.NONE, 50, true)); jul3Data.put("A13", new Site("A13", Hookup.ELECTRIC, 50, false)); jul3Data.put("A14", new Site("A14", Hookup.FULL, 40, true)); jul3Data.put("A15", new Site("A15", Hookup.ELECTRIC, 40, true)); jul3Data.put("A16", new Site("A16", Hookup.FULL, 20, false)); jul3Data.put("A17", new Site("A17", Hookup.FULL, 20, true)); jul3Data.put("A18", new Site("A18", Hookup.ELECTRIC, 60, false)); jul3Data.put("A19", new Site("A19", Hookup.FULL, 60, true)); jul3Data.put("A20", new Site("A20", Hookup.ELECTRIC, 60, false)); jul10Data.put("A1", new Site("A1", Hookup.ELECTRIC, 40, false)); jul10Data.put("A2", new Site("A2", Hookup.ELECTRIC, 20, false)); jul10Data.put("A3", new Site("A3", Hookup.ELECTRIC, 20, true)); jul10Data.put("A4", new Site("A4", Hookup.NONE, 20, true)); jul10Data.put("A5", new Site("A5", Hookup.NONE, 50, false)); jul10Data.put("A6", new Site("A6", Hookup.NONE, 20, false)); jul10Data.put("A7", new Site("A7", Hookup.NONE, 40, false)); jul10Data.put("A8", new Site("A8", Hookup.NONE, 20, false)); jul10Data.put("A9", new Site("A9", Hookup.NONE, 50, true)); jul10Data.put("A10", new Site("A10", Hookup.NONE, 40, false)); jul10Data.put("A11", new Site("A11", Hookup.NONE, 20, false)); jul10Data.put("A12", new Site("A12", Hookup.NONE, 50, false)); jul10Data.put("A13", new Site("A13", Hookup.ELECTRIC, 50, true)); jul10Data.put("A14", new Site("A14", Hookup.FULL, 40, false)); jul10Data.put("A15", new Site("A15", Hookup.ELECTRIC, 40, true)); jul10Data.put("A16", new Site("A16", Hookup.FULL, 20, false)); jul10Data.put("A17", new Site("A17", Hookup.FULL, 20, false)); jul10Data.put("A18", new Site("A18", Hookup.ELECTRIC, 60, false)); jul10Data.put("A19", new Site("A19", Hookup.FULL, 60, true)); jul10Data.put("A20", new Site("A20", Hookup.ELECTRIC, 60, false)); } /* Serialization support for IDEs that need it. */ private void readObject (ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); jul3Data = new LinkedHashMap(); jul10Data = new LinkedHashMap(); makeData(); currentData = jul3Data; } /** Converter class to enable option renderers from the XML file to match data attribute values. Also used by Red and Geo to display attribute values as text. */ public static class HookupConverter extends MapConverter { public HookupConverter() { super(Hookup.values(), true); } } }