#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Drawing; using System.Linq; using HeuristicLab.Visualization; namespace HeuristicLab.Networks.Views.NetworkVisualization { [Primitive(typeof(IAlgorithmNode), true)] public class AlgorithmNodeRectangle : NodeRectangle { protected readonly Brush InactiveBrush = new SolidBrush(Color.FromArgb(255, 255, 200, 100)); protected readonly Brush ActiveBrush = new SolidBrush(Color.FromArgb(255, 100, 200, 100)); public new IAlgorithmNode NetworkItem { get { return (IAlgorithmNode)base.NetworkItem; } set { base.NetworkItem = value; } } public AlgorithmNodeRectangle(IChart chart, IAlgorithmNode node) : base(chart, node) { Brush = InactiveBrush; } protected override void RegisterNetworkItemEvents() { base.RegisterNetworkItemEvents(); NetworkItem.StartedAlgorithmsChanged += NetworkItem_StartedAlgorithmsChanged; if (NetworkItem.Algorithm != null) { NetworkItem.Algorithm.Started += Algorithm_Started; ; NetworkItem.Algorithm.Stopped += Algorithm_Stopped; ; } } protected override void DeregisterNetworkItemEvents() { if (NetworkItem.Algorithm != null) { NetworkItem.Algorithm.Stopped -= Algorithm_Stopped; ; NetworkItem.Algorithm.Started -= Algorithm_Started; ; } NetworkItem.StartedAlgorithmsChanged -= NetworkItem_StartedAlgorithmsChanged; base.DeregisterNetworkItemEvents(); } private void NetworkItem_StartedAlgorithmsChanged(object sender, System.EventArgs e) { Brush = ((IAlgorithmNode)sender).StartedAlgorithms.Any() ? ActiveBrush : InactiveBrush; } private void Algorithm_Started(object sender, System.EventArgs e) { Brush = ActiveBrush; } private void Algorithm_Stopped(object sender, System.EventArgs e) { Brush = InactiveBrush; } } }