source: trunk/sources/HeuristicLab.Optimization.Views/3.3/CreateNewSingleEncodingDialog.cs @ 11963

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

#2174: Moved MultiEncodingView

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