Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Grammar.Editor/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.cs @ 6626

Last change on this file since 6626 was 6377, checked in by mkommend, 14 years ago

#1479: Merged trunk changes into branch.

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.Common.Resources;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.Problems.QuadraticAssignment.Views {
31  [View("Quadratic Assignment Problem View")]
32  [Content(typeof(QuadraticAssignmentProblem), IsDefaultView = true)]
33  public sealed partial class QuadraticAssignmentProblemView : ParameterizedNamedItemView {
34    public new QuadraticAssignmentProblem Content {
35      get { return (QuadraticAssignmentProblem)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public QuadraticAssignmentProblemView() {
40      InitializeComponent();
41      importInstanceButton.Image = VSImageLibrary.Open;
42      Controls.Remove(parameterCollectionView);
43      parameterCollectionView.Dock = DockStyle.Fill;
44      problemTabPage.Controls.Add(parameterCollectionView);
45    }
46
47    protected override void RegisterContentEvents() {
48      base.RegisterContentEvents();
49      Content.DistancesParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
50      Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged);
51      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
52    }
53
54    protected override void DeregisterContentEvents() {
55      Content.DistancesParameter.ValueChanged -= new EventHandler(DistanceMatrixParameter_ValueChanged);
56      Content.WeightsParameter.ValueChanged -= new EventHandler(WeightsParameter_ValueChanged);
57      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
58      base.DeregisterContentEvents();
59    }
60
61    private void DistanceMatrixParameter_ValueChanged(object sender, System.EventArgs e) {
62      qapView.Distances = Content.Distances;
63    }
64
65    private void WeightsParameter_ValueChanged(object sender, System.EventArgs e) {
66      qapView.Weights = Content.Weights;
67    }
68
69    private void BestKnownSolutionParameter_ValueChanged(object sender, System.EventArgs e) {
70      qapView.Assignment = Content.BestKnownSolution;
71    }
72
73    protected override void OnContentChanged() {
74      base.OnContentChanged();
75      instancesComboBox.Items.Clear();
76      if (Content != null) {
77        foreach (string instance in Content.EmbeddedInstances) {
78          instancesComboBox.Items.Add(instance);
79        }
80        qapView.Distances = Content.Distances;
81        qapView.Weights = Content.Weights;
82        qapView.Assignment = Content.BestKnownSolution;
83      } else {
84        qapView.Distances = null;
85        qapView.Weights = null;
86        qapView.Assignment = null;
87      }
88    }
89
90    protected override void SetEnabledStateOfControls() {
91      base.SetEnabledStateOfControls();
92      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null;
93      loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && instancesComboBox.SelectedItem != null;
94      importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null;
95    }
96
97    private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
98      loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null;
99    }
100
101    private void loadInstanceButton_Click(object sender, System.EventArgs e) {
102      string instance = instancesComboBox.SelectedItem as string;
103      try {
104        Content.LoadEmbeddedInstance(instance);
105      } catch (Exception ex) {
106        PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
107      }
108    }
109
110    private void importInstanceButton_Click(object sender, System.EventArgs e) {
111      if (openFileDialog.ShowDialog() == DialogResult.OK) {
112        try {
113          Content.ImportFileInstance(openFileDialog.FileName);
114        } catch (Exception ex) {
115          PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
116        }
117      }
118    }
119
120    private void QAPLIBInstancesLabel_Click(object sender, System.EventArgs e) {
121      System.Diagnostics.Process.Start("http://www.seas.upenn.edu/qaplib/");
122    }
123
124    private void QAPLIBInstancesLabel_MouseEnter(object sender, EventArgs e) {
125      Cursor = Cursors.Hand;
126      QAPLIBInstancesLabel.ForeColor = Color.Red;
127      toolTip.SetToolTip(QAPLIBInstancesLabel, "Browse to http://www.seas.upenn.edu/qaplib/");
128    }
129
130    private void QAPLIBInstancesLabel_MouseLeave(object sender, EventArgs e) {
131      Cursor = Cursors.Default;
132      QAPLIBInstancesLabel.ForeColor = Color.Blue;
133      toolTip.SetToolTip(QAPLIBInstancesLabel, String.Empty);
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.