1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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.Windows.Forms;
|
---|
24 | using HeuristicLab.MainForm;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.Core.Views {
|
---|
27 | /// <summary>
|
---|
28 | /// The visual representation of a <see cref="Variable"/>.
|
---|
29 | /// </summary>
|
---|
30 | [View("Variable Value View")]
|
---|
31 | [Content(typeof(Variable), false)]
|
---|
32 | [Content(typeof(IVariable), false)]
|
---|
33 | public partial class VariableValueView : ItemView {
|
---|
34 | /// <summary>
|
---|
35 | /// Gets or sets the variable to represent visually.
|
---|
36 | /// </summary>
|
---|
37 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
38 | /// No own data storage present.</remarks>
|
---|
39 | public new IVariable Content {
|
---|
40 | get { return (IVariable)base.Content; }
|
---|
41 | set { base.Content = value; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /// <summary>
|
---|
45 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
46 | /// </summary>
|
---|
47 | public VariableValueView() {
|
---|
48 | InitializeComponent();
|
---|
49 | }
|
---|
50 |
|
---|
51 | /// <summary>
|
---|
52 | /// Removes the eventhandlers from the underlying <see cref="Variable"/>.
|
---|
53 | /// </summary>
|
---|
54 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
55 | protected override void DeregisterContentEvents() {
|
---|
56 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
57 | base.DeregisterContentEvents();
|
---|
58 | }
|
---|
59 |
|
---|
60 | /// <summary>
|
---|
61 | /// Adds eventhandlers to the underlying <see cref="Variable"/>.
|
---|
62 | /// </summary>
|
---|
63 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
64 | protected override void RegisterContentEvents() {
|
---|
65 | base.RegisterContentEvents();
|
---|
66 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected override void OnContentChanged() {
|
---|
70 | base.OnContentChanged();
|
---|
71 | if (Content == null) {
|
---|
72 | viewHost.Content = null;
|
---|
73 | } else {
|
---|
74 | viewHost.ViewType = null;
|
---|
75 | viewHost.Content = Content.Value;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected override void SetEnabledStateOfControls() {
|
---|
80 | base.SetEnabledStateOfControls();
|
---|
81 | valuePanel.Enabled = Content != null;
|
---|
82 | }
|
---|
83 |
|
---|
84 | protected virtual void Content_ValueChanged(object sender, EventArgs e) {
|
---|
85 | if (InvokeRequired)
|
---|
86 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
87 | else {
|
---|
88 | viewHost.ViewType = null;
|
---|
89 | viewHost.Content = Content.Value;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
|
---|
94 | e.Effect = DragDropEffects.None;
|
---|
95 | Type type = e.Data.GetData("Type") as Type;
|
---|
96 | if (!ReadOnly && (type != null) && (typeof(IItem).IsAssignableFrom(type))) {
|
---|
97 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
98 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
99 | else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
|
---|
100 | else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
|
---|
101 | else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
|
---|
105 | if (e.Effect != DragDropEffects.None) {
|
---|
106 | IItem item = e.Data.GetData("Value") as IItem;
|
---|
107 | if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
|
---|
108 | Content.Value = item;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|