Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Core.Views/3.3/OperatorGraphView.cs @ 14786

Last change on this file since 14786 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.6 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[14186]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[2520]26using HeuristicLab.MainForm;
[2]27
[2520]28namespace HeuristicLab.Core.Views {
[776]29  /// <summary>
[2655]30  /// The visual representation of an <see cref="OperatorGraph"/>.
[776]31  /// </summary>
[3395]32  [View("OperatorGraph View (Tree)")]
[3361]33  [Content(typeof(OperatorGraph), false)]
[2664]34  public partial class OperatorGraphView : ItemView {
[776]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>
[2713]40    public new OperatorGraph Content {
41      get { return (OperatorGraph)base.Content; }
42      set { base.Content = value; }
[2]43    }
44
[776]45    /// <summary>
46    /// Initializes a new instance of <see cref="OperatorGraphView"/> with caption "Operator Graph".
47    /// </summary>
[2]48    public OperatorGraphView() {
49      InitializeComponent();
50    }
51
[776]52    /// <summary>
53    /// Removes the eventhandlers from the underlying <see cref="IOperatorGraph"/>.
54    /// </summary>
55    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
[2713]56    protected override void DeregisterContentEvents() {
57      Content.InitialOperatorChanged -= new EventHandler(Content_InitialOperatorChanged);
58      base.DeregisterContentEvents();
[2]59    }
[2655]60
[776]61    /// <summary>
62    /// Adds eventhandlers to the underlying <see cref="IOperatorGraph"/>.
63    /// </summary>
64    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
[2713]65    protected override void RegisterContentEvents() {
66      base.RegisterContentEvents();
67      Content.InitialOperatorChanged += new EventHandler(Content_InitialOperatorChanged);
[2]68    }
69
[776]70    /// <summary>
71    /// Updates all controls with the latest data of the model.
72    /// </summary>
73    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
[2713]74    protected override void OnContentChanged() {
75      base.OnContentChanged();
76      operatorsView.Content = null;
[2947]77      operatorTreeView.Content = null;
[2801]78      if (Content != null) {
[2713]79        operatorsView.Content = Content.Operators;
[2655]80        MarkInitialOperator();
[2947]81        operatorTreeView.Content = Content.InitialOperator;
[2]82      }
83    }
84
[3904]85    protected override void SetEnabledStateOfControls() {
86      base.SetEnabledStateOfControls();
[3362]87      operatorsView.Enabled = Content != null;
88      operatorTreeView.Enabled = Content != null;
89      operatorsContextMenuStrip.Enabled = Content != null && !ReadOnly;
90    }
91
[2676]92    protected virtual void MarkInitialOperator() {
[2655]93      foreach (ListViewItem item in operatorsView.ItemsListView.Items) {
[2713]94        if ((Content.InitialOperator != null) && (((IOperator)item.Tag) == Content.InitialOperator))
[2655]95          item.Font = new Font(operatorsView.ItemsListView.Font, FontStyle.Bold);
96        else
97          item.Font = operatorsView.ItemsListView.Font;
[2]98      }
99    }
100
[2949]101    #region Operator Tree View Events
102    protected virtual void operatorTreeView_SelectedOperatorChanged(object sender, EventArgs e) {
103      foreach (ListViewItem item in operatorsView.ItemsListView.Items)
104        item.Selected = item.Tag == operatorTreeView.SelectedOperator;
105    }
106    #endregion
107
[2]108    #region Context Menu Events
[2676]109    protected virtual void operatorsView_Load(object sender, EventArgs e) {
110      operatorsView.ItemsListView.ContextMenuStrip = operatorsContextMenuStrip;
111    }
112    protected virtual void operatorsContextMenuStrip_Opening(object sender, CancelEventArgs e) {
[2]113      initialOperatorToolStripMenuItem.Enabled = false;
114      initialOperatorToolStripMenuItem.Checked = false;
[2655]115      if (operatorsView.ItemsListView.SelectedItems.Count == 1) {
116        IOperator op = (IOperator)operatorsView.ItemsListView.SelectedItems[0].Tag;
[2]117        initialOperatorToolStripMenuItem.Enabled = true;
118        initialOperatorToolStripMenuItem.Tag = op;
[2713]119        if (op == Content.InitialOperator)
[2]120          initialOperatorToolStripMenuItem.Checked = true;
121      }
122    }
[2676]123    protected virtual void initialOperatorToolStripMenuItem_Click(object sender, EventArgs e) {
[2655]124      if (initialOperatorToolStripMenuItem.Checked)
[2713]125        Content.InitialOperator = (IOperator)initialOperatorToolStripMenuItem.Tag;
[2655]126      else
[2713]127        Content.InitialOperator = null;
[2]128    }
129    #endregion
130
[2713]131    #region Content Events
132    protected virtual void Content_InitialOperatorChanged(object sender, EventArgs e) {
[2655]133      if (InvokeRequired)
[2713]134        Invoke(new EventHandler(Content_InitialOperatorChanged), sender, e);
[2655]135      else {
136        MarkInitialOperator();
[2947]137        operatorTreeView.Content = Content.InitialOperator;
[2]138      }
139    }
140    #endregion
141  }
142}
Note: See TracBrowser for help on using the repository browser.