[3260] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 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 |
|
---|
[6818] | 46 | public override bool ReadOnly {
|
---|
| 47 | get { return true; }
|
---|
| 48 | set { /*not needed because runs are always readonly */}
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[3260] | 51 | /// <summary>
|
---|
| 52 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
| 53 | /// </summary>
|
---|
| 54 | public RunView() {
|
---|
| 55 | InitializeComponent();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[3638] | 58 | protected override void RegisterContentEvents() {
|
---|
| 59 | base.RegisterContentEvents();
|
---|
| 60 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 61 | }
|
---|
| 62 | protected override void DeregisterContentEvents() {
|
---|
| 63 | base.DeregisterContentEvents();
|
---|
| 64 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 65 | }
|
---|
| 66 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 67 | if (InvokeRequired)
|
---|
| 68 | this.Invoke(new EventHandler(Content_Changed), sender, e);
|
---|
| 69 | else
|
---|
[4096] | 70 | UpdateColor();
|
---|
[3638] | 71 | }
|
---|
| 72 |
|
---|
[3260] | 73 | protected override void OnContentChanged() {
|
---|
| 74 | base.OnContentChanged();
|
---|
| 75 | viewHost.Content = null;
|
---|
[3764] | 76 | if (Content != null)
|
---|
[4096] | 77 | UpdateColor();
|
---|
[3775] | 78 | FillListView();
|
---|
[3904] | 79 | }
|
---|
[3764] | 80 |
|
---|
[3904] | 81 | protected override void SetEnabledStateOfControls() {
|
---|
| 82 | base.SetEnabledStateOfControls();
|
---|
[3454] | 83 | listView.Enabled = Content != null;
|
---|
[4099] | 84 | detailsGroupBox.Enabled = (Content != null) && (listView.SelectedItems.Count == 1);
|
---|
[3454] | 85 | viewHost.Enabled = Content != null;
|
---|
[6818] | 86 | viewHost.ReadOnly = ReadOnly;
|
---|
[3638] | 87 | changeColorButton.Enabled = Content != null;
|
---|
[4102] | 88 | showAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !Locked;
|
---|
[3260] | 89 | }
|
---|
| 90 |
|
---|
[3638] | 91 | private void changeColorButton_Click(object sender, EventArgs e) {
|
---|
| 92 | if (colorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 93 | this.Content.Color = this.colorDialog.Color;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
[4096] | 96 | private void UpdateColor() {
|
---|
[3638] | 97 | this.colorDialog.Color = this.Content.Color;
|
---|
[4096] | 98 | this.colorArea.BackColor = this.Content.Color;
|
---|
[3638] | 99 | }
|
---|
| 100 |
|
---|
[4011] | 101 | private string selectedName;
|
---|
[3260] | 102 | private void FillListView() {
|
---|
[3775] | 103 | if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
|
---|
| 104 |
|
---|
[3260] | 105 | listView.Items.Clear();
|
---|
[3341] | 106 | listView.SmallImageList.Images.Clear();
|
---|
[3260] | 107 | if (Content != null) {
|
---|
[3341] | 108 | foreach (string key in Content.Parameters.Keys)
|
---|
[3775] | 109 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
|
---|
[3341] | 110 | foreach (string key in Content.Results.Keys)
|
---|
[3775] | 111 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
|
---|
[3260] | 112 | if (listView.Items.Count > 0) {
|
---|
| 113 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 114 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
[4011] | 115 | selectedName = null;
|
---|
[3260] | 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[3775] | 120 | private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
|
---|
[3341] | 121 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
| 122 | item.Tag = value;
|
---|
| 123 | item.Group = group;
|
---|
[5287] | 124 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage);
|
---|
[3341] | 125 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
| 126 | listView.Items.Add(item);
|
---|
[3775] | 127 | if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
|
---|
[3341] | 128 | }
|
---|
| 129 |
|
---|
[3260] | 130 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[4096] | 131 | if (showDetailsCheckBox.Checked) {
|
---|
| 132 | if (listView.SelectedItems.Count == 1) {
|
---|
| 133 | detailsGroupBox.Enabled = true;
|
---|
| 134 | viewHost.Content = listView.SelectedItems[0].Tag as IContent;
|
---|
| 135 | } else {
|
---|
| 136 | viewHost.Content = null;
|
---|
| 137 | detailsGroupBox.Enabled = false;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
[3260] | 140 | }
|
---|
[3300] | 141 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
| 142 | if (listView.SelectedItems.Count == 1) {
|
---|
| 143 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
[3557] | 144 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
[3416] | 145 | if (view != null) {
|
---|
[3766] | 146 | view.ReadOnly = true;
|
---|
[3423] | 147 | view.Locked = Locked;
|
---|
[3416] | 148 | }
|
---|
[3300] | 149 | }
|
---|
| 150 | }
|
---|
| 151 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 152 | if (!Locked) {
|
---|
| 153 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 154 | IItem item = (IItem)listViewItem.Tag;
|
---|
[3731] | 155 | if (item != null) {
|
---|
| 156 | DataObject data = new DataObject();
|
---|
[5837] | 157 | data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
|
---|
[3731] | 158 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
| 159 | }
|
---|
[3432] | 160 | }
|
---|
[3300] | 161 | }
|
---|
[4096] | 162 | private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 163 | if (showDetailsCheckBox.Checked) {
|
---|
| 164 | splitContainer.Panel2Collapsed = false;
|
---|
| 165 | detailsGroupBox.Enabled = listView.SelectedItems.Count == 1;
|
---|
| 166 | viewHost.Content = listView.SelectedItems.Count == 1 ? (IContent)listView.SelectedItems[0].Tag : null;
|
---|
| 167 | } else {
|
---|
| 168 | splitContainer.Panel2Collapsed = true;
|
---|
| 169 | viewHost.Content = null;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
[3300] | 172 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[3454] | 173 | if (!Locked) {
|
---|
[3557] | 174 | MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
|
---|
[3416] | 175 | }
|
---|
[3300] | 176 | }
|
---|
[3260] | 177 | }
|
---|
| 178 | }
|
---|