Index: Core/Components/src/Core.Components.GraphSharp.Forms/Core.Components.GraphSharp.Forms.csproj
===================================================================
diff -u -r9e50d6be40fff988acad2cd410b50d15e2a15a57 -r942a8295ee5a7cd872048d3a2397049fc6531ebb
--- Core/Components/src/Core.Components.GraphSharp.Forms/Core.Components.GraphSharp.Forms.csproj (.../Core.Components.GraphSharp.Forms.csproj) (revision 9e50d6be40fff988acad2cd410b50d15e2a15a57)
+++ Core/Components/src/Core.Components.GraphSharp.Forms/Core.Components.GraphSharp.Forms.csproj (.../Core.Components.GraphSharp.Forms.csproj) (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -80,6 +80,7 @@
Properties\GlobalAssembly.cs
+ UserControl
Index: Core/Components/src/Core.Components.GraphSharp.Forms/Extensions/TextBlockExtensions.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.GraphSharp.Forms/Extensions/TextBlockExtensions.cs (revision 0)
+++ Core/Components/src/Core.Components.GraphSharp.Forms/Extensions/TextBlockExtensions.cs (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -0,0 +1,96 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Xml;
+
+namespace Core.Components.GraphSharp.Forms.Extensions
+{
+ ///
+ /// Class that defines dependency properties that can be used on a .
+ ///
+ public static class TextBlockExtensions
+ {
+ public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
+ "FormattedText", typeof(string), typeof(TextBlockExtensions), new UIPropertyMetadata(default(string), FormattedTextChanged));
+
+ public static void SetFormattedText(DependencyObject element, string value)
+ {
+ element.SetValue(FormattedTextProperty, value);
+ }
+
+ public static string GetFormattedText(DependencyObject element)
+ {
+ return (string) element.GetValue(FormattedTextProperty);
+ }
+
+ private static void FormattedTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
+ {
+ var value = eventArgs.NewValue as string;
+ var textBlock = sender as TextBlock;
+
+ if (textBlock != null)
+ {
+ textBlock.Inlines.Clear();
+ textBlock.Inlines.Add(Convert(value));
+ }
+ }
+
+ private static Inline Convert(string value)
+ {
+ var doc = new XmlDocument();
+ doc.LoadXml(value);
+
+ var span = new Span();
+ ConvertNode(span, doc.ChildNodes[0]);
+
+ return span;
+ }
+
+ private static void ConvertNode(Span span, XmlNode xmlNode)
+ {
+ foreach (XmlNode child in xmlNode)
+ {
+ if (child is XmlText)
+ {
+ span.Inlines.Add(new Run(child.InnerText));
+ }
+ else if (child is XmlElement)
+ {
+ switch (child.Name.ToUpper())
+ {
+ case "BOLD":
+ var boldSpan = new Span();
+ ConvertNode(boldSpan, child);
+ var bold = new Bold(boldSpan);
+ span.Inlines.Add(bold);
+ break;
+ default:
+ span.Inlines.Add(new Run(child.InnerText));
+ break;
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.GraphSharp.Forms/Templates/PointedTreeGraphTemplate.xaml
===================================================================
diff -u -r6189fae3f21e2ee5eac80441472c2bcd5124c3da -r942a8295ee5a7cd872048d3a2397049fc6531ebb
--- Core/Components/src/Core.Components.GraphSharp.Forms/Templates/PointedTreeGraphTemplate.xaml (.../PointedTreeGraphTemplate.xaml) (revision 6189fae3f21e2ee5eac80441472c2bcd5124c3da)
+++ Core/Components/src/Core.Components.GraphSharp.Forms/Templates/PointedTreeGraphTemplate.xaml (.../PointedTreeGraphTemplate.xaml) (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -27,7 +27,8 @@
xmlns:graphSharpConverters="clr-namespace:GraphSharp.Converters;assembly=GraphSharp.Controls"
xmlns:wpfExtensionsAttachedBehaviours="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions"
xmlns:wpfExtensionsControls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
- xmlns:converters="clr-namespace:Core.Components.GraphSharp.Forms.Converters;assembly=Core.Components.GraphSharp.Forms">
+ xmlns:converters="clr-namespace:Core.Components.GraphSharp.Forms.Converters;assembly=Core.Components.GraphSharp.Forms"
+ xmlns:extensions="clr-namespace:Core.Components.GraphSharp.Forms.Extensions;assembly=Core.Components.GraphSharp.Forms">
@@ -49,12 +50,12 @@
-
+
@@ -72,7 +73,10 @@
-
+
Index: Core/Components/test/Core.Components.GraphSharp.Forms.Test/Core.Components.GraphSharp.Forms.Test.csproj
===================================================================
diff -u -r7824b1299ee61690e6bbbb5e665c80e516813653 -r942a8295ee5a7cd872048d3a2397049fc6531ebb
--- Core/Components/test/Core.Components.GraphSharp.Forms.Test/Core.Components.GraphSharp.Forms.Test.csproj (.../Core.Components.GraphSharp.Forms.Test.csproj) (revision 7824b1299ee61690e6bbbb5e665c80e516813653)
+++ Core/Components/test/Core.Components.GraphSharp.Forms.Test/Core.Components.GraphSharp.Forms.Test.csproj (.../Core.Components.GraphSharp.Forms.Test.csproj) (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -85,6 +85,7 @@
Properties\GlobalAssembly.cs
+
Index: Core/Components/test/Core.Components.GraphSharp.Forms.Test/Extensions/TextBlockExtensionsTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.GraphSharp.Forms.Test/Extensions/TextBlockExtensionsTest.cs (revision 0)
+++ Core/Components/test/Core.Components.GraphSharp.Forms.Test/Extensions/TextBlockExtensionsTest.cs (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -0,0 +1,159 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.ComponentModel;
+using System.Linq;
+using System.Threading;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using Core.Components.GraphSharp.Forms.Extensions;
+using NUnit.Framework;
+
+namespace Core.Components.GraphSharp.Forms.Test.Extensions
+{
+ [TestFixture]
+ public class TextBlockExtensionsTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ DependencyPropertyDescriptor dependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(TextBlockExtensions.FormattedTextProperty, typeof(TextBlock));
+
+ // Assert
+ Assert.AreEqual("FormattedText", dependencyPropertyDescriptor.DependencyProperty.Name);
+ Assert.AreEqual(typeof(TextBlockExtensions), dependencyPropertyDescriptor.DependencyProperty.OwnerType);
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void SetFormattedText_ValidXmlWithoutChildNodes_ConvertToInlines()
+ {
+ // Setup
+ const string xmlToConvert = "test";
+ var textBlock = new TextBlock();
+
+ // Precondition
+ CollectionAssert.IsEmpty(textBlock.Inlines);
+
+ // Call
+ TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);
+
+ // Assert
+ Assert.AreEqual(1, textBlock.Inlines.Count);
+ var span = (Span) textBlock.Inlines.First();
+
+ Assert.AreEqual(1, span.Inlines.Count);
+ var run = (Run) span.Inlines.First();
+ Assert.AreEqual("test", run.Text);
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void SetFormattedText_ValidXmlWithSupportedChildNode_ConvertToInlines()
+ {
+ // Setup
+ const string xmlToConvert = "test bold text";
+ var textBlock = new TextBlock();
+
+ // Precondition
+ CollectionAssert.IsEmpty(textBlock.Inlines);
+
+ // Call
+ TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);
+
+ // Assert
+ Assert.AreEqual(1, textBlock.Inlines.Count);
+ var span = (Span) textBlock.Inlines.First();
+
+ Inline[] spanInlines = span.Inlines.ToArray();
+
+ Assert.AreEqual(2, spanInlines.Length);
+ var run = (Run) spanInlines[0];
+ Assert.AreEqual("test ", run.Text);
+
+ var bold = (Bold) spanInlines[1];
+ var boldSpan = (Span) bold.Inlines.First();
+
+ Assert.AreEqual("bold text", ((Run) boldSpan.Inlines.First()).Text);
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void SetFormattedText_ValidXmlWithUnsupportedChildNode_ConvertToInlines()
+ {
+ // Setup
+ const string xmlToConvert = "test unsupported node";
+ var textBlock = new TextBlock();
+
+ // Precondition
+ CollectionAssert.IsEmpty(textBlock.Inlines);
+
+ // Call
+ TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);
+
+ // Assert
+ Assert.AreEqual(1, textBlock.Inlines.Count);
+ var span = (Span) textBlock.Inlines.First();
+
+ Inline[] spanInlines = span.Inlines.ToArray();
+
+ Assert.AreEqual(2, spanInlines.Length);
+ var run = (Run) spanInlines[0];
+ Assert.AreEqual("test ", run.Text);
+
+ var unsupportedNodeRune = (Run) spanInlines[1];
+ Assert.AreEqual("unsupported node", unsupportedNodeRune.Text);
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void GetFormattedText_DefaultValue_ReturnNull()
+ {
+ // Setup
+ var textBlock = new TextBlock();
+
+ // Call
+ string formattedText = TextBlockExtensions.GetFormattedText(textBlock);
+
+ // Assert
+ Assert.IsNull(formattedText);
+
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void GetFormattedText_TextSet_ReturnText()
+ {
+ // Setup
+ const string xmlToConvert = "test bold text";
+ var textBlock = new TextBlock();
+
+ TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);
+
+ // Call
+ string formattedText = TextBlockExtensions.GetFormattedText(textBlock);
+
+ // Assert
+ Assert.AreEqual(xmlToConvert, formattedText);
+ }
+ }
+}
\ No newline at end of file
Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/OpenPointedTreeGraphViewCommand.cs
===================================================================
diff -u -r8b20e259d5d28d37106ec402ac131f710680f009 -r942a8295ee5a7cd872048d3a2397049fc6531ebb
--- Demo/Ringtoets/src/Demo.Ringtoets/Commands/OpenPointedTreeGraphViewCommand.cs (.../OpenPointedTreeGraphViewCommand.cs) (revision 8b20e259d5d28d37106ec402ac131f710680f009)
+++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/OpenPointedTreeGraphViewCommand.cs (.../OpenPointedTreeGraphViewCommand.cs) (revision 942a8295ee5a7cd872048d3a2397049fc6531ebb)
@@ -56,26 +56,26 @@
var lastNodeStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightSkyBlue, Color.Black, 1);
var treeNodeStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightGray, Color.Black, 1);
- var doubleUsedNode = new GraphNode("Double used", new[]
+ var doubleUsedNode = new GraphNode("Double used", new[]
{
- new GraphNode("En", new []
+ new GraphNode("En", new []
{
- new GraphNode("Child 2", new GraphNode[0], false, lastNodeStyle),
- new GraphNode("Child 3", new GraphNode[0], false, lastNodeStyle),
+ new GraphNode("Child 2", new GraphNode[0], false, lastNodeStyle),
+ new GraphNode("Child 3", new GraphNode[0], false, lastNodeStyle),
}, false, diamondStyle),
- new GraphNode("Child 4", new GraphNode[0], false, lastNodeStyle),
+ new GraphNode("Child 4", new GraphNode[0], false, lastNodeStyle),
}, false, treeNodeStyle);
- var node = new GraphNode("Root", new[]
+ var node = new GraphNode("Root", new[]
{
- new GraphNode("Of", new[]
+ new GraphNode("Of", new[]
{
doubleUsedNode,
- new GraphNode("Child 1", new[]
+ new GraphNode("Child 1", new[]
{
- new GraphNode("Of", new[]
+ new GraphNode("Of", new[]
{
- new GraphNode("Child 5", new GraphNode[0], false, lastNodeStyle),
+ new GraphNode("Child 5", new GraphNode[0], false, lastNodeStyle),
doubleUsedNode
}, false, diamondStyle),
}, false, treeNodeStyle)