#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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; using System.Drawing; using System.Windows.Forms; namespace HeuristicLab.Visualization { public abstract class ChartMode { protected readonly ChartControl chartControl; protected Cursor cursor; protected Point buttonDownPoint; protected Point previousLocation; protected int mouseClickCount; public abstract Image Image { get; } public abstract string Text { get; } public virtual string ToolTipText { get { return Text; } } public virtual Cursor Cursor { get { return cursor ?? (cursor = Cursors.Default); } } private bool selected; public bool Selected { get { return selected; } set { if (selected == value) return; selected = value; if (selected) { chartControl.Mode = this; OnSelected(); } else { if (chartControl.Mode == this) chartControl.Mode = null; OnDeselected(); } OnSelectedChanged(); } } protected ChartMode(ChartControl control) { chartControl = control; chartControl.ModeChanged += (sender, args) => Selected = chartControl.Mode == this; } public void Select() { Selected = true; } public void Deselect() { Selected = false; } protected virtual void OnSelected() { } protected virtual void OnDeselected() { } public virtual void HandleOnKeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Escape: Deselect(); break; } } public virtual void HandleOnKeyUp(object sender, KeyEventArgs e) { } public virtual void HandleOnMouseClick(object sender, MouseEventArgs e) { } public virtual void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) { } public virtual void HandleOnMouseDown(object sender, MouseEventArgs e) { buttonDownPoint = e.Location; mouseClickCount = e.Clicks; } public virtual void HandleOnMouseUp(object sender, MouseEventArgs e) { } public virtual void HandleOnMouseMove(object sender, MouseEventArgs e) { previousLocation = e.Location; } public virtual void HandleOnMouseWheel(object sender, MouseEventArgs e) { } public virtual void HandleOnMouseEnter(object sender, EventArgs e) { } public virtual void HandleOnMouseLeave(object sender, EventArgs e) { } public virtual void HandleOnClick(object sender, EventArgs e) { } public event EventHandler SelectedChanged; protected virtual void OnSelectedChanged() { var handler = SelectedChanged; if (handler != null) handler(this, EventArgs.Empty); } } }