private void updateDraggedState()
        {
            int  x             = selectedState.location.X;
            int  y             = selectedState.location.Y;
            bool shouldProcess = enlargeBackBufferAsRequired(ref x, ref y);

            selectedState.location.X = x;
            selectedState.location.Y = y;
            if (shouldProcess)
            {
                Graphics g = Graphics.FromImage(backBuffer);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                GraphicState.drawState(selectedState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);

                foreach (GraphicState state in stateArrayList)
                {
                    foreach (Arrow arrow in state.exitArrowList)
                    {
                        arrow.updateArrowPosition(state, null);
                    }
                    foreach (Arrow arrow in state.entryArrowList)
                    {
                        arrow.updateArrowPosition(null, state);
                    }
                }

                reDrawBackBuffer();

                panel2.Invalidate();
            }
        }
        private void createNewState(int x, int y)
        {
            enlargeBackBufferAsRequired(ref x, ref y);
            Graphics g = Graphics.FromImage(backBuffer);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            GraphicState s = new GraphicState(new Point(x, y), "q" + num);

            stateArrayList.Add(s);
            GraphicState.setZOrderOfStateOnTop(s, stateArrayList);

            GraphicState.drawState(s, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);

            num++;

            updateEdgeStates();


            panel2.Invalidate();
        }
        private void reDrawBackBuffer()
        {
            Graphics g = Graphics.FromImage(backBuffer);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillRectangle(backGroundBrush, 0, 0, backBuffer.Width, backBuffer.Height);
            stateArrayList.Sort((x, y) => x.zOrder.CompareTo(y.zOrder));
            foreach (GraphicState state in stateArrayList)
            {
                foreach (Arrow arrow in state.exitArrowList)
                {
                    Pen arrowPen = (arrow.isHoverOver) ? stateBorderPen2 : stateBorderPen;
                    if (arrow.bezierPoint1.X == -1)
                    {
                        g.DrawLine(arrowPen, arrow.start, arrow.end);
                    }
                    else
                    {
                        g.DrawBezier(arrowPen, arrow.start, arrow.bezierPoint1, arrow.bezierPoint2, arrow.end);
                    }
                    g.DrawLine(arrowPen, arrow.arrowTipPoint1, arrow.end);
                    g.DrawLine(arrowPen, arrow.arrowTipPoint2, arrow.end);

                    g.FillRectangle(backGroundBrush, arrow.textRect.X + GraphicState.STATE_RADII - arrow.transitionToken.Length * 15 / 2, arrow.textRect.Y + GraphicState.STATE_RADII - stateNameFont.Height / 2, arrow.transitionToken.Length * 15, stateNameFont.Height);
                    g.DrawString(arrow.transitionToken, stateNameFont, stateNameBrush, arrow.textRect, stateNameStringFormat);
                }
            }
            foreach (GraphicState state in stateArrayList)
            {
                if (state != selectedState)
                {
                    GraphicState.drawState(state, g, stateBrush, (state == hoverState)?stateBorderPen2: stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);
                }
            }
            if (selectedState != null)
            {
                GraphicState.drawState(selectedState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);
            }
        }
        private void selectTransitionState(int x, int y)
        {
            GraphicState s = GraphicState.getStateSelected(stateArrayList, new Point(x, y));
            Graphics     g = Graphics.FromImage(backBuffer);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            if (s != null)
            {
                if (fromState == null)
                {
                    fromState = s;
                    GraphicState.drawState(s, g, stateBrush, stateBorderPen2, stateNameFont, stateNameBrush, stateNameStringFormat);
                }
                else
                {
                    GraphicState.drawState(fromState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);
                    if (shouldCreateNewTransition(s))
                    {
                        Arrow arrow = new Arrow(fromState, s);
                        allArrowList.Add(arrow);
                        currentTransitionArrow = arrow;
                        initializeTokenTextField();
                        fromState.exitArrowList.Add(arrow);
                        s.entryArrowList.Add(arrow);
                        reDrawBackBuffer();
                    }
                    fromState = null;
                }
                panel2.Invalidate();
            }
            else if (fromState != null)
            {
                GraphicState.drawState(fromState, g, stateBrush, stateBorderPen, stateNameFont, stateNameBrush, stateNameStringFormat);
                fromState = null;
                panel2.Invalidate();
            }
        }