Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (13 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/Plugin.cs.frame

    r7363 r7538  
    2525  [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2728  [PluginDependency("HeuristicLab.Common", "3.3")]
    2829  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
     
    3031  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
    3132  [PluginDependency("HeuristicLab.Data", "3.3")]
     33  [PluginDependency("HeuristicLab.Data.Views", "3.3")]
    3234  [PluginDependency("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3")]
    3335  [PluginDependency("HeuristicLab.MainForm", "3.3")]
     
    3739  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3840  [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment", "3.3")]
     41  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
     42  [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
    3943  public class HeuristicLabProblemsGeneralizedQuadraticAssignmentViewsPlugin : PluginBase {
    4044  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.Designer.cs

    r7523 r7538  
    2121
    2222namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
    23   partial class ProblemInstanceProviderView {
     23  partial class ProblemInstanceProviderView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4848      this.label2 = new System.Windows.Forms.Label();
    4949      this.instancesComboBox = new System.Windows.Forms.ComboBox();
     50      this.importButton = new System.Windows.Forms.Button();
     51      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    5052      this.SuspendLayout();
    5153      //
     
    5355      //
    5456      this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    55       this.loadButton.Location = new System.Drawing.Point(535, -1);
     57      this.loadButton.Location = new System.Drawing.Point(451, -1);
    5658      this.loadButton.Name = "loadButton";
    5759      this.loadButton.Size = new System.Drawing.Size(75, 23);
     
    7880      this.instancesComboBox.Location = new System.Drawing.Point(54, 0);
    7981      this.instancesComboBox.Name = "instancesComboBox";
    80       this.instancesComboBox.Size = new System.Drawing.Size(475, 21);
     82      this.instancesComboBox.Size = new System.Drawing.Size(391, 21);
    8183      this.instancesComboBox.TabIndex = 7;
    8284      this.instancesComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged);
     85      //
     86      // importButton
     87      //
     88      this.importButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     89      this.importButton.Location = new System.Drawing.Point(532, -1);
     90      this.importButton.Name = "importButton";
     91      this.importButton.Size = new System.Drawing.Size(75, 23);
     92      this.importButton.TabIndex = 6;
     93      this.importButton.Text = "Import";
     94      this.importButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     95      this.importButton.UseVisualStyleBackColor = true;
     96      this.importButton.Click += new System.EventHandler(this.importButton_Click);
     97      //
     98      // openFileDialog
     99      //
     100      this.openFileDialog.Filter = "All files|*.*";
    83101      //
    84102      // ProblemInstanceProviderView
     
    87105      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    88106      this.Controls.Add(this.instancesComboBox);
     107      this.Controls.Add(this.importButton);
    89108      this.Controls.Add(this.loadButton);
    90109      this.Controls.Add(this.label2);
     
    101120    private System.Windows.Forms.Label label2;
    102121    private System.Windows.Forms.ComboBox instancesComboBox;
     122    private System.Windows.Forms.Button importButton;
     123    private System.Windows.Forms.OpenFileDialog openFileDialog;
    103124
    104125  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs

    r7505 r7538  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common.Resources;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
     
    2930namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
    3031  [View("ProblemInstanceProviderView")]
    31   [Content(typeof(IProblemInstanceProvider), IsDefaultView = true)]
    32   public partial class ProblemInstanceProviderView : AsynchronousContentView {
     32  [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)]
     33  public partial class ProblemInstanceProviderView<T> : AsynchronousContentView {
    3334
    34     public new IProblemInstanceProvider Content {
    35       get { return (IProblemInstanceProvider)base.Content; }
     35    public new IProblemInstanceProvider<T> Content {
     36      get { return (IProblemInstanceProvider<T>)base.Content; }
    3637      set { base.Content = value; }
    3738    }
     
    3940    public ProblemInstanceProviderView() {
    4041      InitializeComponent();
     42      importButton.Image = VSImageLibrary.Open;
    4143    }
    4244
     
    5355    protected override void SetEnabledStateOfControls() {
    5456      base.SetEnabledStateOfControls();
    55       instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
    56       loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
     57      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
     58      loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
    5759    }
    5860
    5961    private void loadButton_Click(object sender, EventArgs e) {
    60       var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
    61       if (!Content.FeedConsumer(instance)) {
    62         MessageBox.Show("This problem does not support loading the instance " + instance.Name + ".", "Cannot load instance");
     62      var descriptor = (IInstanceDescriptor)instancesComboBox.SelectedItem;
     63      var instance = Content.LoadInstance(descriptor);
     64      if (!Content.Consumer.LoadFrom(instance)) {
     65        MessageBox.Show("This problem does not support loading the instance " + descriptor.Name + ".", "Cannot load instance");
     66      }
     67    }
     68
     69    private void importButton_Click(object sender, EventArgs e) {
     70      if (openFileDialog.ShowDialog() == DialogResult.OK) {
     71        T instance = default(T);
     72        try {
     73          instance = Content.LoadInstance(openFileDialog.FileName);
     74        } catch {
     75          MessageBox.Show("There was an error parsing the file.", "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
     76          return;
     77        }
     78        try {
     79          if (!Content.Consumer.LoadFrom(instance)) {
     80            MessageBox.Show("This problem does not support loading the instance in the file.", "Cannot load instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
     81          }
     82        } catch {
     83          MessageBox.Show("There was an error while importing the file.");
     84        }
    6385      }
    6486    }
     
    6991        comboBox.Items.Clear();
    7092    }
    71 
    72     private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
    73       var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
    74       e.ToolTip = instance.Description;
    75     }
    7693  }
    7794}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.resx

    r7448 r7538  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
     120  <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     121    <value>17, 17</value>
     122  </metadata>
    120123</root>
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.Designer.cs

    r7482 r7538  
    103103      // problemInstanceProviderComboBox
    104104      //
    105       this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     105      this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
    106106      this.problemInstanceProviderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     107      this.problemInstanceProviderComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    107108      this.problemInstanceProviderComboBox.FormattingEnabled = true;
    108109      this.problemInstanceProviderComboBox.Location = new System.Drawing.Point(50, 5);
     110      this.problemInstanceProviderComboBox.MaxDropDownItems = 16;
    109111      this.problemInstanceProviderComboBox.Name = "problemInstanceProviderComboBox";
    110112      this.problemInstanceProviderComboBox.Size = new System.Drawing.Size(173, 21);
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.cs

    r7523 r7538  
    6363      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
    6464        var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
    65         provider.SetConsumer((IProblemInstanceConsumer)Content);
     65        var genericType = provider.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IProblemInstanceProvider<>)).GetGenericArguments().First();
     66        this.GetType().GetMethod("SetConsumable").MakeGenericMethod(genericType).Invoke(this, new object[] { provider, Content });
    6667        problemInstanceProviderViewHost.Content = provider;
    6768      }
     69    }
     70
     71    /// <summary>
     72    /// Do not change method name without changing the string reference above
     73    /// </summary>
     74    private void SetConsumable<T>(IProblemInstanceProvider<T> producer, IConsumable<T> consumer) {
     75      producer.Consumer = consumer;
    6876    }
    6977
     
    7785      var consumerTypes = Content.GetType().GetInterfaces()
    7886        .Where(x => x.IsGenericType
    79           && typeof(IProblemInstanceConsumer).IsAssignableFrom(x));
     87          && x.GetGenericTypeDefinition() == typeof(IConsumable<>));
    8088
    8189      if (consumerTypes.Any()) {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.Designer.cs

    r7482 r7538  
    4848      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    4949      this.SuspendLayout();
     50      //
     51      // ToolTipComboBox
     52      //
     53      this.MaxDropDownItems = 16;
    5054      this.ResumeLayout(false);
    5155
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs

    r7523 r7538  
    2929
    3030    private ComboBoxState comboBoxState = ComboBoxState.Normal;
    31     private bool mouseOver = false;
    3231
    3332    public ToolTipComboBox()
     
    3635      SetStyle(ControlStyles.UserPaint, true);
    3736      InitializeComponent();
    38       DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
     37      DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
    3938      DropDownStyle = ComboBoxStyle.DropDownList;
    40     }
    41 
    42     protected override void OnMeasureItem(MeasureItemEventArgs e) {
    43       base.OnMeasureItem(e);
    44       string text = GetItemText(Items[e.Index]);
    45       if (string.IsNullOrEmpty(text)) text = "test";
    46       var rect = TextRenderer.MeasureText(text, Font);
    47       e.ItemHeight = rect.Height - 2;
    48       e.ItemWidth = rect.Width;
    4939    }
    5040
     
    7262        } else {
    7363          using (var b = new SolidBrush(ForeColor)) {
    74             Rectangle r = e.Bounds;
    75             r.Offset(0, 1);
    76             e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, r);
     64            var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4);
     65            e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, rect);
    7766          }
    7867        }
     
    8473      base.OnPaint(e);
    8574      if (Enabled == false) comboBoxState = ComboBoxState.Disabled;
    86       Rectangle clip = Bounds; // using e.ClipRectangle leads to strange behavior when maximizing/unmaximizing, just redraw the entire region all the time
    87       clip.Offset(-clip.X, -clip.Y); // x and y need to be 0
     75      Rectangle clip = new Rectangle(new Point(0, 0), Size);
     76      clip.Inflate(0, 1);
    8877      if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser) {
    8978        PushButtonState pb_State = PushButtonState.Normal;
     
    10998        ComboBoxRenderer.DrawDropDownButton(e.Graphics, r, comboBoxState);
    11099      }
    111       Rectangle rect = clip;
    112       rect.Inflate(-2, -4);
    113       rect.Offset(1, 0);
     100      var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4);
    114101      if (SelectedIndex > -1 && Items.Count > 0) {
    115102        using (var b = new SolidBrush(ForeColor)) {
     
    141128    protected override void OnMouseEnter(EventArgs e) {
    142129      base.OnMouseEnter(e);
    143       mouseOver = true;
    144130      if (comboBoxState == ComboBoxState.Normal) {
    145131        comboBoxState = ComboBoxState.Hot;
     
    158144    protected override void OnMouseLeave(EventArgs e) {
    159145      base.OnMouseLeave(e);
    160       mouseOver = false;
    161146      if (comboBoxState == ComboBoxState.Hot) {
    162147        comboBoxState = ComboBoxState.Normal;
     
    167152    protected override void OnMouseDown(MouseEventArgs e) {
    168153      base.OnMouseDown(e);
    169       comboBoxState = ComboBoxState.Pressed;
    170       Invalidate();
     154      if (e.Button == MouseButtons.Left) {
     155        comboBoxState = ComboBoxState.Pressed;
     156        Invalidate();
     157      }
    171158    }
    172159
Note: See TracChangeset for help on using the changeset viewer.