Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/09 00:41:56 (16 years ago)
Author:
mstoeger
Message:

implemented IStorable and made use of the PersistenceManager wherever possible. #639

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  
    11using System.Globalization;
    22using System.Xml;
     3using HeuristicLab.Core;
    34
    45namespace HeuristicLab.Visualization.LabelProvider {
    5   public class ContinuousLabelProvider : ILabelProvider {
    6     private readonly string format;
     6  public class ContinuousLabelProvider : StorableBase, ILabelProvider {
     7    private string format;
    78
    89    public ContinuousLabelProvider() {}
     
    1617    }
    1718
    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);
    2221
    23       XmlAttribute idFormat = document.CreateAttribute("format");
    24       idFormat.Value = this.format;
     22      XmlSupport.SetAttribute("Format", format, node);
    2523
    26       lblProvInfo.Attributes.Append(idFormat);
    27 
    28       return lblProvInfo;
     24      return node;
    2925    }
    3026
    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);
    3431    }
    3532  }
  • trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/DiscreteLabelProvider.cs

    r1993 r1996  
    11using System;
    2 using System.Xml;
     2using HeuristicLab.Core;
    33
    44namespace HeuristicLab.Visualization.LabelProvider {
    5   public class DiscreteLabelProvider : ILabelProvider {
     5  public class DiscreteLabelProvider : StorableBase, ILabelProvider {
    66    public string GetLabel(double value) {
    77      int index = (int)Math.Round(value);
     
    1313        return string.Empty;
    1414    }
    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     }
    2815  }
    2916}
  • trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/ILabelProvider.cs

    r1993 r1996  
    1 using System.Xml;
     1using HeuristicLab.Core;
    22
    33namespace HeuristicLab.Visualization.LabelProvider {
    4   public interface ILabelProvider {
     4  public interface ILabelProvider : IStorable {
    55    string GetLabel(double value);
    6     XmlNode GetLabelProviderXmlNode(XmlDocument document);
    7     ILabelProvider PopulateLabelProviderXmlNode(XmlNode node);
    86  }
    97}
  • trunk/sources/HeuristicLab.Visualization/3.2/LabelProvider/StringLabelProvider.cs

    r1993 r1996  
    22using System.Collections.Generic;
    33using System.Xml;
     4using HeuristicLab.Core;
    45
    56namespace HeuristicLab.Visualization.LabelProvider {
    6   public class StringLabelProvider : ILabelProvider {
     7  public class StringLabelProvider : StorableBase, ILabelProvider {
    78    private readonly Dictionary<int, string> labels = new Dictionary<int, string>();
    89
     
    2728    }
    2829
    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);
    3232
    33       foreach (KeyValuePair<int, string> pair in labels)
    34       {
    35         XmlNode strLbl = document.CreateNode(XmlNodeType.Element, "String", null);
     33      XmlNode labelsNode = document.CreateElement("Labels");
    3634
    37         XmlAttribute idStrLbl = document.CreateAttribute("id");
    38         idStrLbl.Value = pair.Key.ToString();
    39         strLbl.Attributes.Append(idStrLbl);
     35      foreach (KeyValuePair<int, string> pair in labels) {
     36        int index = pair.Key;
     37        string label = pair.Value;
    4038
    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);
    4345      }
    44       return lblProvInfo;
     46
     47      node.AppendChild(labelsNode);
     48
     49      return node;
    4550    }
    4651
    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);
    4954
    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);
    5360      }
    54       return labelProvider;
    5561    }
    5662  }
Note: See TracChangeset for help on using the changeset viewer.