Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Constraints/IntBoundedConstraintView.cs @ 381

Last change on this file since 381 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 4.7 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 IntBoundedConstraintView : ViewBase {
34    public IntBoundedConstraint IntBoundedConstraint {
35      get { return (IntBoundedConstraint)Item; }
36      set { base.Item = value; }
37    }
38
39    public IntBoundedConstraintView() {
40      InitializeComponent();
41    }
42
43    public IntBoundedConstraintView(IntBoundedConstraint intBoundedConstraint)
44      : this() {
45      IntBoundedConstraint = intBoundedConstraint;
46    }
47
48    protected override void RemoveItemEvents() {
49      IntBoundedConstraint.Changed -= new EventHandler(IntBoundedConstraint_Changed);
50      base.RemoveItemEvents();
51    }
52
53    protected override void AddItemEvents() {
54      base.AddItemEvents();
55      IntBoundedConstraint.Changed += new EventHandler(IntBoundedConstraint_Changed);
56    }
57
58    protected override void UpdateControls() {
59      base.UpdateControls();
60      if (IntBoundedConstraint == null) {
61        lbTextBox.Enabled = false;
62        lbTextBox.Text = "";
63        lbIncludedCheckBox.Enabled = false;
64        lbEnabledCheckBox.Checked = false;
65
66        ubTextBox.Enabled = false;
67        ubTextBox.Text = "";
68        ubIncludedCheckBox.Enabled = false;
69        ubEnabledCheckBox.Checked = false;
70      } else {
71        lbTextBox.Text = IntBoundedConstraint.LowerBound + "";
72        lbTextBox.Enabled = IntBoundedConstraint.LowerBoundEnabled;
73        lbIncludedCheckBox.Checked = IntBoundedConstraint.LowerBoundIncluded;
74        lbIncludedCheckBox.Enabled = true;
75        lbEnabledCheckBox.Checked = IntBoundedConstraint.LowerBoundEnabled;
76        lbEnabledCheckBox.Enabled = true;
77
78        ubTextBox.Text = IntBoundedConstraint.UpperBound + "";
79        ubTextBox.Enabled = IntBoundedConstraint.UpperBoundEnabled;
80        ubIncludedCheckBox.Checked = IntBoundedConstraint.UpperBoundIncluded;
81        ubIncludedCheckBox.Enabled = true;
82        ubEnabledCheckBox.Checked = IntBoundedConstraint.UpperBoundEnabled;
83        ubEnabledCheckBox.Enabled = true;
84      }
85    }
86
87    void IntBoundedConstraint_Changed(object sender, EventArgs e) {
88      Refresh();
89    }
90
91    private void lbEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
92      IntBoundedConstraint.LowerBoundEnabled = lbEnabledCheckBox.Checked;
93      lbTextBox.Enabled = lbEnabledCheckBox.Checked;
94      lbIncludedCheckBox.Enabled = lbEnabledCheckBox.Checked;
95    }
96
97    private void ubEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
98      IntBoundedConstraint.UpperBoundEnabled = ubEnabledCheckBox.Checked;
99      ubTextBox.Enabled = ubEnabledCheckBox.Checked;
100      ubIncludedCheckBox.Enabled = ubEnabledCheckBox.Checked;
101    }
102
103    private void lbIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
104      IntBoundedConstraint.LowerBoundIncluded = lbIncludedCheckBox.Checked;
105    }
106
107    private void ubIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
108      IntBoundedConstraint.UpperBoundIncluded = ubIncludedCheckBox.Checked;
109    }
110
111    private void lbTextBox_Validating(object sender, CancelEventArgs e) {
112      int result;
113      if (!int.TryParse(lbTextBox.Text, out result)) {
114        e.Cancel = true;
115      }
116    }
117
118    private void lbTextBox_Validated(object sender, EventArgs e) {
119      IntBoundedConstraint.LowerBound = int.Parse(lbTextBox.Text);
120    }
121
122    private void ubTextBox_Validating(object sender, CancelEventArgs e) {
123      int result;
124      if (!int.TryParse(ubTextBox.Text, out result)) {
125        e.Cancel = true;
126      }
127    }
128
129    private void ubTextBox_Validated(object sender, EventArgs e) {
130      IntBoundedConstraint.UpperBound = int.Parse(ubTextBox.Text);
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.