Beispiel #1
0
 public static void Set(this MutableRectangle mutable, IRectangle r)
 {
     mutable.X      = r.X;
     mutable.Y      = r.Y;
     mutable.Width  = r.Width;
     mutable.Height = r.Height;
 }
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            IGraph graph = graphControl.Graph;

            // Create a default editor input mode
            GraphEditorInputMode graphEditorInputMode = new GraphEditorInputMode();

            // Just for user convenience: disable node and edge creation,
            graphEditorInputMode.AllowCreateEdge = false;
            graphEditorInputMode.AllowCreateNode = false;
            // disable deleting items
            graphEditorInputMode.DeletableItems = GraphItemTypes.None;
            // disable node moving
            graphEditorInputMode.MovableItems = GraphItemTypes.None;
            // enable the undo feature
            graph.SetUndoEngineEnabled(true);

            // Finally, set the input mode to the graph control.
            graphControl.InputMode = graphEditorInputMode;

            // Create the rectangle that limits the movement of some nodes
            // and add it to the GraphControl.
            var boundaryRectangle = new MutableRectangle(210, 350, 30, 30);

            graphControl.RootGroup.AddChild(boundaryRectangle, new LimitingRectangleDescriptor());

            RegisterSizeConstraintProvider(boundaryRectangle);

            CreateSampleGraph(graph);

            // reset the Undo queue so the initial graph creation cannot be undone
            graph.GetUndoEngine().Clear();
        }
Beispiel #3
0
 public void ReshapeFinished(IInputModeContext context, RectD originalBounds, RectD newBounds)
 {
     shadowObject.Remove();
     simulationRectangle = null;
     originalHandler.HandleReshape(context, this.originalBounds, newBounds);
     originalHandler.ReshapeFinished(context, this.originalBounds, newBounds);
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            #region Level 0

            string name = " 123456 ";
            name.Trim();
            Console.WriteLine(name.Length);

            name = name.Trim(); // immutable always returns a new string
            Console.WriteLine(name.Length);

            #endregion

            #region Basic

            var r1 = new MutableRectangle();
            r1.Height = 10;
            r1.Length = 5;
            r1.Grow(10, 5);

            Console.WriteLine(r1.ToString());

            #endregion

            #region Patterns

            #region 1. Mutable
            var m = new Mutable();
            m.Value = 10;
            m.Value = 20;
            #endregion

            #region 2. ShallowMutable
            StringBuilder builder = new StringBuilder();
            builder.Append("foo");
            var sm = new ShallowMutable(10, builder);
            sm.Builder.Append("bar");
            Console.WriteLine(sm.Builder);
            #endregion

            #region 3. Popsicle
            var p = new Popsicle();
            p.Value = 10;
            p.Freeze();
            //p.Value = 20; //Bang!
            #endregion

            #region 4. ObservableImmutable

            #endregion

            #endregion

            Console.ReadLine();
        }
Beispiel #5
0
            public void Prove_mutability()
            {
                var rectangle       = new MutableRectangle(1, 2);
                var rectangleBackup = rectangle;

                rectangle.Grow(10);

                Assert.Equal(11, rectangle.Width);
                Assert.NotEqual(1, rectangleBackup.Width);
                Assert.Same(rectangle, rectangleBackup);
            }
        public IVisual CreateVisual(IRenderContext context)
        {
            rectangle = new MutableRectangle(RectD.FromCenter(Center, new SizeD(PageWidth + Margin, PageHeight + Margin)));
            var rectVisual = new RectangleVisual(rectangle)
            {
                Pen = new Pen(Color.Black, 1)
                {
                    DashStyle = DashStyle.Dash
                }
            };

            return(rectVisual);
        }
        private void InitializeInputModes()
        {
            // Create a GraphEditorInputMode instance
            var editMode = new GraphEditorInputMode();

            // and install the edit mode into the canvas.
            graphControl.InputMode = editMode;

            // create the model for the export rectangle
            exportRect = new MutableRectangle(0, 0, 100, 100);
            // visualize it
            new RectangleIndicatorInstaller(exportRect, RectangleIndicatorInstaller.SelectionTemplateKey)
            .AddCanvasObject(graphControl.CanvasContext, graphControl.BackgroundGroup, exportRect);

            AddExportRectInputModes(editMode);
        }
Beispiel #8
0
        /// <summary>
        /// Registers the <see cref="GraphEditorInputMode"/> as the <see cref="CanvasControl.InputMode"/>
        /// and initializes the rectangular area so that it is drawn and can be moved and resized.
        /// </summary>
        private void InitializeInputModes()
        {
            // create a GraphEditorInputMode instance
            var editMode = new GraphEditorInputMode();

            // and install the edit mode into the canvas.
            GraphControl.InputMode = editMode;

            // create the model for the rectangular area
            clearRect = new MutableRectangle(0, 0, 100, 100);

            // visualize it
            new RectangleIndicatorInstaller(clearRect, ClearRectTemplateKey)
            .AddCanvasObject(GraphControl.CanvasContext, GraphControl.HighlightGroup, clearRect);

            AddClearRectInputModes(editMode);
        }
Beispiel #9
0
            public void InitializeReshape(IInputModeContext context)
            {
                simulationRectangle = new MutableRectangle(originalHandler.Bounds);
                var node = new SimpleNode {
                    Layout = simulationRectangle,
                    Style  =
                        new ShapeNodeStyle {
                        Shape = ShapeNodeShape.RoundRectangle,
                        Brush = Brushes.Transparent,
                        Pen   = new Pen(Brushes.Gray, 2)
                    }
                };

                shadowObject = context.CanvasControl.RootGroup.AddChild(node, GraphModelManager.DefaultNodeDescriptor).ToFront();

                originalHandler.InitializeReshape(context);
                originalBounds = originalHandler.Bounds.ToRectD();
            }
        /// <summary>
        /// Shows how to register the custom <see cref="IPositionHandler"/> implementations with the <see cref="IGraph"/>'s
        /// <see cref="ILookupDecorator"/> mechanism.
        /// </summary>
        private void RegisterPositionHandler(MutableRectangle boundaryRectangle)
        {
            var nodeDecorator = graphControl.Graph.GetDecorator().NodeDecorator;

            nodeDecorator.PositionHandlerDecorator.SetImplementationWrapper(
                (node, delegateHandler) => {
                // Obtain the tag from the node
                object nodeTag = node.Tag;

                // Check if it is a known tag and choose the respective implementation.
                // Fallback to the default behavior otherwise.
                if (!(nodeTag is Color))
                {
                    return(delegateHandler);
                }
                else if (Color.Orange.Equals(nodeTag))
                {
                    // This implementation delegates certain behavior to the default implementation
                    return(new OrangePositionHandler(boundaryRectangle, node, delegateHandler));
                }
                else if (Color.Firebrick.Equals(nodeTag))
                {
                    // A simple implementation that prohibits moving
                    return(new RedPositionHandler());
                }
                else if (Color.RoyalBlue.Equals(nodeTag))
                {
                    // Implementation that uses two levels of delegation to create a combined behavior
                    return(new OrangePositionHandler(boundaryRectangle, node, new GreenPositionHandler(delegateHandler)));
                }
                else if (Color.Green.Equals(nodeTag))
                {
                    // Another implementation that delegates certain behavior to the default implementation
                    return(new GreenPositionHandler(delegateHandler));
                }
                else
                {
                    return(delegateHandler);
                }
            });
        }
        private void FormLoaded(object sender, EventArgs e)
        {
            IGraph graph = graphControl.Graph;

            // Create a default editor input mode
            GraphEditorInputMode graphEditorInputMode = new GraphEditorInputMode();

            // Just for user convenience: disable node and edge creation,
            graphEditorInputMode.AllowCreateEdge = false;
            graphEditorInputMode.AllowCreateNode = false;
            // disable deleting items
            graphEditorInputMode.DeletableItems = GraphItemTypes.None;
            // don't show resize handles,
            graphEditorInputMode.ShowHandleItems = GraphItemTypes.None;
            // disable clipboard,
            graphEditorInputMode.AllowClipboardOperations = false;
            // and enable the undo feature.
            graph.SetUndoEngineEnabled(true);

            // Finally, set the input mode to the graph control.
            graphControl.InputMode = graphEditorInputMode;

            // Create the rectangle that limits the movement of some nodes
            // and add it to the GraphControl.
            var boundaryRectangle = new MutableRectangle(20, 20, 480, 400);
            var rectangle         = new RectangleVisual(boundaryRectangle)
            {
                Pen = Pens.Black
            };

            graphControl.RootGroup.AddChild(rectangle, CanvasObjectDescriptors.Visual);

            RegisterPositionHandler(boundaryRectangle);

            CreateSampleGraph(graph);
            // reset the Undo queue so the initial graph creation cannot be undone
            graph.GetUndoEngine().Clear();
        }
Beispiel #12
0
        /// <summary>
        /// Registers a callback function as decorator that provides a custom
        /// <see cref="INodeSizeConstraintProvider"/> for each node.
        /// </summary>
        /// <remarks>
        /// This callback function is called whenever a node in the graph is queried
        /// for its <see cref="INodeSizeConstraintProvider"/>. In this case, the 'node' parameter will be set
        /// to that node.
        /// </remarks>
        public void RegisterSizeConstraintProvider(MutableRectangle boundaryRectangle)
        {
            // One shared instance that will be used by all blue nodes
            var blueSizeConstraintProvider = new BlueSizeConstraintProvider();

            var nodeDecorator = graphControl.Graph.GetDecorator().NodeDecorator;

            nodeDecorator.SizeConstraintProviderDecorator.SetFactory(
                node => {
                // Obtain the tag from the node
                object nodeTag = node.Tag;

                // Check if it is a known tag and choose the respective implementation.
                // Fallback to the default behavior otherwise.
                if (!(nodeTag is Color))
                {
                    return(null);
                }
                else if (Color.RoyalBlue.Equals(nodeTag))
                {
                    return(blueSizeConstraintProvider);
                }
                else if (Color.Green.Equals(nodeTag))
                {
                    return(new GreenSizeConstraintProvider());
                }
                else if (Color.Orange.Equals(nodeTag))
                {
                    return(new NodeSizeConstraintProvider(
                               new SizeD(50, 50), new SizeD(300, 300), boundaryRectangle.ToRectD()));
                }
                else
                {
                    return(null);
                }
            });
        }
 public IVisualCreator GetVisualCreator(object forUserObject)
 {
     this.rect = (MutableRectangle)forUserObject;
     return(this);
 }
 public OrangePositionHandler(MutableRectangle boundaryRectangle, INode node, IPositionHandler wrappedHandler)
     : base(wrappedHandler)
 {
     this.boundaryRectangle = boundaryRectangle;
     this.node = node;
 }
 /// <summary>
 /// Initializes the helper.
 /// </summary>
 /// <param name="graphControl">The control that displays the graph.</param>
 /// <param name="clearRect">The rectangle the is dragged.</param>
 /// <param name="options">Options to control the layout behavior.</param>
 public ClearAreaLayoutHelper(GraphControl graphControl, MutableRectangle clearRect, InteractiveClearAreaForm.LayoutOptions options)
 {
     this.graphControl = graphControl;
     this.clearRect    = clearRect;
     this.options      = options;
 }
Beispiel #16
0
 public void CancelReshape(IInputModeContext context, RectD originalBounds)
 {
     shadowObject.Remove();
     simulationRectangle = null;
     originalHandler.CancelReshape(context, this.originalBounds);
 }