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