de.cau.cs.kieler.kev.mapping.animations
Class MapAnimations

java.lang.Object
  extended by de.cau.cs.kieler.kev.mapping.animations.MapAnimations

public final class MapAnimations
extends Object

This class connects the mapping-file with the corresponding SVG-file.

Rating proposed yellow
(2010-02-17)

Method Summary
 ArrayList<String> attributeParser(String input, boolean isInputAttribute)
          This function is intensively used by the mapInputToOutput() method.
 JSONObject compareDifference(JSONObject oldJSONObject, JSONObject newJSONObject)
           
 String computeRangeValue(String inputValue, String inputRange, String outputRange)
          Maps the current JSON value from an input range to an output range
 void createHashMap()
          This Method creates a HashMap of SVGElements of the actual Mapping file.
static boolean createSingleInstance()
           
 void doAnimations(JSONObject jsonObject)
          Applies the Animations for all JSON-Keys which exists in the mapping file.
 HashMap<String,ArrayList<Pair<String,Animation>>> getDefaultKeyToAnimationsMap()
           
static MapAnimations getInstance()
          Returns the single instance of the EclipseJSVGCanvas.
 HashMap<String,HashMap<String,ArrayList<Pair<String,Animation>>>> getJsonKeyToInputValuesToAnimationsMap()
           
 EclipseJSVGCanvas getJSVGCanvas()
          Returns the actual JSVGCanvas.
 HashMap<String,ArrayList<Pair<String,Animation>>> getKeyToAnimationsMap()
           
 SVGFile getMappingFile()
          Return the current mapping file of this MapAnimations.
 String getMappingFilePath()
           
 HashMap<String,HashSet<String>> getModifiedKeyMap()
           
 org.w3c.dom.svg.SVGDocument getSVGDocument()
          Returns the actual SVGDocument.
 void initializeMappingFile(String filename, boolean isResource)
           
 boolean jsonValueMatchesInputValue(String jsonValue, String inputValue)
          Tests if a value matches the input string of an animation.
 SVGFile loadFromFile(String filename)
          Loads an mapping file from disk.
 SVGFile loadFromResource(String filename)
          Loads an .mapping file from the resource example folder.
 JSONObject makeItFlat(JSONObject inputObject)
          Make the input JSONObject flat if there exists a hierarchy.
 HashMap<String,String> mapInputToOutput(ArrayList<String> inputArray, ArrayList<String> outputArray)
          THIS Method is really important and should be used for all animations! This method maps the input values to the corespondig output values.
 ArrayList<String> parser(String input)
          Scans a string of comma separated values and simple puts them into an array.
 void setDefaultKeyToAnimationsMap(HashMap<String,ArrayList<Pair<String,Animation>>> defaultKeyToAnimationsMap)
           
 void setJsonKeyToInputValuesToAnimationsMap(HashMap<String,HashMap<String,ArrayList<Pair<String,Animation>>>> jsonKeyToInputValuesToAnimationsMap)
           
 void setKeyToAnimationsMap(HashMap<String,ArrayList<Pair<String,Animation>>> keyToAnimationsMap)
           
 boolean valueMatchesRange(String value, String range)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initializeMappingFile

public void initializeMappingFile(String filename,
                                  boolean isResource)

getMappingFilePath

public String getMappingFilePath()

createSingleInstance

public static boolean createSingleInstance()

getInstance

public static MapAnimations getInstance()
Returns the single instance of the EclipseJSVGCanvas.

Returns:
INSTANCE

getJSVGCanvas

public EclipseJSVGCanvas getJSVGCanvas()
Returns the actual JSVGCanvas.

Returns:
svgCanvas

getSVGDocument

public org.w3c.dom.svg.SVGDocument getSVGDocument()
Returns the actual SVGDocument.

Returns:
svgDocument

getMappingFile

public final SVGFile getMappingFile()
Return the current mapping file of this MapAnimations.

Returns:
mappingFile the current mapping file

loadFromResource

public final SVGFile loadFromResource(String filename)
Loads an .mapping file from the resource example folder.

Parameters:
filename - name of the file to load from resource
Returns:
current mapping file (SVGFile see ecore model)

loadFromFile

public final SVGFile loadFromFile(String filename)
Loads an mapping file from disk.

Parameters:
filename - name of the file to load from disk
Returns:
current mapping file

createHashMap

public void createHashMap()
This Method creates a HashMap of SVGElements of the actual Mapping file.

Parameters:
mappingFile - current mapping file for which the hashmap should be created

doAnimations

public void doAnimations(JSONObject jsonObject)
Applies the Animations for all JSON-Keys which exists in the mapping file.

Parameters:
jsonObject - the actual JSON-object

valueMatchesRange

public boolean valueMatchesRange(String value,
                                 String range)

parser

public ArrayList<String> parser(String input)
Scans a string of comma separated values and simple puts them into an array.


attributeParser

public ArrayList<String> attributeParser(String input,
                                         boolean isInputAttribute)
This function is intensively used by the mapInputToOutput() method. It simply creates an ArrayList with no duplicates of the inputstring.

Parameters:
input - String to parse
isInputAttribute - true means save all input values of a range. Example: true = 1..5 => 1,2,3,4,5 | false = 1..5 => 1,5
Returns:
An ArrayList with all parsed values

mapInputToOutput

public HashMap<String,String> mapInputToOutput(ArrayList<String> inputArray,
                                               ArrayList<String> outputArray)
THIS Method is really important and should be used for all animations! This method maps the input values to the corespondig output values. input is always the input from mapping file whereby output can be any value of the special animation to which the input values should be mapped. Example: input="1..10,20..30,40,45,50,900" output=x_range="[200..215,220,225,230,235,240];[1..3];200" PROBLEME MIT DEM PARSEN DES OUTPUTS HIER NOCHMAL SCHAUEN! UPDATE: This method does no parsing at all! it just maps an input arraylist to an outputarraylist

Parameters:
inputArray - the array with all valid input values
outputArray - the array with the animation specific values to which the input values should be mapped
Returns:
hashMap a hashmap with input values as the key and output values as the value

compareDifference

public JSONObject compareDifference(JSONObject oldJSONObject,
                                    JSONObject newJSONObject)

makeItFlat

public final JSONObject makeItFlat(JSONObject inputObject)
                            throws JSONException
Make the input JSONObject flat if there exists a hierarchy. This one should be called instead of the other version of makeItFlat, which has some initial value parameters for recursive computation.

Parameters:
inputObject - the input JSONObject, which may not be flat
Returns:
A JSONObject which has a flat hierarchy
Throws:
JSONException - , is thrown if a conversion fails

setJsonKeyToInputValuesToAnimationsMap

public void setJsonKeyToInputValuesToAnimationsMap(HashMap<String,HashMap<String,ArrayList<Pair<String,Animation>>>> jsonKeyToInputValuesToAnimationsMap)
Parameters:
jsonKeyToInputValuesToAnimationsMap - the jsonKeyToInputValuesToAnimationsMap to set

getJsonKeyToInputValuesToAnimationsMap

public HashMap<String,HashMap<String,ArrayList<Pair<String,Animation>>>> getJsonKeyToInputValuesToAnimationsMap()
Returns:
the jsonKeyToInputValuesToAnimationsMap

setDefaultKeyToAnimationsMap

public void setDefaultKeyToAnimationsMap(HashMap<String,ArrayList<Pair<String,Animation>>> defaultKeyToAnimationsMap)
Parameters:
defaultKeyToAnimationsMap - the defaultKeyToAnimationsMap to set

getDefaultKeyToAnimationsMap

public HashMap<String,ArrayList<Pair<String,Animation>>> getDefaultKeyToAnimationsMap()
Returns:
the defaultKeyToAnimationsMap

setKeyToAnimationsMap

public void setKeyToAnimationsMap(HashMap<String,ArrayList<Pair<String,Animation>>> keyToAnimationsMap)

getKeyToAnimationsMap

public HashMap<String,ArrayList<Pair<String,Animation>>> getKeyToAnimationsMap()

getModifiedKeyMap

public HashMap<String,HashSet<String>> getModifiedKeyMap()

computeRangeValue

public final String computeRangeValue(String inputValue,
                                      String inputRange,
                                      String outputRange)
Maps the current JSON value from an input range to an output range

Parameters:
jsonValue -
input -
output -
Returns:

jsonValueMatchesInputValue

public boolean jsonValueMatchesInputValue(String jsonValue,
                                          String inputValue)
Tests if a value matches the input string of an animation.

Parameters:
jsonValue -
inputValue -
Returns: