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