Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Constraints/DoubleBoundedConstraintView.cs @ 5955

Last change on this file since 5955 was 345, checked in by gkronber, 17 years ago
  • merged r338 r341 and r343 from the ticket-specific trunk into the HL3.0 stable branch
  • fixed serialization and display of floating point numbers in HL3.0 stable plugins HeuristicLab.Functions and HeuristicLab.DataAnalysis

(ticket #175)

File size: 4.8 KB
RevLine 
[2]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 DoubleBoundedConstraintView : ViewBase {
34    public DoubleBoundedConstraint DoubleBoundedConstraint {
35      get { return (DoubleBoundedConstraint)Item; }
36      set { base.Item = value; }
37    }
38
39    public DoubleBoundedConstraintView() {
40      InitializeComponent();
41    }
42
43    public DoubleBoundedConstraintView(DoubleBoundedConstraint doubleBoundedConstraint)
44      : this() {
45      DoubleBoundedConstraint = doubleBoundedConstraint;
46    }
47
48    protected override void RemoveItemEvents() {
49      DoubleBoundedConstraint.Changed -= new EventHandler(DoubleBoundedConstraint_Changed);
50      base.RemoveItemEvents();
51    }
52
53    protected override void AddItemEvents() {
54      base.AddItemEvents();
55      DoubleBoundedConstraint.Changed += new EventHandler(DoubleBoundedConstraint_Changed);
56    }
57
58    protected override void UpdateControls() {
59      base.UpdateControls();
60      if (DoubleBoundedConstraint == 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.Checked = false;
69        ubEnabledCheckBox.Enabled = false;
70      } else {
[345]71        lbTextBox.Text = DoubleBoundedConstraint.LowerBound.ToString("r");
[2]72        lbTextBox.Enabled = DoubleBoundedConstraint.LowerBoundEnabled;
73        lbIncludedCheckBox.Checked = DoubleBoundedConstraint.LowerBoundIncluded;
74        lbIncludedCheckBox.Enabled = true;
75        lbEnabledCheckBox.Checked = DoubleBoundedConstraint.LowerBoundEnabled;
76        lbEnabledCheckBox.Enabled = true;
77
[345]78        ubTextBox.Text = DoubleBoundedConstraint.UpperBound.ToString("r");
[2]79        ubTextBox.Enabled = DoubleBoundedConstraint.UpperBoundEnabled;
80        ubIncludedCheckBox.Checked = DoubleBoundedConstraint.UpperBoundIncluded;
81        ubIncludedCheckBox.Enabled = true;
82        ubEnabledCheckBox.Checked = DoubleBoundedConstraint.UpperBoundEnabled;
83        ubEnabledCheckBox.Enabled = true;
84      }
85    }
86
87    void DoubleBoundedConstraint_Changed(object sender, EventArgs e) {
88      Refresh();
89    }
90
91    private void lbEnabledCheckBox_CheckedChanged(object sender, EventArgs e) {
92      DoubleBoundedConstraint.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      DoubleBoundedConstraint.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      DoubleBoundedConstraint.LowerBoundIncluded = lbIncludedCheckBox.Checked;
105    }
106
107    private void ubIncludedCheckBox_CheckedChanged(object sender, EventArgs e) {
108      DoubleBoundedConstraint.UpperBoundIncluded = ubIncludedCheckBox.Checked;
109    }
110
111    private void lbTextBox_Validating(object sender, CancelEventArgs e) {
112      double result;
113      if (!double.TryParse(lbTextBox.Text, out result)) {
114        e.Cancel = true;
115      }
116    }
117
118    private void ubTextBox_Validating(object sender, CancelEventArgs e) {
119      double result;
120      if (!double.TryParse(ubTextBox.Text, out result)) {
121        e.Cancel = true;
122      }
123    }
124
125    private void lbTextBox_Validated(object sender, EventArgs e) {
126      DoubleBoundedConstraint.LowerBound = double.Parse(lbTextBox.Text);
127    }
128
129    private void ubTextBox_Validated(object sender, EventArgs e) {
130      DoubleBoundedConstraint.UpperBound = double.Parse(ubTextBox.Text);
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.