Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/14 14:24:40 (10 years ago)
Author:
aesterer
Message:

Refactored LineChartLogic and added CheckedItemListView to LineChartView

Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/HeuristicLab.DataPreprocessing.Views-3.3.csproj

    r10614 r10628  
    9797    </Compile>
    9898    <Compile Include="Plugin.cs" />
     99    <Compile Include="PreprocessingCheckedItemListView.cs">
     100      <SubType>UserControl</SubType>
     101    </Compile>
     102    <Compile Include="PreprocessingCheckedItemListView.Designer.cs">
     103      <DependentUpon>PreprocessingCheckedItemListView.cs</DependentUpon>
     104    </Compile>
    99105    <Compile Include="PreprocessingDataTableView.cs">
    100106      <SubType>UserControl</SubType>
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/LineChartView.Designer.cs

    r10558 r10628  
    2020#endregion
    2121
     22using HeuristicLab.Data;
    2223namespace HeuristicLab.DataPreprocessing.Views {
    2324  partial class LineChartView {
     
    4647    private void InitializeComponent() {
    4748      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    48       this.variablesListBox = new System.Windows.Forms.CheckedListBox();
    49       this.groupBoxAttributs = new System.Windows.Forms.GroupBox();
    5049      this.groupBoxOptions = new System.Windows.Forms.GroupBox();
    51       this.groupBoxAttributs.SuspendLayout();
     50      this.checkedItemList = new HeuristicLab.DataPreprocessing.Views.PreprocessingCheckedItemListView();
    5251      this.SuspendLayout();
    5352      //
    5453      // viewHost
    5554      //
    56       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    57             | System.Windows.Forms.AnchorStyles.Left)
     55      this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     56            | System.Windows.Forms.AnchorStyles.Left) 
    5857            | System.Windows.Forms.AnchorStyles.Right)));
    5958      this.viewHost.Caption = "View";
     
    6867      this.viewHost.ViewType = null;
    6968      //
    70       // variablesListBox
    71       //
    72       this.variablesListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    73             | System.Windows.Forms.AnchorStyles.Left)
    74             | System.Windows.Forms.AnchorStyles.Right)));
    75       this.variablesListBox.FormattingEnabled = true;
    76       this.variablesListBox.Location = new System.Drawing.Point(6, 19);
    77       this.variablesListBox.Name = "variablesListBox";
    78       this.variablesListBox.Size = new System.Drawing.Size(141, 229);
    79       this.variablesListBox.TabIndex = 1;
    80       this.variablesListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.variablesListBox_ItemCheck);
    81       //
    82       // groupBoxAttributs
    83       //
    84       this.groupBoxAttributs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    85             | System.Windows.Forms.AnchorStyles.Left)));
    86       this.groupBoxAttributs.Controls.Add(this.variablesListBox);
    87       this.groupBoxAttributs.Location = new System.Drawing.Point(3, 4);
    88       this.groupBoxAttributs.Name = "groupBoxAttributs";
    89       this.groupBoxAttributs.Size = new System.Drawing.Size(153, 252);
    90       this.groupBoxAttributs.TabIndex = 2;
    91       this.groupBoxAttributs.TabStop = false;
    92       this.groupBoxAttributs.Text = "Attributes";
    93       //
    9469      // groupBoxOptions
    9570      //
     
    10277      this.groupBoxOptions.Text = "Options";
    10378      //
     79      // checkedItemList
     80      //
     81      this.checkedItemList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     82            | System.Windows.Forms.AnchorStyles.Left)));
     83      this.checkedItemList.Caption = "View";
     84      this.checkedItemList.Content = null;
     85      this.checkedItemList.Location = new System.Drawing.Point(4, 4);
     86      this.checkedItemList.Name = "checkedItemList";
     87      this.checkedItemList.ReadOnly = false;
     88      this.checkedItemList.Size = new System.Drawing.Size(152, 252);
     89      this.checkedItemList.TabIndex = 4;
     90      //
    10491      // LineChartView
    10592      //
    10693      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    10794      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     95      this.Controls.Add(this.checkedItemList);
    10896      this.Controls.Add(this.groupBoxOptions);
    109       this.Controls.Add(this.groupBoxAttributs);
    11097      this.Controls.Add(this.viewHost);
    11198      this.Name = "LineChartView";
    11299      this.Size = new System.Drawing.Size(654, 403);
    113       this.groupBoxAttributs.ResumeLayout(false);
    114100      this.ResumeLayout(false);
    115101
     
    119105
    120106    private MainForm.WindowsForms.ViewHost viewHost;
    121     private System.Windows.Forms.CheckedListBox variablesListBox;
    122     private System.Windows.Forms.GroupBox groupBoxAttributs;
    123107    private System.Windows.Forms.GroupBox groupBoxOptions;
     108    private PreprocessingCheckedItemListView checkedItemList;
    124109  }
    125110}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/LineChartView.cs

    r10573 r10628  
    2121
    2222using System.Windows.Forms;
     23using HeuristicLab.Analysis;
     24using HeuristicLab.Collections;
     25using HeuristicLab.Core;
    2326using HeuristicLab.Core.Views;
     27using HeuristicLab.Data;
    2428using HeuristicLab.MainForm;
    2529
     
    3034  public partial class LineChartView : ItemView {
    3135
     36    private ILineChartLogic logic;
     37    private DataTable dataTable;
     38    private ICheckedItemList<StringValue> itemList;
     39    private const string LINE_CHART_TITLE = "LineChart";
     40
    3241    public LineChartView() {
    3342      InitializeComponent();
    3443    }
    3544
     45    private void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
     46      foreach(IndexedItem<StringValue> item in checkedItems.Items)
     47      {
     48        string variableName = item.Value.Value;
     49        if (VariableIsDisplayed(variableName)) {
     50          dataTable.Rows.Remove(variableName);
     51        } else {
     52          dataTable.Rows.Add(logic.CreateDataRow(variableName));
     53        }
     54      }
     55    }
     56
     57    public bool VariableIsDisplayed(string name) {
     58
     59      foreach (var item in dataTable.Rows) {
     60        if (item.Name == name)
     61          return true;
     62      }
     63      return false;
     64    }
     65
    3666    private void InitDataTable() {
    37       ILineChartLogic logic = Content.LineChartLogic;
    38       viewHost.Content = logic.GetDataTable();
     67      dataTable = logic.CreateDataTable(LINE_CHART_TITLE);
     68      viewHost.Content = dataTable;
     69    }
     70
     71    private void InitVariablesListBox() {
     72      itemList = logic.CreateVariableItemList();
     73      checkedItemList.Content = itemList;
    3974    }
    4075
     
    6196      base.OnContentChanged();
    6297      if (Content != null) {
     98        logic = Content.LineChartLogic;
    6399        InitDataTable();
    64100        InitVariablesListBox();
     101        itemList.CheckedItemsChanged += CheckedItemsChanged;
     102        logic.Changed += PreprocessingData_Changed;
    65103      }
    66104    }
    67105
    68     private void InitVariablesListBox() {
    69       ILineChartLogic logic = Content.LineChartLogic;
    70 
    71       foreach (var variableName in logic.GetVariableNames()) {
    72         variablesListBox.Items.Add(variableName, true);
     106    //TODO: refactor: possible code duplication with HistogramLogic
     107    void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
     108      switch (e.Type) {
     109        case DataPreprocessingChangedEventType.DeleteColumn:
     110          RemoveVariable(logic.GetVariableNameByIndex(e.Column));
     111          break;
     112        case DataPreprocessingChangedEventType.AddColumn:
     113          AddVariable(logic.GetVariableNameByIndex(e.Column));
     114          break;
     115        case DataPreprocessingChangedEventType.ChangeColumn:
     116        case DataPreprocessingChangedEventType.ChangeItem:
     117          dataTable.Rows.Remove(logic.GetVariableNameByIndex(e.Column));
     118          dataTable.Rows.Add(logic.CreateDataRow((logic.GetVariableNameByIndex(e.Column))));
     119          break;
     120        case DataPreprocessingChangedEventType.DeleteRow:
     121        case DataPreprocessingChangedEventType.AddRow:
     122          InitDataTable();
     123          break;
    73124      }
    74125    }
    75126
    76     private void variablesListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
    77       string item = variablesListBox.Items[e.Index] as string;
     127    // add variable to data table and item list
     128    private void AddVariable(string name) {
     129      dataTable.Rows.Add(logic.CreateDataRow(name));
     130      itemList.Add(new StringValue(name));
     131    }
     132
     133    // remove variable from data table and item list
     134    private void RemoveVariable(string name) {
     135      dataTable.Rows.Remove(name);
     136
     137      StringValue stringValue = FindVariableItemList(name);
     138      if (stringValue != null)
     139        itemList.Remove(stringValue);
     140
     141    }
     142
     143    private StringValue FindVariableItemList(string name) {
     144      foreach (StringValue stringValue in itemList) {
     145        if (stringValue.Value == name)
     146          return stringValue;
     147      }
     148      return null;
     149    }
    78150
    79151
    80       if (e.NewValue == CheckState.Checked && !Content.LineChartLogic.VariableIsDisplayed(item))
    81         Content.LineChartLogic.AddVariable(item);
    82       else if (e.NewValue == CheckState.Unchecked && Content.LineChartLogic.VariableIsDisplayed(item))
    83         Content.LineChartLogic.RemoveVariable(item);
    84     }
    85152  }
    86153}
Note: See TracChangeset for help on using the changeset viewer.