[357] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 |
|
---|
[377] | 31 | namespace HeuristicLab.CEDMA.Core {
|
---|
[357] | 32 | public partial class AgentListView : ViewBase {
|
---|
| 33 | public IAgentList AgentList {
|
---|
| 34 | get { return (IAgentList)Item; }
|
---|
| 35 | set { base.Item = value; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public AgentListView() {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 | Caption = "Agent View";
|
---|
| 41 | }
|
---|
| 42 | public AgentListView(IAgentList agentList)
|
---|
| 43 | : this() {
|
---|
| 44 | AgentList = agentList;
|
---|
| 45 | agentList.Changed += new EventHandler(agentList_Changed);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void agentList_Changed(object sender, EventArgs e) {
|
---|
| 49 | UpdateControls();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void UpdateControls() {
|
---|
| 53 | base.UpdateControls();
|
---|
| 54 | detailsGroupBox.Controls.Clear();
|
---|
| 55 | detailsGroupBox.Enabled = false;
|
---|
| 56 | if(AgentList == null) {
|
---|
| 57 | Caption = "Agents View";
|
---|
[389] | 58 | agentTreeView.Enabled = false;
|
---|
[357] | 59 | } else {
|
---|
[389] | 60 | agentTreeView.Enabled = true;
|
---|
| 61 | agentTreeView.Nodes.Clear();
|
---|
[357] | 62 | foreach(IAgent agent in AgentList) {
|
---|
[389] | 63 | TreeNode node = new TreeNode();
|
---|
| 64 | node.Text = agent.Name;
|
---|
| 65 | node.Tag = agent;
|
---|
[393] | 66 | node.Nodes.Add("dummy");
|
---|
[514] | 67 | node.ContextMenuStrip = entryContextMenuStrip;
|
---|
[389] | 68 | agentTreeView.Nodes.Add(node);
|
---|
[357] | 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[390] | 73 | #region Button Events
|
---|
| 74 | private void addButton_Click(object sender, EventArgs e) {
|
---|
| 75 | AgentList.CreateAgent();
|
---|
| 76 | }
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
| 79 | private void agentTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) {
|
---|
[393] | 80 | e.Node.Nodes.Clear();
|
---|
[394] | 81 | if(e.Node.Tag is IAgent) {
|
---|
| 82 | IAgent agent = (IAgent)e.Node.Tag;
|
---|
| 83 | foreach(IAgent subAgent in agent.SubAgents) {
|
---|
| 84 | TreeNode node = new TreeNode();
|
---|
| 85 | node.Text = subAgent.Name;
|
---|
| 86 | node.Tag = subAgent;
|
---|
[514] | 87 | node.ContextMenuStrip = entryContextMenuStrip;
|
---|
[394] | 88 | node.Nodes.Add("dummy");
|
---|
| 89 | e.Node.Nodes.Add(node);
|
---|
| 90 | }
|
---|
| 91 | foreach(IResult result in agent.Results) {
|
---|
| 92 | TreeNode node = new TreeNode();
|
---|
| 93 | node.Text = result.Summary;
|
---|
| 94 | node.Tag = result;
|
---|
| 95 | node.Nodes.Add("dummy");
|
---|
| 96 | e.Node.Nodes.Add(node);
|
---|
| 97 | }
|
---|
| 98 | } else if(e.Node.Tag is IResult) {
|
---|
| 99 | IResult result = (IResult)e.Node.Tag;
|
---|
| 100 | foreach(IResult subResult in result.SubResults) {
|
---|
| 101 | TreeNode node = new TreeNode();
|
---|
| 102 | node.Text = subResult.Summary;
|
---|
| 103 | node.Tag = subResult;
|
---|
| 104 | node.Nodes.Add("dummy");
|
---|
| 105 | e.Node.Nodes.Add(node);
|
---|
| 106 | }
|
---|
[393] | 107 | }
|
---|
[390] | 108 | }
|
---|
| 109 |
|
---|
| 110 | private void agentTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
|
---|
[357] | 111 | if(detailsGroupBox.Controls.Count > 0)
|
---|
| 112 | detailsGroupBox.Controls[0].Dispose();
|
---|
| 113 | detailsGroupBox.Controls.Clear();
|
---|
| 114 | detailsGroupBox.Enabled = false;
|
---|
[390] | 115 | if(agentTreeView.SelectedNode != null) {
|
---|
[393] | 116 | IViewable viewable = (IViewable)agentTreeView.SelectedNode.Tag;
|
---|
| 117 | Control control = (Control)viewable.CreateView();
|
---|
[357] | 118 | detailsGroupBox.Controls.Add(control);
|
---|
| 119 | control.Dock = DockStyle.Fill;
|
---|
| 120 | detailsGroupBox.Enabled = true;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[510] | 123 |
|
---|
| 124 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 125 | UpdateControls();
|
---|
| 126 | }
|
---|
[514] | 127 |
|
---|
| 128 | private void exportAllResultsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 129 | TreeNode node = agentTreeView.SelectedNode;
|
---|
| 130 | Agent agent = (Agent)node.Tag;
|
---|
| 131 | ResultExporter exporter = new ResultExporter();
|
---|
| 132 | ResultTable table = new ResultTable();
|
---|
| 133 | exporter.Export(agent, table);
|
---|
| 134 |
|
---|
| 135 | using(System.IO.FileStream s = new System.IO.FileStream("exported-results.txt", System.IO.FileMode.Create)) {
|
---|
| 136 | table.Write(s);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
[357] | 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|