Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/OperatorGraphView.cs @ 3613

Last change on this file since 3613 was 3566, checked in by mkommend, 14 years ago

removed ctors with contents in all views (ticket #972)

File size: 5.9 KB
Line 
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
22using System;
23using System.ComponentModel;
24using System.Drawing;
25using System.Windows.Forms;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Core.Views {
29  /// <summary>
30  /// The visual representation of an <see cref="OperatorGraph"/>.
31  /// </summary>
32  [View("OperatorGraph View (Tree)")]
33  [Content(typeof(OperatorGraph), false)]
34  public partial class OperatorGraphView : ItemView {
35    /// <summary>
36    /// Gets or sets the operator graph to represent visually.
37    /// </summary>
38    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
39    /// No own data storage present.</remarks>
40    public new OperatorGraph Content {
41      get { return (OperatorGraph)base.Content; }
42      set { base.Content = value; }
43    }
44
45    /// <summary>
46    /// Initializes a new instance of <see cref="OperatorGraphView"/> with caption "Operator Graph".
47    /// </summary>
48    public OperatorGraphView() {
49      InitializeComponent();
50      Caption = "Operator Graph";
51    }
52
53    /// <summary>
54    /// Removes the eventhandlers from the underlying <see cref="IOperatorGraph"/>.
55    /// </summary>
56    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
57    protected override void DeregisterContentEvents() {
58      Content.InitialOperatorChanged -= new EventHandler(Content_InitialOperatorChanged);
59      base.DeregisterContentEvents();
60    }
61
62    /// <summary>
63    /// Adds eventhandlers to the underlying <see cref="IOperatorGraph"/>.
64    /// </summary>
65    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
66    protected override void RegisterContentEvents() {
67      base.RegisterContentEvents();
68      Content.InitialOperatorChanged += new EventHandler(Content_InitialOperatorChanged);
69    }
70
71    /// <summary>
72    /// Updates all controls with the latest data of the model.
73    /// </summary>
74    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
75    protected override void OnContentChanged() {
76      base.OnContentChanged();
77      Caption = "Operator Graph";
78      operatorsView.Content = null;
79      operatorTreeView.Content = null;
80      if (Content != null) {
81        Caption = Content.ItemName + " (" + Content.GetType().Name + ")";
82        operatorsView.Content = Content.Operators;
83        MarkInitialOperator();
84        operatorTreeView.Content = Content.InitialOperator;
85      }
86      SetEnabledStateOfControls();
87    }
88
89    protected override void OnReadOnlyChanged() {
90      base.OnReadOnlyChanged();
91      SetEnabledStateOfControls();
92    }
93
94    private void SetEnabledStateOfControls() {
95      operatorsView.Enabled = Content != null;
96      operatorTreeView.Enabled = Content != null;
97      operatorsContextMenuStrip.Enabled = Content != null && !ReadOnly;
98    }
99
100
101    protected virtual void MarkInitialOperator() {
102      foreach (ListViewItem item in operatorsView.ItemsListView.Items) {
103        if ((Content.InitialOperator != null) && (((IOperator)item.Tag) == Content.InitialOperator))
104          item.Font = new Font(operatorsView.ItemsListView.Font, FontStyle.Bold);
105        else
106          item.Font = operatorsView.ItemsListView.Font;
107      }
108    }
109
110    #region Operator Tree View Events
111    protected virtual void operatorTreeView_SelectedOperatorChanged(object sender, EventArgs e) {
112      foreach (ListViewItem item in operatorsView.ItemsListView.Items)
113        item.Selected = item.Tag == operatorTreeView.SelectedOperator;
114    }
115    #endregion
116
117    #region Context Menu Events
118    protected virtual void operatorsView_Load(object sender, EventArgs e) {
119      operatorsView.ItemsListView.ContextMenuStrip = operatorsContextMenuStrip;
120    }
121    protected virtual void operatorsContextMenuStrip_Opening(object sender, CancelEventArgs e) {
122      initialOperatorToolStripMenuItem.Enabled = false;
123      initialOperatorToolStripMenuItem.Checked = false;
124      if (operatorsView.ItemsListView.SelectedItems.Count == 1) {
125        IOperator op = (IOperator)operatorsView.ItemsListView.SelectedItems[0].Tag;
126        initialOperatorToolStripMenuItem.Enabled = true;
127        initialOperatorToolStripMenuItem.Tag = op;
128        if (op == Content.InitialOperator)
129          initialOperatorToolStripMenuItem.Checked = true;
130      }
131    }
132    protected virtual void initialOperatorToolStripMenuItem_Click(object sender, EventArgs e) {
133      if (initialOperatorToolStripMenuItem.Checked)
134        Content.InitialOperator = (IOperator)initialOperatorToolStripMenuItem.Tag;
135      else
136        Content.InitialOperator = null;
137    }
138    #endregion
139
140    #region Content Events
141    protected virtual void Content_InitialOperatorChanged(object sender, EventArgs e) {
142      if (InvokeRequired)
143        Invoke(new EventHandler(Content_InitialOperatorChanged), sender, e);
144      else {
145        MarkInitialOperator();
146        operatorTreeView.Content = Content.InitialOperator;
147      }
148    }
149    #endregion
150  }
151}
Note: See TracBrowser for help on using the repository browser.