1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Optimization.Views {
|
---|
29 | /// <summary>
|
---|
30 | /// The visual representation of a <see cref="Variable"/>.
|
---|
31 | /// </summary>
|
---|
32 | [View("Result View")]
|
---|
33 | [Content(typeof(Result), true)]
|
---|
34 | [Content(typeof(IResult), false)]
|
---|
35 | public sealed partial class ResultView : NamedItemView {
|
---|
36 | /// <summary>
|
---|
37 | /// Gets or sets the variable to represent visually.
|
---|
38 | /// </summary>
|
---|
39 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
40 | /// No own data storage present.</remarks>
|
---|
41 | public new IResult Content {
|
---|
42 | get { return (IResult)base.Content; }
|
---|
43 | set { base.Content = value; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override bool ReadOnly {
|
---|
47 | get { return base.ReadOnly; }
|
---|
48 | set { /*not needed because results are always readonly */}
|
---|
49 | }
|
---|
50 |
|
---|
51 | /// <summary>
|
---|
52 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
53 | /// </summary>
|
---|
54 | public ResultView() {
|
---|
55 | InitializeComponent();
|
---|
56 | Caption = "Result";
|
---|
57 | base.ReadOnly = true;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /// <summary>
|
---|
61 | /// Removes the eventhandlers from the underlying <see cref="Variable"/>.
|
---|
62 | /// </summary>
|
---|
63 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
64 | protected override void DeregisterContentEvents() {
|
---|
65 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
66 | base.DeregisterContentEvents();
|
---|
67 | }
|
---|
68 |
|
---|
69 | /// <summary>
|
---|
70 | /// Adds eventhandlers to the underlying <see cref="Variable"/>.
|
---|
71 | /// </summary>
|
---|
72 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
73 | protected override void RegisterContentEvents() {
|
---|
74 | base.RegisterContentEvents();
|
---|
75 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void OnContentChanged() {
|
---|
79 | base.OnContentChanged();
|
---|
80 | if (Content == null) {
|
---|
81 | Caption = "Result";
|
---|
82 | dataTypeTextBox.Text = "-";
|
---|
83 | viewHost.Content = null;
|
---|
84 | } else {
|
---|
85 | Caption = Content.Name + " (" + Content.GetType().Name + ")";
|
---|
86 | dataTypeTextBox.Text = Content.DataType.GetPrettyName();
|
---|
87 | viewHost.ViewType = null;
|
---|
88 | viewHost.Content = Content.Value;
|
---|
89 | }
|
---|
90 | SetEnabledStateOfControls();
|
---|
91 | }
|
---|
92 | protected override void OnReadOnlyChanged() {
|
---|
93 | base.OnReadOnlyChanged();
|
---|
94 | SetEnabledStateOfControls();
|
---|
95 | }
|
---|
96 | private void SetEnabledStateOfControls() {
|
---|
97 | dataTypeTextBox.Enabled = Content != null;
|
---|
98 | viewHost.Enabled = Content != null;
|
---|
99 | }
|
---|
100 |
|
---|
101 | private void Content_ValueChanged(object sender, EventArgs e) {
|
---|
102 | if (InvokeRequired)
|
---|
103 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
104 | else {
|
---|
105 | viewHost.Content = Content.Value;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|