Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Constraints/ItemTypeConstraintView.cs @ 1478

Last change on this file since 1478 was 1176, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.BitVector and HeuristicLab.Constraints namespace and changed a comment in HeuristicLab.IntVector namespace(#331)

File size: 4.0 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="ItemTypeConstraint"/>.
35  /// </summary>
36  public partial class ItemTypeConstraintView : ViewBase {
37    /// <summary>
38    /// Gets or sets the ItemTypeConstraint 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    private ItemTypeConstraint ItemTypeConstraint {
43      get { return (ItemTypeConstraint)base.Item; }
44      set { base.Item = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="ItemTypeConstraintView"/>.
49    /// </summary>
50    public ItemTypeConstraintView() {
51      InitializeComponent();
52      typeTextBox.Enabled = false;
53    }
54
55    /// <summary>
56    /// Initializes a new instance of <see cref="ItemTypeConstraintView"/> with the given
57    /// <paramref name="itemTypeConstraint"/> to display.
58    /// </summary>
59    /// <param name="itemTypeConstraint">The constraint to represent visually.</param>
60    public ItemTypeConstraintView(ItemTypeConstraint itemTypeConstraint)
61      : this() {
62      ItemTypeConstraint = itemTypeConstraint;
63    }
64
65    /// <summary>
66    /// Removes the eventhandler from the underlying <see cref="ItemTypeConstraint"/>.
67    /// </summary>
68    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.
69    /// </remarks>
70    protected override void RemoveItemEvents() {
71      ItemTypeConstraint.Changed -= new EventHandler(ItemTypeConstraint_Changed);
72      base.RemoveItemEvents();
73    }
74
75    /// <summary>
76    /// Adds an eventhandler to the underlying <see cref="ItemTypeConstraint"/>.
77    /// </summary>
78    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.
79    /// </remarks>
80    protected override void AddItemEvents() {
81      base.AddItemEvents();
82      ItemTypeConstraint.Changed += new EventHandler(ItemTypeConstraint_Changed);
83    }
84
85    void ItemTypeConstraint_Changed(object sender, EventArgs e) {
86      Refresh();
87    }
88
89    /// <summary>
90    /// Updates all controls with the latest values.
91    /// </summary>
92    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
93    protected override void UpdateControls() {
94      base.UpdateControls();
95      if (ItemTypeConstraint == null) {
96        setButton.Enabled = false;
97      } else {
98        typeTextBox.Text = ItemTypeConstraint.Type.ToString();
99        setButton.Enabled = true;
100      }
101    }
102
103    private void setButton_Click(object sender, EventArgs e) {
104      using (ChooseTypeDialog dialog = new ChooseTypeDialog()) {
105        dialog.Caption = "Set Item Type";
106        if (dialog.ShowDialog(this) == DialogResult.OK) {
107          ItemTypeConstraint.Type = dialog.Type;
108        }
109      }
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.