Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Optimization.Views/3.3/CreateNewSingleEncodingDialog.cs @ 17204

Last change on this file since 17204 was 16956, checked in by abeham, 5 years ago

#2457: merged trunk into branch

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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.Windows.Forms;
25using HeuristicLab.PluginInfrastructure;
26
27namespace HeuristicLab.Optimization.Views {
28  public partial class CreateNewSingleEncodingDialog : Form {
29    private HashSet<string> forbiddenNames;
30    public IEnumerable<string> ForbiddenNames {
31      get { return forbiddenNames; }
32      set { forbiddenNames = new HashSet<string>(value); }
33    }
34
35    public Type EncodingType { get; private set; }
36    public string EncodingName { get; private set; }
37
38    public CreateNewSingleEncodingDialog() {
39      InitializeComponent();
40      forbiddenNames = new HashSet<string>();
41    }
42
43    private void CreateNewSingleEncodingDialog_Load(object sender, EventArgs e) {
44      encodingTypeComboBox.Items.Clear();
45      var encodings = ApplicationManager.Manager.GetTypes(typeof(IEncoding));
46      foreach (var enc in encodings) {
47        if (enc != typeof(MultiEncoding))
48          encodingTypeComboBox.Items.Add(enc);
49      }
50      if (encodingTypeComboBox.Items.Count > 0)
51        encodingTypeComboBox.SelectedIndex = 0;
52      else encodingTypeComboBox.SelectedIndex = -1;
53    }
54
55    private void encodingNameTextBox_TextChanged(object sender, EventArgs e) {
56      EncodingName = encodingNameTextBox.Text;
57      SetEnabledStateOfControls();
58    }
59
60    private void encodingTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
61      if (encodingTypeComboBox.SelectedIndex >= 0)
62        EncodingType = (Type)encodingTypeComboBox.SelectedItem;
63      else EncodingType = null;
64      SetEnabledStateOfControls();
65    }
66
67    private void SetEnabledStateOfControls() {
68      okButton.Enabled = EncodingType != null
69                         && !string.IsNullOrEmpty(EncodingName)
70                         && !forbiddenNames.Contains(EncodingName);
71    }
72
73    private void okButton_Click(object sender, EventArgs e) {
74      DialogResult = DialogResult.OK;
75      Close();
76    }
77
78    private void cancelButton_Click(object sender, EventArgs e) {
79      DialogResult = DialogResult.Cancel;
80      Close();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.