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

package mdot_gui;

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

/**
 * @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 MainScreen.courseRect1 into allRects;
        insert MainScreen.courseRect2 into allRects;
        insert MainScreen.courseRect3 into allRects;
        insert MainScreen.courseRect4 into allRects;
        insert MainScreen.courseRect5 into allRects;
        insert MainScreen.courseRect6 into allRects;
        insert MainScreen.courseRect7 into allRects;
        insert MainScreen.courseRect8 into allRects;
        insert MainScreen.fineRect1 into allRects;
        insert MainScreen.fineRect2 into allRects;
        insert MainScreen.fineRect3 into allRects;
        insert MainScreen.fineRect4 into allRects;
        insert MainScreen.fineRect5 into allRects;
        insert MainScreen.fineRect6 into allRects;
        insert MainScreen.fineRect7 into allRects;
        insert MainScreen.fineRect8 into allRects;
        insert MainScreen.fineRect9 into allRects;
        insert MainScreen.fineRect10 into allRects;
        insert MainScreen.fineRect11 into allRects;
        insert MainScreen.fineRect12 into allRects;
        insert MainScreen.fineRect13 into allRects;
        insert MainScreen.fineRect14 into allRects;
        insert MainScreen.fineRect15 into allRects;
        insert MainScreen.fineRect16 into allRects;
        insert MainScreen.fineRect17 into allRects;
        insert MainScreen.fineRect18 into allRects;
        insert MainScreen.fineRect19 into allRects;
        insert MainScreen.fineRect20 into allRects;
        insert MainScreen.fineRect21 into allRects;
        insert MainScreen.fineRect22 into allRects;
        insert MainScreen.fineRect23 into allRects;
        insert MainScreen.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);

                //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);
                    def loc = locANDColorArray[0];

                    if(loc.equals(Constants.FRONT_LEFT_STRING)){
                    MainScreen.courseRect8.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect8 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.FRONT_CENTER_STRING)){
                    MainScreen.courseRect1.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect1 into locationsToBlink;
                        }
                    else if(loc.equals(Constants.FRONT_RIGHT_STRING)){
                    MainScreen.courseRect2.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect2 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.LEFT_STRING)){
                    MainScreen.courseRect7.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect7 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.RIGHT_STRING)){
                    MainScreen.courseRect3.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect3 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_LEFT_STRING)){
                    MainScreen.courseRect6.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect6 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_CENTER_STRING)){
                    MainScreen.courseRect5.setNewColor(locANDColorArray[1]);
                    insert MainScreen.courseRect5 into locationsToBlink;
                    }
                    else if(loc.equals(Constants.BACK_RIGHT_STRING)){
                    MainScreen.courseRect4.setNewColor(locANDColorArray[1]);
                    insert MainScreen.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);

                //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[] = locANDColor.split(structures.Constants.DELIMITER);
                    def locFine = locANDColorArray[0];

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

    return locationsToBlink;
}

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;

}

public function DisableApps(appButtons:Object[])
{
        for(b in appButtons)
        {
            (b as ApplicationButton).opacity = 0.25;
            (b as ApplicationButton).disable = true;

        }
}

public function EnableApps(appButtons:Object[])
{
        for(b in appButtons)
        {
            (b as ApplicationButton).opacity = 1;
            (b as ApplicationButton).disable = false;

        }
}

public function EnableButtons(btn1:SceneButton, btn2:SceneButton, btn3:SceneButton)
{

    btn1.displayimage = getImage("app_lg");
    btn1.opacity = 1.0;
    btn1.disable = false;
    btn2.displayimage = getImage("speak_lg");
    btn2.opacity = 1.0;
    btn2.disable = false;
    btn3.displayimage = getImage("phone_lg");
    btn3.opacity = 1.0;
    btn3.disable = false;
}

public function DisableButtons(btn1:SceneButton, btn2:SceneButton, btn3:SceneButton)
{
    //LOCK EVERYTHING!
    btn1.displayimage = getImage("lock_lg");
    btn1.opacity = 0.25;
    btn1.disable = true;
    btn2.displayimage = getImage("lock_lg");
    btn2.opacity = 0.25;
    btn2.disable = true;
    btn3.displayimage = getImage("lock_lg");
    btn3.opacity = 0.25;
    btn3.disable = true;

    
}