public void SetNewInstance(TChild newInstance)
 {
     childContext.SetNewInstance(newInstance);
 }
 public void SetNewInstance(T1 newInstance)
 {
     context.SetNewInstance(newInstance);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for edge styles in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetStylePropertyMapBuilder"/> to retrieve the builder for the style.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildStyleProperties(IPropertyBuildContext <INode> context)
        {
            INode node = context.CurrentInstance;

            if (node != null)
            {
                INodeStyle style = node.Style;
                if (style != null)
                {
                    GetInstanceDelegate <INodeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                    SetInstanceDelegate <INodeStyle> styleSetter = delegate(INodeStyle newValue) {
                        IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                        INode  currentNode = context.CurrentInstance;
                        if (graph != null)
                        {
                            graph.SetStyle(currentNode, newValue);
                            var foldingView = graph.Lookup(typeof(IFoldingView)) as IFoldingView;
                            if (foldingView != null)
                            {
                                var masterNode = foldingView.GetMasterItem(currentNode);
                                if (foldingView.IsInFoldingState(currentNode))
                                {
                                    // update non-dummy node
                                    foldingView.Manager.MasterGraph.SetStyle(masterNode, newValue);
                                }
                                else if (foldingView.IsExpanded(currentNode))
                                {
                                    // update dummy node
                                    if (foldingView.Manager.HasFolderNodeState(masterNode))
                                    {
                                        foldingView.Manager.GetFolderNodeState(masterNode).Style = newValue;
                                    }
                                }
                            }
                        }
                    };
                    IPropertyBuildContext <INodeStyle> styleContext =
                        context.CreateChildContext(StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy);
                    styleContext.AddEntry("Shadow",
                                          new DelegateGetter <bool>(
                                              delegate { return(context.CurrentInstance.Style is ShadowNodeStyleDecorator); },
                                              delegate {
                        //show item only for !PanelNodeStyle...
                        return(!(context.CurrentInstance.Style is PanelNodeStyle));
                    }),
                                          new DelegateSetter <bool>(delegate(bool isShadow) {
                        INodeStyle currentStyle = context.CurrentInstance.Style;
                        if (isShadow && !(currentStyle is ShadowNodeStyleDecorator))
                        {
                            //don't decorate if already decorated...
                            INodeStyle newStyle =
                                new ShadowNodeStyleDecorator(currentStyle);
                            styleContext.SetNewInstance(newStyle);
                        }
                        else
                        {
                            if (!isShadow && currentStyle is ShadowNodeStyleDecorator)
                            {
                                //remove decoration
                                styleContext.SetNewInstance(
                                    ((ShadowNodeStyleDecorator)currentStyle).Wrapped);
                            }
                        }
                    },
                                                                    delegate { return(!(context.CurrentInstance.Style is PanelNodeStyle)); }
                                                                    ));

                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <INodeStyle> innerStyleGetter = delegate { return(styleContext.CurrentInstance); };
                        SetInstanceDelegate <INodeStyle> innerStyleSetter = delegate(INodeStyle newValue) { styleContext.SetNewInstance(newValue); };
                        propertyBuilder.BuildPropertyMap(styleContext.CreateChildContext(string.Empty, innerStyleGetter, innerStyleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <Brush> context)
        {
            IValueGetter fillTypeGetter = new DelegateGetter <object>(
                delegate() {
                Brush brush = context.CurrentInstance;
                if (brush == null)
                {
                    return(null);
                }
                if (brush is SolidBrush)
                {
                    return(BrushTypes.SolidBrush);
                }
                if (brush is HatchBrush)
                {
                    return(BrushTypes.HatchBrush);
                }
                if (brush is LinearGradientBrush)
                {
                    return(BrushTypes.LinearGradientBrush);
                }
                if (brush is TextureBrush)
                {
                    return(BrushTypes.TextureBrush);
                }
                return(BrushTypes.Custom);
            });

            IValueSetter fillTypeSetter = new DelegateSetter <object>(
                delegate(object value) {
                if (value != null)
                {
                    if (!(value is BrushTypes))
                    {
                        return;
                    }
                    BrushTypes type = (BrushTypes)value;
                    Brush brush     = context.CurrentInstance;
                    if (type == BrushTypes.Custom)
                    {
                        context.SetNewInstance(brush);
                        return;
                    }
                    //todo: this code should be replaced by a composite brush editor some day
                    Color fg = Color.Black;
                    Color bg = Color.Empty;

                    if (brush != null)
                    {
                        if (brush is SolidBrush)
                        {
                            fg = ((SolidBrush)brush).Color;
                        }
                        if (brush is HatchBrush)
                        {
                            HatchBrush hb = (HatchBrush)brush;
                            fg            = hb.ForegroundColor;
                            bg            = hb.BackgroundColor;
                        }
                        if (brush is LinearGradientBrush)
                        {
                            LinearGradientBrush lb = (LinearGradientBrush)brush;
                            Color[] colors         = lb.LinearColors;
                            if (colors != null)
                            {
                                fg = colors[0];
                                bg = colors[1];
                            }
                        }
                    }
                    switch (type)
                    {
                    case BrushTypes.SolidBrush:
                        if (!(brush is SolidBrush))
                        {
                            context.SetNewInstance(new SolidBrush(fg));
                            return;
                        }
                        break;

                    case BrushTypes.HatchBrush:
                        if (!(brush is HatchBrush))
                        {
                            context.SetNewInstance(new HatchBrush(System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal, fg, bg));
                            return;
                        }
                        break;

                    case BrushTypes.TextureBrush:
                        if (!(brush is TextureBrush))
                        {
                            Image img = new Bitmap(1, 1);
                            context.SetNewInstance(new TextureBrush(img));
                            return;
                        }
                        break;

                    case BrushTypes.LinearGradientBrush:
                        if (!(brush is LinearGradientBrush))
                        {
                            //Accomodate for rounding errors
                            LinearGradientBrush lgb = new LinearGradientBrush(new PointF(), new PointF(1.01f, 0), fg, bg);
                            context.SetNewInstance(lgb);
                            return;
                        }
                        break;
                    }
                }
                else
                {
                    context.SetNewInstance(null);
                }
            });

            context.AddEntry(FillType, fillTypeGetter, fillTypeSetter, null);


            DelegateGetter <Color> foregroundColorGetter = new DelegateGetter <Color>(
                delegate() {
                Brush brush = context.CurrentInstance;
                if (brush == null)
                {
                    return(Color.Empty);
                }
                if (brush is SolidBrush)
                {
                    return(((SolidBrush)brush).Color);
                }
                if (brush is HatchBrush)
                {
                    return
                    (((HatchBrush)brush).ForegroundColor);
                }
                if (brush is LinearGradientBrush)
                {
                    Color[] colors =
                        ((LinearGradientBrush)brush).
                        LinearColors;
                    return
                    (colors == null
                ? Color.Empty
                : colors[0]);
                }
                return(Color.Empty);
            });

            DelegateSetter <Color> foregroundColorSetter =
                new DelegateSetter <Color>(
                    delegate(Color value) {
                Brush brush = context.CurrentInstance;
                if (brush is SolidBrush)
                {
                    SolidBrush newBrush = new SolidBrush(value);
                    context.SetNewInstance(newBrush);
                    return;
                }

                if (brush is HatchBrush)
                {
                    HatchBrush hb       = (HatchBrush)brush;
                    HatchBrush newBrush = new HatchBrush(hb.HatchStyle, value, hb.BackgroundColor);
                    context.SetNewInstance(newBrush);
                    return;
                }

                if (brush is LinearGradientBrush)
                {
                    LinearGradientBrush lb       = (LinearGradientBrush)brush;
                    Color[] colors               = lb.LinearColors;
                    LinearGradientBrush newBrush = new LinearGradientBrush(lb.Rectangle, value, colors[1], 0f);
                    newBrush.WrapMode            = lb.WrapMode;
                    newBrush.Transform           = lb.Transform;
                    //(LinearGradientBrush)lb.Clone();

                    //            newBrush.LinearColors = new Color[] { colors[0], value };
                    context.SetNewInstance(newBrush);
                    return;
                }

//          if (brush is LinearGradientBrush) {
//            LinearGradientBrush lb = (LinearGradientBrush)brush;
//            Color[] colors = lb.LinearColors;
//            LinearGradientBrush newBrush = (LinearGradientBrush)lb.Clone();
//            newBrush.LinearColors = new Color[] { value, colors[1] };
//
//            context.SetNewInstance(newBrush);
//            return;
//          }
            }, delegate() {
                Brush brush = context.CurrentInstance;
                if (brush is SolidBrush || brush is HatchBrush)
                {
                    return(true);
                }

                if (brush is LinearGradientBrush)
                {
                    LinearGradientBrush lb = (LinearGradientBrush)brush;
                    Color[] colors         = lb.LinearColors;
                    return(colors != null);
                }
                return(false);
            });

            context.AddEntry(ForegroundColor,
                             foregroundColorGetter, foregroundColorSetter, new ArgbEqualityComparer());

            DelegateGetter <Color> backgroundColorGetter = new DelegateGetter <Color>(
                delegate() {
                Brush brush = context.CurrentInstance;
                if (brush == null)
                {
                    return(Color.Empty);
                }
                if (brush is HatchBrush)
                {
                    return
                    (((HatchBrush)brush).BackgroundColor);
                }
                if (brush is LinearGradientBrush)
                {
                    Color[] colors =
                        ((LinearGradientBrush)brush).
                        LinearColors;
                    return
                    (colors == null
                ? Color.Empty
                : colors[1]);
                }
                return(Color.Empty);
            });

            DelegateSetter <Color> backgroundColorSetter =
                new DelegateSetter <Color>(
                    delegate(Color value) {
                Brush brush = context.CurrentInstance;
                if (brush is HatchBrush)
                {
                    HatchBrush hb       = (HatchBrush)brush;
                    HatchBrush newBrush = new HatchBrush(hb.HatchStyle, hb.ForegroundColor, value);
                    context.SetNewInstance(newBrush);
                    return;
                }

                if (brush is LinearGradientBrush)
                {
                    LinearGradientBrush lb       = (LinearGradientBrush)brush;
                    Color[] colors               = lb.LinearColors;
                    LinearGradientBrush newBrush = new LinearGradientBrush(lb.Rectangle, colors[0], value, 0f);
                    newBrush.Transform           = lb.Transform;
                    newBrush.WrapMode            = lb.WrapMode;
                    //(LinearGradientBrush)lb.Clone();

//            newBrush.LinearColors = new Color[] { colors[0], value };
                    context.SetNewInstance(newBrush);
                    return;
                }
            }, delegate() {
                Brush brush = context.CurrentInstance;
                if (brush is SolidBrush || brush is HatchBrush)
                {
                    return(true);
                }

                if (brush is LinearGradientBrush)
                {
                    LinearGradientBrush lb = (LinearGradientBrush)brush;
                    Color[] colors         = lb.LinearColors;
                    return(colors != null);
                }
                return(false);
            });

            context.AddEntry(BackgroundColor, backgroundColorGetter, backgroundColorSetter, new ArgbEqualityComparer());

            context.AddEntry(HatchStyle,
                             new DelegateGetter <object>(delegate() {
                Brush brush   = context.CurrentInstance;
                HatchBrush hb = brush as HatchBrush;
                if (hb != null)
                {
                    return(hb.HatchStyle);
                }
                else
                {
                    return(OptionItem.VALUE_UNDEFINED);
                }
            }),
                             new DelegateSetter <HatchStyle>(
                                 delegate(HatchStyle value) {
                HatchBrush hb = context.CurrentInstance as HatchBrush;
                if (hb != null)
                {
                    HatchBrush newBrush = new HatchBrush(value, hb.ForegroundColor, hb.BackgroundColor);
                    context.SetNewInstance(newBrush);
                }
            }));

            context.AddEntry(Rotation,
                             new DelegateGetter <float>(delegate() {
                LinearGradientBrush lb = context.CurrentInstance as LinearGradientBrush;
                if (lb != null)
                {
                    return((float)CalculateAngle(lb.Transform));
                }
                else
                {
                    return(0);
                }
            }),
                             new DelegateSetter <float>(
                                 delegate(float value) {
                LinearGradientBrush lb = context.CurrentInstance as LinearGradientBrush;
                if (lb != null)
                {
                    context.SetNewInstance(RotateBrush(lb, value));
                }
            }));
            context.AddEntry(Image,
                             new DelegateGetter <Image>(delegate() {
                TextureBrush textureBrush = context.CurrentInstance as TextureBrush;
                if (textureBrush != null)
                {
                    return(textureBrush.Image);
                }
                else
                {
                    return(null);
                }
            }),
                             new DelegateSetter <Image>(
                                 delegate(Image value) {
                TextureBrush newBrush = new TextureBrush(value);
                context.SetNewInstance(newBrush);
            }));

            #endregion
        }
Exemplo n.º 5
0
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <Pen> context)
        {
            Brush b = context.CurrentInstance == null ? null : context.CurrentInstance.Brush;
            IPropertyMapBuilder brushBuilder;

            if (b == null)
            {
                brushBuilder = context.GetPropertyMapBuilder(typeof(Brush), b);
            }
            else
            {
                brushBuilder = context.GetPropertyMapBuilder(b);
            }

            if (brushBuilder != null)
            {
                brushBuilder.BuildPropertyMap(context.CreateChildContext <Brush>("",
                                                                                 delegate() {
                    Pen p = context.CurrentInstance;
                    return(p == null ? null:context.CurrentInstance.Brush);
                },
                                                                                 delegate(Brush newInstance) {
                    Pen p = context.CurrentInstance;
                    if (newInstance == null)
                    {
                        context.SetNewInstance(null);
                        return;
                    }
                    if (p == null)
                    {
                        context.SetNewInstance(new Pen(newInstance));
                    }
                    else
                    {
                        Pen clone   = (Pen)p.Clone();
                        clone.Brush = newInstance;
                        context.SetNewInstance(clone);
                    }
                }, AssignmentPolicy.CreateNewInstance));
            }

            context.AddEntry <float>(Width,
                                     delegate {
                Pen pen = context.CurrentInstance;
                return(pen == null ? 0 : pen.Width);
            },
                                     delegate(float value) {
                Pen pen   = context.CurrentInstance;
                Pen clone = pen.Clone() as Pen;
                if (clone != null)
                {
                    clone.Width = value;
                    context.SetNewInstance(clone);
                }
            });
            context.AddEntry(DashStyle,
                             new DelegateGetter <object>(
                                 delegate() {
                Pen pen = context.CurrentInstance;
                return(pen == null ? OptionItem.VALUE_UNDEFINED : pen.DashStyle);
            }),
                             new DelegateSetter <DashStyle>(delegate(DashStyle value) {
                Pen pen   = context.CurrentInstance;
                Pen clone = pen.Clone() as Pen;
                if (clone != null)
                {
                    clone.DashStyle = value;
                    context.SetNewInstance(clone);
                }
            }));
        }
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for edge styles in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetStylePropertyMapBuilder"/> to retrieve the builder for the style.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildStyleProperties(IPropertyBuildContext <INode> context)
        {
            INode node = context.CurrentInstance;

            if (node != null)
            {
                INodeStyle style = node.Style;
                if (style != null)
                {
                    GetInstanceDelegate <INodeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                    SetInstanceDelegate <INodeStyle> styleSetter = delegate(INodeStyle newValue) {
                        IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                        INode  currentNode = context.CurrentInstance;
                        if (graph != null)
                        {
                            graph.SetStyle(currentNode, newValue);
                            var foldingView = graph.Lookup(typeof(IFoldingView)) as IFoldingView;
                            if (foldingView != null)
                            {
                                var masterNode = foldingView.GetMasterItem(currentNode);
                                if (foldingView.IsInFoldingState(currentNode))
                                {
                                    // update non-dummy node
                                    foldingView.Manager.MasterGraph.SetStyle(masterNode, newValue);
                                }
                                else if (foldingView.IsExpanded(currentNode))
                                {
                                    // update dummy node
                                    if (foldingView.Manager.HasFolderNodeState(masterNode))
                                    {
                                        foldingView.Manager.GetFolderNodeState(masterNode).Style = newValue;
                                    }
                                }
                            }
                        }
                    };
                    IPropertyBuildContext <INodeStyle> styleContext =
                        context.CreateChildContext(StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy);

                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <INodeStyle> innerStyleGetter = delegate { return(styleContext.CurrentInstance); };
                        SetInstanceDelegate <INodeStyle> innerStyleSetter = delegate(INodeStyle newValue) { styleContext.SetNewInstance(newValue); };
                        propertyBuilder.BuildPropertyMap(styleContext.CreateChildContext(string.Empty, innerStyleGetter, innerStyleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }