[3260] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 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;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Optimization.Views {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// The visual representation of a <see cref="Variable"/>.
|
---|
| 32 | /// </summary>
|
---|
| 33 | [View("Run View")]
|
---|
[3280] | 34 | [Content(typeof(IRun), true)]
|
---|
[3260] | 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>
|
---|
[3280] | 41 | public new IRun Content {
|
---|
| 42 | get { return (IRun)base.Content; }
|
---|
[3260] | 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 |
|
---|
[3638] | 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
|
---|
[4096] | 65 | UpdateColor();
|
---|
[3638] | 66 | }
|
---|
| 67 |
|
---|
[3260] | 68 | protected override void OnContentChanged() {
|
---|
| 69 | base.OnContentChanged();
|
---|
| 70 | viewHost.Content = null;
|
---|
[3764] | 71 | if (Content != null)
|
---|
[4096] | 72 | UpdateColor();
|
---|
[3775] | 73 | FillListView();
|
---|
[3904] | 74 | }
|
---|
[3764] | 75 |
|
---|
[3904] | 76 | protected override void SetEnabledStateOfControls() {
|
---|
| 77 | base.SetEnabledStateOfControls();
|
---|
[3454] | 78 | listView.Enabled = Content != null;
|
---|
[4099] | 79 | detailsGroupBox.Enabled = (Content != null) && (listView.SelectedItems.Count == 1);
|
---|
[3638] | 80 | changeColorButton.Enabled = Content != null;
|
---|
[4102] | 81 | showAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !Locked;
|
---|
[3260] | 82 | }
|
---|
| 83 |
|
---|
[7760] | 84 | protected override void PropagateStateChanges(Control control, Type type, System.Reflection.PropertyInfo propertyInfo) {
|
---|
| 85 | if (propertyInfo.Name == "ReadOnly") return;
|
---|
| 86 | base.PropagateStateChanges(control, type, propertyInfo);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[3638] | 89 | private void changeColorButton_Click(object sender, EventArgs e) {
|
---|
| 90 | if (colorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 91 | this.Content.Color = this.colorDialog.Color;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
[4096] | 94 | private void UpdateColor() {
|
---|
[3638] | 95 | this.colorDialog.Color = this.Content.Color;
|
---|
[4096] | 96 | this.colorArea.BackColor = this.Content.Color;
|
---|
[3638] | 97 | }
|
---|
| 98 |
|
---|
[4011] | 99 | private string selectedName;
|
---|
[3260] | 100 | private void FillListView() {
|
---|
[3775] | 101 | if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
|
---|
| 102 |
|
---|
[3260] | 103 | listView.Items.Clear();
|
---|
[3341] | 104 | listView.SmallImageList.Images.Clear();
|
---|
[3260] | 105 | if (Content != null) {
|
---|
[3341] | 106 | foreach (string key in Content.Parameters.Keys)
|
---|
[3775] | 107 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
|
---|
[3341] | 108 | foreach (string key in Content.Results.Keys)
|
---|
[3775] | 109 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
|
---|
[3260] | 110 | if (listView.Items.Count > 0) {
|
---|
| 111 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 112 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
[4011] | 113 | selectedName = null;
|
---|
[3260] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[3775] | 118 | private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
|
---|
[3341] | 119 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
| 120 | item.Tag = value;
|
---|
| 121 | item.Group = group;
|
---|
[5287] | 122 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage);
|
---|
[3341] | 123 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
| 124 | listView.Items.Add(item);
|
---|
[3775] | 125 | if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
|
---|
[3341] | 126 | }
|
---|
| 127 |
|
---|
[3260] | 128 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[4096] | 129 | if (showDetailsCheckBox.Checked) {
|
---|
| 130 | if (listView.SelectedItems.Count == 1) {
|
---|
| 131 | detailsGroupBox.Enabled = true;
|
---|
| 132 | viewHost.Content = listView.SelectedItems[0].Tag as IContent;
|
---|
| 133 | } else {
|
---|
| 134 | viewHost.Content = null;
|
---|
| 135 | detailsGroupBox.Enabled = false;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
[3260] | 138 | }
|
---|
[3300] | 139 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
| 140 | if (listView.SelectedItems.Count == 1) {
|
---|
| 141 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
[3557] | 142 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
[3416] | 143 | if (view != null) {
|
---|
[3766] | 144 | view.ReadOnly = true;
|
---|
[3423] | 145 | view.Locked = Locked;
|
---|
[3416] | 146 | }
|
---|
[3300] | 147 | }
|
---|
| 148 | }
|
---|
| 149 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 150 | if (!Locked) {
|
---|
| 151 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 152 | IItem item = (IItem)listViewItem.Tag;
|
---|
[3731] | 153 | if (item != null) {
|
---|
| 154 | DataObject data = new DataObject();
|
---|
[5837] | 155 | data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
|
---|
[3731] | 156 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
| 157 | }
|
---|
[3432] | 158 | }
|
---|
[3300] | 159 | }
|
---|
[4096] | 160 | private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 161 | if (showDetailsCheckBox.Checked) {
|
---|
| 162 | splitContainer.Panel2Collapsed = false;
|
---|
| 163 | detailsGroupBox.Enabled = listView.SelectedItems.Count == 1;
|
---|
| 164 | viewHost.Content = listView.SelectedItems.Count == 1 ? (IContent)listView.SelectedItems[0].Tag : null;
|
---|
| 165 | } else {
|
---|
| 166 | splitContainer.Panel2Collapsed = true;
|
---|
| 167 | viewHost.Content = null;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
[3300] | 170 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[3454] | 171 | if (!Locked) {
|
---|
[3557] | 172 | MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
|
---|
[3416] | 173 | }
|
---|
[3300] | 174 | }
|
---|
[3260] | 175 | }
|
---|
| 176 | }
|
---|