private void Panel2_MouseDown(object sender, MouseEventArgs e)
 {
     if (attributeEditorRadioButton.Checked && e.Button == MouseButtons.Left)
     {
         selectedState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y), ref deviation);
     }
 }
        private bool getCurrentTransitionArrow(int x, int y)
        {
            bool reDraw = false;

            currentTransitionArrow = null;
            foreach (Arrow arrow in allArrowList)
            {
                if (arrow.textRect.Contains(x, y) && GraphicState.getStateSelected(stateArrayList, new Point(x, y)) == null)
                {
                    currentTransitionArrow = arrow;
                    if (arrow.isHoverOver)
                    {
                        break;
                    }
                    arrow.isHoverOver = true;
                    reDraw            = true;
                    break;
                }
            }
            foreach (Arrow arrow in allArrowList)
            {
                if (arrow.isHoverOver && arrow != currentTransitionArrow)
                {
                    reDraw            = true;
                    arrow.isHoverOver = false;
                }
            }
            return(reDraw);
        }
        private void Panel2_MouseMove(object sender, MouseEventArgs e)
        {
            if (selectedState != null)
            {
                dragPoint.X = e.X - panel2.AutoScrollPosition.X;
                dragPoint.Y = e.Y - panel2.AutoScrollPosition.Y;


                if (!dragDropTimer.Enabled)
                {
                    dragDropTimer.Start();
                }
            }
            else if (attributeEditorRadioButton.Checked && !transitionTokenTextField.Visible)
            {
                getSelectedTransition(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y);
            }
            else if (deleterRadioButton.Checked)
            {
                GraphicState prevHoverState      = hoverState;
                Arrow        prevTransitionArrow = currentTransitionArrow;
                hoverState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y));
                getCurrentTransitionArrow(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y);
                if (hoverState != prevHoverState || currentTransitionArrow != prevTransitionArrow)
                {
                    reDrawBackBuffer();
                    panel2.Invalidate();
                }
            }
        }
 private void panel2_Click(object sebder, MouseEventArgs e)
 {
     if (transitionTokenTextField.Visible)
     {
         getTextFieldData();
     }
     if (stateCreatorRadioButton.Checked && e.Button == MouseButtons.Left)
     {
         createNewState(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y);
     }
     else if (transitionCreatorRadioButton.Checked && e.Button == MouseButtons.Left)
     {
         selectTransitionState(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y);
     }
     else if (attributeEditorRadioButton.Checked && e.Button == MouseButtons.Left && currentTransitionArrow != null)
     {
         initializeTokenTextField();
     }
     else if (deleterRadioButton.Checked && e.Button == MouseButtons.Left)
     {
         deleteItem();
     }
     else if (e.Button == MouseButtons.Right && attributeEditorRadioButton.Checked)
     {
         if ((propertyChangingState = GraphicState.getStateSelected(stateArrayList, new Point(e.X - panel2.AutoScrollPosition.X, e.Y - panel2.AutoScrollPosition.Y))) != null)
         {
             if (propertyChangingState.final)
             {
                 finalStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
             }
             else
             {
                 finalStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Unchecked;
             }
             if (propertyChangingState.initial)
             {
                 initialStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
             }
             else
             {
                 initialStateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Unchecked;
             }
             StateContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);
         }
     }
 }
        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();
            }
        }