Ejemplo n.º 1
0
        /// <summary>
        /// Method that <see cref="IPropertyBuildContext{TSubject}.AddEntry(string,IValueGetter,Demo.yFiles.Option.DataBinding.IValueSetter)">adds entries</see>
        /// for the <see cref="INode.Layout"/> of a node.
        /// </summary>
        /// <remarks>
        /// This implementation create a <see cref="IPropertyBuildContext{TSubject}.CreateChildContext{TChild}">child context</see>
        /// and adds properties for x,y,width, and height.
        /// </remarks>
        /// <param name="context">The context to use.</param>
        protected virtual void BuildLayoutProperties(IPropertyBuildContext <INode> context)
        {
            IPropertyBuildContext <IMutableRectangle> childContext = context.CreateChildContext <IMutableRectangle>(LayoutPropertyName,
                                                                                                                    delegate {
                return((IMutableRectangle)context.CurrentInstance.Lookup(typeof(IMutableRectangle)));
            },
                                                                                                                    delegate {
                //we work directly on the mutable rectangle
            }, AssignmentPolicy.ModifyInstance);

            childContext.AddEntry <double>(LayoutXName, delegate { return(childContext.CurrentInstance.X); },
                                           delegate(double value) {
                childContext.CurrentInstance.X = value;
            });
            childContext.AddEntry <double>(LayoutYName, delegate { return(childContext.CurrentInstance.Y); },
                                           delegate(double value) {
                childContext.CurrentInstance.Y = value;
            });
            childContext.AddEntry <double>(LayoutWidthName, delegate { return(childContext.CurrentInstance.Width); },
                                           delegate(double value) {
                childContext.CurrentInstance.Width = value;
            });
            childContext.AddEntry <double>(LayoutHeightName, delegate { return(childContext.CurrentInstance.Height); },
                                           delegate(double value) {
                childContext.CurrentInstance.Height = value;
            });
        }
Ejemplo n.º 2
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 <IEdge> context)
        {
            IEdge edge = context.CurrentInstance;

            if (edge != null)
            {
                IEdgeStyle style = edge.Style;
                if (style != null)
                {
                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <IEdgeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                        SetInstanceDelegate <IEdgeStyle> styleSetter = delegate(IEdgeStyle newInstance) {
                            IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                            IEdge  currentEdge = context.CurrentInstance;
                            if (graph != null)
                            {
                                graph.SetStyle(currentEdge, newInstance);
                            }
                        };
                        propertyBuilder.BuildPropertyMap(context.CreateChildContext(DefaultEdgeOptionBuilder.StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds the properties for the labels's <see cref="ILabelModel"/> type.
        /// </summary>
        protected virtual void BuildModelProperties(IPropertyBuildContext <ILabel> context)
        {
            ValueGetterDelegate <Type> labelModelGetter = new ValueGetterDelegate <Type>(
                delegate {
                var type = context.CurrentInstance.LayoutParameter.Model.GetType();
                while (!type.IsPublic)
                {
                    type = type.BaseType;
                }
                return(type);
            });
            ValueSetterDelegate <Type> labelModelSetter = new ValueSetterDelegate <Type>(
                delegate(Type value) {
                IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
                if (graph != null)
                {
                    ILabelModel model = Activator.CreateInstance(value) as ILabelModel;
                    if (model != null)
                    {
                        ILabelModelParameterFinder finder =
                            model.Lookup(typeof(ILabelModelParameterFinder)) as ILabelModelParameterFinder;
                        ILabelModelParameter parameter;
                        ILabel subject = context.CurrentInstance;
                        if (finder != null)
                        {
                            parameter = finder.FindBestParameter(subject, model, subject.GetLayout());
                        }
                        else
                        {
                            parameter = model.CreateDefaultParameter();
                        }
                        graph.SetLabelLayoutParameter(subject, parameter);
                    }
                }
            });
            ILabel currentLabel;

            currentLabel = context.CurrentInstance;
            if (currentLabel == null)
            {
                return;
            }
            if (currentLabel.Owner is IEdge)
            {
                context.AddEntry(EdgeLabelModelProperty,
                                 labelModelGetter,
                                 labelModelSetter, null);
            }

            if (currentLabel.Owner is INode)
            {
                context.AddEntry(NodeLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }

            if (currentLabel.Owner is IPort)
            {
                context.AddEntry(PortLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <IPort> context)
        {
            IPort currentPort = context.CurrentInstance;

            if (currentPort == null)
            {
                return;
            }
            BuildLabelProperties(context);
            BuildPortStylesProperty(context);
            BuildStyleProperties(context, currentPort.Style);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Builds the property for the labels's <see cref="ILabel.Text"/>.
 /// </summary>
 protected virtual void BuildLabelTextProperty(IPropertyBuildContext <ILabel> context)
 {
     context.AddEntry(TextProperty
                      , new ValueGetterDelegate <string>(delegate { return(context.CurrentInstance.Text); })
                      , new ValueSetterDelegate <string>(delegate(string value) {
         IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
         if (graph != null)
         {
             graph.SetLabelText(context.CurrentInstance, value);
         }
     }), null);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Builds the properties for the labels's <see cref="ILabel.PreferredSize"/>.
 /// </summary>
 protected virtual void BuildPreferredSizeProperties(IPropertyBuildContext <ILabel> context)
 {
     context.AddEntry(PreferredSizeProperty,
                      new ValueGetterDelegate <SizeD>(delegate() {
         return(context.CurrentInstance.PreferredSize);
     }),
                      new ValueSetterDelegate <SizeD>(delegate(SizeD value) {
         IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
         if (graph != null)
         {
             graph.SetLabelPreferredSize(context.CurrentInstance, value);
         }
     }), null);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds the properties for the labels's <see cref="ILabel.LayoutParameter"/>
        /// and <see cref="ILabelModel"/>.
        /// </summary>
        protected virtual void BuildLabelModelParameterProperties(IPropertyBuildContext <ILabel> context, ILabelModelParameter layoutParameter)
        {
            IPropertyMapBuilder modelBuilder = GetLabelModelPropertyMapBuilder(context, layoutParameter.Model);

            if (modelBuilder != null)
            {
                modelBuilder.BuildPropertyMap(context.CreateChildContext <ILabelModel>("Model",
                                                                                       delegate {
                    return(context.CurrentInstance.LayoutParameter.Model);
                }, delegate(ILabelModel newInstance) {
                    return;
                }, AssignmentPolicy.ModifyInstance));
            }
        }
        /// <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));
                    }
                }
            }
        }
 /// <summary>
 /// Creates a copy of the provided item to comply with the <see cref="AssignmentPolicy.CreateNewInstance"/> policy
 /// if that policy is set on the current context.
 /// </summary>
 /// <remarks>
 /// See the description of <see cref="PropertyMapBuilderBase{TSubject}">this type</see>.
 /// </remarks>
 /// <param name="context">The context that the subject needs to be cloned for. Note that this method should not
 /// have side effects on the context.</param>
 /// <param name="item">The item to create a (deep) copy of.</param>
 /// <returns>A clone of this item.</returns>
 protected internal virtual TSubject CreateCopy(IPropertyBuildContext <TSubject> context, TSubject item)
 {
     if (useClone)
     {
         if (cloner != null)
         {
             return(cloner(item));
         }
         else if (item is ICloneable)
         {
             return((TSubject)((ICloneable)item).Clone());
         }
     }
     return(item);
 }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <ILabel> context)
        {
            BuildLabelTextProperty(context);
            BuildPreferredSizeProperties(context);
            BuildModelProperties(context);
            ILabel currentLabel;

            currentLabel = context.CurrentInstance;
            if (currentLabel == null)
            {
                return;
            }
            BuildLabelModelParameterProperties(context, currentLabel.LayoutParameter);
            BuildLabelStylesProperty(context);
            BuildStyleProperties(context, currentLabel.Style);
        }
Ejemplo n.º 11
0
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <StringFormat> context)
        {
            context.AddEntry(DirectionProperty,
                             new DelegateGetter <object>(delegate {
                StringFormat format = context.CurrentInstance;
                if ((format.FormatFlags & StringFormatFlags.DirectionRightToLeft) ==
                    StringFormatFlags.DirectionRightToLeft)
                {
                    return(StringFormatFlags.DirectionRightToLeft);
                }
                if ((format.FormatFlags & StringFormatFlags.DirectionVertical) ==
                    StringFormatFlags.DirectionVertical)
                {
                    return(StringFormatFlags.DirectionVertical);
                }
                return(null);
            }),
                             new DelegateSetter <object>(
                                 delegate(object value) {
                if (value == null)
                {
                    context.CurrentInstance.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
                    context.CurrentInstance.FormatFlags &= ~StringFormatFlags.DirectionVertical;
                }
                else if (value is StringFormatFlags)
                {
                    if ((StringFormatFlags)value == StringFormatFlags.DirectionRightToLeft)
                    {
                        context.CurrentInstance.FormatFlags &= ~StringFormatFlags.DirectionVertical;
                        context.CurrentInstance.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }
                    else if ((StringFormatFlags)value == StringFormatFlags.DirectionVertical)
                    {
                        context.CurrentInstance.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
                        context.CurrentInstance.FormatFlags |= StringFormatFlags.DirectionVertical;
                    }
                }
            }));
            context.AddEntry <StringAlignment>(AlignmentProperty, delegate { return(context.CurrentInstance.Alignment); },
                                               delegate(StringAlignment value) { context.CurrentInstance.Alignment = value; });

            context.AddEntry <StringAlignment>(LineAlignmentProperty,
                                               delegate { return(context.CurrentInstance.LineAlignment); },
                                               delegate(StringAlignment value) { context.CurrentInstance.LineAlignment = value; });
            context.AddEntry <StringTrimming>(TrimmingProperty, delegate { return(context.CurrentInstance.Trimming); },
                                              delegate(StringTrimming value) { context.CurrentInstance.Trimming = value; });
        }
 /// <summary>
 /// Default implementation that wraps the provided context as needed and
 /// delegates to <see cref="BuildPropertyMapImpl"/>, which needs to be implemented by subclasses.
 /// </summary>
 /// <remarks>
 /// See the description of <see cref="PropertyMapBuilderBase{TSubject}">this type</see>
 /// for what this implementation actually does. Normally subclasses need not care about this method but need
 /// to implement <see cref="BuildPropertyMapImpl"/>, only.
 /// </remarks>
 /// <typeparam name="T">The type of the context that is passed in.</typeparam>
 /// <param name="context">The context to use for the building of the property map.</param>
 /// <seealso cref="BuildPropertyMapImpl"/>
 public virtual void BuildPropertyMap <T>(IPropertyBuildContext <T> context) where T : class
 {
     if (!useClone && typeof(T) == typeof(TSubject))
     {
         object ctx = context;
         BuildPropertyMapImpl((IPropertyBuildContext <TSubject>)ctx);
     }
     else
     {
         if (typeof(T).IsAssignableFrom(typeof(TSubject)))
         {
             object o = typeof(WrappingBuildContext <,>).MakeGenericType(typeof(TSubject), typeof(T)).GetConstructor(
                 new Type[] { typeof(PropertyMapBuilderBase <TSubject>), typeof(IPropertyBuildContext <T>) }).Invoke(new object[] { this, context });
             BuildPropertyMapImpl((IPropertyBuildContext <TSubject>)o);
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for labels in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetLabelPropertyMapBuilder{T}"/> to retrieve the builder for the label.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildLabelProperties <T>(IPropertyBuildContext <T> context) where T : class, ILabelOwner
        {
            IPropertyBuildContext <ILabel> childContext = context.CreateChildContext <ILabel>(LabelPropertyName,
                                                                                              delegate() {
                T item = context.CurrentInstance;
                return(item.Labels.Count > 0 ? item.Labels[0] : null);
            },
                                                                                              delegate(ILabel newInstance) { }, AssignmentPolicy.ModifyInstance);

            if (context.CurrentInstance.Labels.Count > 0)
            {
                IPropertyMapBuilder builder = GetLabelPropertyMapBuilder(context, context.CurrentInstance.Labels[0]);
                if (builder != null)
                {
                    builder.BuildPropertyMap(childContext);
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Builds the property for the port's <see cref="IPort.Style"/>.
 /// </summary>
 protected virtual void BuildPortStylesProperty(IPropertyBuildContext <IPort> context)
 {
     context.AddEntry(PortStyleProperty,
                      new ValueGetterDelegate <Type>(delegate {
         var type = context.CurrentInstance.Style.GetType();
         while (!type.IsPublic)
         {
             type = type.BaseType;
         }
         return(type);
     })
                      , new ValueSetterDelegate <Type>(delegate(Type value) {
         IGraph graph     = context.Lookup(typeof(IGraph)) as IGraph;
         IPortStyle style = Activator.CreateInstance(value) as IPortStyle;
         if (graph != null && style != null)
         {
             graph.SetStyle(context.CurrentInstance, style);
         }
     }), null);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Builds the properties for the port's <see cref="IPort.Style"/>
 /// </summary>
 protected virtual void BuildStyleProperties(IPropertyBuildContext <IPort> context, IPortStyle style)
 {
     //style group...
     //retrieve current style...
     if (style != null)
     {
         IPropertyMapBuilder propertyBuilder = GetStyleBuilder(context, style);
         if (propertyBuilder != null)
         {
             propertyBuilder.BuildPropertyMap(context.CreateChildContext <IPortStyle>(StyleProperty,
                                                                                      delegate { return(context.CurrentInstance.Style); },
                                                                                      delegate(IPortStyle newInstance) {
                 IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
                 if (graph != null)
                 {
                     graph.SetStyle(context.CurrentInstance, newInstance);
                 }
             }, styleAssignmentPolicy));
         }
     }
 }
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <TSubject> builder)
        {
            MethodInfo[] infos =
                typeof(IPropertyBuildContext <>).MakeGenericType(typeof(TSubject)).GetMethods(BindingFlags.DeclaredOnly |
                                                                                              BindingFlags.Instance |
                                                                                              BindingFlags.Public);
            MethodInfo buildChildContextMethod =
                infos.FirstOrDefault(info => info.IsGenericMethod && info.ReturnType.IsGenericType);

            if (buildChildContextMethod == null)
            {
                throw new Exception("Method not found!");
            }

            TSubject instance = builder.CurrentInstance;

            var properties = instance.GetType().GetProperties();

            foreach (PropertyInfo d  in properties)
            {
                AddProperty(builder, buildChildContextMethod, d);
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Retrieves the builder for the given label model.
 /// </summary>
 protected virtual IPropertyMapBuilder GetLabelModelPropertyMapBuilder(IPropertyBuildContext <ILabel> context, ILabelModel model)
 {
     return(context.GetPropertyMapBuilder(model));
 }
 public HelperSetInstanceDelegate(PropertyInfo descriptor, IPropertyBuildContext <TSubject> context)
 {
     this.descriptor = descriptor;
     this.context    = context;
 }
 public ReflectionSetter(PropertyInfo setInstance, IPropertyBuildContext <T> context)
 {
     this.setInstance = setInstance;
     this.context     = context;
 }
Ejemplo n.º 20
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
        }
 public OuterWrappingBuildContext(WrappingBuildContext <T1, T2> wrapper, IPropertyBuildContext <TChild> childContext)
 {
     this.wrapper      = wrapper;
     this.childContext = childContext;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Method that retrieves the <see cref="IPropertyMapBuilder"/> for the provided style instance.
 /// </summary>
 /// <remarks>
 /// This implementation simply delegates to <see cref="IPropertyBuildContext{TSubject}.GetPropertyMapBuilder(object)"/>.
 /// </remarks>
 /// <param name="context">The context to use for queries.</param>
 /// <param name="style">The style instance currently associated with the node.</param>
 /// <returns>A builder or <see langword="null"/></returns>
 protected virtual IPropertyMapBuilder GetStylePropertyMapBuilder(IPropertyBuildContext <INode> context, INodeStyle style)
 {
     return(context.GetPropertyMapBuilder(style));
 }
Ejemplo n.º 23
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));
                    }
                }
            }
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Retrieves the builder for the given style.
 /// </summary>
 protected virtual IPropertyMapBuilder GetStyleBuilder(IPropertyBuildContext <IPort> context, IPortStyle style)
 {
     return(context.GetPropertyMapBuilder(style));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Called by the base class to actually build the properties for the <see cref="INode"/>.
 /// </summary>
 /// <remarks>
 /// This implementation simply delegates its work to
 /// <see cref="BuildLayoutProperties"/>,
 /// <see cref="BuildLabelProperties{T}"/>,
 /// and <see cref="BuildStyleProperties"/>.
 /// </remarks>
 /// <param name="context">The context to use as the builder.</param>
 protected override void BuildPropertyMapImpl(IPropertyBuildContext <INode> context)
 {
     BuildLayoutProperties(context);
     BuildLabelProperties(context);
     BuildStyleProperties(context);
 }
 /// <summary>
 /// The core method that needs to be implemented by subclasses.
 /// </summary>
 /// <remarks>
 /// This method actually builds the property map using the provided context.
 /// Note that if this instance has been created using the automatic cloning feature
 /// that can be turned on in the constructor, it is not necessary to take special
 /// action if the <see cref="IPropertyBuildContext{TSubject}.Policy"/> is set to
 /// <see cref="AssignmentPolicy.CreateNewInstance"/>. Instead the <see cref="CreateCopy"/>
 /// method will be used to seemlessly create a copy of the instance before the
 /// instance is modified by calls to the setter implementations that are
 /// registered through the context.
 /// </remarks>
 /// <param name="context">The context to use.</param>
 protected abstract void BuildPropertyMapImpl(IPropertyBuildContext <TSubject> context);
 public WrappingBuildContext(PropertyMapBuilderBase <T1> parent, IPropertyBuildContext <T2> context)
 {
     this.parent  = parent;
     this.context = context;
 }
        private void AddProperty(IPropertyBuildContext <TSubject> context, MethodInfo buildChildContextMethod, PropertyInfo d)
        {
            PropertyInfo descriptor   = d;
            Type         propertyType = descriptor.PropertyType;

            AssignmentPolicyAttribute assignmentPolicyAttribute = descriptor.GetAttribute <AssignmentPolicyAttribute>();

            NullableAttribute nullableAttribute = descriptor.GetAttribute <NullableAttribute>();
            bool nullable = nullableAttribute == null || nullableAttribute.IsNullable;

            AssignmentPolicy policy;

            if (assignmentPolicyAttribute != null && context.Policy == AssignmentPolicy.Default)
            {
                policy = assignmentPolicyAttribute.Policy;
            }
            else
            {
                policy = context.Policy == AssignmentPolicy.Default ? AssignmentPolicy.CreateNewInstance : context.Policy;
            }

            object childbuilder;
            object currentPropertyValue = descriptor.GetValue(context.CurrentInstance, null);

            if (currentPropertyValue == null && nullable)
            {
                //todo: make this dependent on yet-to-implement nullable attribute
                childbuilder = context.GetPropertyMapBuilder(propertyType, currentPropertyValue);
            }
            else
            {
                childbuilder = context.GetPropertyMapBuilder(currentPropertyValue);
            }

            string name = descriptor.GetDisplayName();

            if (childbuilder != null)
            {
                // Create the SetInstanceDelegate that uses the builders' CurrentInstance for the set operation
                Delegate setMemberInstanceDelegate;
                {
                    Type helperSetInstanceDelegateType = typeof(HelperSetInstanceDelegate <,>)
                                                         .MakeGenericType(propertyType, typeof(TSubject));
                    ConstructorInfo setterConstructorInfo = helperSetInstanceDelegateType
                                                            .GetConstructor(new[] { typeof(PropertyInfo), typeof(IPropertyBuildContext <TSubject>) });
                    object helperSetInstanceDelegateInstance = setterConstructorInfo
                                                               .Invoke(new object[] { descriptor, context });

                    MethodInfo method =
                        helperSetInstanceDelegateType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                                 BindingFlags.Instance)[0];
                    setMemberInstanceDelegate =
                        Delegate.CreateDelegate(typeof(SetInstanceDelegate <>).MakeGenericType(propertyType),
                                                helperSetInstanceDelegateInstance, method);
                }

                // Create the SetInstanceDelegate that uses the builders' CurrentInstance for the set operation
                Delegate getMemberInstanceDelegate;
                {
                    Type helperInstanceDelegateType = typeof(HelperGetInstanceDelegate <,>)
                                                      .MakeGenericType(propertyType, typeof(TSubject));
                    ConstructorInfo getterConstructorInfo = helperInstanceDelegateType
                                                            .GetConstructor(new[] { typeof(PropertyInfo), typeof(IPropertyBuildContext <TSubject>) });
                    object helperGetInstanceDelegateInstance = getterConstructorInfo
                                                               .Invoke(new object[] { descriptor, context });

                    MethodInfo method =
                        helperInstanceDelegateType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                              BindingFlags.Instance)[0];
                    getMemberInstanceDelegate =
                        Delegate.CreateDelegate(typeof(GetInstanceDelegate <>).MakeGenericType(propertyType),
                                                helperGetInstanceDelegateInstance, method);
                }
                object childContext = buildChildContextMethod.MakeGenericMethod(propertyType).Invoke(context,
                                                                                                     new object[]
                {
                    name,
                    getMemberInstanceDelegate
                    ,
                    setMemberInstanceDelegate
                    ,
                    policy
                });

                MethodInfo buildPropertyMapMethod =
                    typeof(IPropertyMapBuilder).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                           BindingFlags.Instance)[0];

                buildPropertyMapMethod.MakeGenericMethod(propertyType).Invoke(childbuilder, new[] { childContext });
            }
            else
            {
                context.AddEntry(name, new ReflectionGetter <TSubject>(descriptor, context),
                                 new ReflectionSetter <TSubject>(descriptor, context));
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Method that retrieves the <see cref="IPropertyMapBuilder"/> for the provided label instance.
 /// </summary>
 /// <remarks>
 /// This implementation simply delegates to <see cref="IPropertyBuildContext{TSubject}.GetPropertyMapBuilder(object)"/>.
 /// </remarks>
 /// <param name="context">The context to use for queries.</param>
 /// <param name="label">The label instance currently associated with the <see cref="ILabelOwner"/>.</param>
 /// <returns>A builder or <see langword="null"/></returns>
 protected virtual IPropertyMapBuilder GetLabelPropertyMapBuilder <T>(IPropertyBuildContext <T> context, ILabel label) where T : class, ILabelOwner
 {
     return(context.GetPropertyMapBuilder(label));
 }
 public ReflectionGetter(PropertyInfo getInstance, IPropertyBuildContext <T> context)
 {
     this.getInstance = getInstance;
     this.context     = context;
 }