Ejemplo n.º 1
0
        /// <summary>
        /// Reads the component metadata and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            //Debug.Log(string.Format("DefaultValuesFactory->Produce [{0}]", _componentType));

            if (null == _cached)
            {
                _cached = new StyleTable();

                var attributes = StyleReflector.GetStyleAttributes(_componentType);

#if DEBUG
                if (null != StyleProtoChain.TYPE_TO_MONITOR)
                {
                    if (_componentType == StyleProtoChain.TYPE_TO_MONITOR)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (StyleAttribute attribute in attributes)
                        {
                            sb.AppendLine(string.Format("[{0}, {1}]", attribute.Name, attribute.GetDefault()));
                        }
                        Debug.Log(string.Format(@"DefaultValuesFactory->Produced [{0}]
{1}", _componentType, sb));
                    }
                }
#endif

                foreach (StyleAttribute attribute in attributes)
                {
                    /**
                     * 1. Validate proxy
                     * */
                    ValidateAttribute(attribute);

                    /**
                     * 2. Extract possible value
                     * */
                    var def = attribute.GetDefault(); // ovdje je bio bug kod boja - nije se koristilo GetDefault(), već samo Default
                    if (null != def)
                    {
                        _cached.Add(attribute.Name, def);
                    }
                }
            }

            return((StyleTable)_cached.Clone());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the serialized declaration and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            if (null == _cached)
            {
                _cached = new StyleTable();

//#if DEBUG
//                        StringBuilder sb = new StringBuilder();
//                        foreach (StyleProperty property in _styleSheetDeclaration.Properties)
//                        {
//                            sb.AppendLine(string.Format("[{0}, {1}]", property.Name, property.Value));
//                        }
//                        Debug.Log(string.Format(@"StyleSheetValuesFactory->Produced
//{0}", sb));
//#endif

                foreach (StyleProperty property in _styleSheetDeclaration.Properties)
                {
                    _cached.Add(property.Name, property.Value);
                }
            }

            return((StyleTable)_cached.Clone());
        }
Ejemplo n.º 3
0
// ReSharper restore UnassignedField.Global
#endif

        ///<summary>
        ///</summary>
        ///<param name="chain">Replikativni Dictionary</param>
        ///<param name="target"></param>
        ///<returns></returns>
        internal virtual StyleTable AddStyleToProtoChain(StyleTable chain, object target /*, object filterMap*/)
        {
            //Debug.Log("AddStyleToProtoChain: chain: " + chain + "; target: " + target);

            bool nodeAddedToChain = false;

            //var originalChain = chain;

            //if (filterMap)
            //{
            //    chain = {};
            //}

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 0. " + chain);
            }
#endif

            // If there's a defaultFactory for this style sheet,
            // then add the object it produces to the chain.
            if (null != Set1)
            {
                chain            = chain.CloneAndOverrideWith(Set1.Produce());
                nodeAddedToChain = true;
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 1. " + chain);
            }
#endif

            // If there's a factory for this style sheet,
            // then add the object it produces to the chain.
            if (null != Set2)
            {
                chain            = chain.CloneAndOverrideWith(Set2.Produce());
                nodeAddedToChain = true;
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 2. " + chain);
            }
#endif

            //Debug.Log("-- chain: " + chain);

            // If someone has called setStyle() on this StyleDeclaration,
            // then some of the values returned from the factory are
            // out-of-date. Overwrite them with the up-to-date values.
            if (null != _overrides)
            {
                // Before we add our overrides to the object at the head of
                // the chain, make sure that we added an object at the head
                // of the chain.
                if (null == Set1 && null == Set2)
                {
                    chain            = (StyleTable)chain.Clone();
                    nodeAddedToChain = true;
                }

                foreach (string p in _overrides.Keys)
                {
                    if (!UNDEFINED.Equals(_overrides[p]))
                    {
                        chain[p] = _overrides[p];
                    }

                    /*if (UNDEFINED.Equals(_overrides[p]))
                     *      chain.Remove(p);
                     * else
                     *      chain[p] = _overrides[p];*/
                }
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 3. " + chain);
            }
#endif

            #region _complex

            ////if (filterMap)
            ////{
            //    if (nodeAddedToChain)
            //    {
            //        //Debug.Log("nodeAddedToChain");
            //        //var filteredChain = new Dictionary<string, object>();
            //        //for (string i in chain)
            //        //{
            //        //    if (filterMap[i] != null)
            //        //    {
            //        //        filteredChain[filterMap[i]] = chain[i];
            //        //    }
            //        //}

            //        //var f = new StyleTableValuesFactory(originalChain);

            //        chain = (StyleTable) originalChain.Clone();

            //        //chain = originalChain;

            //        //chain = filteredChain;
            //        //chain = f.Produce();

            //        //chain[FILTERMAP_PROP] = filterMap;
            //    }
            //    else
            //    {
            //        chain = originalChain;
            //    }
            ////}

            #endregion

            if (nodeAddedToChain)
            {
                _clones.Add(chain);
            }

            return(chain);
        }