[3260] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 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);
|
---|
[3454] | 80 | viewHost.Enabled = Content != null;
|
---|
[3638] | 81 | changeColorButton.Enabled = Content != null;
|
---|
[4102] | 82 | showAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !Locked;
|
---|
[3260] | 83 | }
|
---|
| 84 |
|
---|
[3638] | 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 | }
|
---|
[4096] | 90 | private void UpdateColor() {
|
---|
[3638] | 91 | this.colorDialog.Color = this.Content.Color;
|
---|
[4096] | 92 | this.colorArea.BackColor = this.Content.Color;
|
---|
[3638] | 93 | }
|
---|
| 94 |
|
---|
[4011] | 95 | private string selectedName;
|
---|
[3260] | 96 | private void FillListView() {
|
---|
[3775] | 97 | if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
|
---|
| 98 |
|
---|
[3260] | 99 | listView.Items.Clear();
|
---|
[3341] | 100 | listView.SmallImageList.Images.Clear();
|
---|
[3260] | 101 | if (Content != null) {
|
---|
[3341] | 102 | foreach (string key in Content.Parameters.Keys)
|
---|
[3775] | 103 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
|
---|
[3341] | 104 | foreach (string key in Content.Results.Keys)
|
---|
[3775] | 105 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
|
---|
[3260] | 106 | if (listView.Items.Count > 0) {
|
---|
| 107 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 108 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
[4011] | 109 | selectedName = null;
|
---|
[3260] | 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[3775] | 114 | private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
|
---|
[3341] | 115 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
| 116 | item.Tag = value;
|
---|
| 117 | item.Group = group;
|
---|
[5287] | 118 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage);
|
---|
[3341] | 119 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
| 120 | listView.Items.Add(item);
|
---|
[3775] | 121 | if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
|
---|
[3341] | 122 | }
|
---|
| 123 |
|
---|
[3260] | 124 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[4096] | 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 | }
|
---|
[3260] | 134 | }
|
---|
[3300] | 135 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
| 136 | if (listView.SelectedItems.Count == 1) {
|
---|
| 137 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
[3557] | 138 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
[3416] | 139 | if (view != null) {
|
---|
[3766] | 140 | view.ReadOnly = true;
|
---|
[3423] | 141 | view.Locked = Locked;
|
---|
[3416] | 142 | }
|
---|
[3300] | 143 | }
|
---|
| 144 | }
|
---|
| 145 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 146 | if (!Locked) {
|
---|
| 147 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 148 | IItem item = (IItem)listViewItem.Tag;
|
---|
[3731] | 149 | if (item != null) {
|
---|
| 150 | DataObject data = new DataObject();
|
---|
[5837] | 151 | data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
|
---|
[3731] | 152 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
| 153 | }
|
---|
[3432] | 154 | }
|
---|
[3300] | 155 | }
|
---|
[4096] | 156 | private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 157 | if (showDetailsCheckBox.Checked) {
|
---|
| 158 | splitContainer.Panel2Collapsed = false;
|
---|
| 159 | detailsGroupBox.Enabled = listView.SelectedItems.Count == 1;
|
---|
| 160 | viewHost.Content = listView.SelectedItems.Count == 1 ? (IContent)listView.SelectedItems[0].Tag : null;
|
---|
| 161 | } else {
|
---|
| 162 | splitContainer.Panel2Collapsed = true;
|
---|
| 163 | viewHost.Content = null;
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
[3300] | 166 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[3454] | 167 | if (!Locked) {
|
---|
[3557] | 168 | MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
|
---|
[3416] | 169 | }
|
---|
[3300] | 170 | }
|
---|
[3260] | 171 | }
|
---|
| 172 | }
|
---|