// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Components.Charting.Data; using Core.Components.OxyPlot.Forms; namespace Core.Plugins.OxyPlot.Legend { /// /// This class controls the actions which are related to controlling visibility and updating contents of a . /// public class LegendController { private readonly IToolViewController toolViewController; private IView legendView; /// /// Creates a new instance of . /// /// The to invoke actions upon. public LegendController(IToolViewController toolViewController) { if (toolViewController == null) { throw new ArgumentNullException("toolViewController", "Cannot create a LegendController when the plugin is null."); } this.toolViewController = toolViewController; } /// /// Toggles the . /// public void ToggleLegend() { if (IsLegendViewOpen()) { CloseLegendView(); } else { OpenLegendView(); } } /// /// Checks whether a is open. /// /// true if the is open, false otherwise. public bool IsLegendViewOpen() { return toolViewController.IsToolWindowOpen(); } /// /// Open the . /// private void OpenLegendView() { legendView = new LegendView(); toolViewController.OpenToolView(legendView); } /// /// Closes the . /// private void CloseLegendView() { toolViewController.CloseToolView(legendView); legendView.Dispose(); legendView = null; } /// /// Updates the data for the if it is open. /// /// The for which to show data. If null the /// data will be cleared. public void Update(ChartData data) { if (IsLegendViewOpen()) { legendView.Data = data; } } } }