1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HEAL.Attic;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
|
---|
10 |
|
---|
11 | [StorableType("29AED0E8-1190-4DFC-92FC-0AC69FE4DBC1")]
|
---|
12 | public class StringConstantBoxChartElementGenerator : EmptyBoxChartElementGenerator {
|
---|
13 |
|
---|
14 | public ValueParameter<StringValue> TextParameter {
|
---|
15 | get { return (ValueParameter<StringValue>)Parameters["Text"]; }
|
---|
16 | }
|
---|
17 | public ValueParameter<IntValue> FontSizeParameter {
|
---|
18 | get { return (ValueParameter<IntValue>) Parameters["FontSize"]; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | protected string Text { get { return TextParameter.Value.Value; } }
|
---|
22 | protected int FontSize { get { return FontSizeParameter.Value.Value; }}
|
---|
23 |
|
---|
24 | #region Construction & Cloning
|
---|
25 | [StorableConstructor]
|
---|
26 | protected StringConstantBoxChartElementGenerator(StorableConstructorFlag _) : base(_) { }
|
---|
27 | protected StringConstantBoxChartElementGenerator(StringConstantBoxChartElementGenerator original, Cloner cloner) : base(original, cloner) {
|
---|
28 | RegisterEvents();
|
---|
29 | }
|
---|
30 | public StringConstantBoxChartElementGenerator() {
|
---|
31 | Parameters.Add(new ValueParameter<StringValue>("Text", "The text to be rendered inside this element.", new StringValue("Text")));
|
---|
32 | Parameters.Add(new ValueParameter<IntValue>("FontSize", "The font size to be used for the text.", new IntValue(11)));
|
---|
33 | RegisterEvents();
|
---|
34 | if (GetType() == typeof(StringConstantBoxChartElementGenerator))
|
---|
35 | UpdateName();
|
---|
36 | }
|
---|
37 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
38 | return new StringConstantBoxChartElementGenerator(this, cloner);
|
---|
39 | }
|
---|
40 | [StorableHook(HookType.AfterDeserialization)]
|
---|
41 | private void AfterDeserialization() {
|
---|
42 | RegisterEvents();
|
---|
43 | }
|
---|
44 | #endregion
|
---|
45 |
|
---|
46 | private void RegisterEvents() {
|
---|
47 | TextParameter.ToStringChanged += new EventHandler(Parameters_Changed);
|
---|
48 | }
|
---|
49 |
|
---|
50 | private void Parameters_Changed(object sender, EventArgs eventArgs) {
|
---|
51 | UpdateName();
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override string CalculateName() {
|
---|
55 | return string.Format("{0} \"{1}\" ({2})", base.CalculateName(), Text, FontSize);
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override void Draw(IRun run, Graphics g) {
|
---|
59 | using(var font = new Font("Helvetica", FontSize)) {
|
---|
60 | var size = g.MeasureString(Text, font);
|
---|
61 | g.DrawString(Text, font, Brushes.Black,
|
---|
62 | g.ClipBounds.Left+(g.ClipBounds.Width - size.Width)/2,
|
---|
63 | g.ClipBounds.Top+(g.ClipBounds.Height - size.Height)/2);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|