{**********************************************}
{   TCustomBoxSeries Editor dialog             }
{     TBoxSeries                               }
{     THorizBoxSeries                          }
{                                              }
{   Copyright (c) 2000-2020 by Steema Software }
{**********************************************}
unit TeeBoxPlotEditor;
{$I TeeDefs.inc}

interface

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

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

     TeCanvas, TeePenDlg, TeeBoxPlot, TeeProcs;

type
  TBoxSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabMedian: TTabSheet;
    TabWhisker: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    EPos: TEdit;
    ELength: TEdit;
    procedure FormShow(Sender: TObject);
    procedure ELengthChange(Sender: TObject);
    procedure EPosChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    BoxPointerForm  : TCustomForm;
    ExtrPointerForm : TCustomForm;
    MildPointerForm : TCustomForm;
    Box             : TCustomBoxSeries;
  public
    { Public declarations }
  end;

implementation

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

Uses TeePoEdi, TeeProCo;

procedure TBoxSeriesEditor.FormShow(Sender: TObject);
begin
  Box:=TCustomBoxSeries(Tag);

  if Assigned(Box) then
  begin
    with Box do
    begin
      ELength.Text:=FloatToStr(WhiskerLength);
      EPos.Text:=FloatToStr(Position);
    end;

    if Assigned(Parent) then
    begin
      if not Assigned(BoxPointerForm) then
         BoxPointerForm:=TeeInsertPointerForm(Parent,Box.Pointer,TeeMsg_Box);

      if not Assigned(ExtrPointerForm) then
         ExtrPointerForm:=TeeInsertPointerForm(Parent,Box.ExtrOut,TeeMsg_ExtrOut);

      if not Assigned(MildPointerForm) then
         MildPointerForm:=TeeInsertPointerForm(Parent,Box.MildOut,TeeMsg_MildOut);
    end;
  end;
end;

procedure TBoxSeriesEditor.ELengthChange(Sender: TObject);
begin
  if Showing and (ELength.Text<>'') then
     Box.WhiskerLength:=StrToFloat(ELength.Text);
end;

procedure TBoxSeriesEditor.EPosChange(Sender: TObject);
begin
  if Showing and (EPos.Text<>'') then
     Box.Position:=StrToFloat(EPos.Text);
end;

procedure TBoxSeriesEditor.FormCreate(Sender: TObject);
begin
  Align:=alClient;
end;

procedure TBoxSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(MildPointerForm);
  FreeAndNil(ExtrPointerForm);
  FreeAndNil(BoxPointerForm);
end;

procedure TBoxSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabMedian) and (TabMedian.ControlCount=0) then
     TPenDialog.InsertForm(Box.MedianPen,TabMedian)
  else
  if (PageControl1.ActivePage=TabWhisker) and (TabWhisker.ControlCount=0) then
     TPenDialog.InsertForm(Box.WhiskerPen,TabWhisker);
end;

initialization
  RegisterClass(TBoxSeriesEditor);
end.

