Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/VariableValueView.cs @ 6089

Last change on this file since 6089 was 5837, checked in by swagner, 14 years ago

Implemented review comments of mkommend (#1112)

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25
26namespace 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 virtual void Content_ValueChanged(object sender, EventArgs e) {
80      if (InvokeRequired)
81        Invoke(new EventHandler(Content_ValueChanged), sender, e);
82      else {
83        viewHost.ViewType = null;
84        viewHost.Content = Content.Value;
85      }
86    }
87
88    protected virtual void VariableValueView_DragEnterOver(object sender, DragEventArgs e) {
89      e.Effect = DragDropEffects.None;
90      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IItem)) {
91        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
92        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
93        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
94        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
95        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
96      }
97    }
98    protected virtual void VariableValueView_DragDrop(object sender, DragEventArgs e) {
99      if (e.Effect != DragDropEffects.None) {
100        IItem item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IItem;
101        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
102        Content.Value = item;
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.