Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Constraints/3.2/DoubleBoundedConstraintView.cs @ 3695

Last change on this file since 3695 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.3 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 a <see cref="DoubleBoundedConstraint"/>.
35  /// </summary>
36  public partial class DoubleBoundedConstraintView : ViewBase {
37    /// <summary>
38    /// Gets or sets the DoubleBoundedConstraint 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 DoubleBoundedConstraint DoubleBoundedConstraint {
43      get { return (DoubleBoundedConstraint)Item; }
44      set { base.Item = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="DoubleBoundedConstraintView"/>.
49    /// </summary>
50    public DoubleBoundedConstraintView() {
51      InitializeComponent();
52    }
53
54    /// <summary>
55    /// Initializes a new instance of <see cref="DoubleBoundedConstraintView"/> with the given
56    /// <paramref name="doubleBoundedConstraint"/> to display.
57    /// </summary>
58    /// <param name="doubleBoundedConstraint">The constraint to represent visually.</param>
59    public DoubleBoundedConstraintView(DoubleBoundedConstraint doubleBoundedConstraint)
60      : this() {
61      DoubleBoundedConstraint = doubleBoundedConstraint;
62    }
63
64    /// <summary>
65    /// Removes the eventhandler from the underlying <see cref="DoubleBoundedConstraint"/>.
66    /// </summary>
67    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.
68    /// </remarks>
69    protected override void RemoveItemEvents() {
70      DoubleBoundedConstraint.Changed -= new EventHandler(DoubleBoundedConstraint_Changed);
71      base.RemoveItemEvents();
72    }
73
74    /// <summary>
75    /// Adds an eventhandler to the underlying <see cref="DoubleBoundedConstraint"/>.
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      DoubleBoundedConstraint.Changed += new EventHandler(DoubleBoundedConstraint_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 (DoubleBoundedConstraint == 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.Checked = false;
99        ubEnabledCheckBox.Enabled = false;
100      } else {
101        lbTextBox.Text = DoubleBoundedConstraint.LowerBound.ToString("r");
102        lbTextBox.Enabled = DoubleBoundedConstraint.LowerBoundEnabled;
103        lbIncludedCheckBox.Checked = DoubleBoundedConstraint.LowerBoundIncluded;
104        lbIncludedCheckBox.Enabled = true;
105        lbEnabledCheckBox.Checked = DoubleBoundedConstraint.LowerBoundEnabled;
106        lbEnabledCheckBox.Enabled = true;
107
108        ubTextBox.Text = DoubleBoundedConstraint.UpperBound.ToString("r");
109        ubTextBox.Enabled = DoubleBoundedConstraint.UpperBoundEnabled;
110        ubIncludedCheckBox.Checked = DoubleBoundedConstraint.UpperBoundIncluded;
111        ubIncludedCheckBox.Enabled = true;
112        ubEnabledCheckBox.Checked = DoubleBoundedConstraint.UpperBoundEnabled;
113        ubEnabledCheckBox.Enabled = true;
114      }
115    }
116
117    void DoubleBoundedConstraint_Changed(object sender, EventArgs e) {
118      Refresh();
119    }
120
121    private void lbEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
122      DoubleBoundedConstraint.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      DoubleBoundedConstraint.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      DoubleBoundedConstraint.LowerBoundIncluded = lbIncludedCheckBox.Checked;
135    }
136
137    private void ubIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
138      DoubleBoundedConstraint.UpperBoundIncluded = ubIncludedCheckBox.Checked;
139    }
140
141    private void lbTextBox_Validating(object sender, CancelEventArgs e) {
142      double result;
143      if (!double.TryParse(lbTextBox.Text, out result)) {
144        e.Cancel = true;
145      }
146    }
147
148    private void ubTextBox_Validating(object sender, CancelEventArgs e) {
149      double result;
150      if (!double.TryParse(ubTextBox.Text, out result)) {
151        e.Cancel = true;
152      }
153    }
154
155    private void lbTextBox_Validated(object sender, EventArgs e) {
156      DoubleBoundedConstraint.LowerBound = double.Parse(lbTextBox.Text);
157    }
158
159    private void ubTextBox_Validated(object sender, EventArgs e) {
160      DoubleBoundedConstraint.UpperBound = double.Parse(ubTextBox.Text);
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.