Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Constraints/3.3/IntBoundedConstraintView.cs @ 2285

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

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

File size: 6.1 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  /// The visual representation of an <see cref="IntBoundedConstraint"/>.
35  /// </summary>
36  public partial class IntBoundedConstraintView : ViewBase {
37    /// <summary>
38    /// Gets or sets the the IntBoundedConstraint 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 IntBoundedConstraint IntBoundedConstraint {
43      get { return (IntBoundedConstraint)Item; }
44      set { base.Item = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="IntBoundedConstraintView"/>.
49    /// </summary>
50    public IntBoundedConstraintView() {
51      InitializeComponent();
52    }
53
54    /// <summary>
55    /// Initializes a new instance of <see cref="IntBoundedConstraintView"/> with the given
56    /// <paramref name="intBoundedConstraint"/> to display.
57    /// </summary>
58    /// <param name="intBoundedConstraint">The constraint to represent visually.</param>
59    public IntBoundedConstraintView(IntBoundedConstraint intBoundedConstraint)
60      : this() {
61      IntBoundedConstraint = intBoundedConstraint;
62    }
63
64    /// <summary>
65    /// Removes the eventhandler from the underlying <see cref="IntBoundedConstraint"/>.
66    /// </summary>
67    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.
68    /// </remarks>
69    protected override void RemoveItemEvents() {
70      IntBoundedConstraint.Changed -= new EventHandler(IntBoundedConstraint_Changed);
71      base.RemoveItemEvents();
72    }
73
74    /// <summary>
75    /// Adds an eventhandler to the underlying <see cref="IntBoundedConstraint"/>.
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      IntBoundedConstraint.Changed += new EventHandler(IntBoundedConstraint_Changed);
82    }
83
84    /// <summary>
85    /// Updates all controls with the latest values.
86    /// </summary>
87    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
88    protected override void UpdateControls() {
89      base.UpdateControls();
90      if (IntBoundedConstraint == null) {
91        lbTextBox.Enabled = false;
92        lbTextBox.Text = "";
93        lbIncludedCheckBox.Enabled = false;
94        lbEnabledCheckBox.Checked = false;
95
96        ubTextBox.Enabled = false;
97        ubTextBox.Text = "";
98        ubIncludedCheckBox.Enabled = false;
99        ubEnabledCheckBox.Checked = false;
100      } else {
101        lbTextBox.Text = IntBoundedConstraint.LowerBound + "";
102        lbTextBox.Enabled = IntBoundedConstraint.LowerBoundEnabled;
103        lbIncludedCheckBox.Checked = IntBoundedConstraint.LowerBoundIncluded;
104        lbIncludedCheckBox.Enabled = true;
105        lbEnabledCheckBox.Checked = IntBoundedConstraint.LowerBoundEnabled;
106        lbEnabledCheckBox.Enabled = true;
107
108        ubTextBox.Text = IntBoundedConstraint.UpperBound + "";
109        ubTextBox.Enabled = IntBoundedConstraint.UpperBoundEnabled;
110        ubIncludedCheckBox.Checked = IntBoundedConstraint.UpperBoundIncluded;
111        ubIncludedCheckBox.Enabled = true;
112        ubEnabledCheckBox.Checked = IntBoundedConstraint.UpperBoundEnabled;
113        ubEnabledCheckBox.Enabled = true;
114      }
115    }
116
117    void IntBoundedConstraint_Changed(object sender, EventArgs e) {
118      Refresh();
119    }
120
121    private void lbEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
122      IntBoundedConstraint.LowerBoundEnabled = lbEnabledCheckBox.Checked;
123      lbTextBox.Enabled = lbEnabledCheckBox.Checked;
124      lbIncludedCheckBox.Enabled = lbEnabledCheckBox.Checked;
125    }
126
127    private void ubEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
128      IntBoundedConstraint.UpperBoundEnabled = ubEnabledCheckBox.Checked;
129      ubTextBox.Enabled = ubEnabledCheckBox.Checked;
130      ubIncludedCheckBox.Enabled = ubEnabledCheckBox.Checked;
131    }
132
133    private void lbIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
134      IntBoundedConstraint.LowerBoundIncluded = lbIncludedCheckBox.Checked;
135    }
136
137    private void ubIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
138      IntBoundedConstraint.UpperBoundIncluded = ubIncludedCheckBox.Checked;
139    }
140
141    private void lbTextBox_Validating(object sender, CancelEventArgs e) {
142      int result;
143      if (!int.TryParse(lbTextBox.Text, out result)) {
144        e.Cancel = true;
145      }
146    }
147
148    private void lbTextBox_Validated(object sender, EventArgs e) {
149      IntBoundedConstraint.LowerBound = int.Parse(lbTextBox.Text);
150    }
151
152    private void ubTextBox_Validating(object sender, CancelEventArgs e) {
153      int result;
154      if (!int.TryParse(ubTextBox.Text, out result)) {
155        e.Cancel = true;
156      }
157    }
158
159    private void ubTextBox_Validated(object sender, EventArgs e) {
160      IntBoundedConstraint.UpperBound = int.Parse(ubTextBox.Text);
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.