Free cookie consent management tool by TermsFeed Policy Generator

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

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