using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts { [StorableClass] public class EmptyBoxChartElementGenerator : ParameterizedNamedItem, IBoxChartElementGenerator { public ValueParameter XParameter { get { return (ValueParameter)Parameters["X"]; } } public ValueParameter YParameter { get { return (ValueParameter)Parameters["Y"]; } } public ValueParameter RowSpanParameter { get { return (ValueParameter)Parameters["RowSpan"]; } } public ValueParameter ColSpanParameter { get { return (ValueParameter)Parameters["ColSpan"]; } } public int X { get { return XParameter.Value.Value; } set { XParameter.Value.Value = value; } } public int Y { get { return YParameter.Value.Value; } set { YParameter.Value.Value = value; } } public int ColSpan { get { return ColSpanParameter.Value.Value; } set { ColSpanParameter.Value.Value = value; } } public int RowSpan { get { return RowSpanParameter.Value.Value; } set { RowSpanParameter.Value.Value = value; } } #region Construction & Cloning [StorableConstructor] protected EmptyBoxChartElementGenerator(bool deserializing) : base(deserializing) { } protected EmptyBoxChartElementGenerator(EmptyBoxChartElementGenerator original, Cloner cloner) : base(original, cloner) { RegisterEvents(); } public EmptyBoxChartElementGenerator() { Parameters.Add(new ValueParameter("X", "The x coordinate of the generated element.", new IntValue(0))); Parameters.Add(new ValueParameter("Y", "The y coordinate of the generated element.", new IntValue(0))); Parameters.Add(new ValueParameter("RowSpan", "The number of rows occupied by the generated element.", new IntValue(1))); Parameters.Add(new ValueParameter("ColSpan", "The number of columns occupied by the generated element.", new IntValue(1))); RegisterEvents(); if (GetType() == typeof(EmptyBoxChartElementGenerator)) UpdateName(); } public override IDeepCloneable Clone(Cloner cloner) { return new EmptyBoxChartElementGenerator(this, cloner); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEvents(); } #endregion private void RegisterEvents() { XParameter.ToStringChanged += new EventHandler(Parameters_Changed); YParameter.ToStringChanged += new EventHandler(Parameters_Changed); RowSpanParameter.ToStringChanged +=new EventHandler(Parameters_Changed); ColSpanParameter.ToStringChanged += new EventHandler(Parameters_Changed); } private void Parameters_Changed(object sender, EventArgs e) { UpdateName(); } protected virtual string CalculateName() { var sb = new StringBuilder(); sb.AppendFormat("({0}, {1})", X, Y); if (RowSpan != 1 || ColSpan != 1) sb.AppendFormat("+[{0}, {1}]", ColSpan, RowSpan); return sb.ToString(); } protected void UpdateName() { name = CalculateName(); OnNameChanged(); } public virtual void Draw(IRun run, Graphics g) { } } }