[5875] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5875] | 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.Core.Views;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Optimization.Views {
|
---|
| 28 | [View("Result Value View")]
|
---|
[5896] | 29 | [Content(typeof(Result), true)]
|
---|
[5875] | 30 | [Content(typeof(IResult), false)]
|
---|
| 31 | public sealed partial class ResultValueView : ItemView {
|
---|
[7235] | 32 | private const string infoLabelToolTipSuffix = "Double-click to open description editor.";
|
---|
| 33 |
|
---|
[5875] | 34 | public new IResult Content {
|
---|
| 35 | get { return (IResult)base.Content; }
|
---|
| 36 | set { base.Content = value; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public override bool ReadOnly {
|
---|
| 40 | get { return true; }
|
---|
| 41 | set { /*not needed because results are always readonly */}
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public ResultValueView() {
|
---|
| 45 | InitializeComponent();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void DeregisterContentEvents() {
|
---|
[7235] | 49 | Content.NameChanged -= new EventHandler(Content_NameChanged);
|
---|
| 50 | Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
|
---|
[5875] | 51 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
| 52 | base.DeregisterContentEvents();
|
---|
| 53 | }
|
---|
| 54 | protected override void RegisterContentEvents() {
|
---|
| 55 | base.RegisterContentEvents();
|
---|
[7235] | 56 | Content.NameChanged += new EventHandler(Content_NameChanged);
|
---|
| 57 | Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
|
---|
[5875] | 58 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected override void OnContentChanged() {
|
---|
| 62 | base.OnContentChanged();
|
---|
| 63 | if (Content == null) {
|
---|
| 64 | viewHost.Content = null;
|
---|
[7235] | 65 | toolTip.SetToolTip(infoLabel, string.Empty);
|
---|
| 66 | if (ViewAttribute.HasViewAttribute(this.GetType()))
|
---|
| 67 | this.Caption = ViewAttribute.GetViewName(this.GetType());
|
---|
| 68 | else
|
---|
| 69 | this.Caption = "ResultValue View";
|
---|
[5875] | 70 | } else {
|
---|
| 71 | viewHost.ViewType = null;
|
---|
| 72 | viewHost.Content = Content.Value;
|
---|
[7235] | 73 | toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
|
---|
| 74 | Caption = Content.Name;
|
---|
[5875] | 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | protected override void SetEnabledStateOfControls() {
|
---|
| 79 | base.SetEnabledStateOfControls();
|
---|
| 80 | viewHost.Enabled = Content != null;
|
---|
| 81 | viewHost.ReadOnly = this.ReadOnly;
|
---|
[7235] | 82 | infoLabel.Enabled = Content != null;
|
---|
[5875] | 83 | }
|
---|
| 84 |
|
---|
[7235] | 85 | private void Content_NameChanged(object sender, EventArgs e) {
|
---|
| 86 | if (InvokeRequired)
|
---|
| 87 | Invoke(new EventHandler(Content_NameChanged), sender, e);
|
---|
| 88 | else
|
---|
| 89 | Caption = Content.Name;
|
---|
| 90 | }
|
---|
| 91 | private void Content_DescriptionChanged(object sender, EventArgs e) {
|
---|
| 92 | if (InvokeRequired)
|
---|
| 93 | Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
|
---|
| 94 | else
|
---|
| 95 | toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
|
---|
| 96 | }
|
---|
[5875] | 97 | private void Content_ValueChanged(object sender, EventArgs e) {
|
---|
| 98 | if (InvokeRequired)
|
---|
| 99 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
| 100 | else {
|
---|
| 101 | viewHost.Content = Content.Value;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[7235] | 104 |
|
---|
| 105 | private void infoLabel_DoubleClick(object sender, System.EventArgs e) {
|
---|
| 106 | using (TextDialog dialog = new TextDialog("Description of " + Content.Name, Content.Description, ReadOnly || !Content.CanChangeDescription)) {
|
---|
| 107 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
| 108 | Content.Description = dialog.Content;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
[5875] | 111 | }
|
---|
| 112 | }
|
---|