private void AddItemsFor(NTreeViewItemCollection items, NXmlElement element) { int childCount = element.ChildrenCount; for (int i = 0; i < childCount; i++) { NXmlElement child = element.GetChildAt(i) as NXmlElement; if (child == null) { continue; } NTreeViewItem item = CreateTreeViewItem(child); if (item != null) { items.Add(item); if (item.Tag is NXmlElement == false) { // This is a folder item, so add items for its children, too AddItemsFor(item.Items, child); } } else { AddItemsFor(items, child); } } }
/// <summary> /// Parses the background colors of the status labels defined in the examples XML file. /// </summary> /// <param name="styleElement"></param> private void ParseStatusColors(NXmlElement styleElement) { m_StatusColorMap = new NMap <string, NColor>(); if (styleElement == null) { return; } for (int i = 0, count = styleElement.ChildrenCount; i < count; i++) { NXmlElement child = styleElement.GetChildAt(i) as NXmlElement; if (child == null || child.Name != "status") { continue; } // Get the status name string name = child.GetAttributeValue("name"); if (name == null) { continue; } // Parse the status color string colorStr = child.GetAttributeValue("color"); NColor color; if (NColor.TryParse(colorStr, out color) == false) { continue; } // Add the name/color pair to the status color map m_StatusColorMap.Set(name, color); } }
/// <summary> /// Creates a stack panel for the given row element. Row elements can contain only /// group elements and label elements. /// </summary> /// <param name="row"></param> /// <returns></returns> private NStackPanel CreateRow(NXmlElement row, NColor categoryColor) { NStackPanel stack = new NStackPanel(); stack.Direction = ENHVDirection.LeftToRight; stack.FillMode = ENStackFillMode.Equal; // FIX: make this a setting stack.HorizontalSpacing = GroupHorizontalSpacing; stack.Padding = new NMargins(GroupHorizontalSpacing, 0); for (int i = 0, count = row.ChildrenCount; i < count; i++) { NXmlElement child = row.GetChildAt(i) as NXmlElement; if (child == null) { continue; } switch (child.Name) { case "group": stack.Add(CreateGroup(child, categoryColor)); break; case "label": stack.Add(CreateLabel(child)); break; default: throw new Exception("Unsuppoted row child element"); } } return(stack); }
/// <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); }
private NTreeViewItem CreateTreeViewItem(NXmlElement element) { if (IsSingleExampleTile(element)) { // This is a tile with a single example, so create only the example tree view item return(CreateTreeViewItem((NXmlElement)element.GetChildAt(0))); } NImage icon; string name = element.GetAttributeValue("name"); if (String.IsNullOrEmpty(name)) { return(null); } switch (element.Name) { case "tile": case "group": case "folder": icon = NResources.Image__16x16_Folders_png; break; case "example": icon = NResources.Image__16x16_Contacts_png; break; default: return(null); } NExampleTile tile = new NExampleTile(icon, name); tile.Status = element.GetAttributeValue("status"); tile.Box2.VerticalPlacement = ENVerticalPlacement.Center; tile.Spacing = NDesign.HorizontalSpacing; NTreeViewItem item = new NTreeViewItem(tile); if (element.Name == "example") { // This is an example element item.Tag = element; if (NApplication.Platform == ENPlatform.Silverlight) { // Handle the right click event in Silverlight to show a context menu // for copying a link to the example item.MouseDown += OnTreeViewItemMouseDown; } } return(item); }
/// <summary> /// Creates a table panel, which is the content of a group. /// </summary> /// <param name="owner"></param> /// <param name="borderColor"></param> /// <returns></returns> private NTableFlowPanel CreateTablePanel(NXmlElement owner, NColor borderColor) { int maxRows; if (TryGetInt(owner, "maxRows", out maxRows) == false) { maxRows = defaultMaxRows; } // Create a table flow panel for the items NTableFlowPanel table = new NTableFlowPanel(); table.UniformWidths = ENUniformSize.Max; table.UniformHeights = ENUniformSize.Max; table.ColFillMode = ENStackFillMode.Equal; table.Direction = ENHVDirection.TopToBottom; table.HorizontalSpacing = ItemHorizontalSpacing; table.VerticalSpacing = ItemVerticalSpacing; table.MaxOrdinal = maxRows; // Create the items and add them to the table panel string categoryNamespace = GetNamespace(owner); int childCount = owner.ChildrenCount; for (int i = 0; i < childCount; i++) { NXmlElement child = owner.GetChildAt(i) as NXmlElement; if (child == null) { continue; } switch (child.Name) { case "tile": table.Add(CreateTile(child, categoryNamespace)); break; case "group": table.Add(CreateGroup(child, borderColor)); break; case "label": table.Add(CreateLabel(child)); break; default: throw new Exception("New examples XML tag?"); } } return(table); }
public void LoadFromStream(Stream stream) { // Load an xml document from the stream NXmlDocument xmlDocument = NXmlDocument.LoadFromStream(stream); // Process it if (xmlDocument == null || xmlDocument.ChildrenCount != 1) { return; } m_ExamplesMap = new NStringMap <NWidget>(false); // Get the root element (i.e. the <document> element) NXmlElement rootElement = (NXmlElement)xmlDocument.GetChildAt(0); // Process the head NXmlElement titleElement = (NXmlElement)rootElement.GetFirstChild("title"); m_HeaderLabel.Text = ((NXmlTextNode)titleElement.GetChildAt(0)).Text; NXmlElement statusColorsElement = (NXmlElement)rootElement.GetFirstChild("statusColors"); ParseStatusColors(statusColorsElement); // Process the categories NXmlElement categoriesElement = (NXmlElement)rootElement.GetFirstChild("categories"); ((NWelcomePanel)m_PagePanel[0]).Initialize(categoriesElement); for (int i = 0, count = categoriesElement.ChildrenCount; i < count; i++) { NXmlElement child = categoriesElement.GetChildAt(i) as NXmlElement; if (child == null) { continue; } if (child.Name != "category") { throw new Exception("The body element can contain only category elements"); } // Create a widget and add it to the categories panel NWidget category = CreateCategory(child); m_PagePanel.Add(category); } // Init the search box m_SearchBox.InitAutoComplete(m_ExamplesMap, new NExampleFactory()); m_SearchBox.ListBoxItemSelected += OnSearchBoxListBoxItemSelected; }
/// <summary> /// Creates a widget for the given category element. /// Category elements can contain only row elements. /// </summary> /// <param name="category"></param> /// <returns></returns> private NWidget CreateCategory(NXmlElement category) { string categoryTitle = category.GetAttributeValue("name"); NColor color = NColor.ParseHex(category.GetAttributeValue("color")); NColor lightColor = color.Lighten(0.6f); // Create the header label NExampleCategoryHeader categoryHeader = new NExampleCategoryHeader(categoryTitle); categoryHeader.BackgroundFill = new NColorFill(color); categoryHeader.Status = category.GetAttributeValue("status"); // Create a stack panel for the category widgets NStackPanel stack = new NStackPanel(); stack.VerticalSpacing = ItemVerticalSpacing; stack.BackgroundFill = new NColorFill(lightColor); stack.Tag = category; // Add the header label stack.Add(categoryHeader); // Loop through the rows for (int i = 0, count = category.ChildrenCount; i < count; i++) { NXmlElement row = category.GetChildAt(i) as NXmlElement; if (row == null) { continue; } if (row.Name != "row") { throw new Exception("Category elements should contain only rows"); } NStackPanel rowStack = CreateRow(row, color); stack.Add(rowStack); } return(stack); }
/// <summary> /// /// </summary> /// <returns></returns> protected override NWidget CreateExampleContent() { NChartView chartView = CreateTreeMapView(); // configure title chartView.Surface.Titles[0].Text = "TreeMap Legend"; NTreeMapChart treeMap = (NTreeMapChart)chartView.Surface.Charts[0]; // Get the country list XML stream Stream stream = NResources.Instance.GetResourceStream("RSTR_TreeMapDataSmall_xml"); // Load an xml document from the stream NXmlDocument xmlDocument = NXmlDocument.LoadFromStream(stream); m_RootTreeMapNode = new NGroupTreeMapNode(); NThreeColorPalette palette = new NThreeColorPalette(); palette.OriginColor = NColor.White; palette.BeginColor = NColor.Red; palette.EndColor = NColor.Green; m_RootTreeMapNode.Label = "Tree Map - Industry by Sector"; m_RootTreeMapNode.Palette = palette; m_RootTreeMapNode.LegendView = new NGroupTreeMapNodeLegendView(); treeMap.RootTreeMapNode = m_RootTreeMapNode; NXmlElement rootElement = (NXmlElement)xmlDocument.GetChildAt(0); for (int i = 0; i < rootElement.ChildrenCount; i++) { NXmlElement industry = (NXmlElement)rootElement.GetChildAt(i); NGroupTreeMapNode treeMapSeries = new NGroupTreeMapNode(); treeMapSeries.BorderThickness = new NMargins(4.0); treeMapSeries.Border = NBorder.CreateFilledBorder(NColor.Black); treeMapSeries.Padding = new NMargins(2.0); m_RootTreeMapNode.ChildNodes.Add(treeMapSeries); treeMapSeries.Label = industry.GetAttributeValue("Name"); treeMapSeries.Tooltip = new NTooltip(treeMapSeries.Label); for (int j = 0; j < industry.ChildrenCount; j++) { NXmlElement company = (NXmlElement)industry.GetChildAt(j); double value = Double.Parse(company.GetAttributeValue("Size"), CultureInfo.InvariantCulture); double change = Double.Parse(company.GetAttributeValue("Change"), CultureInfo.InvariantCulture); string label = company.GetAttributeValue("Name"); NValueTreeMapNode node = new NValueTreeMapNode(value, change, label); node.Format = "<label> <change_percent>"; node.ChangeValueType = ENChangeValueType.Percentage; node.Tooltip = new NTooltip(label); treeMapSeries.ChildNodes.Add(node); } } return(chartView); }
/// <summary> /// Checks whether the given XML element represents a tile, which contains only one example. /// </summary> /// <param name="element"></param> /// <returns></returns> internal static bool IsSingleExampleTile(NXmlElement element) { return(element.Name == "tile" && element.ChildrenCount == 1 && element.GetChildAt(0).Name == "example"); }