org.placelab.demo.mapview
Class WadData

java.lang.Object
  extended byorg.placelab.demo.mapview.WadData

public class WadData
extends java.lang.Object

This class reads a map wad and gets out all the maps and allows accessing of all the maps and places in it. Alternatively, it can write a map wad.

 Wads are zip files with the following structure:
 + map.wad
 		- apcache.txt (a text file of the aps like from placelab.org)
 		- defaults.txt (a SectionedFile described below)
 		+ maps
 			- maps.index (a SectionedFile described below)
 			- mapname.jpg/gif/png/png OR mapname.tiger.zip (us census tiger format data)
 			- mapname.meta (a SectionedFile described below)
 		+ places
 			- places.index (a SectionedFile described below)
 			- place-set-name.txt (a SectionedFile described below)
 			- icons
 				- beer-icon.jpg/gif/png
 
 maps.index has the following structure
 [Maps]
 mapname=mapname.meta
 
 
 mapname.meta has the following structure
 [Map]
 # origin_lat and origin_lon are lower left corner values
 origin_lat=47.349829
 origin_lon=-122.98327
 pixels_per_lat=100.01
 pixels_per_lon=9994.39828
 # OR you may specify the upper right corner's lat and lon
 upper_right_lat=47.449829
 upper_right_lon=-122.99327
 
 image=images/mapimage1.jpg/gif/png
 
 NEW: alternatively you can specify the following structure
 for us census tiger data embedded in a mapwad:
 [TigerMap]
 data=maps/mapname.tiger.txt
 
 The Tiger data is the type 1 and type 2 record files
 concatenated together in that order.  This is likely
 to change in the future.
 
 
 places.index has the following structure
 [Places]
 place-set-name=place-set-name.txt
 
 
 place-set-name.txt has the following structure
 [place name]
 # image references are relative to the root of the wad
 icon_file=places/icons/beer_icon.jpg
 lat=46.19829
 lon=-122.8132
 text=Some descriptive text
 url=http://www.whitehouse.gov
 type=radical/AP/etc
 
 [other place name]
 etc ...
 
 NEW: Regions can specify rectangular areas on the map.
 They do not have types like places do
 In a directory called regions ...
 
 regions.index has the following structure
 [Regions]
 region_name=region_name.meta
 
 region.meta has the following structure
 [Region]
 origin_lat=47.1
 origin_lon=-122.1
 upper_right_lat=47.8
 upper_right_lon=-122.0
 text=Some descriptive text
 url=http://www.whitehouse.gov
 
 defaults.txt has the following structure
 [Map]
 mapname=1
 
 [Places]
 placeset1=1
 placeset2=1
 placeset3=1
 # ... and as many place sets as you would like to specify
 
the defaults file specifies what the wad author thinks should be the first set of things that people might want to see. There is no guarantee that they will be the first things displayed, it is only a suggestion. Also note that while you must specify a map if you have a defaults file, you needn't specify any place sets. Defaults files are not required.

Note that while place set definition file references in places.index are relative references, the image file references actually in the place set files are relative to the root of the wad. This is done so that people can put their images wherever they want in the wad, since ../ type references are not allowed.


Field Summary
protected  java.lang.String defaultMap
           
protected  java.util.Hashtable defaultPlaces
           
protected  java.util.Hashtable imageResources
           
protected  java.util.Hashtable maps
           
protected  java.util.Hashtable places
           
protected  java.util.Hashtable regions
           
protected  java.util.zip.ZipFile wad
           
protected  java.lang.String wadPath
           
 
Constructor Summary
WadData()
           
WadData(java.lang.String pathToWad)
           
 
Method Summary
 void addPlace(java.lang.String setName, PlaceBacking place)
           
 java.util.Hashtable allPlaceSets()
           
 boolean containsAPCache()
          Find out whether the map wad contains an ap cache or not
 java.io.InputStream getArbitraryResource(java.lang.String path)
           
 MapBacking getDefaultMap()
          Returns the MapBacking specified as the default for the wad or null if no MapBacking is specified
 java.util.Hashtable getDefaultPlaceSets()
          Returns a Hashtable containing the default place sets (Hashtables of PlaceBackings) for the wad or null if no default place sets are specified.
 org.eclipse.swt.graphics.ImageData getImageData(java.lang.String path)
          Returns an ImageData for the file at path in the wad
 MapBacking getMap(java.lang.String mapName)
           
 java.util.Hashtable getMaps()
           
 PlaceBacking getPlace(java.lang.String setName, java.lang.String placeName)
           
 java.util.Hashtable getPlaceSet(java.lang.String setName)
           
 java.util.Enumeration getPlaceSetNames()
           
 RegionBacking getRegion(java.lang.String regionName)
           
 java.util.Hashtable getRegions()
           
 java.util.Hashtable loadAPCacheAsPlaces(org.eclipse.swt.graphics.ImageData useIcon)
          Loads the ap cache into a special place set accessable under the place set name APs.
 JDBMMapper loadAPCacheIntoMapper(java.lang.String dbPath)
          Uses JDBMMapLoader to load the ap cache into the WifiMapper
 void putMap(BitmapMapBacking map)
           
 void putPlaceSet(java.lang.String setName, java.util.Hashtable set)
           
 void putRegion(RegionBacking region)
           
 void saveWad()
           
 void saveWad(java.io.OutputStream out)
          Writes out the current state of the waddata as a zip file to the supplied OutputStream Note that since images from waddata are lazily loaded you should not do this: WadData wad = new WadData(somePath); wad.putRegion(someRegionYouWantToAdd); wad.saveWad(new FileOutputStream(somePath))); If you do the above, it will break because the wad may need to load the image data from disk as it is copying them, but those images are now gone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maps

protected java.util.Hashtable maps

places

protected java.util.Hashtable places

regions

protected java.util.Hashtable regions

imageResources

protected java.util.Hashtable imageResources

defaultMap

protected java.lang.String defaultMap

defaultPlaces

protected java.util.Hashtable defaultPlaces

wad

protected java.util.zip.ZipFile wad

wadPath

protected java.lang.String wadPath
Constructor Detail

WadData

public WadData(java.lang.String pathToWad)
        throws java.io.IOException,
               WadDataFormatException

WadData

public WadData()
Method Detail

getImageData

public org.eclipse.swt.graphics.ImageData getImageData(java.lang.String path)
                                                throws java.io.IOException
Returns an ImageData for the file at path in the wad

Throws:
java.io.IOException

containsAPCache

public boolean containsAPCache()
Find out whether the map wad contains an ap cache or not


loadAPCacheIntoMapper

public JDBMMapper loadAPCacheIntoMapper(java.lang.String dbPath)
                                 throws java.io.IOException,
                                        WadDataFormatException
Uses JDBMMapLoader to load the ap cache into the WifiMapper

Throws:
java.io.IOException
WadDataFormatException

loadAPCacheAsPlaces

public java.util.Hashtable loadAPCacheAsPlaces(org.eclipse.swt.graphics.ImageData useIcon)
                                        throws java.io.IOException,
                                               WadDataFormatException
Loads the ap cache into a special place set accessable under the place set name APs. This is used so we can display the aps on maps like we do with places.

Parameters:
useIcon - you must provide an ImageData to use as an icon for the place, because every place must have an icon, and I surely don't have one laying around.
Returns:
the place set for the aps
Throws:
java.io.IOException
WadDataFormatException

getMap

public MapBacking getMap(java.lang.String mapName)

getMaps

public java.util.Hashtable getMaps()

putMap

public void putMap(BitmapMapBacking map)

getPlaceSetNames

public java.util.Enumeration getPlaceSetNames()

getRegion

public RegionBacking getRegion(java.lang.String regionName)

getRegions

public java.util.Hashtable getRegions()

putRegion

public void putRegion(RegionBacking region)

saveWad

public void saveWad(java.io.OutputStream out)
             throws java.io.IOException
Writes out the current state of the waddata as a zip file to the supplied OutputStream Note that since images from waddata are lazily loaded you should not do this: WadData wad = new WadData(somePath); wad.putRegion(someRegionYouWantToAdd); wad.saveWad(new FileOutputStream(somePath))); If you do the above, it will break because the wad may need to load the image data from disk as it is copying them, but those images are now gone. If you want to do this use the saveWad() method instead, which will manage setting up a temporary file for you to get around this problem.

Throws:
java.io.IOException

saveWad

public void saveWad()
             throws java.io.IOException
Throws:
java.io.IOException

allPlaceSets

public java.util.Hashtable allPlaceSets()
Returns:
a Hashtable where place set names => Hashtables where place names => PlaceBackings

getPlaceSet

public java.util.Hashtable getPlaceSet(java.lang.String setName)

getPlace

public PlaceBacking getPlace(java.lang.String setName,
                             java.lang.String placeName)

putPlaceSet

public void putPlaceSet(java.lang.String setName,
                        java.util.Hashtable set)

addPlace

public void addPlace(java.lang.String setName,
                     PlaceBacking place)

getDefaultMap

public MapBacking getDefaultMap()
Returns the MapBacking specified as the default for the wad or null if no MapBacking is specified


getDefaultPlaceSets

public java.util.Hashtable getDefaultPlaceSets()
Returns a Hashtable containing the default place sets (Hashtables of PlaceBackings) for the wad or null if no default place sets are specified.


getArbitraryResource

public java.io.InputStream getArbitraryResource(java.lang.String path)
                                         throws java.io.IOException
Throws:
java.io.IOException