/******************************************************************* Copyright (c) 2001-2010 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 { private DataModelSupport support = new DataModelSupport(this); private Map jul3Data = new LinkedHashMap(); private Map jul10Data = new LinkedHashMap(); private Map currentData; // set to one of the above public CampData() { makeData(); currentData = jul3Data; } /* DataModel interface methods. */ public void addAGDataListener (AGDataListener listener) { support.addAGDataListener(listener); } public void removeAGDataListener (AGDataListener listener) { support.removeAGDataListener(listener); } public AGDataListener[] getAGDataListeners() { return support.getAGDataListeners(); } public Collection keySet() { return currentData.keySet(); } public Site get (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. */ public void reserve (Set keys) { for (Object key : keys) { get(key).reserve(); } support.fireUpdate(keys); } public void cancel (Set keys) { for (Object key : keys) { get(key).cancel(); } support.fireUpdate(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)); } /** Converter class to enable renderers read from the 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); } } }