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