Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2738_QAPGenerators/HeuristicLab.Problems.Instances.QAPGenerator.Views/3.3/QAPInstanceGeneratorDescriptorView.cs @ 16752

Last change on this file since 16752 was 14704, checked in by abeham, 8 years ago

#2738: added branch

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.ComponentModel;
24using System.Globalization;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Problems.Instances.QAPGenerator.Views {
29  [View("QAP Instance Generator Descriptor View")]
30  [Content(typeof(QAPInstanceGeneratorDescriptor), IsDefaultView = true)]
31  public partial class QAPInstanceGeneratorDescriptorView : AsynchronousContentView {
32    protected bool SuppressEvents { get; set; }
33
34    public new QAPInstanceGeneratorDescriptor Content {
35      get { return (QAPInstanceGeneratorDescriptor)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public QAPInstanceGeneratorDescriptorView() {
40      InitializeComponent();
41    }
42
43    protected override void DeregisterContentEvents() {
44      Content.PropertyChanged -= ContentOnPropertyChanged;
45      base.DeregisterContentEvents();
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50      Content.PropertyChanged += ContentOnPropertyChanged;
51    }
52
53    #region Event Handlers (Content)
54    protected virtual void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs eventArgs) {
55      SuppressEvents = true;
56      try {
57        switch (eventArgs.PropertyName) {
58          case "N":
59            sizeNumericUpDown.Value = Content.N;
60            break;
61          case "Seed":
62            seedTextBox.Text = Content.Seed.ToString(CultureInfo.CurrentCulture.NumberFormat);
63            break;
64        }
65      } finally { SuppressEvents = false; }
66    }
67    #endregion
68
69    protected override void OnContentChanged() {
70      base.OnContentChanged();
71      SuppressEvents = true;
72      try {
73        if (Content == null) {
74          sizeNumericUpDown.Value = 0;
75          seedTextBox.Text = string.Empty;
76        } else {
77          sizeNumericUpDown.Value = Content.N;
78          seedTextBox.Text = Content.Seed.ToString(CultureInfo.CurrentCulture.NumberFormat);
79        }
80      } finally { SuppressEvents = false; }
81    }
82
83
84    protected override void SetEnabledStateOfControls() {
85      base.SetEnabledStateOfControls();
86      sizeNumericUpDown.Enabled = !Locked && !ReadOnly && Content != null;
87      seedTextBox.Enabled = !Locked && !ReadOnly && Content != null;
88    }
89
90    #region Event Handlers (child controls)
91    protected virtual void sizeNumericUpDown_ValueChanged(object sender, EventArgs e) {
92      if (SuppressEvents) return;
93      Content.N = (int)sizeNumericUpDown.Value;
94    }
95
96    protected virtual void seedTextBox_Validating(object sender, CancelEventArgs e) {
97      if (SuppressEvents) return;
98      int seed;
99      e.Cancel = !int.TryParse(seedTextBox.Text, NumberStyles.Integer, CultureInfo.CurrentCulture.NumberFormat, out seed) || seed < 0;
100      if (e.Cancel) errorProvider.SetError(seedTextBox, "The given seed is not valid, enter a positive number smaller than 2^31.");
101      else errorProvider.SetError(seedTextBox, String.Empty);
102    }
103
104    protected virtual void seedTextBox_Validated(object sender, EventArgs e) {
105      if (SuppressEvents) return;
106      var seed = int.Parse(seedTextBox.Text);
107      Content.Seed = seed;
108    }
109    #endregion
110  }
111}
Note: See TracBrowser for help on using the repository browser.