Пример #1
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));
                    }
                }
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
 }
Пример #4
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);
 }
        /// <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));
                    }
                }
            }
        }
Пример #6
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);
 }
Пример #7
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));
         }
     }
 }
 public object Lookup(Type type)
 {
     return(childContext.Lookup(type));
 }
Пример #9
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));
                    }
                }
            }
        }