Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1996


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

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

Location:
trunk/sources
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/3.2/LineChartPersistenceTests.cs

    r1993 r1996  
    9898      Assert.AreEqual(10.3, restoredModel.Rows[0][1]);
    9999      Assert.AreEqual(5, restoredModel.Rows[0][2]);
     100      Assert.AreEqual(0, restoredModel.Rows[0].MinValue);
     101      Assert.AreEqual(10.3, restoredModel.Rows[0].MaxValue);
    100102
    101103      Assert.AreEqual(true, restoredModel.Rows[0].YAxis.ClipChangeable);
     
    119121      Assert.AreEqual(2, restoredModel.Rows[1][1]);
    120122      Assert.AreEqual(3, restoredModel.Rows[1][2]);
     123      Assert.AreEqual(1, restoredModel.Rows[1].MinValue);
     124      Assert.AreEqual(3, restoredModel.Rows[1].MaxValue);
    121125
    122126      Assert.AreEqual(false, restoredModel.Rows[1].YAxis.ClipChangeable);
  • trunk/sources/HeuristicLab.Visualization/3.2/AvgAggregator.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Xml;
    43
    54namespace HeuristicLab.Visualization {
     
    148147    }
    149148
    150     public override XmlNode ToXml(XmlDocument document)
    151     {
    152       throw new System.NotImplementedException();
    153     }
    154 
    155     public override IDataRow FromXml(XmlNode xmlNode)
    156     {
    157       throw new System.NotImplementedException();
    158     }
    159 
    160149    #endregion
    161150  }
  • trunk/sources/HeuristicLab.Visualization/3.2/AvgLineAggregator.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Xml;
    43
    54namespace HeuristicLab.Visualization {
     
    159158    }
    160159
    161     public override XmlNode ToXml(XmlDocument document)
    162     {
    163       throw new System.NotImplementedException();
    164     }
    165 
    166     public override IDataRow FromXml(XmlNode xmlNode)
    167     {
    168       throw new System.NotImplementedException();
    169     }
    170 
    171160    #endregion
    172161  }
  • trunk/sources/HeuristicLab.Visualization/3.2/ChartDataRowsModel.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Drawing;
    4 using System.Globalization;
    53using System.Xml;
    64using HeuristicLab.Core;
    75using HeuristicLab.Visualization.Options;
    8 using HeuristicLab.Visualization.Test;
    96
    107namespace HeuristicLab.Visualization{
     
    1613    private string title = "Title";
    1714    private ViewSettings viewSettings = new ViewSettings();
    18     private readonly XAxisDescriptor xAxisDescriptor = new XAxisDescriptor();
     15    private XAxisDescriptor xAxisDescriptor;
    1916    private YAxisDescriptor defaultYAxisDescriptor = new YAxisDescriptor();
    2017    private readonly List<IDataRow> rows = new List<IDataRow>();
    2118
    2219    public ChartDataRowsModel() {
    23       this.XAxis.XAxisDescriptorChanged += delegate { OnModelChanged(); };
     20      this.XAxis = new XAxisDescriptor();
    2421    }
    2522
     
    3835    public XAxisDescriptor XAxis {
    3936      get { return xAxisDescriptor; }
     37      private set {
     38        this.xAxisDescriptor = value;
     39        this.xAxisDescriptor.XAxisDescriptorChanged += delegate { OnModelChanged(); };
     40      }
    4041    }
    4142
     
    125126
    126127      XmlSupport.SetAttribute("Title", title, node);
    127      
    128       List<YAxisDescriptor> yAxes = new List<YAxisDescriptor>();
    129       yAxes.Add(defaultYAxisDescriptor);
    130       foreach (IDataRow row in rows) {
    131         if (!yAxes.Contains(row.YAxis)) {
    132           yAxes.Add(row.YAxis);
    133         }
    134       }
    135 
    136       foreach (YAxisDescriptor yAxis in yAxes) {
    137         XmlNode yAxisElement = document.CreateElement("YAxis");
    138 
    139         XmlSupport.SetAttribute("Label", yAxis.Label, yAxisElement);
    140         XmlSupport.SetAttribute("GridColor", yAxis.GridColor.ToArgb().ToString(), yAxisElement);
    141         XmlSupport.SetAttribute("Position", yAxis.Position.ToString(), yAxisElement);
    142         XmlSupport.SetAttribute("ShowGrid", yAxis.ShowGrid ? "true" : "false", yAxisElement);
    143         XmlSupport.SetAttribute("ShowYAxis", yAxis.ShowYAxis ? "true" : "false", yAxisElement);
    144         XmlSupport.SetAttribute("ShowYAxisLabel", yAxis.ShowYAxisLabel ? "true" : "false", yAxisElement);
    145         XmlSupport.SetAttribute("ClipChangeable", yAxis.ClipChangeable ? "true" : "false", yAxisElement);
    146 
    147         if (yAxis == defaultYAxisDescriptor)
    148           XmlSupport.SetAttribute("Default", "true", yAxisElement);
    149 
    150         node.AppendChild(yAxisElement);
    151       }
    152 
    153       XmlNode xAxisElement = document.CreateElement("XAxis");
    154       XmlSupport.SetAttribute("Color", xAxisDescriptor.Color.ToArgb().ToString(), xAxisElement);
    155       XmlSupport.SetAttribute("GridColor", xAxisDescriptor.GridColor.ToArgb().ToString(), xAxisElement);
    156       XmlSupport.SetAttribute("Label", xAxisDescriptor.Label, xAxisElement);
    157       XmlSupport.SetAttribute("ShowGrid", xAxisDescriptor.ShowGrid ? "true" : "false", xAxisElement);
    158       XmlSupport.SetAttribute("ShowLabel", xAxisDescriptor.ShowLabel ? "true" : "false", xAxisElement);
    159       node.AppendChild(xAxisElement);
    160128
    161129      foreach (IDataRow row in rows) {
    162         node.AppendChild(row.ToXml(document));
     130        node.AppendChild(PersistenceManager.Persist("DataRow", row, document, persistedObjects));
    163131      }
    164 
    165       node.AppendChild(XAxis.LabelProvider.GetLabelProviderXmlNode(document));
     132      node.AppendChild(PersistenceManager.Persist("DefaultYAxis", this.DefaultYAxis, document, persistedObjects));
     133      node.AppendChild(PersistenceManager.Persist("XAxis", this.XAxis, document, persistedObjects));
    166134
    167135      return node;
     
    173141      title = XmlSupport.GetAttribute("Title", "", node);
    174142
    175       List<YAxisDescriptor> yAxes = new List<YAxisDescriptor>();
    176       foreach (XmlNode yAxisNode in node.SelectNodes("YAxis")) {
    177         YAxisDescriptor yAxis = new YAxisDescriptor();
    178         yAxis.Label = XmlSupport.GetAttribute("Label", "", yAxisNode);
    179         yAxis.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), yAxisNode)));
    180         yAxis.Position = (AxisPosition)Enum.Parse(typeof(AxisPosition), XmlSupport.GetAttribute("Position", "Left", yAxisNode));
    181         yAxis.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", yAxisNode) == "true";
    182         yAxis.ShowYAxis = XmlSupport.GetAttribute("ShowYAxis", "true", yAxisNode) == "true";
    183         yAxis.ShowYAxisLabel = XmlSupport.GetAttribute("ShowYAxisLabel", "true", yAxisNode) == "true";
    184         yAxis.ClipChangeable = XmlSupport.GetAttribute("ClipChangeable", "true", yAxisNode) == "true";
    185         yAxes.Add(yAxis);
    186 
    187         if (XmlSupport.GetAttribute("Default", null, yAxisNode) != null)
    188           defaultYAxisDescriptor = yAxis;
     143      foreach (XmlNode dataRowNode in node.SelectNodes("DataRow")) {
     144        IDataRow dataRow = (IDataRow)PersistenceManager.Restore(dataRowNode, restoredObjects);
     145        AddDataRow(dataRow);
    189146      }
    190147
    191       XmlNode xAxisElement = node.SelectSingleNode("XAxis");
    192       if (xAxisElement != null) {
    193         xAxisDescriptor.Color = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("Color", Color.Blue.ToArgb().ToString(), xAxisElement)));
    194         xAxisDescriptor.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), xAxisElement)));
    195         xAxisDescriptor.Label = XmlSupport.GetAttribute("Label", "", xAxisElement);
    196         xAxisDescriptor.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", xAxisElement) == "true";
    197         xAxisDescriptor.ShowLabel = XmlSupport.GetAttribute("ShowLabel", "true", xAxisElement) == "true";
    198       }
     148      XmlNode defaultYAxisNode = node.SelectSingleNode("DefaultYAxis");
     149      if (defaultYAxisNode != null)
     150        this.defaultYAxisDescriptor = (YAxisDescriptor)PersistenceManager.Restore(defaultYAxisNode, restoredObjects);
    199151
    200       XmlNode xAxisLabelProviderNode = node.SelectSingleNode("LabelProvider");
    201       xAxisDescriptor.LabelProvider = xAxisDescriptor.LabelProvider.PopulateLabelProviderXmlNode(xAxisLabelProviderNode);
    202 
    203       foreach (XmlNode dataRow in node.SelectNodes("Row")) {
    204         string rowLabel = XmlSupport.GetAttribute("Label", "", dataRow);
    205 
    206         DataRow row = new DataRow();
    207         row.RowSettings.Label = rowLabel;
    208         row.RowSettings.Color = Color.FromArgb(Int32.Parse(XmlSupport.GetAttribute("Color", Color.Black.ToArgb().ToString(), dataRow)));
    209         row.RowSettings.LineType = (DataRowType)Enum.Parse(typeof(DataRowType), XmlSupport.GetAttribute("LineType", "Normal", dataRow));
    210         row.RowSettings.Thickness = Int32.Parse(XmlSupport.GetAttribute("Thickness", "2", dataRow));
    211         row.RowSettings.ShowMarkers = XmlSupport.GetAttribute("ShowMarkers", "true", dataRow) == "true";
    212         row.RowSettings.Style = (DrawingStyle)Enum.Parse(typeof (DrawingStyle), XmlSupport.GetAttribute("Style", DrawingStyle.Solid.ToString(), dataRow));
    213 
    214         foreach (YAxisDescriptor yAxis in yAxes) {
    215           if (yAxis.Label.Equals(XmlSupport.GetAttribute("YAxis", dataRow)))
    216             row.YAxis = yAxis;
    217         }
    218 
    219         string[] tokens = dataRow.InnerText.Split(';');
    220         foreach (string token in tokens) {
    221           double value = double.Parse(token, CultureInfo.InvariantCulture);
    222           row.AddValue(value);
    223         }
    224 
    225         AddDataRow(row);
    226       }
     152      XmlNode xAxisNode = node.SelectSingleNode("XAxis");
     153      if (xAxisNode != null)
     154        this.XAxis = (XAxisDescriptor)PersistenceManager.Restore(xAxisNode, restoredObjects);
    227155    }
    228156  }
  • trunk/sources/HeuristicLab.Visualization/3.2/DataRow.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
     3using System.Drawing;
    34using System.Globalization;
    45using System.Xml;
     6using HeuristicLab.Core;
    57
    68namespace HeuristicLab.Visualization {
     
    156158    }
    157159
    158     public override XmlNode ToXml(XmlDocument document) {
    159       XmlNode columnElement = document.CreateNode(XmlNodeType.Element, "Row", null);
    160 
    161       XmlSupport.SetAttribute("Label", RowSettings.Label, columnElement);
    162       XmlSupport.SetAttribute("Color", RowSettings.Color.ToArgb().ToString(), columnElement);
    163       XmlSupport.SetAttribute("LineType", RowSettings.LineType.ToString(), columnElement);
    164       XmlSupport.SetAttribute("Thickness", RowSettings.Thickness.ToString(), columnElement);
    165       XmlSupport.SetAttribute("ShowMarkers", RowSettings.ShowMarkers ? "true" : "false", columnElement);
    166       XmlSupport.SetAttribute("Style", RowSettings.Style.ToString(), columnElement);
    167 
    168       XmlSupport.SetAttribute("YAxis", YAxis.Label, columnElement);
    169 
    170       List<string> strValues = new List<string>();
    171       for (int i = 0; i < this.Count; i++) {
    172         strValues.Add(this[i].ToString(CultureInfo.InvariantCulture));
    173       }
    174       columnElement.InnerText = string.Join(";", strValues.ToArray());
    175 
    176       return columnElement;
    177     }
    178 
    179     public override IDataRow FromXml(XmlNode xmlNode)
    180     {
    181       throw new System.NotImplementedException();
    182     }
    183 
    184160    private void UpdateMinMaxValue(double newValue, int oldValueIndex) {
    185161      if (minValue != dataRow[oldValueIndex] && maxValue != dataRow[oldValueIndex])
     
    200176      minValue = Math.Min(value, minValue);
    201177    }
     178
     179    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     180      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     181
     182      XmlSupport.SetAttribute("Label", RowSettings.Label, node);
     183      XmlSupport.SetAttribute("Color", RowSettings.Color.ToArgb().ToString(), node);
     184      XmlSupport.SetAttribute("LineType", RowSettings.LineType.ToString(), node);
     185      XmlSupport.SetAttribute("Thickness", RowSettings.Thickness.ToString(), node);
     186      XmlSupport.SetAttribute("ShowMarkers", RowSettings.ShowMarkers ? "true" : "false", node);
     187      XmlSupport.SetAttribute("Style", RowSettings.Style.ToString(), node);
     188
     189      node.AppendChild(PersistenceManager.Persist("YAxis", this.YAxis, document, persistedObjects));
     190
     191      List<string> strValues = new List<string>();
     192      for (int i = 0; i < this.Count; i++) {
     193        strValues.Add(this[i].ToString(CultureInfo.InvariantCulture));
     194      }
     195      XmlElement valuesElement = document.CreateElement("Values");
     196      valuesElement.InnerText = string.Join(";", strValues.ToArray());
     197      node.AppendChild(valuesElement);
     198
     199      return node;
     200    }
     201
     202    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     203      base.Populate(node, restoredObjects);
     204
     205      this.RowSettings.Label = XmlSupport.GetAttribute("Label", "", node);
     206      this.RowSettings.Color = Color.FromArgb(Int32.Parse(XmlSupport.GetAttribute("Color", Color.Black.ToArgb().ToString(), node)));
     207      this.RowSettings.LineType = (DataRowType)Enum.Parse(typeof(DataRowType), XmlSupport.GetAttribute("LineType", "Normal", node));
     208      this.RowSettings.Thickness = Int32.Parse(XmlSupport.GetAttribute("Thickness", "2", node));
     209      this.RowSettings.ShowMarkers = XmlSupport.GetAttribute("ShowMarkers", "true", node) == "true";
     210      this.RowSettings.Style = (DrawingStyle)Enum.Parse(typeof(DrawingStyle), XmlSupport.GetAttribute("Style", DrawingStyle.Solid.ToString(), node));
     211
     212      XmlNode yAxisNode = node.SelectSingleNode("YAxis");
     213      if (yAxisNode != null) {
     214        this.YAxis = (YAxisDescriptor)PersistenceManager.Restore(yAxisNode, restoredObjects);
     215      }
     216
     217      XmlNode valuesNode = node.SelectSingleNode("Values");
     218      if (valuesNode != null) {
     219        string[] strValues = valuesNode.InnerText.Split(';');
     220        foreach (string strValue in strValues) {
     221          double value = double.Parse(strValue, CultureInfo.InvariantCulture);
     222          this.AddValue(value);
     223        }
     224      }
     225    }
    202226  }
    203227}
  • trunk/sources/HeuristicLab.Visualization/3.2/DataRowBase.cs

    r1993 r1996  
    1 using System.Xml;
     1using HeuristicLab.Core;
    22using HeuristicLab.Visualization.Options;
    33
    44namespace HeuristicLab.Visualization {
    5   public abstract class DataRowBase : IDataRow {
    6     private YAxisDescriptor yAxis;
     5  public abstract class DataRowBase : StorableBase, IDataRow {
     6    protected YAxisDescriptor yAxis;
    77
    88    private DataRowSettings rowSettings ;
     
    1717    }
    1818
    19     public DataRowBase() {
     19    protected DataRowBase() {
    2020      rowSettings = new DataRowSettings();
    2121      rowSettings.DataVisualSettingChanged += value_DataVisualSettingChanged;
     
    5555
    5656    public abstract void AddValue(double value);
    57 
    5857    public abstract void AddValue(double value, int index);
    59 
    6058    public abstract void AddValues(double[] values);
    61 
    6259    public abstract void AddValues(double[] values, int index);
    63 
    6460    public abstract void ModifyValue(double value, int index);
    65 
    6661    public abstract void ModifyValues(double[] values, int index);
    67 
    6862    public abstract void RemoveValue(int index);
    69 
    7063    public abstract void RemoveValues(int index, int count);
    7164
     
    7568
    7669    public abstract double MinValue { get; }
    77 
    7870    public abstract double MaxValue { get; }
    7971
    80     public abstract XmlNode ToXml(XmlDocument document);
    81     public abstract IDataRow FromXml(XmlNode xmlNode);
    82    
    83 
    8472    public event ValuesChangedHandler ValuesChanged;
    85 
    8673    public event ValueChangedHandler ValueChanged;
    87 
    8874    public event DataRowChangedHandler DataRowChanged;
    8975  }
  • trunk/sources/HeuristicLab.Visualization/3.2/FloatingAvgAggregator.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Xml;
    43
    54namespace HeuristicLab.Visualization {
     
    182181    }
    183182
    184     public override XmlNode ToXml(XmlDocument document)
    185     {
    186       throw new System.NotImplementedException();
    187     }
    188 
    189     public override IDataRow FromXml(XmlNode xmlNode)
    190     {
    191       throw new System.NotImplementedException();
    192     }
    193 
    194183    #endregion
    195184  }
  • trunk/sources/HeuristicLab.Visualization/3.2/IDataRow.cs

    r1993 r1996  
    1 using System.Xml;
     1using HeuristicLab.Core;
    22using HeuristicLab.Visualization.Options;
    33
     
    88  }
    99
    10   public interface IDataRow {
     10  public interface IDataRow : IStorable {
    1111    DataRowSettings RowSettings { get; set; }
    1212 
     
    3030    double MaxValue { get; }
    3131
    32     XmlNode ToXml(XmlDocument document);
    33     IDataRow FromXml(XmlNode xmlNode);
    34 
    3532    event ValuesChangedHandler ValuesChanged;
    3633    event ValueChangedHandler ValueChanged;
  • 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  }
  • trunk/sources/HeuristicLab.Visualization/3.2/MaxAggregator.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Xml;
    43
    54namespace HeuristicLab.Visualization {
     
    116115    }
    117116
    118     public override XmlNode ToXml(XmlDocument document)
    119     {
    120       throw new System.NotImplementedException();
    121     }
    122 
    123     public override IDataRow FromXml(XmlNode xmlNode)
    124     {
    125       throw new System.NotImplementedException();
    126     }
    127 
    128117    #endregion
    129118  }
  • trunk/sources/HeuristicLab.Visualization/3.2/MinAggregator.cs

    r1993 r1996  
    11using System;
    22using System.Collections.Generic;
    3 using System.Xml;
    43
    54namespace HeuristicLab.Visualization {
     
    117116    }
    118117
    119     public override XmlNode ToXml(XmlDocument document)
    120     {
    121       throw new System.NotImplementedException();
    122     }
    123 
    124     public override IDataRow FromXml(XmlNode xmlNode)
    125     {
    126       throw new System.NotImplementedException();
    127     }
    128 
    129118    #endregion
    130119  }
  • trunk/sources/HeuristicLab.Visualization/3.2/XAxisDescriptor.cs

    r1993 r1996  
     1using System;
     2using System.Collections.Generic;
    13using System.Drawing;
     4using System.Xml;
     5using HeuristicLab.Core;
    26using HeuristicLab.Visualization.LabelProvider;
    37
     
    59  public delegate void XAxisDescriptorChangedHandler(XAxisDescriptor sender);
    610
    7   public class XAxisDescriptor {
     11  public class XAxisDescriptor : StorableBase {
    812    private string label = "";
    913    private Font font = new Font("Arial", 8);
     
    7680        XAxisDescriptorChanged(this);
    7781    }
     82
     83    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     84      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     85
     86      XmlSupport.SetAttribute("Color", this.Color.ToArgb().ToString(), node);
     87      XmlSupport.SetAttribute("GridColor", this.GridColor.ToArgb().ToString(), node);
     88      XmlSupport.SetAttribute("Label", this.Label, node);
     89      XmlSupport.SetAttribute("ShowGrid", this.ShowGrid ? "true" : "false", node);
     90      XmlSupport.SetAttribute("ShowLabel", this.ShowLabel ? "true" : "false", node);
     91
     92      node.AppendChild(PersistenceManager.Persist("LabelProvider", this.LabelProvider, document, persistedObjects));
     93
     94      return node;
     95    }
     96
     97    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     98      base.Populate(node, restoredObjects);
     99
     100      this.Color = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("Color", Color.Blue.ToArgb().ToString(), node)));
     101      this.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), node)));
     102      this.Label = XmlSupport.GetAttribute("Label", "", node);
     103      this.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", node) == "true";
     104      this.ShowLabel = XmlSupport.GetAttribute("ShowLabel", "true", node) == "true";
     105
     106      XmlNode labelProviderNode = node.SelectSingleNode("XAxis");
     107      if (labelProviderNode != null)
     108        this.labelProvider = (ILabelProvider)PersistenceManager.Restore(labelProviderNode, restoredObjects);
     109    }
    78110  }
    79111}
  • trunk/sources/HeuristicLab.Visualization/3.2/YAxisDescriptor.cs

    r1969 r1996  
    22using System.Collections.Generic;
    33using System.Drawing;
     4using System.Xml;
     5using HeuristicLab.Core;
    46using HeuristicLab.Visualization.LabelProvider;
    57using HeuristicLab.Visualization.Test;
     
    810  public delegate void YAxisDescriptorChangedHandler(YAxisDescriptor sender);
    911
    10   public class YAxisDescriptor {
    11     private ILabelProvider yAxisLabelProvider = new ContinuousLabelProvider("0.##");
     12  public class YAxisDescriptor : StorableBase {
     13    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
    1214    private readonly List<IDataRow> dataRows = new List<IDataRow>();
    1315    private bool showYAxis = true;
     
    4850    }
    4951
    50     public ILabelProvider YAxisLabelProvider {
    51       get { return yAxisLabelProvider; }
     52    public ILabelProvider LabelProvider {
     53      get { return labelProvider; }
    5254      set {
    53         yAxisLabelProvider = value;
     55        labelProvider = value;
    5456        OnYAxisDescriptorChanged();
    5557      }
     
    124126      OnYAxisDescriptorChanged();
    125127    }
     128
     129    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     130      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     131
     132      XmlSupport.SetAttribute("Label", this.Label, node);
     133      XmlSupport.SetAttribute("GridColor", this.GridColor.ToArgb().ToString(), node);
     134      XmlSupport.SetAttribute("Position", this.Position.ToString(), node);
     135      XmlSupport.SetAttribute("ShowGrid", this.ShowGrid ? "true" : "false", node);
     136      XmlSupport.SetAttribute("ShowYAxis", this.ShowYAxis ? "true" : "false", node);
     137      XmlSupport.SetAttribute("ShowYAxisLabel", this.ShowYAxisLabel ? "true" : "false", node);
     138      XmlSupport.SetAttribute("ClipChangeable", this.ClipChangeable ? "true" : "false", node);
     139
     140      node.AppendChild(PersistenceManager.Persist("LabelProvider", this.LabelProvider, document, persistedObjects));
     141
     142      foreach (IDataRow row in dataRows) {
     143        node.AppendChild(PersistenceManager.Persist("DataRow", row, document, persistedObjects));
     144      }
     145
     146      return node;
     147    }
     148
     149    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     150      base.Populate(node, restoredObjects);
     151
     152      this.Label = XmlSupport.GetAttribute("Label", "", node);
     153      this.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), node)));
     154      this.Position = (AxisPosition)Enum.Parse(typeof(AxisPosition), XmlSupport.GetAttribute("Position", "Left", node));
     155      this.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", node) == "true";
     156      this.ShowYAxis = XmlSupport.GetAttribute("ShowYAxis", "true", node) == "true";
     157      this.ShowYAxisLabel = XmlSupport.GetAttribute("ShowYAxisLabel", "true", node) == "true";
     158      this.ClipChangeable = XmlSupport.GetAttribute("ClipChangeable", "true", node) == "true";
     159
     160      XmlNode labelProviderNode = node.SelectSingleNode("LabelProvider");
     161      if (labelProviderNode != null)
     162        this.labelProvider = (ILabelProvider)PersistenceManager.Restore(labelProviderNode, restoredObjects);
     163
     164      foreach (XmlNode dataRowNode in node.SelectNodes("DataRow")) {
     165        IDataRow row = (IDataRow)PersistenceManager.Restore(dataRowNode, restoredObjects);
     166        AddDataRow(row);
     167      }
     168    }
    126169  }
    127170}
Note: See TracChangeset for help on using the changeset viewer.