Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Logging/3.2/Linechart.cs @ 6452

Last change on this file since 6452 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 6.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Logging {
30  /// <summary>
31  /// Class to represent a Linechart.
32  /// </summary>
33  public class Linechart : ItemBase, IVisualizationItem {
34    private IntData myNumberOfLines;
35    /// <summary>
36    /// Gets or sets the number of lines of the current instance.
37    /// </summary>
38    /// <remarks>Calls <see cref="OnNumberOfLinesChanged"/> in the setter.</remarks>
39    public int NumberOfLines {
40      get { return myNumberOfLines.Data; }
41      set {
42        if (value != myNumberOfLines.Data) {
43          myNumberOfLines.Data = value;
44          OnNumberOfLinesChanged();
45        }
46      }
47    }
48    private ItemList myValues;
49    /// <summary>
50    /// Gets or sets the values of the current instance.
51    /// </summary>
52    /// <remarks>Calls <see cref="OnValuesChanged"/> in the setter.</remarks>
53    public ItemList Values {
54      get { return myValues; }
55      set {
56        if (value != myValues) {
57          myValues = value;
58          OnValuesChanged();
59        }
60      }
61    }
62
63
64    /// <summary>
65    /// Initializes a new instance of <see cref="Linechart"/>.
66    /// </summary>
67    public Linechart() {
68      myNumberOfLines = new IntData(0);
69    }
70    /// <summary>
71    /// Initializes a new instance of <see cref="Linechart"/> with the given <paramref name="numberOfLines"/>
72    /// and the given <paramref name="values"/>.
73    /// </summary>
74    /// <param name="numberOfLines">The number of lines with which to initialize the current instance.</param>
75    /// <param name="values">The values with which to initialize the current instance.</param>
76    public Linechart(int numberOfLines, ItemList values) {
77      myNumberOfLines = new IntData(numberOfLines);
78      myValues = values;
79    }
80
81    /// <summary>
82    /// Clones the current instance (deep clone).
83    /// </summary>
84    /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
85    /// <see cref="Auxiliary"/>.</remarks>
86    /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
87    /// <returns>The cloned object as <see cref="Linechart"/>.</returns>
88    public override object Clone(IDictionary<Guid, object> clonedObjects) {
89      Linechart clone = (Linechart)base.Clone(clonedObjects);
90      clone.myNumberOfLines = (IntData)Auxiliary.Clone(myNumberOfLines, clonedObjects);
91      clone.myValues = (ItemList)Auxiliary.Clone(Values, clonedObjects);
92      return clone;
93    }
94
95    /// <summary>
96    /// Creates an instance of <see cref="LinechartView"/> to represent the current instance visually.
97    /// </summary>
98    /// <returns>The created view as <see cref="LinechartView"/>.</returns>
99    public override IView CreateView() {
100      return new LinechartView(this);
101    }
102
103    /// <summary>
104    /// Occurs when the number of lines has been changed.
105    /// </summary>
106    public event EventHandler NumberOfLinesChanged;
107    /// <summary>
108    /// Fires a new <c>NumberOfLinesChanged</c> event.
109    /// </summary>
110    protected virtual void OnNumberOfLinesChanged() {
111      if (NumberOfLinesChanged != null)
112        NumberOfLinesChanged(this, new EventArgs());
113    }
114    /// <summary>
115    /// Occurs when the values have been changed.
116    /// </summary>
117    public event EventHandler ValuesChanged;
118    /// <summary>
119    /// Fires a new <c>ValuesChanged</c> event.
120    /// </summary>
121    protected virtual void OnValuesChanged() {
122      if (ValuesChanged != null)
123        ValuesChanged(this, new EventArgs());
124    }
125
126    #region Persistence Methods
127    /// <summary>
128    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
129    /// </summary>
130    /// <remarks>The number of lines and the values are saved as child nodes with tag
131    /// name <c>NumberOfLines</c> and <c>Values</c> respectively.</remarks>
132    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
133    /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
134    /// <param name="persistedObjects">The dictionary of all already persisted objects.
135    /// (Needed to avoid cycles.)</param>
136    /// <returns>The saved <see cref="XmlNode"/>.</returns>
137    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
138      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
139      node.AppendChild(PersistenceManager.Persist("NumberOfLines", myNumberOfLines, document, persistedObjects));
140      node.AppendChild(PersistenceManager.Persist("Values", Values, document, persistedObjects));
141      return node;
142    }
143    /// <summary>
144    /// Loads the persisted item from the specified <paramref name="node"/>.
145    /// </summary>
146    /// <remarks>Has to be saved in a special way, see <see cref="GetXmlNode"/> for further information.</remarks>
147    /// <param name="node">The <see cref="XmlNode"/> where the Linechart is saved.</param>
148    /// <param name="restoredObjects">The dictionary of all already restored objects.
149    /// (Needed to avoid cycles.)</param>
150    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
151      base.Populate(node, restoredObjects);
152      myNumberOfLines = (IntData)PersistenceManager.Restore(node.SelectSingleNode("NumberOfLines"), restoredObjects);
153      myValues = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Values"), restoredObjects);
154    }
155    #endregion
156  }
157}
Note: See TracBrowser for help on using the repository browser.