[2655] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
[2714] | 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Core.Views;
|
---|
[2655] | 31 | using HeuristicLab.MainForm;
|
---|
| 32 |
|
---|
[2714] | 33 | namespace HeuristicLab.Parameters.Views {
|
---|
[2655] | 34 | /// <summary>
|
---|
| 35 | /// The visual representation of a <see cref="Parameter"/>.
|
---|
| 36 | /// </summary>
|
---|
[2664] | 37 | [Content(typeof(ItemParameter), true)]
|
---|
| 38 | public partial class ItemParameterView : ParameterView {
|
---|
[2676] | 39 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
[2655] | 40 |
|
---|
| 41 | /// <summary>
|
---|
| 42 | /// Gets or sets the variable to represent visually.
|
---|
| 43 | /// </summary>
|
---|
| 44 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 45 | /// No own data storage present.</remarks>
|
---|
[2713] | 46 | public new ItemParameter Content {
|
---|
| 47 | get { return (ItemParameter)base.Content; }
|
---|
| 48 | set { base.Content = value; }
|
---|
[2655] | 49 | }
|
---|
| 50 |
|
---|
| 51 | /// <summary>
|
---|
| 52 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
| 53 | /// </summary>
|
---|
[2664] | 54 | public ItemParameterView() {
|
---|
[2655] | 55 | InitializeComponent();
|
---|
| 56 | Caption = "Parameter";
|
---|
| 57 | }
|
---|
| 58 | /// <summary>
|
---|
| 59 | /// Initializes a new instance of <see cref="VariableView"/> with the given <paramref name="variable"/>.
|
---|
| 60 | /// </summary>
|
---|
| 61 | /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
|
---|
| 62 | /// <param name="variable">The variable to represent visually.</param>
|
---|
[2664] | 63 | public ItemParameterView(ItemParameter parameter)
|
---|
[2655] | 64 | : this() {
|
---|
[2713] | 65 | Content = parameter;
|
---|
[2655] | 66 | }
|
---|
| 67 |
|
---|
| 68 | /// <summary>
|
---|
| 69 | /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
|
---|
| 70 | /// </summary>
|
---|
| 71 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2713] | 72 | protected override void DeregisterContentEvents() {
|
---|
| 73 | Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
|
---|
| 74 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
| 75 | base.DeregisterContentEvents();
|
---|
[2655] | 76 | }
|
---|
| 77 |
|
---|
| 78 | /// <summary>
|
---|
| 79 | /// Adds eventhandlers to the underlying <see cref="IVariable"/>.
|
---|
| 80 | /// </summary>
|
---|
| 81 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2713] | 82 | protected override void RegisterContentEvents() {
|
---|
| 83 | base.RegisterContentEvents();
|
---|
| 84 | Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
|
---|
| 85 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
[2655] | 86 | }
|
---|
| 87 |
|
---|
[2713] | 88 | protected override void OnContentChanged() {
|
---|
| 89 | base.OnContentChanged();
|
---|
| 90 | if (Content == null) {
|
---|
[2655] | 91 | Caption = "Parameter";
|
---|
| 92 | actualNameTextBox.Text = "-";
|
---|
| 93 | actualNameTextBox.Enabled = false;
|
---|
| 94 | setValueButton.Enabled = false;
|
---|
| 95 | clearValueButton.Enabled = false;
|
---|
| 96 | valueGroupBox.Enabled = false;
|
---|
[2713] | 97 | viewHost.Content = null;
|
---|
[2655] | 98 | } else {
|
---|
[2713] | 99 | Caption = Content.Name + " (" + Content.GetType().Name + ")";
|
---|
| 100 | actualNameTextBox.Text = Content.ActualName;
|
---|
| 101 | actualNameTextBox.Enabled = Content.Value == null;
|
---|
| 102 | setValueButton.Enabled = Content.Value == null;
|
---|
| 103 | clearValueButton.Enabled = Content.Value != null;
|
---|
[2655] | 104 | valueGroupBox.Enabled = true;
|
---|
[2713] | 105 | viewHost.Content = Content.Value;
|
---|
[2655] | 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[2713] | 109 | protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
|
---|
[2655] | 110 | if (InvokeRequired)
|
---|
[2713] | 111 | Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
|
---|
[2655] | 112 | else
|
---|
[2713] | 113 | actualNameTextBox.Text = Content.ActualName;
|
---|
[2655] | 114 | }
|
---|
[2713] | 115 | protected virtual void Content_ValueChanged(object sender, EventArgs e) {
|
---|
[2655] | 116 | if (InvokeRequired)
|
---|
[2713] | 117 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
[2655] | 118 | else {
|
---|
[2713] | 119 | actualNameTextBox.Enabled = Content.Value == null;
|
---|
| 120 | setValueButton.Enabled = Content.Value == null;
|
---|
| 121 | clearValueButton.Enabled = Content.Value != null;
|
---|
| 122 | viewHost.Content = Content.Value;
|
---|
[2655] | 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[2676] | 126 | protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
|
---|
[2713] | 127 | Content.ActualName = actualNameTextBox.Text;
|
---|
[2655] | 128 | }
|
---|
[2676] | 129 | protected virtual void setValueButton_Click(object sender, EventArgs e) {
|
---|
[2655] | 130 | if (typeSelectorDialog == null) {
|
---|
| 131 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
| 132 | typeSelectorDialog.Caption = "Select Value Type";
|
---|
| 133 | }
|
---|
[2713] | 134 | typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
|
---|
[2655] | 135 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
|
---|
[2713] | 136 | Content.Value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
[2655] | 137 | }
|
---|
[2676] | 138 | protected virtual void clearValueButton_Click(object sender, EventArgs e) {
|
---|
[2713] | 139 | Content.Value = null;
|
---|
[2655] | 140 | }
|
---|
[2676] | 141 | protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
|
---|
[2655] | 142 | e.Effect = DragDropEffects.None;
|
---|
| 143 | Type type = e.Data.GetData("Type") as Type;
|
---|
[2713] | 144 | if ((type != null) && (Content.DataType.IsAssignableFrom(type))) {
|
---|
[2655] | 145 | if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy; // CTRL key
|
---|
[2694] | 146 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
| 147 | else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
|
---|
| 148 | else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
|
---|
| 149 | else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
|
---|
[2655] | 150 | }
|
---|
| 151 | }
|
---|
[2676] | 152 | protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
|
---|
[2655] | 153 | if (e.Effect != DragDropEffects.None) {
|
---|
| 154 | IItem item = e.Data.GetData("Value") as IItem;
|
---|
| 155 | if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
|
---|
[2713] | 156 | Content.Value = item;
|
---|
[2655] | 157 | }
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | }
|
---|