[7558] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7558] | 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.ComponentModel;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.Instances.TSPLIB.Views {
|
---|
| 29 | public sealed partial class TSPLIBImportDialog : Form {
|
---|
| 30 | private string tspFileName;
|
---|
| 31 | public string TSPFileName {
|
---|
| 32 | get { return tspFileName; }
|
---|
| 33 | }
|
---|
| 34 | private double? quality;
|
---|
| 35 | public double? Quality {
|
---|
| 36 | get { return quality; }
|
---|
| 37 | }
|
---|
| 38 | private string tourFileName;
|
---|
| 39 | public string TourFileName {
|
---|
| 40 | get { return tourFileName; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public TSPLIBImportDialog() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | tspFileName = string.Empty;
|
---|
| 46 | tourFileName = string.Empty;
|
---|
| 47 | quality = null;
|
---|
| 48 | errorProvider.SetIconAlignment(qualityTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
| 49 | errorProvider.SetIconPadding(qualityTextBox, 2);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private void openTSPFileButton_Click(object sender, EventArgs e) {
|
---|
| 53 | if (openTSPFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 54 | tspFileTextBox.Text = openTSPFileDialog.FileName;
|
---|
| 55 | tspFileTextBox.Enabled = true;
|
---|
| 56 | tspFileName = openTSPFileDialog.FileName;
|
---|
| 57 | okButton.Enabled = true;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | private void openTourFileButton_Click(object sender, EventArgs e) {
|
---|
| 61 | if (openTourFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 62 | tourFileTextBox.Text = openTourFileDialog.FileName;
|
---|
| 63 | tourFileTextBox.Enabled = true;
|
---|
| 64 | tourFileName = openTourFileDialog.FileName;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | private void clearTourFileButton_Click(object sender, EventArgs e) {
|
---|
| 68 | tourFileTextBox.Text = string.Empty;
|
---|
| 69 | tourFileTextBox.Enabled = false;
|
---|
| 70 | tourFileName = string.Empty;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | private void qualityTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 74 | double val;
|
---|
| 75 | if ((!string.IsNullOrEmpty(qualityTextBox.Text)) && (!double.TryParse(qualityTextBox.Text, out val))) {
|
---|
| 76 | e.Cancel = true;
|
---|
| 77 | StringBuilder sb = new StringBuilder();
|
---|
| 78 | sb.Append("Invalid Value (Valid Value Format: \"");
|
---|
| 79 | sb.Append(FormatPatterns.GetDoubleFormatPattern());
|
---|
| 80 | sb.Append("\")");
|
---|
| 81 | errorProvider.SetError(qualityTextBox, sb.ToString());
|
---|
| 82 | qualityTextBox.SelectAll();
|
---|
| 83 | CancelButton = null;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | private void qualityTextBox_Validated(object sender, EventArgs e) {
|
---|
| 87 | if (string.IsNullOrEmpty(qualityTextBox.Text)) quality = null;
|
---|
| 88 | else quality = double.Parse(qualityTextBox.Text);
|
---|
| 89 | errorProvider.SetError(qualityTextBox, string.Empty);
|
---|
| 90 | CancelButton = cancelButton;
|
---|
| 91 | }
|
---|
| 92 | private void qualityTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 93 | if (e.KeyCode == Keys.Escape) {
|
---|
| 94 | qualityTextBox.Text = quality == null ? string.Empty : quality.ToString();
|
---|
| 95 | qualityLabel.Focus(); // set focus on label to validate data
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|