Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/EmptyBoxChartElementGenerator.cs @ 14128

Last change on this file since 14128 was 7210, checked in by epitzer, 13 years ago

#1696: Improve usability of BoxChart creator: add automatic positioning of new chart elements

File size: 3.7 KB
RevLine 
[7128]1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Drawing.Drawing2D;
5using System.Linq;
6using System.Text;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10using HeuristicLab.Optimization;
11using HeuristicLab.Parameters;
12using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
13
14namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
15 
16  [StorableClass]
17  public class EmptyBoxChartElementGenerator : ParameterizedNamedItem, IBoxChartElementGenerator {
18
19    public ValueParameter<IntValue> XParameter {
20      get { return (ValueParameter<IntValue>)Parameters["X"]; }
21    }
22    public ValueParameter<IntValue> YParameter {
23      get { return (ValueParameter<IntValue>)Parameters["Y"]; }
24    }
25    public ValueParameter<IntValue> RowSpanParameter {
26      get { return (ValueParameter<IntValue>)Parameters["RowSpan"]; }
27    }
28    public ValueParameter<IntValue> ColSpanParameter {
29      get { return (ValueParameter<IntValue>)Parameters["ColSpan"]; }
30    }
31
[7210]32    public int X {
33      get { return XParameter.Value.Value; }
34      set { XParameter.Value.Value = value; }
35    }
36    public int Y {
37      get { return YParameter.Value.Value; }
38      set { YParameter.Value.Value = value; }
39    }
40    public int ColSpan {
41      get { return ColSpanParameter.Value.Value; }
42      set { ColSpanParameter.Value.Value = value; }
43    }
44    public int RowSpan {
45      get { return RowSpanParameter.Value.Value; }
46      set { RowSpanParameter.Value.Value = value; }
47    }
[7128]48
49    #region Construction & Cloning
50    [StorableConstructor]
51    protected EmptyBoxChartElementGenerator(bool deserializing) : base(deserializing) { }
52    protected EmptyBoxChartElementGenerator(EmptyBoxChartElementGenerator original, Cloner cloner) : base(original, cloner) {
53      RegisterEvents();
54    }
55    public EmptyBoxChartElementGenerator() {
56      Parameters.Add(new ValueParameter<IntValue>("X", "The x coordinate of the generated element.", new IntValue(0)));
57      Parameters.Add(new ValueParameter<IntValue>("Y", "The y coordinate of the generated element.", new IntValue(0)));
58      Parameters.Add(new ValueParameter<IntValue>("RowSpan", "The number of rows occupied by the generated element.", new IntValue(1)));
59      Parameters.Add(new ValueParameter<IntValue>("ColSpan", "The number of columns occupied by the generated element.", new IntValue(1)));
60      RegisterEvents();
61      if (GetType() == typeof(EmptyBoxChartElementGenerator))
62        UpdateName();
63    }
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new EmptyBoxChartElementGenerator(this, cloner);
66    }
67    [StorableHook(HookType.AfterDeserialization)]
68    private void AfterDeserialization() {
69      RegisterEvents();
70    }
71    #endregion
72
73    private void RegisterEvents() {
74      XParameter.ToStringChanged += new EventHandler(Parameters_Changed);
75      YParameter.ToStringChanged += new EventHandler(Parameters_Changed);
76      RowSpanParameter.ToStringChanged +=new EventHandler(Parameters_Changed);
77      ColSpanParameter.ToStringChanged += new EventHandler(Parameters_Changed);
78    }
79
80    private void Parameters_Changed(object sender, EventArgs e) {
81      UpdateName();
82    }
83
84    protected virtual string CalculateName() {
85      var sb = new StringBuilder();
86      sb.AppendFormat("({0}, {1})", X, Y);
87      if (RowSpan != 1 || ColSpan != 1)
88        sb.AppendFormat("+[{0}, {1}]", ColSpan, RowSpan);
89      return sb.ToString();
90    }
91
92    protected void UpdateName() {
93      name = CalculateName();
94      OnNameChanged();
95    }
96
97    public virtual void Draw(IRun run, Graphics g) { }
98  }
99}
Note: See TracBrowser for help on using the repository browser.