[3260] | 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.Core;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Optimization.Views {
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// The visual representation of a <see cref="Variable"/>.
|
---|
| 31 | /// </summary>
|
---|
| 32 | [View("Run View")]
|
---|
[3280] | 33 | [Content(typeof(IRun), true)]
|
---|
[3260] | 34 | public sealed partial class RunView : NamedItemView {
|
---|
| 35 | /// <summary>
|
---|
| 36 | /// Gets or sets the variable to represent visually.
|
---|
| 37 | /// </summary>
|
---|
| 38 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 39 | /// No own data storage present.</remarks>
|
---|
[3280] | 40 | public new IRun Content {
|
---|
| 41 | get { return (IRun)base.Content; }
|
---|
[3260] | 42 | set { base.Content = value; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[3350] | 45 | public override bool ReadOnly {
|
---|
| 46 | get { return base.ReadOnly; }
|
---|
| 47 | set { /*not needed because results are always readonly */}
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[3260] | 50 | /// <summary>
|
---|
| 51 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
| 52 | /// </summary>
|
---|
| 53 | public RunView() {
|
---|
| 54 | InitializeComponent();
|
---|
| 55 | Caption = "Run";
|
---|
[3350] | 56 | base.ReadOnly = true;
|
---|
[3260] | 57 | }
|
---|
| 58 | /// <summary>
|
---|
| 59 | /// Initializes a new instance of <see cref="VariableView"/> with the given <paramref name="variable"/>.
|
---|
| 60 | /// </summary>
|
---|
| 61 | /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
|
---|
| 62 | /// <param name="variable">The variable to represent visually.</param>
|
---|
[3280] | 63 | public RunView(IRun content)
|
---|
[3260] | 64 | : this() {
|
---|
| 65 | Content = content;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override void OnContentChanged() {
|
---|
| 69 | base.OnContentChanged();
|
---|
| 70 | FillListView();
|
---|
| 71 | viewHost.ViewType = null;
|
---|
| 72 | viewHost.Content = null;
|
---|
[3350] | 73 | if (Content == null)
|
---|
| 74 | Caption = "Run";
|
---|
| 75 | else
|
---|
| 76 | Caption = Content.Name + " (" + Content.GetType().Name + ")";
|
---|
[3362] | 77 | SetEnabledStateOfControls();
|
---|
[3350] | 78 | }
|
---|
| 79 | protected override void OnReadOnlyChanged() {
|
---|
| 80 | base.OnReadOnlyChanged();
|
---|
[3362] | 81 | SetEnabledStateOfControls();
|
---|
[3350] | 82 | }
|
---|
[3362] | 83 | private void SetEnabledStateOfControls() {
|
---|
[3260] | 84 | if (Content == null) {
|
---|
| 85 | parametersResultsGroupBox.Enabled = false;
|
---|
[3350] | 86 | viewHost.Enabled = false;
|
---|
[3260] | 87 | } else {
|
---|
| 88 | parametersResultsGroupBox.Enabled = true;
|
---|
[3350] | 89 | viewHost.Enabled = true;
|
---|
| 90 | viewHost.ReadOnly = ReadOnly;
|
---|
[3260] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | private void FillListView() {
|
---|
| 95 | listView.Items.Clear();
|
---|
[3341] | 96 | listView.SmallImageList.Images.Clear();
|
---|
[3260] | 97 | if (Content != null) {
|
---|
[3341] | 98 | foreach (string key in Content.Parameters.Keys)
|
---|
| 99 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]);
|
---|
| 100 | foreach (string key in Content.Results.Keys)
|
---|
| 101 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]);
|
---|
[3260] | 102 | if (listView.Items.Count > 0) {
|
---|
| 103 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 104 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[3341] | 109 | private void CreateListViewItem(string name, IItem value, ListViewGroup group) {
|
---|
| 110 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
| 111 | item.Tag = value;
|
---|
| 112 | item.Group = group;
|
---|
| 113 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : value.ItemImage);
|
---|
| 114 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
| 115 | listView.Items.Add(item);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[3260] | 118 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 119 | if (listView.SelectedItems.Count == 1) {
|
---|
| 120 | viewHost.ViewType = null;
|
---|
| 121 | viewHost.Content = listView.SelectedItems[0].Tag;
|
---|
| 122 | } else {
|
---|
| 123 | viewHost.Content = null;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
[3300] | 126 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
| 127 | if (listView.SelectedItems.Count == 1) {
|
---|
| 128 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
[3367] | 129 | IView view = MainFormManager.CreateDefaultView(item,ReadOnly);
|
---|
[3300] | 130 | if (view != null) view.Show();
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
| 134 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 135 | IItem item = (IItem)listViewItem.Tag;
|
---|
| 136 | DataObject data = new DataObject();
|
---|
| 137 | data.SetData("Type", item.GetType());
|
---|
| 138 | data.SetData("Value", item);
|
---|
[3341] | 139 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
[3300] | 140 | }
|
---|
| 141 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[3367] | 142 | MainFormManager.CreateDefaultView(Content.Algorithm.Clone(),ReadOnly).Show();
|
---|
[3300] | 143 | }
|
---|
[3260] | 144 | }
|
---|
| 145 | }
|
---|