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.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimization.Views {
|
---|
30 | /// <summary>
|
---|
31 | /// The visual representation of a <see cref="Variable"/>.
|
---|
32 | /// </summary>
|
---|
33 | [View("Run View")]
|
---|
34 | [Content(typeof(IRun), true)]
|
---|
35 | public sealed partial class RunView : NamedItemView {
|
---|
36 | /// <summary>
|
---|
37 | /// Gets or sets the variable to represent visually.
|
---|
38 | /// </summary>
|
---|
39 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
40 | /// No own data storage present.</remarks>
|
---|
41 | public new IRun Content {
|
---|
42 | get { return (IRun)base.Content; }
|
---|
43 | set { base.Content = value; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | /// <summary>
|
---|
47 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
48 | /// </summary>
|
---|
49 | public RunView() {
|
---|
50 | InitializeComponent();
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void RegisterContentEvents() {
|
---|
54 | base.RegisterContentEvents();
|
---|
55 | Content.Changed += new EventHandler(Content_Changed);
|
---|
56 | }
|
---|
57 | protected override void DeregisterContentEvents() {
|
---|
58 | base.DeregisterContentEvents();
|
---|
59 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
60 | }
|
---|
61 | private void Content_Changed(object sender, EventArgs e) {
|
---|
62 | if (InvokeRequired)
|
---|
63 | this.Invoke(new EventHandler(Content_Changed), sender, e);
|
---|
64 | else
|
---|
65 | UpdateColor();
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected override void OnContentChanged() {
|
---|
69 | base.OnContentChanged();
|
---|
70 | viewHost.Content = null;
|
---|
71 | if (Content != null)
|
---|
72 | UpdateColor();
|
---|
73 | FillListView();
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void SetEnabledStateOfControls() {
|
---|
77 | base.SetEnabledStateOfControls();
|
---|
78 | listView.Enabled = Content != null;
|
---|
79 | detailsGroupBox.Enabled = (Content != null) && (listView.SelectedItems.Count == 1);
|
---|
80 | viewHost.Enabled = Content != null;
|
---|
81 | changeColorButton.Enabled = Content != null;
|
---|
82 | showAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !Locked;
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void changeColorButton_Click(object sender, EventArgs e) {
|
---|
86 | if (colorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
87 | this.Content.Color = this.colorDialog.Color;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | private void UpdateColor() {
|
---|
91 | this.colorDialog.Color = this.Content.Color;
|
---|
92 | this.colorArea.BackColor = this.Content.Color;
|
---|
93 | }
|
---|
94 |
|
---|
95 | private string selectedName;
|
---|
96 | private void FillListView() {
|
---|
97 | if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
|
---|
98 |
|
---|
99 | listView.Items.Clear();
|
---|
100 | listView.SmallImageList.Images.Clear();
|
---|
101 | if (Content != null) {
|
---|
102 | foreach (string key in Content.Parameters.Keys)
|
---|
103 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
|
---|
104 | foreach (string key in Content.Results.Keys)
|
---|
105 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
|
---|
106 | if (listView.Items.Count > 0) {
|
---|
107 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
108 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
109 | selectedName = null;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
|
---|
115 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
116 | item.Tag = value;
|
---|
117 | item.Group = group;
|
---|
118 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage);
|
---|
119 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
120 | listView.Items.Add(item);
|
---|
121 | if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
|
---|
122 | }
|
---|
123 |
|
---|
124 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
125 | if (showDetailsCheckBox.Checked) {
|
---|
126 | if (listView.SelectedItems.Count == 1) {
|
---|
127 | detailsGroupBox.Enabled = true;
|
---|
128 | viewHost.Content = listView.SelectedItems[0].Tag as IContent;
|
---|
129 | } else {
|
---|
130 | viewHost.Content = null;
|
---|
131 | detailsGroupBox.Enabled = false;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
136 | if (listView.SelectedItems.Count == 1) {
|
---|
137 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
138 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
139 | if (view != null) {
|
---|
140 | view.ReadOnly = true;
|
---|
141 | view.Locked = Locked;
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|
145 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
146 | if (!Locked) {
|
---|
147 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
148 | IItem item = (IItem)listViewItem.Tag;
|
---|
149 | if (item != null) {
|
---|
150 | DataObject data = new DataObject();
|
---|
151 | data.SetData("Type", item.GetType());
|
---|
152 | data.SetData("Value", item);
|
---|
153 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|
157 | private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
158 | if (showDetailsCheckBox.Checked) {
|
---|
159 | splitContainer.Panel2Collapsed = false;
|
---|
160 | detailsGroupBox.Enabled = listView.SelectedItems.Count == 1;
|
---|
161 | viewHost.Content = listView.SelectedItems.Count == 1 ? (IContent)listView.SelectedItems[0].Tag : null;
|
---|
162 | } else {
|
---|
163 | splitContainer.Panel2Collapsed = true;
|
---|
164 | viewHost.Content = null;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
168 | if (!Locked) {
|
---|
169 | MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|