/*
 * CommonFunctions.fx
 *
 * Created on Nov 30, 2009, 12:49:57 AM
 */

package vismobile;

import javafx.scene.image.Image;
import java.lang.String;
import com.sun.javafx.runtime.sequence.Sequence;
import java.util.Enumeration;
import structures.Constants;
import structures.HashContext;

/**
 * @author Jamie Lynn
 */

public class CommonFunctionsFX {



}
 public static function getImage(name: String)
        {
            Image { url: "{__DIR__}images/{name}.png"};

        }

public static function getAllRects()
{
    var allRects:Sequence;

        insert Main.courseRect1 into allRects;
        insert Main.courseRect2 into allRects;
        insert Main.courseRect3 into allRects;
        insert Main.courseRect4 into allRects;
        insert Main.courseRect5 into allRects;
        insert Main.courseRect6 into allRects;
        insert Main.courseRect7 into allRects;
        insert Main.courseRect8 into allRects;
        insert Main.fineRect1 into allRects;
        insert Main.fineRect2 into allRects;
        insert Main.fineRect3 into allRects;
        insert Main.fineRect4 into allRects;
        insert Main.fineRect5 into allRects;
        insert Main.fineRect6 into allRects;
        insert Main.fineRect7 into allRects;
        insert Main.fineRect8 into allRects;
        insert Main.fineRect9 into allRects;
        insert Main.fineRect10 into allRects;
        insert Main.fineRect11 into allRects;
        insert Main.fineRect12 into allRects;
        insert Main.fineRect13 into allRects;
        insert Main.fineRect14 into allRects;
        insert Main.fineRect15 into allRects;
        insert Main.fineRect16 into allRects;
        insert Main.fineRect17 into allRects;
        insert Main.fineRect18 into allRects;
        insert Main.fineRect19 into allRects;
        insert Main.fineRect20 into allRects;
        insert Main.fineRect21 into allRects;
        insert Main.fineRect22 into allRects;
        insert Main.fineRect23 into allRects;
        insert Main.fineRect24 into allRects;
       
 
    return allRects;

}


public static function searchContextHashTable(activeScene:String)
{
    var locationsToBlink:Sequence;

    if(activeScene == "CarContextCourse")
    {
           

     //Get the keys from the Context: key is the VIN of a vehicle
     def enKeys:Enumeration = mdot.Main.getContext().keys();

            //size = number of vehicles in our context
            def size = mdot.Main.getContext().size();

            //while there are still vehicles to check...
            while(enKeys.hasMoreElements()){
                def key = enKeys.nextElement() as String;

                //get the context of the vehicle we are cheking
                def tmp:HashContext = (mdot.Main.getContext().get(key)) as HashContext;

                //if there is a "location" key in this context...
                if (tmp.GetObjectAsString(Constants.HASH_LOCATION) != null){

                    def locANDColor = tmp.GetObjectAsString(Constants.HASH_LOCATION);
                    //var locANDColorArray:String[] = locANDColor.split(structures.Constants.DELIMITER);

                     var locANDColorArray:String[];

                    locANDColorArray[0] = locANDColor.substring(0, locANDColor.indexOf(structures.Constants.DELIMITER));
                    var begin = locANDColor.indexOf(structures.Constants.DELIMITER) + 1;
                    var end = locANDColor.length();

                    locANDColorArray[1] = locANDColor.substring(begin, end);


                    java.lang.System.out.println("{locANDColorArray[0]}.......{locANDColorArray[1]}");



                    def loc = locANDColorArray[0];

                    if(loc.equals(Constants.FRONT_LEFT_STRING)){
                    Main.courseRect8.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect8 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.FRONT_CENTER_STRING)){
                    Main.courseRect1.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect1 into locationsToBlink;
                        }
                    else if(loc.equals(Constants.FRONT_RIGHT_STRING)){
                    Main.courseRect2.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect2 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.LEFT_STRING)){

                    Main.courseRect7.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect7 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.RIGHT_STRING)){
                    Main.courseRect3.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect3 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_LEFT_STRING)){
                    Main.courseRect6.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect6 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_CENTER_STRING)){
                    Main.courseRect5.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect5 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_RIGHT_STRING)){
                    Main.courseRect4.setNewColor(locANDColorArray[1]);
                    insert Main.courseRect4 into locationsToBlink;
                    }
                   }
               }
           }
    else if(activeScene == "CarContextFine"){

     //Get the keys from the Context: key is the VIN of a vehicle
     def enKeysFine:Enumeration = mdot.Main.getContext().keys();

            //size = number of vehicles in our context
            def sizeFine = mdot.Main.getContext().size();

            //while there are still vehicles to check...
            while(enKeysFine.hasMoreElements()){
                def keyFine = enKeysFine.nextElement() as String;

                //get the context of the vehicle we are cheking
                def tmpFine:HashContext = (mdot.Main.getContext().get(keyFine)) as HashContext;

                //if there is a "location" key in this context...
                if (tmpFine.GetObjectAsString(Constants.HASH_LOCATION1) != null){

                    def locANDColor = tmpFine.GetObjectAsString(Constants.HASH_LOCATION1);
                    var locANDColorArray:String[];

                    locANDColorArray[0] = locANDColor.substring(0, locANDColor.indexOf(structures.Constants.DELIMITER));
                    var begin = locANDColor.indexOf(structures.Constants.DELIMITER) + 1;
                    var end = locANDColor.length();

                    locANDColorArray[1] = locANDColor.substring(begin, end);


                    java.lang.System.out.println("{locANDColorArray[0]}.......{locANDColorArray[1]}");


                    def locFine = locANDColorArray[0];

                    if (locFine.equals("1.0")){
                        Main.fineRect1.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect1 into locationsToBlink
                    }
                    else if (locFine.equals("2.0")){
                        Main.fineRect2.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect2 into locationsToBlink
                    }
                    else if (locFine.equals("3.0")){
                        Main.fineRect3.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect3 into locationsToBlink
                    }
                    else if (locFine.equals("4.0")){
                        Main.fineRect4.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect4 into locationsToBlink
                    }
                    else if (locFine.equals("5.0")){
                        Main.fineRect5.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect5 into locationsToBlink
                    }
                    else if (locFine.equals("6.0")){
                        Main.fineRect6.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect6 into locationsToBlink
                    }
                    else if (locFine.equals("7.0")){
                        Main.fineRect7.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect7 into locationsToBlink
                    }
                    else if (locFine.equals("8.0")){
                        Main.fineRect8.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect8 into locationsToBlink
                    }
                    else if (locFine.equals("9.0")){
                        Main.fineRect9.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect9 into locationsToBlink
                    }
                    else if(locFine.equals("10.0")){
                        Main.fineRect10.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect10 into locationsToBlink
                    }
                    else if (locFine.equals("11.0")){
                        Main.fineRect11.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect11 into locationsToBlink
                    }
                    else if (locFine.equals("12.0")){
                        Main.fineRect12.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect12 into locationsToBlink
                    }
                    else if (locFine.equals("13.0")){
                        Main.fineRect13.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect13 into locationsToBlink
                    }
                    else if (locFine.equals("14.0")){
                        Main.fineRect14.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect14 into locationsToBlink
                    }
                    else if (locFine.equals("15.0")){
                        Main.fineRect15.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect15 into locationsToBlink
                    }
                    else if (locFine.equals("16.0")){
                        Main.fineRect16.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect16 into locationsToBlink
                    }
                    else if (locFine.equals("17.0")){
                        Main.fineRect17.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect17 into locationsToBlink
                    }
                    else if (locFine.equals("18.0")){
                        Main.fineRect18.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect18 into locationsToBlink
                    }
                    else if (locFine.equals("19.0")){
                        Main.fineRect19.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect19 into locationsToBlink
                    }
                    else if(locFine.equals("20.0")){
                        Main.fineRect20.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect20 into locationsToBlink
                    }
                    else if (locFine.equals("21.0")){
                        Main.fineRect21.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect21 into locationsToBlink
                    }
                    else if (locFine.equals("22.0")){
                        Main.fineRect22.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect22 into locationsToBlink
                    }
                    else if (locFine.equals("23.0")){
                        Main.fineRect23.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect23 into locationsToBlink
                    }
                    else if (locFine.equals("24.0")){
                        Main.fineRect24.setNewColor(locANDColorArray[1]);
                        insert Main.fineRect24 into locationsToBlink
                    }

                }
        }
    }

//java.lang.System.out.println(locationsToBlink.toString());
    return locationsToBlink;
}

/*
public function getVoipStatus()
{

    return local.ua.TestWithoutGUI.getCall_status();
}

public function getHeadingRange(heading:String)
{
        var directions:Sequence;
        if(heading.equals("N"))
        {
            insert "NW" into directions;
            insert heading into directions;
            insert "NE" into directions;
        }
        else if(heading.equals("NE"))
        {
            insert "N" into directions;
            insert heading into directions;
            insert "E" into directions;
        }
        else if(heading.equals("E"))
        {
            insert "NE" into directions;
            insert heading into directions;
            insert "SE" into directions;
        }
        else if(heading.equals("SE"))
        {
            insert "E" into directions;
            insert heading into directions;
            insert "S" into directions;
        }
        else if(heading.equals("S"))
        {
            insert "SE" into directions;
            insert heading into directions;
            insert "SW" into directions;
        }
        else if(heading.equals("SW"))
        {
            insert "S" into directions;
            insert heading into directions;
            insert "W" into directions;
        }
        else if(heading.equals("W"))
        {
            insert "SW" into directions;
            insert heading into directions;
            insert "NW" into directions;
        }
        else if(heading.equals("NW"))
        {
            insert "W" into directions;
            insert heading into directions;
            insert "N" into directions;
        }

        return directions;

}*/