Example #1
0
        public static Color ToColorT(object value)
        {
            if (value is Color)
            {
                return((Color)value);
            }

            if (value is int)
            {
                return(NColor.ColorFromUInt32(0xFF000000 | (uint)(int)value));
            }

            if (value is uint)
            {
                return(NColor.ColorFromUInt32((uint)value));
            }

            var s = value as string;

            if (s != null)
            {
                return(NColor.Parse(s));
            }

            throw new InvalidCastException();
        }
Example #2
0
        /// <summary>
        /// Creates the product groups stack panel.
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        private NStackPanel CreateProductGroupsStack(NXmlElement root)
        {
            NMap <string, NStackPanel> stackMap = new NMap <string, NStackPanel>();

            // Create the main stack
            NStackPanel mainStack = new NStackPanel();

            mainStack.Direction = ENHVDirection.LeftToRight;
            mainStack.Margins   = new NMargins(0, LaneSpacing * 2);

            // Create a stack panel for each license groups and add it to the main stack
            int count = root.ChildrenCount;

            for (int i = 0; i < count; i++)
            {
                NXmlElement categoryElement = root.GetChildAt(i) as NXmlElement;
                if (categoryElement == null)
                {
                    continue;
                }

                string license = categoryElement.GetAttributeValue("license");

                NStackPanel licenseGroupStack;
                if (!stackMap.TryGet(license, out licenseGroupStack))
                {
                    // A stack panel for the license group not found, so create one
                    licenseGroupStack = CreateProductGroupStack();
                    stackMap.Add(license, licenseGroupStack);

                    // Create a stack for the current group and its name
                    NStackPanel stack = new NStackPanel();
                    stack.Direction = ENHVDirection.TopToBottom;

                    // 1. Add the license group stack
                    stack.Add(licenseGroupStack);

                    // 2. Add the bracket
                    NColor  color   = NColor.Parse(categoryElement.GetAttributeValue("color"));
                    NWidget bracket = CreateLicenseGroupBracket(color);
                    stack.Add(bracket);

                    // 3. Add the label
                    NLabel label = new NLabel(license);
                    label.HorizontalPlacement = ENHorizontalPlacement.Center;
                    label.TextFill            = new NColorFill(color);
                    label.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, InfoFontSize);
                    stack.Add(label);

                    mainStack.Add(stack);
                }

                // Create an image box for the current category
                NImageBox imageBox = CreateImageBox(categoryElement);
                licenseGroupStack.Add(imageBox);
            }

            return(mainStack);
        }