Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Constraints/3.3/VariableComparisonConstraintView.cs @ 4783

Last change on this file since 4783 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 5.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31
32namespace HeuristicLab.Constraints {
33  /// <summary>
34  /// Visual representation of a <see cref="VariableComparisonConstraint"/>.
35  /// </summary>
36  public partial class VariableComparisonConstraintView : ViewBase {
37    /// <summary>
38    /// Gets or sets the VariableComparisonConstraint to represent visually.
39    /// </summary>
40    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
41    /// No own data storage present.</remarks>
42    public VariableComparisonConstraint VariableComparisonConstraint {
43      get { return (VariableComparisonConstraint)base.Item; }
44      set { base.Item = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="VariableComparisonConstraintView"/>.
49    /// </summary>
50    public VariableComparisonConstraintView() {
51      InitializeComponent();
52    }
53
54    /// <summary>
55    /// Initializes a new instance of <see cref="VariableComparisonConstraintView"/> with the given
56    /// <paramref name="variableComparisonConstraint"/> to display.
57    /// </summary>
58    /// <param name="variableComparisonConstraint">The constraint to represent visually.</param>
59    public VariableComparisonConstraintView(VariableComparisonConstraint variableComparisonConstraint)
60      : this() {
61      VariableComparisonConstraint = variableComparisonConstraint;
62    }
63
64    /// <summary>
65    /// Removes the eventhandler from the underlying <see cref="VariableComparisonConstraint"/>.
66    /// </summary>
67    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.
68    /// </remarks>
69    protected override void RemoveItemEvents() {
70      VariableComparisonConstraint.Changed -= new EventHandler(VariableComparisonConstraint_Changed);
71      base.RemoveItemEvents();
72    }
73
74    /// <summary>
75    /// Adds an eventhandler to the underlying <see cref="VariableComparisonConstraint"/>.
76    /// </summary>
77    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.
78    /// </remarks>
79    protected override void AddItemEvents() {
80      base.AddItemEvents();
81      VariableComparisonConstraint.Changed += new EventHandler(VariableComparisonConstraint_Changed);
82    }
83
84    void VariableComparisonConstraint_Changed(object sender, EventArgs e) {
85      Refresh();
86    }
87
88    /// <summary>
89    /// Updates all controls with the latest values.
90    /// </summary>
91    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.
92    /// </remarks>
93    protected override void UpdateControls() {
94      base.UpdateControls();
95      if (VariableComparisonConstraint == null) {
96        leftVarNameStringDataView.Enabled = false;
97        leftVarNameStringDataView.StringData = null;
98        rightVarNameStringDataView.Enabled = false;
99        rightVarNameStringDataView.StringData = null;
100        comparerGroupBox.Enabled = false;
101      } else {
102        leftVarNameStringDataView.StringData = VariableComparisonConstraint.LeftVarName;
103        leftVarNameStringDataView.Enabled = true;
104        rightVarNameStringDataView.StringData = VariableComparisonConstraint.RightVarName;
105        rightVarNameStringDataView.Enabled = true;
106        comparerGroupBox.Enabled = true;
107        switch (VariableComparisonConstraint.Comparer.Data) {
108          case 0:
109            lessRadioButton.Checked = true;
110            break;
111          case 1:
112            lessOrEqualRadioButton.Checked = true;
113            break;
114          case 2:
115            equalRadioButton.Checked = true;
116            break;
117          case 3:
118            greaterOrEqualRadioButton.Checked = true;
119            break;
120          case 4:
121            greaterRadioButton.Checked = true;
122            break;
123        }
124      }
125    }
126
127    private void anyRadioButton_CheckedChanged(object sender, EventArgs e) {
128      if (VariableComparisonConstraint != null) {
129        if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("lessOrEqual")) {
130          VariableComparisonConstraint.Comparer.Data = 1;
131        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("less")) {
132          VariableComparisonConstraint.Comparer.Data = 0;
133        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("greaterOrEqual")) {
134          VariableComparisonConstraint.Comparer.Data = 3;
135        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("greater")) {
136          VariableComparisonConstraint.Comparer.Data = 4;
137        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("equal")) {
138          VariableComparisonConstraint.Comparer.Data = 2;
139        } else if (((RadioButton)sender).Checked) {
140          Auxiliary.ShowErrorMessageBox("Unknown radio button selected: " + ((RadioButton)sender).Name.ToString());
141        }
142      }
143    }
144  }
145}
Note: See TracBrowser for help on using the repository browser.