using System;
using Core.Common.Controls.Views;
using Core.Components.OxyPlot.Forms;
namespace Core.Plugins.OxyPlot.Legend
{
///
/// This class controls the actions which are related to a and act upon a .
///
public class LegendController
{
private readonly IOxyPlotGuiPlugin plugin;
private IView legendView;
///
/// Creates a new instance of .
///
/// The to invoke actions upon.
public LegendController(IOxyPlotGuiPlugin plugin)
{
if (plugin == null)
{
throw new ArgumentNullException("plugin", "Cannot create a LegendController when the plugin is null.");
}
this.plugin = plugin;
}
///
/// 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 plugin.IsToolWindowOpen();
}
///
/// Open the .
///
private void OpenLegendView()
{
legendView = new LegendView();
plugin.OpenToolView(legendView);
}
///
/// Closes the .
///
private void CloseLegendView()
{
plugin.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 UpdateForChart(BaseChart chart)
{
if (IsLegendViewOpen())
{
legendView.Data = chart;
}
}
}
}