[3890] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3890] | 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.Windows.Forms;
|
---|
[4068] | 25 | using HeuristicLab.Core.Views;
|
---|
[3890] | 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.ExternalEvaluation.Views {
|
---|
| 29 | [View("TCP Channel View")]
|
---|
| 30 | [Content(typeof(EvaluationTCPChannel), IsDefaultView = true)]
|
---|
| 31 | public sealed partial class EvaluationTCPChannelView : NamedItemView {
|
---|
| 32 | public new EvaluationTCPChannel Content {
|
---|
| 33 | get { return (EvaluationTCPChannel)base.Content; }
|
---|
| 34 | set { base.Content = value; }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public EvaluationTCPChannelView() {
|
---|
| 38 | InitializeComponent();
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override void DeregisterContentEvents() {
|
---|
| 42 | Content.Connected -= new EventHandler(Content_Connected);
|
---|
| 43 | Content.Disconnected -= new EventHandler(Content_Disconnected);
|
---|
| 44 | Content.IpAddressChanged -= new EventHandler(Content_IpAddressChanged);
|
---|
| 45 | Content.PortChanged -= new EventHandler(Content_PortChanged);
|
---|
| 46 | base.DeregisterContentEvents();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | protected override void RegisterContentEvents() {
|
---|
| 50 | base.RegisterContentEvents();
|
---|
| 51 | Content.Connected += new EventHandler(Content_Connected);
|
---|
| 52 | Content.Disconnected += new EventHandler(Content_Disconnected);
|
---|
| 53 | Content.IpAddressChanged += new EventHandler(Content_IpAddressChanged);
|
---|
| 54 | Content.PortChanged += new EventHandler(Content_PortChanged);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | #region Event Handlers (Content)
|
---|
| 58 | private void Content_Connected(object sender, EventArgs e) {
|
---|
| 59 | SetEnabledStateOfControls();
|
---|
| 60 | }
|
---|
| 61 | private void Content_Disconnected(object sender, EventArgs e) {
|
---|
| 62 | SetEnabledStateOfControls();
|
---|
| 63 | }
|
---|
| 64 | private void Content_IpAddressChanged(object sender, EventArgs e) {
|
---|
| 65 | ipAddressTextBox.Text = Content.IpAddress;
|
---|
| 66 | }
|
---|
| 67 | private void Content_PortChanged(object sender, EventArgs e) {
|
---|
| 68 | portTextBox.Text = Content.Port.ToString();
|
---|
| 69 | }
|
---|
| 70 | #endregion
|
---|
| 71 |
|
---|
| 72 | protected override void OnContentChanged() {
|
---|
| 73 | base.OnContentChanged();
|
---|
| 74 | if (Content == null) {
|
---|
| 75 | ipAddressTextBox.Text = String.Empty;
|
---|
| 76 | portTextBox.Text = String.Empty;
|
---|
| 77 | } else {
|
---|
| 78 | ipAddressTextBox.Text = Content.IpAddress;
|
---|
| 79 | portTextBox.Text = Content.Port.ToString();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[3904] | 83 | protected override void SetEnabledStateOfControls() {
|
---|
| 84 | base.SetEnabledStateOfControls();
|
---|
[3890] | 85 | bool readOnlyDriverNullOrStarted = ReadOnly || Content == null || Content.IsInitialized;
|
---|
| 86 | ipAddressTextBox.Enabled = !readOnlyDriverNullOrStarted;
|
---|
| 87 | portTextBox.Enabled = !readOnlyDriverNullOrStarted;
|
---|
| 88 | connectButton.Enabled = !readOnlyDriverNullOrStarted;
|
---|
| 89 | disconnectButton.Enabled = !ReadOnly && Content != null && Content.IsInitialized;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | #region Event Handlers (child controls)
|
---|
| 93 | private void ipAddressTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 94 | if (Content != null) {
|
---|
| 95 | try {
|
---|
| 96 | System.Net.IPAddress.Parse(ipAddressTextBox.Text);
|
---|
[3904] | 97 | }
|
---|
| 98 | catch (FormatException) {
|
---|
[3890] | 99 | e.Cancel = true;
|
---|
| 100 | }
|
---|
| 101 | if (!e.Cancel) Content.IpAddress = ipAddressTextBox.Text;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | private void portTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 105 | if (Content != null) {
|
---|
| 106 | int port;
|
---|
| 107 | e.Cancel = !int.TryParse(portTextBox.Text, out port);
|
---|
| 108 | if (!e.Cancel) Content.Port = port;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | private void connectButton_Click(object sender, EventArgs e) {
|
---|
| 112 | try {
|
---|
| 113 | Content.Open();
|
---|
[3904] | 114 | }
|
---|
| 115 | catch (Exception ex) {
|
---|
[3896] | 116 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
[3890] | 117 | }
|
---|
| 118 | }
|
---|
| 119 | private void disconnectButton_Click(object sender, EventArgs e) {
|
---|
| 120 | try {
|
---|
| 121 | Content.Close();
|
---|
[3904] | 122 | }
|
---|
| 123 | catch (Exception ex) {
|
---|
[3896] | 124 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
[3890] | 125 | }
|
---|
| 126 | }
|
---|
| 127 | #endregion
|
---|
| 128 | }
|
---|
| 129 | }
|
---|