/// <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 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 group box for the given group element or a directly a table panel if the /// given group element does not have a name. Group elements can contain only tile /// elements, label elements and other group elements. /// </summary> /// <param name="group"></param> /// <param name="borderColor"></param> /// <returns></returns> private NWidget CreateGroup(NXmlElement group, NColor borderColor) { // Create a table panel NTableFlowPanel tablePanel = CreateTablePanel(group, borderColor); // Get the group title string groupTitle = group.GetAttributeValue("name"); if (String.IsNullOrEmpty(groupTitle)) { return(tablePanel); } // Create a group box NLabel headerLabel = new NLabel(groupTitle); NGroupBox groupBox = new NGroupBox(headerLabel); groupBox.Header.HorizontalPlacement = ENHorizontalPlacement.Center; groupBox.Padding = new NMargins(ItemVerticalSpacing); groupBox.Border = NBorder.CreateFilledBorder(borderColor); // Create the table panel with the examples tiles groupBox.Content = CreateTablePanel(group, borderColor); return(groupBox); }
private static bool TryGetFactor(NXmlElement element, string attribute, out double result) { string str = NStringHelpers.SafeTrim(element.GetAttributeValue(attribute)); if (str == null || str.Length == 0) { result = 0; return(false); } bool isPercent = str[str.Length - 1] == '%'; if (isPercent) { str = str.Substring(0, str.Length - 1); } if (Double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result) == false) { return(false); } if (isPercent) { result = result / 100; } return(true); }
private NImageBox CreateImageBox(NXmlElement categoryElement) { string emfName = categoryElement.GetAttributeValue("namespace") + ".emf"; // Get the metafile byte[] metaImage = EmfDecompressor.GetMetaImage(emfName); // Create an image box for it NComponentImageBox imageBox = new NComponentImageBox(); imageBox.Image = new NImage(new NBytesImageSource(metaImage)); imageBox.Status = categoryElement.GetAttributeValue("status"); imageBox.Tag = categoryElement; return(imageBox); }
private static NTreeViewItem GetDefaultExampleItem(NTreeViewItem item, int maxDepth, int depth) { NXmlElement xmlElement = item.Tag as NXmlElement; if (xmlElement != null && xmlElement.GetAttributeValue("default") == "true") { return(item); } if (depth < maxDepth) { depth++; NTreeViewItemCollection items = item.Items; for (int i = 0, count = items.Count; i < count; i++) { NTreeViewItem defaultItem = GetDefaultExampleItem(items[i], maxDepth, depth); if (defaultItem != null) { return(defaultItem); } } } return(null); }
/// <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); }
private void LoadExample(NXmlElement element) { string groupNamespace = NExamplesHomePage.GetNamespace(element); string name = element.GetAttributeValue("name"); string type = groupNamespace + "." + element.GetAttributeValue("type"); try { type = "Nevron.Nov.Examples." + type; Type exampleType = Type.GetType(type); if (exampleType != null) { NDomType domType = NDomType.FromType(exampleType); NDebug.Assert(domType != null, "The example type:" + type + " is not a valid type"); // Create the example DateTime start = DateTime.Now; NExampleBase example = domType.CreateInstance() as NExampleBase; example.Title = name; example.Initialize(); m_Splitter.Pane2.Content = example; string stats = "Example created in: " + (DateTime.Now - start).TotalSeconds + " seconds, "; // Evaluate the example start = DateTime.Now; OwnerDocument.Evaluate(); stats += " evaluated in: " + (DateTime.Now - start).TotalSeconds + " seconds"; m_StatusLabel.Text = stats; } // Set the breadcrumb CreateBreadcrumb(element); } catch (Exception ex) { NTrace.WriteException("Failed to load example", ex); m_Splitter.Pane2.Content = new NErrorPanel("Failed to load example. Exception was: " + ex.Message); } }
private static bool TryGetInt(NXmlElement element, string attribute, out int result) { string str = element.GetAttributeValue(attribute); if (str == null || str.Length == 0) { result = 0; return(false); } return(Int32.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result)); }
internal static string GetNamespace(NXmlElement element) { string result; do { result = element.GetAttributeValue("namespace"); element = element.Parent as NXmlElement; }while ((result == null || result.Length == 0) && element != null); return(result); }
private void CreateBreadcrumb(NXmlElement element) { NList <NXmlElement> path = GetBreadcrumbPath(element); for (int i = 0, count = path.Count; i < count; i++) { NXmlElement curElement = path[i]; if (IsSingleExampleTile(curElement)) { continue; } string name = curElement.GetAttributeValue("name"); if (String.IsNullOrEmpty(name)) { continue; } if (m_Toolbar.Items[m_Toolbar.Items.Count - 1] is NButton) { NLabel label = new NLabel(" > "); label.TextAlignment = ENContentAlignment.MiddleCenter; label.VerticalPlacement = ENVerticalPlacement.Fit; m_Toolbar.Items.Add(label); } if (i != (count - 1)) { NButton button = new NButton(name); button.Content.VerticalPlacement = ENVerticalPlacement.Center; button.Click += OnBreadcrumbButtonClick; button.Tag = path[i]; m_Toolbar.Items.Add(button); } else { NLabel label = new NLabel(name); label.VerticalPlacement = ENVerticalPlacement.Center; m_Toolbar.Items.Add(label); } } }
private static NXmlElement GetExampleElement(NXmlNode node, string type) { NXmlElement element = node as NXmlElement; if (element != null && element.Name == "example" && element.GetAttributeValue("type") == type) { return(element); } for (int i = 0, count = node.ChildrenCount; i < count; i++) { element = GetExampleElement(node.GetChildAt(i), type); if (element != null) { return(element); } } return(null); }
/// <summary> /// Gets the full path to the given example by prepending the names of its parent XML elements. /// </summary> /// <param name="exampleElement"></param> /// <returns></returns> private static string GetExamplePath(NXmlElement exampleElement) { string path = null; NXmlElement element = exampleElement; while (element.Name != "document") { if (NExampleHost.IsSingleExampleTile(element) == false) { // The current XML element is not a tile with a single example string name = element.GetAttributeValue("name"); if (String.IsNullOrEmpty(name) == false) { // The current element has a "name" attribute value, so prepend it to the path path = String.IsNullOrEmpty(path) ? name : name + " > " + path; } } element = (NXmlElement)element.Parent; } return(path); }
/// <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); }
private void OnCopyLinkToClipboardClick(NEventArgs arg) { NDataObject dataObject = new NDataObject(); NXmlElement element = (NXmlElement)arg.CurrentTargetNode.Tag; dataObject.SetData(NDataFormat.TextFormat, m_ExamplesPath + "?example=" + element.GetAttributeValue("type")); NClipboard.SetDataObject(dataObject); }
/// <summary> /// Creates a tile. Tile elements can contain only examples. /// </summary> /// <param name="element"></param> /// <param name="categoryNamespace"></param> /// <returns></returns> private NWidget CreateTile(NXmlElement element, string categoryNamespace) { string tileTitle = element.GetAttributeValue("name"); string iconName = element.GetAttributeValue("icon"); // Get the icon for the tile NImage icon = null; if (iconName != null) { if (NApplication.IOService.DirectorySeparatorChar != '\\') { iconName = iconName.Replace('\\', NApplication.IOService.DirectorySeparatorChar); } string imageFolder = NPath.GetFullDirectoryName(iconName); if (String.IsNullOrEmpty(imageFolder)) { // The icon is in the folder for the current category imageFolder = categoryNamespace; } else { // The icon is in a folder of another category imageFolder = NPath.Normalize(NPath.Combine(categoryNamespace, imageFolder)); if (imageFolder[imageFolder.Length - 1] == NApplication.IOService.DirectorySeparatorChar) { imageFolder = imageFolder.Remove(imageFolder.Length - 1); } // Update the icon name iconName = NPath.GetFileName(iconName); } iconName = "RIMG_ExampleIcons_" + imageFolder + "_" + iconName.Replace('.', '_'); icon = new NImage(new NEmbeddedResourceRef(NResources.Instance, iconName)); } // Create and configure the tile NExampleTile tile = new NExampleTile(icon, tileTitle); tile.HorizontalPlacement = ENHorizontalPlacement.Left; tile.Status = element.GetAttributeValue("status"); tile.Tag = new NItemInfo(element); // Add the examples of the current tile to the examples map INIterator <NXmlNode> iter = element.GetChildNodesIterator(); while (iter.MoveNext()) { NXmlElement exampleElement = iter.Current as NXmlElement; if (exampleElement == null) { continue; } string examplePath = GetExamplePath(exampleElement); if (icon != null) { icon = new NImage(icon.ImageSource); } NExampleTile example = new NExampleTile(icon, examplePath); example.Status = exampleElement.GetAttributeValue("status"); example.Tag = new NItemInfo(exampleElement); if (m_ExamplesMap.Contains(examplePath) == false) { m_ExamplesMap.Add(examplePath, example); } } return(tile); }