Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/XAxisDescriptor.cs @ 2608

Last change on this file since 2608 was 1996, checked in by mstoeger, 15 years ago

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

File size: 3.5 KB
RevLine 
[1996]1using System;
2using System.Collections.Generic;
[1885]3using System.Drawing;
[1996]4using System.Xml;
5using HeuristicLab.Core;
[1880]6using HeuristicLab.Visualization.LabelProvider;
7
8namespace HeuristicLab.Visualization {
9  public delegate void XAxisDescriptorChangedHandler(XAxisDescriptor sender);
10
[1996]11  public class XAxisDescriptor : StorableBase {
[1881]12    private string label = "";
[1993]13    private Font font = new Font("Arial", 8);
14    private Color color = Color.Blue;
[1881]15    private bool showLabel = true;
16    private bool showGrid = true;
[1885]17    private Color gridColor = Color.LightBlue;
[1881]18    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
[1880]19
20    public event XAxisDescriptorChangedHandler XAxisDescriptorChanged;
21
[1993]22    public string Label {
23      get { return label; }
[1880]24      set {
[1993]25        label = value;
[1880]26        FireXAxisDescriptorChanged();
27      }
28    }
29
[1993]30    public Font Font {
31      get { return font; }
[1880]32      set {
[1993]33        font = value;
[1880]34        FireXAxisDescriptorChanged();
35      }
36    }
37
[1993]38    public Color Color {
39      get { return color; }
[1880]40      set {
[1993]41        color = value;
[1880]42        FireXAxisDescriptorChanged();
43      }
44    }
45
[1881]46    public bool ShowLabel {
47      get { return showLabel; }
[1880]48      set {
[1881]49        showLabel = value;
[1880]50        FireXAxisDescriptorChanged();
51      }
52    }
53
[1993]54    public bool ShowGrid {
55      get { return showGrid; }
56      set {
57        this.showGrid = value;
58        FireXAxisDescriptorChanged();
59      }
60    }
61
[1885]62    public Color GridColor {
63      get { return this.gridColor; }
64      set {
65        this.gridColor = value;
66        FireXAxisDescriptorChanged();
67      }
68    }
69
[1993]70    public ILabelProvider LabelProvider {
71      get { return labelProvider; }
72      set {
73        this.labelProvider = value;
74        FireXAxisDescriptorChanged();
75      }
76    }
77
[1880]78    private void FireXAxisDescriptorChanged() {
79      if (XAxisDescriptorChanged != null)
80        XAxisDescriptorChanged(this);
81    }
[1996]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    }
[1880]110  }
111}
Note: See TracBrowser for help on using the repository browser.