Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Logging/3.2/PointXYChart.cs @ 2508

Last change on this file since 2508 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.5 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 for point xy charts.
32  /// </summary>
33  public class PointXYChart : ItemBase, IVisualizationItem {
34    private ItemList myValues;
35    /// <summary>
36    /// Gets or sets the values of the current instance.
37    /// </summary>
38    /// <remarks>Calls <see cref="OnValuesChanged"/> in the setter.</remarks>
39    public ItemList Values {
40      get { return myValues; }
41      set {
42        if (value != myValues) {
43          myValues = value;
44          OnValuesChanged();
45        }
46      }
47    }
48
49    private BoolData myConnectDots;
50    /// <summary>
51    /// Gets or sets the flag whether the dots should be connected or not.
52    /// </summary>
53    /// <remarks>Calls <see cref="OnConnectDotsChanged"/> in the setter.</remarks>
54    public BoolData ConnectDots {
55      get { return myConnectDots; }
56      set {
57        if (value != myConnectDots) {
58          myConnectDots = value;
59          OnConnectDotsChanged();
60        }
61      }
62    }
63 
64         
65    /// <summary>
66    /// Initializes a new instance of <see cref="PointXYChart"/> with the <c>ConnectDots</c> flag set to
67    /// <c>true</c>.
68    /// </summary>
69    public PointXYChart() {
70      myConnectDots = new BoolData(true);
71    }
72    /// <summary>
73    /// Initializes a new instance of <see cref="PointXYChart"/> with the given <paramref name="connectDots"/>
74    /// flag and the specified <paramref name="values"/>.
75    /// </summary>
76    /// <param name="connectDots">The flag whether the dots should be connected or not.</param>
77    /// <param name="values">The values with which the current instance should be initialized.</param>
78    public PointXYChart(bool connectDots,ItemList values) {
79      myConnectDots = new BoolData(connectDots);
80      myValues = values;
81    }
82
83    /// <summary>
84    /// Clones the current instance (deep clone).
85    /// </summary>
86    /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
87    /// <see cref="Auxiliary"/>.</remarks>
88    /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
89    /// <returns>The cloned object as <see cref="PointXYChart"/>.</returns>
90    public override object Clone(IDictionary<Guid, object> clonedObjects) {
91      PointXYChart clone = (PointXYChart)base.Clone(clonedObjects);
92      clone.myValues = (ItemList)Auxiliary.Clone(Values, clonedObjects);
93      return clone;
94    }
95
96    /// <summary>
97    /// Creates a new instance of <see cref="PointXYChartView"/> to represent the current instance visually.
98    /// </summary>
99    /// <returns>The created view as <see cref="PointXYChartView"/>.</returns>
100    public override IView CreateView() {
101      return new PointXYChartView(this);
102    }
103
104    /// <summary>
105    /// Occurs when the values of the current instance have been changed.
106    /// </summary>
107    public event EventHandler ValuesChanged;
108    /// <summary>
109    /// Fires a <c>ValuesChanged</c> event.
110    /// </summary>
111    protected virtual void OnValuesChanged() {
112      if (ValuesChanged != null)
113        ValuesChanged(this, new EventArgs());
114    }
115    /// <summary>
116    /// Occurs when the boolean flag has been changed.
117    /// </summary>
118    public event EventHandler ConnectDotsChanged;
119    /// <summary>
120    /// Fires a <c>ConnectDotsChanged</c> event.
121    /// </summary>
122    protected virtual void OnConnectDotsChanged() {
123      if (ConnectDotsChanged != null)
124        ConnectDotsChanged(this, new EventArgs());
125    }
126
127    #region Persistence Methods
128    /// <summary>
129    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
130    /// </summary>
131    /// <remarks>The ConnectDots flag and the values of the current instance are saved as child nodes
132    /// with tag names <c>ConnectDots</c> and <c>Values</c> respectively.</remarks>
133    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
134    /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
135    /// <param name="persistedObjects">The dictionary of all already persisted objects.
136    /// (Needed to avoid cycles.)</param>
137    /// <returns>The saved <see cref="XmlNode"/>.</returns>
138    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
139      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
140      node.AppendChild(PersistenceManager.Persist("ConnectDots",ConnectDots,document,persistedObjects));
141      node.AppendChild(PersistenceManager.Persist("Values", Values, document, persistedObjects));
142      return node;
143    }
144    /// <summary>
145    /// Loads the persisted item from the specified <paramref name="node"/>.
146    /// </summary>
147    /// <remarks>Has to be saved in a special way, see <see cref="GetXmlNode"/> for further information.</remarks>
148    /// <param name="node">The <see cref="XmlNode"/> where the PointXYChart is saved.</param>
149    /// <param name="restoredObjects">The dictionary of all already restored objects.
150    /// (Needed to avoid cycles.)</param>
151    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
152      base.Populate(node, restoredObjects);
153      myConnectDots = (BoolData)PersistenceManager.Restore(node.SelectSingleNode("ConnectDots"), restoredObjects);
154      myValues = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Values"), restoredObjects);
155    }
156    #endregion
157  }
158}
Note: See TracBrowser for help on using the repository browser.