Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.Constraints/VariableComparisonConstraintView.cs @ 5234

Last change on this file since 5234 was 349, checked in by abeham, 16 years ago

fixed bug in ticket #186 (trunk)

File size: 4.4 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  public partial class VariableComparisonConstraintView : ViewBase {
34    public VariableComparisonConstraint VariableComparisonConstraint {
35      get { return (VariableComparisonConstraint)base.Item; }
36      set { base.Item = value; }
37    }
38
39    public VariableComparisonConstraintView() {
40      InitializeComponent();
41    }
42
43    public VariableComparisonConstraintView(VariableComparisonConstraint variableComparisonConstraint)
44      : this() {
45      VariableComparisonConstraint = variableComparisonConstraint;
46    }
47
48    protected override void RemoveItemEvents() {
49      VariableComparisonConstraint.Changed -= new EventHandler(VariableComparisonConstraint_Changed);
50      base.RemoveItemEvents();
51    }
52
53    protected override void AddItemEvents() {
54      base.AddItemEvents();
55      VariableComparisonConstraint.Changed += new EventHandler(VariableComparisonConstraint_Changed);
56    }
57
58    void VariableComparisonConstraint_Changed(object sender, EventArgs e) {
59      Refresh();
60    }
61
62    protected override void UpdateControls() {
63      base.UpdateControls();
64      if (VariableComparisonConstraint == null) {
65        leftVarNameStringDataView.Enabled = false;
66        leftVarNameStringDataView.StringData = null;
67        rightVarNameStringDataView.Enabled = false;
68        rightVarNameStringDataView.StringData = null;
69        comparerGroupBox.Enabled = false;
70      } else {
71        leftVarNameStringDataView.StringData = VariableComparisonConstraint.LeftVarName;
72        leftVarNameStringDataView.Enabled = true;
73        rightVarNameStringDataView.StringData = VariableComparisonConstraint.RightVarName;
74        rightVarNameStringDataView.Enabled = true;
75        comparerGroupBox.Enabled = true;
76        switch (VariableComparisonConstraint.Comparer.Data) {
77          case 0:
78            lessRadioButton.Checked = true;
79            break;
80          case 1:
81            lessOrEqualRadioButton.Checked = true;
82            break;
83          case 2:
84            equalRadioButton.Checked = true;
85            break;
86          case 3:
87            greaterOrEqualRadioButton.Checked = true;
88            break;
89          case 4:
90            greaterRadioButton.Checked = true;
91            break;
92        }
93      }
94    }
95
96    private void anyRadioButton_CheckedChanged(object sender, EventArgs e) {
97      if (VariableComparisonConstraint != null) {
98        if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("lessOrEqual")) {
99          VariableComparisonConstraint.Comparer.Data = 1;
100        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("less")) {
101          VariableComparisonConstraint.Comparer.Data = 0;
102        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("greaterOrEqual")) {
103          VariableComparisonConstraint.Comparer.Data = 3;
104        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("greater")) {
105          VariableComparisonConstraint.Comparer.Data = 4;
106        } else if (((RadioButton)sender).Checked && ((RadioButton)sender).Name.StartsWith("equal")) {
107          VariableComparisonConstraint.Comparer.Data = 2;
108        } else if (((RadioButton)sender).Checked) {
109          Auxiliary.ShowErrorMessageBox("Unknown radio button selected: " + ((RadioButton)sender).Name.ToString());
110        }
111      }
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.