- Timestamp:
- 06/04/09 00:41:56 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/ContinuousLabelProvider.cs
r1993 r1996 1 1 using System.Globalization; 2 2 using System.Xml; 3 using HeuristicLab.Core; 3 4 4 5 namespace HeuristicLab.Visualization.LabelProvider { 5 public class ContinuousLabelProvider : ILabelProvider {6 private readonlystring format;6 public class ContinuousLabelProvider : StorableBase, ILabelProvider { 7 private string format; 7 8 8 9 public ContinuousLabelProvider() {} … … 16 17 } 17 18 18 public XmlNode GetLabelProviderXmlNode(XmlDocument document) 19 { 20 XmlNode lblProvInfo = document.CreateNode(XmlNodeType.Element, "LabelProvider", null); 21 lblProvInfo.InnerText = "ContinuousLabelProvider"; 19 public override XmlNode GetXmlNode(string name, XmlDocument document, System.Collections.Generic.IDictionary<System.Guid, IStorable> persistedObjects) { 20 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 22 21 23 XmlAttribute idFormat = document.CreateAttribute("format"); 24 idFormat.Value = this.format; 22 XmlSupport.SetAttribute("Format", format, node); 25 23 26 lblProvInfo.Attributes.Append(idFormat); 27 28 return lblProvInfo; 24 return node; 29 25 } 30 26 31 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) { 32 var labelProvider = new ContinuousLabelProvider(node.SelectSingleNode("//LabelProvider").Attributes[0].Value); 33 return labelProvider; 27 public override void Populate(XmlNode node, System.Collections.Generic.IDictionary<System.Guid, IStorable> restoredObjects) { 28 base.Populate(node, restoredObjects); 29 30 this.format = XmlSupport.GetAttribute("Format", "0", node); 34 31 } 35 32 } -
trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/DiscreteLabelProvider.cs
r1993 r1996 1 1 using System; 2 using System.Xml;2 using HeuristicLab.Core; 3 3 4 4 namespace HeuristicLab.Visualization.LabelProvider { 5 public class DiscreteLabelProvider : ILabelProvider {5 public class DiscreteLabelProvider : StorableBase, ILabelProvider { 6 6 public string GetLabel(double value) { 7 7 int index = (int)Math.Round(value); … … 13 13 return string.Empty; 14 14 } 15 16 public XmlNode GetLabelProviderXmlNode(XmlDocument document)17 {18 XmlNode lblProvInfo = document.CreateNode(XmlNodeType.Element, "LabelProvider", null);19 lblProvInfo.InnerText = "DiscreteLabelProvider";20 21 return lblProvInfo;22 }23 24 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) {25 var labelProvider = new DiscreteLabelProvider();26 return labelProvider;27 }28 15 } 29 16 } -
trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/ILabelProvider.cs
r1993 r1996 1 using System.Xml;1 using HeuristicLab.Core; 2 2 3 3 namespace HeuristicLab.Visualization.LabelProvider { 4 public interface ILabelProvider {4 public interface ILabelProvider : IStorable { 5 5 string GetLabel(double value); 6 XmlNode GetLabelProviderXmlNode(XmlDocument document);7 ILabelProvider PopulateLabelProviderXmlNode(XmlNode node);8 6 } 9 7 } -
trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/StringLabelProvider.cs
r1993 r1996 2 2 using System.Collections.Generic; 3 3 using System.Xml; 4 using HeuristicLab.Core; 4 5 5 6 namespace HeuristicLab.Visualization.LabelProvider { 6 public class StringLabelProvider : ILabelProvider {7 public class StringLabelProvider : StorableBase, ILabelProvider { 7 8 private readonly Dictionary<int, string> labels = new Dictionary<int, string>(); 8 9 … … 27 28 } 28 29 29 public XmlNode GetLabelProviderXmlNode(XmlDocument document) { 30 XmlNode lblProvInfo = document.CreateNode(XmlNodeType.Element, "LabelProvider", null); 31 lblProvInfo.InnerText = "StringLabelProvider"; 30 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 31 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 32 32 33 foreach (KeyValuePair<int, string> pair in labels) 34 { 35 XmlNode strLbl = document.CreateNode(XmlNodeType.Element, "String", null); 33 XmlNode labelsNode = document.CreateElement("Labels"); 36 34 37 XmlAttribute idStrLbl = document.CreateAttribute("id");38 i dStrLbl.Value = pair.Key.ToString();39 str Lbl.Attributes.Append(idStrLbl);35 foreach (KeyValuePair<int, string> pair in labels) { 36 int index = pair.Key; 37 string label = pair.Value; 40 38 41 strLbl.InnerText = pair.Value; 42 lblProvInfo.AppendChild(strLbl); 39 XmlNode labelNode = document.CreateElement("Label"); 40 41 XmlSupport.SetAttribute("Index", index.ToString(), labelNode); 42 XmlSupport.SetAttribute("Value", label, labelNode); 43 44 labelsNode.AppendChild(labelNode); 43 45 } 44 return lblProvInfo; 46 47 node.AppendChild(labelsNode); 48 49 return node; 45 50 } 46 51 47 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) {48 var labelProvider = new StringLabelProvider();52 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 53 base.Populate(node, restoredObjects); 49 54 50 foreach (XmlNode strLbl in node.SelectNodes("//String")) 51 { 52 labelProvider.SetLabel(int.Parse(strLbl.Attributes[0].Value), strLbl.InnerText); 55 foreach (XmlNode labelNode in node.SelectNodes("Labels/Label")) { 56 int index = int.Parse(XmlSupport.GetAttribute("Index", labelNode)); 57 string label = XmlSupport.GetAttribute("Value", labelNode); 58 59 this.SetLabel(index, label); 53 60 } 54 return labelProvider;55 61 } 56 62 }
Note: See TracChangeset
for help on using the changeset viewer.