Exemplo n.º 1
0
        /// <summary>
        ///     Handles a click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void HandleClick(object sender, EventArgs e)
        {
            MouseEventArgs mouseEventArgs = e as MouseEventArgs;

            if (mouseEventArgs != null)
            {
                GraphicElement element = ElementForLocation(mouseEventArgs.Location, null);
                if (element != null)
                {
                    Selected = element;
                    Refresh();
                    element.HandleClick(sender, mouseEventArgs);
                }

                if (mouseEventArgs.Button == MouseButtons.Right)
                {
                    // Build the contextual menu according to the enclosing panel tree view
                    ContextMenu menu = BuildContextMenu(element);
                    if (menu != null)
                    {
                        if (element != null)
                        {
                            Selected = element;
                        }

                        Point location = new Point(mouseEventArgs.Location.X - HorizontalScroll.Value,
                                                   mouseEventArgs.Y - VerticalScroll.Value);
                        menu.Show(this, location);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Selects the graphical element for the model provided
        /// </summary>
        /// <param name="model"></param>
        public virtual void SelectModel(object model)
        {
            GraphicElement element = GetControl(model);

            if (element != null)
            {
                Selected = element;
                Refresh();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Provides the element for the given location
        /// </summary>
        /// <param name="location"></param>
        /// <param name="excludedElement">This element should not be considered during search</param>
        /// <returns></returns>
        protected GraphicElement ElementForLocation(Point location, GraphicElement excludedElement)
        {
            GraphicElement retVal = ArrowForLocation(location, excludedElement);

            if (retVal == null)
            {
                retVal = BoxForLocation(location, excludedElement);
            }

            return(retVal);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the graphical element which corresponds to the model provided
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public GraphicElement GetControl(object model)
        {
            GraphicElement retVal = GetBoxControl(model as TBoxModel);

            if (retVal == null)
            {
                retVal = GetArrowControl(model as TArrowModel);
            }

            return(retVal);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Handles a mouse up event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void HandleMouseUp(object sender, MouseEventArgs mouseEventArgs)
        {
            GraphicElement element = ElementForLocation(mouseEventArgs.Location, _movingBox);

            if (element != null)
            {
                element.HandleMouseUp(sender, mouseEventArgs);
            }

            if (_changingArrow != null)
            {
                _changingArrow      = null;
                _chaningArrowAction = ChangeAction.None;
                RefreshControl();
            }

            if (_movingBox != null)
            {
                if (_movingBoxHasMoved)
                {
                    if (element != null)
                    {
                        BaseTreeNode targetNode = CorrespondingNode(element.Model as IModelElement);
                        BaseTreeNode sourceNode = CorrespondingNode(_movingBox.Model as IModelElement);

                        if (targetNode != null && sourceNode != null && sourceNode != targetNode)
                        {
                            targetNode.AcceptDrop(sourceNode);
                            _movingBox.Location = new Point(0, 0);

                            if (Settings.Default.AllowRefactor)
                            {
                                RefactorAndRelocateOperation refactorAndRelocate =
                                    new RefactorAndRelocateOperation(sourceNode.Model as ModelElement);
                                refactorAndRelocate.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Refactoring", false);
                            }
                        }
                    }

                    // Register the fact that the element has moved
                    // because
                    if (_movingBox.TypedModel.X != _positionBeforeMove.X ||
                        _movingBox.TypedModel.Y != _positionBeforeMove.Y)
                    {
                        EfsSystem.Instance.Context.HandleChangeEvent(_movingBox.Model as BaseModelElement,
                                                                     Context.ChangeKind.ModelChange);
                    }
                }

                _movingBox         = null;
                _movingBoxHasMoved = false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Handles a double click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void HandleDoubleClick(object sender, EventArgs e)
        {
            MouseEventArgs mouseEventArgs = e as MouseEventArgs;

            if (mouseEventArgs != null)
            {
                GraphicElement element = ElementForLocation(mouseEventArgs.Location, null);
                if (element != null)
                {
                    element.HandleDoubleClick(sender, mouseEventArgs);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Provides the IModelElement element from the graphic element
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected virtual IModelElement GetModelFromGraphicElement(GraphicElement element)
        {
            IModelElement model = null;

            if (element != null)
            {
                model = element.Model as IModelElement;
            }
            if (model == null)
            {
                model = Model as IModelElement;
            }
            return(model);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Builds teh context menu associated to either the selected element or the panel
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected virtual ContextMenu BuildContextMenu(GraphicElement element)
        {
            ContextMenu retVal = null;

            IModelElement model = GetModelFromGraphicElement(element);
            BaseTreeNode  node  = CorrespondingNode(model);

            if (node == null)
            {
                node = CorrespondingNode(Model as IModelElement);
            }
            if (node != null)
            {
                retVal = node.ContextMenu;
            }

            return(retVal);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Handles a mouse down event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        public void HandleMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            GraphicElement element = ElementForLocation(mouseEventArgs.Location, null);

            if (element != null)
            {
                element.HandleMouseDown(sender, mouseEventArgs);
            }

            if (mouseEventArgs.Button == MouseButtons.Left)
            {
                Point clickPoint = new Point(mouseEventArgs.X, mouseEventArgs.Y);
                foreach (ArrowControl <TEnclosing, TBoxModel, TArrowModel> arrow in _arrows.Values)
                {
                    if (Around(arrow.StartLocation, clickPoint))
                    {
                        _changingArrow      = arrow;
                        _chaningArrowAction = ChangeAction.InitialBox;
                        Selected            = arrow;
                        break;
                    }
                    if (Around(arrow.TargetLocation, clickPoint))
                    {
                        _changingArrow      = arrow;
                        _chaningArrowAction = ChangeAction.TargetBox;
                        Selected            = arrow;
                        break;
                    }
                }

                if (_changingArrow == null)
                {
                    BoxControl <TEnclosing, TBoxModel, TArrowModel> box = BoxForLocation(clickPoint, null);
                    if (box != null)
                    {
                        _movingBox          = box;
                        _movingBoxHasMoved  = false;
                        _moveStartLocation  = mouseEventArgs.Location;
                        _positionBeforeMove = box.Location;
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Handles the move event, which, in case of an arrow is selected to be modified,
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void HandleMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            GraphicElement element = ElementForLocation(mouseEventArgs.Location, null);

            if (element != null)
            {
                element.HandleMouseMove(sender, mouseEventArgs);
            }

            if (_changingArrow != null && _chaningArrowAction != ChangeAction.None)
            {
                BoxControl <TEnclosing, TBoxModel, TArrowModel> box = BoxForLocation(mouseEventArgs.Location, null);
                if (box != null)
                {
                    switch (_chaningArrowAction)
                    {
                    case ChangeAction.InitialBox:
                        if (_changingArrow.TypedModel.Source != box.Model)
                        {
                            _changingArrow.SetInitialBox(box.TypedModel);
                        }
                        break;

                    case ChangeAction.TargetBox:
                        if (_changingArrow.TypedModel.Target != box.Model)
                        {
                            if (_changingArrow.TypedModel.Source != null)
                            {
                                _changingArrow.SetTargetBox(box.TypedModel);
                            }
                        }
                        break;
                    }
                }
            }

            if (_movingBox != null)
            {
                Point mouseMoveLocation = mouseEventArgs.Location;

                int deltaX = mouseMoveLocation.X - _moveStartLocation.X;
                int deltaY = mouseMoveLocation.Y - _moveStartLocation.Y;

                if (Math.Abs(deltaX) > 5 || Math.Abs(deltaY) > 5)
                {
                    IModelElement model = _movingBox.TypedModel;
                    if (model != null && !_movingBoxHasMoved)
                    {
                        Context.SelectionCriteria criteria = GuiUtils.SelectionCriteriaBasedOnMouseEvent(mouseEventArgs);
                        EfsSystem.Instance.Context.SelectElement(model, this, criteria);
                        _movingBoxHasMoved = true;
                    }

                    Util.DontNotify(() =>
                    {
                        int newX = _positionBeforeMove.X + deltaX;
                        int newY = _positionBeforeMove.Y + deltaY;
                        SetBoxPosition(_movingBox, newX, newY);
                        UpdatePositions();
                    });
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Provides the arrow at a given location
        /// </summary>
        /// <param name="location"></param>
        /// <param name="excludedElement">This element should not be considered during search</param>
        /// <returns></returns>
        protected ArrowControl <TEnclosing, TBoxModel, TArrowModel> ArrowForLocation(Point location, GraphicElement excludedElement)
        {
            ArrowControl <TEnclosing, TBoxModel, TArrowModel> retVal = null;

            foreach (ArrowControl <TEnclosing, TBoxModel, TArrowModel> arrow in _arrows.Values)
            {
                if ((location.X > arrow.Location.X && location.X < arrow.Location.X + arrow.Width) &&
                    (location.Y > arrow.Location.Y && location.Y < arrow.Location.Y + arrow.Height))
                {
                    if (arrow != excludedElement)
                    {
                        retVal = arrow;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 12
0
        /// <summary>
        ///     Provides the box at a given location
        /// </summary>
        /// <param name="location"></param>
        /// <param name="excludedElement">This element should not be considered during search</param>
        /// <returns></returns>
        protected BoxControl <TEnclosing, TBoxModel, TArrowModel> BoxForLocation(Point location, GraphicElement excludedElement)
        {
            BoxControl <TEnclosing, TBoxModel, TArrowModel> retVal = null;

            foreach (BoxControl <TEnclosing, TBoxModel, TArrowModel> box in _boxes.Values)
            {
                if ((location.X > box.Location.X && location.X < box.Location.X + box.Width) &&
                    (location.Y > box.Location.Y && location.Y < box.Location.Y + box.Height))
                {
                    if (box != excludedElement)
                    {
                        retVal = box;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 13
0
        /// <summary>
        ///     Indicates whether the control is selected
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public bool IsSelected(GraphicElement element)
        {
            bool retVal = element == Selected;

            return(retVal);
        }