Ejemplo n.º 1
0
        private void Parse(object data)
        {
            // Parse the content of the text box
            NXmlDocument document = null;

            if (data is string)
            {
                // Method 1 - use a parser and a listener
                NXmlDocumentParserListener listener = new NXmlDocumentParserListener();
                NXmlParser parser = new NXmlParser(listener);
                parser.Parse(((string)data).ToCharArray());
                document = listener.Document;
            }
            else if (data is Stream)
            {
                // Method 2 - call the static Load method of the XML document class
                document = NXmlDocument.LoadFromStream((Stream)data);
            }
            else
            {
                throw new ArgumentException("Unsupported data type", "data");
            }

            // Populate the DOM tree view
            m_DomTree.SelectedItem = null;
            m_DomTree.Items.Clear();
            m_DomTree.Items.Add(CreateTreeViewItem(document));

            // Expand all items up to the second level
            ExpandTreeViewItems(m_DomTree.Items[0], 2, 1);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Navigates to the given example. This is used by the Silverlight examples when
        /// there's an example specified in the query string, for example:
        /// "SilverlightTestPage.html?example=UI.NTooBarExample".
        /// </summary>
        /// <param name="exampleType"></param>
        public void NavigateToExample(string exampleType)
        {
            NXmlDocument document;

            using (Stream stream = NResources.Instance.GetResourceStream("RSTR_Examples_xml"))
            {
                document = NXmlDocument.LoadFromStream(stream);
            }

            // Find the XML element with the given example type:
            NXmlElement element = GetExampleElement(document, exampleType);

            if (element != null)
            {
                NavigateToExample(element);
            }
        }
Ejemplo n.º 4
0
        private void OnSerializeButtonClick(NEventArgs arg)
        {
            // Create the XML document
            NXmlDocument  document     = new NXmlDocument();
            NTreeViewItem documentItem = DocumentItem;

            for (int i = 0, childCount = documentItem.Items.Count; i < childCount; i++)
            {
                document.AddChild(SerializeTreeViewItem(documentItem.Items[i]));
            }

            // Serialize the document to the XML text box
            using (MemoryStream stream = new MemoryStream())
            {
                // Serialize the document to a memory stream
                document.SaveToStream(stream, NEncoding.UTF8);

                // Populate the XML text box from the memory stream
                byte[] data = stream.ToArray();
                m_XmlTextBox.Text = NEncoding.UTF8.GetString(data);
            }
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        private NList <NCountry> LoadCountryData()
        {
            // Get the country list XML stream
            Stream stream = NResources.Instance.GetResourceStream("RSTR_CountryList_xml");

            // Load an xml document from the stream
            NXmlDocument xmlDocument = NXmlDocument.LoadFromStream(stream);

            // Process it
            NXmlNode         rows      = xmlDocument.GetChildAt(0).GetChildAt(1);
            NList <NCountry> countries = new NList <NCountry>();

            for (int i = 0, countryCount = rows.ChildrenCount; i < countryCount; i++)
            {
                NXmlNode row = rows.GetChildAt(i);

                // Get the country name
                NCountry country = new NCountry(GetValue(row.GetChildAt(1)));
                if (String.IsNullOrEmpty(country.Name))
                {
                    continue;
                }

                // Get the country's capital
                country.Capital = GetValue(row.GetChildAt(6));
                if (String.IsNullOrEmpty(country.Capital))
                {
                    continue;
                }

                // Get the country's currency
                country.CurrencyCode = GetValue(row.GetChildAt(7));
                country.CurrencyName = GetValue(row.GetChildAt(8));
                if (String.IsNullOrEmpty(country.CurrencyCode) || String.IsNullOrEmpty(country.CurrencyName))
                {
                    continue;
                }

                // Get the country code (ISO 3166-1 2 Letter Code)
                country.Code = GetValue(row.GetChildAt(10));
                if (String.IsNullOrEmpty(country.Code))
                {
                    continue;
                }

                // Get the country flag
                string            flagResourceName = "RIMG_CountryFlags_" + country.Code.ToLower() + "_png";
                NEmbeddedResource flagResource     = NResources.Instance.GetResource(flagResourceName);
                if (flagResource == null)
                {
                    continue;
                }

                country.Flag = new NImage(new NEmbeddedResourceRef(flagResource));

                // Add the country to the list
                countries.Add(country);
            }

            // Sort the countries by name and return them
            countries.Sort();
            return(countries);
        }