#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using HeuristicLab.Core;
using HeuristicLab.Data;
namespace HeuristicLab.Logging {
///
/// Class to represent a Linechart.
///
public class Linechart : ItemBase, IVisualizationItem {
private IntData myNumberOfLines;
///
/// Gets or sets the number of lines of the current instance.
///
/// Calls in the setter.
public int NumberOfLines {
get { return myNumberOfLines.Data; }
set {
if (value != myNumberOfLines.Data) {
myNumberOfLines.Data = value;
OnNumberOfLinesChanged();
}
}
}
private ItemList myValues;
///
/// Gets or sets the values of the current instance.
///
/// Calls in the setter.
public ItemList Values {
get { return myValues; }
set {
if (value != myValues) {
myValues = value;
OnValuesChanged();
}
}
}
///
/// Initializes a new instance of .
///
public Linechart() {
myNumberOfLines = new IntData(0);
}
///
/// Initializes a new instance of with the given
/// and the given .
///
/// The number of lines with which to initialize the current instance.
/// The values with which to initialize the current instance.
public Linechart(int numberOfLines, ItemList values) {
myNumberOfLines = new IntData(numberOfLines);
myValues = values;
}
///
/// Clones the current instance (deep clone).
///
/// Deep clone through method of helper class
/// .
/// Dictionary of all already clone objects. (Needed to avoid cycles.)
/// The cloned object as .
public override object Clone(IDictionary clonedObjects) {
Linechart clone = (Linechart)base.Clone(clonedObjects);
clone.myNumberOfLines = (IntData)Auxiliary.Clone(myNumberOfLines, clonedObjects);
clone.myValues = (ItemList)Auxiliary.Clone(Values, clonedObjects);
return clone;
}
///
/// Creates an instance of to represent the current instance visually.
///
/// The created view as .
public override IView CreateView() {
return new LinechartView(this);
}
///
/// Occurs when the number of lines has been changed.
///
public event EventHandler NumberOfLinesChanged;
///
/// Fires a new NumberOfLinesChanged event.
///
protected virtual void OnNumberOfLinesChanged() {
if (NumberOfLinesChanged != null)
NumberOfLinesChanged(this, new EventArgs());
}
///
/// Occurs when the values have been changed.
///
public event EventHandler ValuesChanged;
///
/// Fires a new ValuesChanged event.
///
protected virtual void OnValuesChanged() {
if (ValuesChanged != null)
ValuesChanged(this, new EventArgs());
}
#region Persistence Methods
///
/// Saves the current instance as in the specified .
///
/// The number of lines and the values are saved as child nodes with tag
/// name NumberOfLines and Values respectively.
/// The (tag)name of the .
/// The where to save the data.
/// The dictionary of all already persisted objects.
/// (Needed to avoid cycles.)
/// The saved .
public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary persistedObjects) {
XmlNode node = base.GetXmlNode(name, document, persistedObjects);
node.AppendChild(PersistenceManager.Persist("NumberOfLines", myNumberOfLines, document, persistedObjects));
node.AppendChild(PersistenceManager.Persist("Values", Values, document, persistedObjects));
return node;
}
///
/// Loads the persisted item from the specified .
///
/// Has to be saved in a special way, see for further information.
/// The where the Linechart is saved.
/// The dictionary of all already restored objects.
/// (Needed to avoid cycles.)
public override void Populate(XmlNode node, IDictionary restoredObjects) {
base.Populate(node, restoredObjects);
myNumberOfLines = (IntData)PersistenceManager.Restore(node.SelectSingleNode("NumberOfLines"), restoredObjects);
myValues = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Values"), restoredObjects);
}
#endregion
}
}