Ejemplo n.º 1
0
        //for highlighting suggestions
        private void SourceCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            DependencyObject test = Mouse.DirectlyOver as DependencyObject;//get what is under mouse

            if (test != null)
            {
                while (test != null && (test as FrameworkElement) != null && String.IsNullOrEmpty((test as FrameworkElement).Name))//traverse visual tree to get to actual element with name
                    test = VisualTreeHelper.GetParent(test);

                if (test != null && (test as FrameworkElement) != null && !(test as FrameworkElement).Name.Equals("SourceCanvas"))//show adorner for test element (but not for Source Canvas)
                {
                    AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(test as FrameworkElement);

                    foreach (Adorner a in sourceAdorners)
                        myAdornerLayer.Remove(a);

                    //highlight element
                    VisualElementMouseAdorner visualMouseAdorner = new VisualElementMouseAdorner(test as UIElement);
                    if (visualMouseAdorner.Parent == null && myAdornerLayer != null)
                    {
                        myAdornerLayer.Add(visualMouseAdorner);
                        sourceAdorners.Add(visualMouseAdorner);
                    }

                    DependencyObject test2 = test;//start from the element
                    string localAddr = "";
                    string fullAddr = "";

                    do //traverse logical tree to find the address of this element
                    {
                        if (!String.IsNullOrEmpty((test2 as FrameworkElement).Name))
                        {
                            if (String.IsNullOrEmpty(localAddr))
                                localAddr = (test2 as FrameworkElement).Name;
                            else
                                localAddr = (test2 as FrameworkElement).Name + "/" + localAddr;
                        }
                        test2 = LogicalTreeHelper.GetParent(test2);

                    } while (test2 != null && !(test2 is VisualElement) && !((test2 as FrameworkElement).Name.Equals("SourceCanvas")));

                    if (test2 is VisualElement)
                    {
                        string topPortionOfAddress = "";
                        AbstractTreeLatticeNode test2AbstractNode = sourceASTL.Root.findInChildrenByName((test2 as VisualElement).Data.Name);
                        if (test2AbstractNode != null && test2AbstractNode.parent != null)
                            topPortionOfAddress = test2AbstractNode.parent.Address;

                        if (!string.IsNullOrEmpty(topPortionOfAddress))
                            fullAddr = topPortionOfAddress + "/" + localAddr;
                        else
                            fullAddr = localAddr;
                    }

                    ReportStatusBar.ShowStatus((test as FrameworkElement).Name + " ===> " + fullAddr, ReportIcon.Info);

                    if (TargetCanvas.Children.Count > 0)
                        highlightSuggestedCorrespondeces(QualifiedNameString.Convert(fullAddr));
                }
            }
        }
Ejemplo n.º 2
0
        public VisualElement()
        {
            //this.Loaded += new RoutedEventHandler(VisualELement_Loaded);

            //add event handler for droping elements on visual element
            this.Drop += new DragEventHandler(VisualElement_Drop);

            this.MouseDown += new MouseButtonEventHandler(VisualElement_MouseDown);

            this.MouseMove += new MouseEventHandler(VisualELement_MouseMove);

            this.MouseRightButtonDown += new MouseButtonEventHandler(VisualElement_RightClick);

            this.MouseEnter += new MouseEventHandler(VisualElement_MouseEnter);

            this.MouseLeave += new MouseEventHandler(VisualElement_MouseLeave);

            this.DragEnter += new DragEventHandler(VisualElement_DragEnter);

            this.DragLeave += new DragEventHandler(VisualElement_DragLeave);

            this.TouchDown += new EventHandler<TouchEventArgs>(VisualElement_TouchDrag);

            //this.MouseDoubleClick += new MouseButtonEventHandler(VisualElement_MouseDoubleClick);//suggestion representation

            elementList = new List<Element>();

            abstractTree = new AbstractLattice();
            //abstractTreeReverse = new AbstractLattice();

            visualMouseAdorner = new VisualElementMouseAdorner(this);
            visualDragAdorner = new VisualElementDragAdorner(this);

            MyItemsHost = new ListBox();

            this.Unloaded += VisualElement_Unloaded;
        }