public DataLedArrayNode(int newStateNumber, int newLedNumber)
 {
     ledNumber = newLedNumber;
     stateNumber = newStateNumber;
     ledData = new ArrayList();
     // Init default data
     for (int stateIndex = 0; stateIndex < stateNumber; stateIndex++)
     {
         // Init data for each state
         ArrayList curState = new ArrayList();
         curState.Add(Constants.StateType.Data);//Add default state type
         curState.Add(Constants.DEFAULT_BRIGHTTIME);//Add default common value for TypeStateData
         for (int ledIndex = 0; ledIndex < ledNumber; ledIndex++)
         {
             LedNode curNode = new LedNode(Constants.DEFAULT_BRIGHT);
             curState.Insert(ledIndex + 2, curNode);
         }
         ledData.Add(curState);
     }
 }
        public Boolean AddLed(int ledIndex)
        {
            if ((ledIndex >= 0) && (ledIndex <= ledNumber))
            {

                for (int stateIndex = 0; stateIndex < stateNumber; stateIndex++)
                {
                    ArrayList curState = (ArrayList)ledData[stateIndex];
                    Constants.StateType stateType = (Constants.StateType)curState[0];
                    switch (stateType)
                    {
                        case Constants.StateType.Data:
                            LedNode curNode = new LedNode(Constants.DEFAULT_BRIGHT);
                            curState.Insert(ledIndex + 2, curNode);
                            break;
                        case Constants.StateType.StartFor:
                        case Constants.StateType.Endfor:
                            break;
                        default:
                            return false;
                    }
                }
                ledNumber++;
                return true;
            }
            else return false;
        }
        //This function is used to get data from specific format and apply to specific index
        public Boolean SetState(int stateIndex, ArrayList stateData)
        {
            ArrayList curState = new ArrayList();
            Constants.StateType stateType = (Constants.StateType)stateData[0];
            int stateCommonValue;
            curState.Add(stateType);
            switch (stateType)
            {
                case Constants.StateType.Data:
                    stateCommonValue = (int)stateData[1];
                    curState.Add(stateCommonValue);
                    if (ledNumber < (stateData.Count-2)) ledNumber = stateData.Count-2;
                    for (int ledIndex = 0; ledIndex < ledNumber; ledIndex++)
                    {

                        int bright = (int)stateData[ledIndex + 2];
                        LedNode curNode = new LedNode(bright);
                        curState.Add(curNode);
                    }

                    break;
                case Constants.StateType.StartFor:
                    stateCommonValue = (int)stateData[1];
                    curState.Add(stateCommonValue);
                    break;
                case Constants.StateType.Endfor:
                    break;
                default:
                    return false;
            }
            ledData[stateIndex] = curState;
            return true;
        }
 public Boolean InsertState(int stateIndex, Constants.StateType stateType)
 {
     if ((stateIndex >= 0) && (stateIndex <= stateNumber))
     {
         ArrayList curState = new ArrayList();
         curState.Add(stateType);
         switch (stateType)
         {
             case Constants.StateType.Data:
                 curState.Add(Constants.DEFAULT_BRIGHTTIME);
                 for (int ledIndex = 0; ledIndex < ledNumber; ledIndex++)
                 {
                     LedNode curNode = new LedNode(Constants.DEFAULT_BRIGHT);
                     curState.Insert(ledIndex + 2, curNode);
                 }
                 break;
             case Constants.StateType.StartFor:
                 curState.Add(Constants.DEFAULT_LOOP_TIME);
                 break;
             case Constants.StateType.Endfor:
                 break;
             default:
                 return false;
         }
         ledData.Insert(stateIndex, curState);
         stateNumber++;
         return true;
     }
     return false;
 }