Ejemplo n.º 1
0
        public void SetContext(DiagramDocument context)
        {
            var existingContext = context as ISelectionContext;

            if (existingContext != null)
            {
                existingContext.SelectionChanged -= Context_SelectionChanged;
            }

            var graphAdapter = new HyperGraphAdapter();

            graphAdapter.HighlightCompatible = true;
            graphAdapter.LargeGridStep       = 160F;
            graphAdapter.SmallGridStep       = 20F;
            graphAdapter.LargeStepGridColor  = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(90)))), ((int)(((byte)(90)))));
            graphAdapter.SmallStepGridColor  = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
            graphAdapter.ShowLabels          = false;
            graphAdapter.Model           = context.Model;
            graphAdapter.Selection       = context.DiagramSelection;
            graphAdapter.Context         = context.UnderlyingDocument;
            graphAdapter.ModelConversion = _modelConversion;
            graphAdapter.NodeFactory     = _nodeFactory;
            graphAdapter.Document        = context.UnderlyingDocument;

            // calling Adapt will unbind previous adapters
            var hoverAdapter = new HoverAdapter();

            hoverAdapter.HoverStarted += (object sender, HoverEventArgs <object, object> args) =>
            {
                if (_hover != null)
                {
                    return;
                }

                var n = args.Object as HyperGraph.Node;
                if (n == null)
                {
                    var i = args.Object as HyperGraph.NodeItem;
                    if (i != null)
                    {
                        n = i.Node;
                    }
                }
                if (n != null)
                {
                    _hover = new HoverLabel(n.Title)
                    {
                        Location = new Point(MousePosition.X - 8, MousePosition.Y + 8)
                    };
                    _hover.ShowWithoutFocus();
                }
            };
            hoverAdapter.HoverStopped += EndHover;
            MouseLeave += EndHover;
            Adapt(
                new IControlAdapter[] {
                graphAdapter,
                new PickingAdapter {
                    Context = context
                },
                new CanvasAdapter(),
                new ViewingAdapter(graphAdapter),
                hoverAdapter
            });
            context.SelectionChanged += Context_SelectionChanged;

            // Our context is actually a collection of 2 separate context objects
            // - What represents the model itself
            // - Another is the "ViewingContext", which is how we're looking at the model
            // Curiously, there seems to be a bit of an overlap between control adapters
            // and the viewing context. For example, ViewingContext, PickingAdapter and ViewingAdapter
            // duplicate some of the same functionality.
            // However, all of these are needed to use the standard ATF commands for framing and aligning
            _contextSet = new AdaptableSet(new object[] { context, new ViewingContext {
                                                              Control = this
                                                          } });
            Context = _contextSet;
        }
Ejemplo n.º 2
0
        public void SetContext(DiagramDocument context)
        {
            var existingContext = context as ISelectionContext;
            if (existingContext != null)
                existingContext.SelectionChanged -= Context_SelectionChanged;

            var graphAdapter = new HyperGraphAdapter();
            graphAdapter.HighlightCompatible = true;
            graphAdapter.LargeGridStep = 160F;
            graphAdapter.SmallGridStep = 20F;
            graphAdapter.LargeStepGridColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(90)))), ((int)(((byte)(90)))));
            graphAdapter.SmallStepGridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
            graphAdapter.ShowLabels = false;
            graphAdapter.Model = context.Model;
            graphAdapter.Selection = context.DiagramSelection; 
            graphAdapter.Context = context.UnderlyingDocument;
            graphAdapter.ModelConversion = _modelConversion;
            graphAdapter.NodeFactory = _nodeFactory;
            graphAdapter.Document = context.UnderlyingDocument;

            // calling Adapt will unbind previous adapters
            var hoverAdapter = new HoverAdapter();
            hoverAdapter.HoverStarted += (object sender, HoverEventArgs<object, object> args) =>
                {
                    if (_hover != null) return;

                    var n = args.Object as HyperGraph.Node;
                    if (n == null)
                    {
                        var i = args.Object as HyperGraph.NodeItem;
                        if (i != null) n = i.Node;
                    }
                    if (n != null)
                    {
                        _hover = new HoverLabel(n.Title)
                        {
                            Location = new Point(MousePosition.X - 8, MousePosition.Y + 8)
                        };
                        _hover.ShowWithoutFocus();
                    }
                };
            hoverAdapter.HoverStopped += EndHover;
            MouseLeave += EndHover;
            Adapt(
                new IControlAdapter[] {
                    graphAdapter,
                    new PickingAdapter { Context = context },
                    new CanvasAdapter(),
                    new ViewingAdapter(graphAdapter),
                    hoverAdapter
                });
            context.SelectionChanged += Context_SelectionChanged;

            // Our context is actually a collection of 2 separate context objects
            // - What represents the model itself
            // - Another is the "ViewingContext", which is how we're looking at the model
            // Curiously, there seems to be a bit of an overlap between control adapters
            // and the viewing context. For example, ViewingContext, PickingAdapter and ViewingAdapter
            // duplicate some of the same functionality.
            // However, all of these are needed to use the standard ATF commands for framing and aligning
            _contextSet = new AdaptableSet(new object[]{ context, new ViewingContext { Control = this } });
            Context = _contextSet;
        }