Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Data.Views/3.3/BoolValueView.cs @ 3494

Last change on this file since 3494 was 3430, checked in by swagner, 15 years ago

Added ReadOnly property to all items of HeuristicLab.Data (#969)

File size: 3.0 KB
RevLine 
[2665]1#region License Information
2/* HeuristicLab
[2790]3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2665]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.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Data.Views {
[3048]28  [View("BoolValue View")]
29  [Content(typeof(BoolValue), true)]
30  public partial class BoolValueView : ItemView {
31    public new BoolValue Content {
32      get { return (BoolValue)base.Content; }
[2713]33      set { base.Content = value; }
[2665]34    }
35
[3430]36    public override bool ReadOnly {
37      get {
38        if ((Content != null) && Content.ReadOnly) return true;
39        return base.ReadOnly;
40      }
41      set { base.ReadOnly = value; }
42    }
43
[3048]44    public BoolValueView() {
[2665]45      InitializeComponent();
[3048]46      Caption = "BoolValue View";
[2665]47    }
[3048]48    public BoolValueView(BoolValue content)
[2665]49      : this() {
[2727]50      Content = content;
[2665]51    }
52
[2713]53    protected override void DeregisterContentEvents() {
[2932]54      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
[2713]55      base.DeregisterContentEvents();
[2665]56    }
57
[2713]58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
[2932]60      Content.ValueChanged += new EventHandler(Content_ValueChanged);
[2665]61    }
62
[2713]63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content == null) {
[3048]66        Caption = "BoolValue View";
[2665]67        valueCheckBox.Checked = false;
68      } else {
[2713]69        Caption = Content.ToString() + " (" + Content.GetType().Name + ")";
70        valueCheckBox.Checked = Content.Value;
[2665]71      }
[3362]72      SetEnabledStateOfControls();
[2665]73    }
74
[3350]75    protected override void OnReadOnlyChanged() {
76      base.OnReadOnlyChanged();
[3362]77      SetEnabledStateOfControls();
[3350]78    }
[3362]79    private void SetEnabledStateOfControls() {
[3350]80      if (Content == null) valueCheckBox.Enabled = false;
81      else valueCheckBox.Enabled = !ReadOnly;
82    }
83
[2932]84    private void Content_ValueChanged(object sender, EventArgs e) {
[2665]85      if (InvokeRequired)
[2932]86        Invoke(new EventHandler(Content_ValueChanged), sender, e);
[2665]87      else
[2713]88        valueCheckBox.Checked = Content.Value;
[2665]89    }
90
91    private void valueCheckBox_CheckedChanged(object sender, EventArgs e) {
[3430]92      if (!Content.ReadOnly) Content.Value = valueCheckBox.Checked;
[2665]93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.