using System; using System.Drawing; using System.Text; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts { [StorableType("A3B05023-AFF2-4550-A78C-F0513F308316")] 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(StorableConstructorFlag _) : base(_) { } 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) { } } }