Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/12 16:46:35 (12 years ago)
Author:
gkronber
Message:

#1847: merged r8084:8205 from trunk into GP move operators branch

Location:
branches/GP-MoveOperators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Clients.Hive.Views/3.3/StateLog/StateLogGanttChartListView.cs

    r7728 r8206  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.Linq;
     26using System.Windows.Forms;
     27using System.Windows.Forms.DataVisualization.Charting;
    2528using HeuristicLab.Core.Views;
    2629using HeuristicLab.MainForm;
     
    3134  [Content(typeof(StateLogListList), true)]
    3235  public sealed partial class StateLogGanttChartListView : ItemView {
     36    private IList<LegendItem> invisibleLegendItems;
     37
    3338    public new StateLogListList Content {
    3439      get { return (StateLogListList)base.Content; }
     
    3843    public StateLogGanttChartListView() {
    3944      InitializeComponent();
     45      invisibleLegendItems = new List<LegendItem>();
    4046    }
    4147
    4248    protected override void DeregisterContentEvents() {
    4349      // Deregister your event handlers here
     50      ganttChart.chart.MouseMove -= new System.Windows.Forms.MouseEventHandler(chart_MouseDown);
     51      ganttChart.chart.MouseDown -= new System.Windows.Forms.MouseEventHandler(chart_MouseDown);
     52      ganttChart.chart.CustomizeLegend -= new EventHandler<CustomizeLegendEventArgs>(chart_CustomizeLegend);
    4453      base.DeregisterContentEvents();
    4554    }
     
    4857      base.RegisterContentEvents();
    4958      // Register your event handlers here
     59      ganttChart.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(chart_MouseMove);
     60      ganttChart.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(chart_MouseDown);
     61      ganttChart.chart.CustomizeLegend += new EventHandler<CustomizeLegendEventArgs>(chart_CustomizeLegend);
    5062    }
    5163
     
    7587          for (int i = Content.Count - 1; i >= 0; i--) {
    7688            for (int j = 0; j < Content[i].Count - 1; j++) {
    77               if (Content[i][j].State != TaskState.Offline)
     89              if (Content[i][j].State != TaskState.Offline && invisibleLegendItems.All(x => x.Name != Content[i][j].State.ToString()))
    7890                AddData(ganttChart, i.ToString(), Content[i][j], Content[i][j + 1], upperLimit);
    7991            }
    80             if (Content[i].Count > 0) {
     92            if (Content[i].Count > 0 && invisibleLegendItems.All(x => x.Name != Content[i][Content[i].Count - 1].State.ToString())) {
    8193              AddData(ganttChart, i.ToString(), Content[i][Content[i].Count - 1], null, upperLimit);
    8294            }
     
    113125      base.SetEnabledStateOfControls();
    114126    }
     127
     128    #region Events
     129    void chart_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
     130      HitTestResult result = ganttChart.chart.HitTest(e.X, e.Y);
     131      if (result.ChartElementType == ChartElementType.LegendItem)
     132        Cursor = Cursors.Hand;
     133      else
     134        Cursor = Cursors.Default;
     135    }
     136
     137    private void chart_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
     138      HitTestResult result = ganttChart.chart.HitTest(e.X, e.Y);
     139      if (result.ChartElementType == ChartElementType.LegendItem)
     140        ToggleLegendItemVisibility(result.Object as LegendItem);
     141      ganttChart.Reset();
     142      OnContentChanged();
     143    }
     144
     145    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
     146      foreach (var item in e.LegendItems)
     147        foreach (var cell in item.Cells)
     148          cell.ForeColor = invisibleLegendItems.Any(x => x.Name == item.Name) ? Color.Gray : Color.Black;
     149    }
     150    #endregion
     151
     152    #region Helpers
     153    private void ToggleLegendItemVisibility(LegendItem legendItem) {
     154      var item = invisibleLegendItems.FirstOrDefault(x => x.Name == legendItem.Name);
     155      if (item != null) invisibleLegendItems.Remove(item);
     156      else invisibleLegendItems.Add(legendItem);
     157    }
     158    #endregion
    115159  }
    116160}
Note: See TracChangeset for help on using the changeset viewer.