Free cookie consent management tool by TermsFeed Policy Generator

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

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

Abandoned policy that the names of all abstract base classes have to end in "Base" (#95)

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