[11892] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.PluginInfrastructure;
|
---|
| 26 |
|
---|
[11963] | 27 | namespace HeuristicLab.Optimization.Views {
|
---|
[11892] | 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) {
|
---|
[13388] | 47 | if (enc != typeof(CombinedEncoding))
|
---|
[11892] | 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 | }
|
---|