{********************************************}
{     TeeChart Pro Charting Library          }
{ Copyright (c) 1995-2020 by Steema Software }
{         All Rights Reserved                }
{********************************************}
unit TeeBollingerEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,

  TeCanvas, TeePenDlg, StatChar, TeeBaseFuncEdit, ExtCtrls;

type
  TBollingerFuncEditor = class(TBaseFunctionEditor)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    TabUpper: TTabSheet;
    TabLower: TTabSheet;
    Label3: TLabel;
    Label1: TLabel;
    ENum: TEdit;
    UpDown1: TUpDown;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    procedure ENumChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure ApplyFormChanges; override;
    Procedure SetFunction; override;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

procedure TBollingerFuncEditor.ApplyFormChanges;
begin
  inherited;

  with TBollingerFunction(IFunction) do
  begin
    BeginUpdate;
    try
      Period:=UpDown1.Position;
      Exponential:=CheckBox1.Checked;
      Deviation:=StrToFloat(Edit1.Text);
    finally
      EndUpdate;
    end;
  end;
end;

procedure TBollingerFuncEditor.ENumChange(Sender: TObject);
begin
  EnableApply;
end;

Procedure TBollingerFuncEditor.SetFunction;
begin
  inherited;

  with TBollingerFunction(IFunction) do
  begin
    UpDown1.Position:=Round(Period);
    CheckBox1.Checked:=Exponential;
    Edit1.Text:=FloatToStr(Deviation);
  end;
end;

procedure TBollingerFuncEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage.ControlCount=0 then
     if PageControl1.ActivePage=TabUpper then
        TPenDialog.InsertForm(TBollingerFunction(IFunction).UpperBandPen,TabUpper)
     else
     if PageControl1.ActivePage=TabLower then
        TPenDialog.InsertForm(TBollingerFunction(IFunction).LowBandPen,TabLower);
end;

initialization
  RegisterClass(TBollingerFuncEditor);
end.
