;+
; PROJECT
;          Solar-B EIS
; NAME
;          eis_splash__DEFINE
; PURPOSE
;          GUI Class
; INPUTS
;          parentClass - the eis_mk_plan object
; CATEGORY
;          EIS Timeline Planning
; WRITTEN
;          John A Rainnie RAL 17-Apr-2008
; HISTORY
;          v0.1 JAR 22-Apr-2008
;               Changed wait time to 0.05 seconds
;          v0.2 JAR 12-Jun-2008
;               Added FILENAME keyword to "plot_logo" method
;          v0.3 JAR 7-Aug-2008
;               Changed wait time to 0.0001 seconds
;          v0.4 JAR 11-Aug-2009
;               Added title, xOffset and yOffset keywords
;          v0.5 JAR 22-Jul-2010
;               Remove colour table stuff. Use Fanning's FSC_COLOR instead.
;               It's already included in SSW.
;
;-
;______________________________________________________________________________
FUNCTION eis_splash::Init , parentClass                              ,     $
                            title   = title                          ,     $
                            xOffset = xOffset                        ,     $
                            yOffset = yOffset

Self.parentClass  = parentClass
Self.group_leader = parentClass->tlbID()

IF (N_ELEMENTS(title)   LT 1) THEN title   = "Loading Databases"
IF (N_ELEMENTS(xOffset) LT 1) THEN xOffset = 0
IF (N_ELEMENTS(yOffset) LT 1) THEN yOffset = 0

;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = title + pt_version
TLB_EVENT                  = {eis_splash_Event}
TLB_EVENT.eis_splash       = Self
TLB_EVENT.Type             = "TLB"
Self.tlbID                 = WIDGET_BASE(                                  $
                                   TITLE       = widTitle            ,     $
                                   COLUMN      = 1                   ,     $
                                   /FLOATING                         ,     $
                                   ;/MODAL                           ,     $
                                   GROUP_LEADER = Self.group_leader  ,     $
                                   UValue      = TLB_EVENT           ,     $
                                   xOffset     = xOffset             ,     $
                                   yOffset     = yOffset             ,     $
                                   TLB_FRAME_ATTR = 9)

;-------------------create the GUI------------------------------;
;logo is [140,70]
Self.xySize = [280,140]

PLOT_EVENT                 = {eis_splash_Event}
PLOT_EVENT.eis_splash      = Self
PLOT_EVENT.Type            = "PLOT"
Self.drawID                = WIDGET_DRAW(Self.tlbID                  ,     $
                                   xSize      = Self.xySize[0] ,           $
                                   ySize      = Self.xySize[1] ,           $
                                   ;/MOTION_EVENTS   ,                      $
                                   ;/TRACKING_EVENTS ,                      $
                                   ;/BUTTON_EVENTS   ,                      $
                                   Event_Pro   = 'eis_splash_EV',          $
                                   uValue      = PLOT_EVENT ,              $
                                   frame       = 4)

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_splash_Event
OBJ_DESTROY    , eis_splash_Event.eis_splash

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_splash::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash::setProperty, start_time = start_time

IF (N_ELEMENTS(start_time) GT 0) THEN BEGIN

    stop

ENDIF

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash::GetProperty, tlbID      = tlbID

tlbID      = Self.tlbID

END
;______________________________________________________________________________
; Return widget id
;______________________________________________________________________________
FUNCTION eis_splash::tlbID

    RETURN, Self.tlbID
END
;______________________________________________________________________________
; Widget_Control wrapper
;______________________________________________________________________________
PRO eis_splash::Control, _Ref_Extra=Widget_Control_Keywords

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End
;______________________________________________________________________________
; Widget_Info wrapper
;______________________________________________________________________________
FUNCTION eis_splash::Info, _Ref_Extra=Widget_Info_Keywords

Return, Widget_Info(Self.tlbID, _Extra=Widget_Info_Keywords)

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_splash::Realize

Widget_Control, Self.tlbID, /Realize

End

;______________________________________________________________________________
; XManager wrapper
;______________________________________________________________________________
PRO eis_splash::XManager;,group=group

XMANAGER , "eis_splash" ,   Self.tlbID ,                                 $
    Event_Handler  = "eis_splash_EV",                                    $
    cleanup        = "eis_splash_Cleanup",                               $
    GROUP_LEADER   = Self.group_leader ,                                    $
    /NO_BLOCK

end

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash_Event__Define

    struct = {  eis_splash_Event,                                              $
                Type            : "",        $ ;Unique identifier for event
                eis_splash   : OBJ_NEW(), $ ;Reference to object passed
                extra           : 0          $ ;to - often object associated
             }
END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_splash_EV , Event

;Get event handler structure containing eis_splash type object
Widget_CONTROL,Event.ID,get_uvalue = eis_splash_Event
;If a WIDGET_TAB event , just quit
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TAB') THEN BEGIN
    ;print,'tab event'
    RETURN
ENDIF

;Call eis_splash's class member procedure "Handler"
eis_splash_Event.eis_splash->Handler,Event

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_splash_Ev above.
;
; Event Handler - handle events.  Derived classes must
; contain their own implementation in order to handle events or else pass in an
; procedure name/function name using the Event_Pro/Event_Func keywords to
; CWidget::Init()
;______________________________________________________________________________
PRO eis_splash::Handler, Event

WIDGET_CONTROL, Event.ID, Get_UValue = eis_splash_Event
CASE eis_splash_Event.Type OF
;    "QUIT"      : Self->Control, /Destroy
    ELSE        : print,eis_splash_Event.Type
ENDCASE
END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash::update_counter , index

WIDGET_CONTROL , Self.progID , get_value = progID
WSET , progID
POLYFILL,[0,0,index+1,index+1,0],[-1,1,1,-1,-1],color=FSC_COLOR('Sky Blue');9
WAIT , 0.0001

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_splash::create_prog_bar , num_tl_entries

xySize = [280,10]
PLOT_EVENT                 = {eis_splash_Event}
PLOT_EVENT.eis_splash      = Self
PLOT_EVENT.Type            = "PLOT"
Self.progID                = WIDGET_DRAW(Self.tlbID                  ,     $
                                   xSize      = xySize[0] ,           $
                                   ySize      = xySize[1] ,           $
                                   ;/MOTION_EVENTS   ,                      $
                                   ;/TRACKING_EVENTS ,                      $
                                   ;/BUTTON_EVENTS   ,                      $
                                   Event_Pro   = 'eis_splash_EV',          $
                                   uValue      = PLOT_EVENT ,              $
                                   frame       = 4)

; 22-Jul-2010
; Remove colour table stuff. Use Fanning's FSC_COLOR instead.
;; Retrieve default colour table properties
;Self.parentClass->getProperty , o_def_ct = o_def_ct
;o_def_ct->getProperty , plotsCT = plotsCT , imageCT = imageCT
;TVLCT,plotsCT[*,0] , plotsCT[*,1] , plotsCT[*,2] ;PLOT ct

WIDGET_CONTROL , Self.progID , get_value = progID
WSET , progID
PLOT , [0,num_tl_entries]                  ,                            $
       [-1,1]                                 ,                            $
       /NODATA                                ,                            $
       xCharsize      = 1.e-3                 ,                            $
       yCharsize      = 1.e-3                 ,                            $
       xMargin        = [0,0]                 ,                            $
       yMargin        = [0,0]                 ,                            $
       ticklen        = 0.0                   ,                            $
       xStyle         = 1                     ,                            $
       background     = FSC_COLOR('Light Yellow');8

END
;______________________________________________________________________________
; Kill gui
;______________________________________________________________________________
PRO eis_splash::kill

Self->Control, /Destroy

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_splash::wait , wait_period

WAIT , wait_period

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_splash::plot_logo , fileName = fileName

IF (N_ELEMENTS(fileName) EQ 0) THEN BEGIN
   fileName = concat_dir(GETENV('ancillary') , 'hinode_small.jpg')
ENDIF

WIDGET_CONTROL , Self.drawID , get_value = drawID
WSET , drawID

; Ensure file is really there
IF (FILE_TEST(fileName) NE 1) THEN RETURN
status = QUERY_JPEG(fileName)
IF (status NE 1) THEN RETURN

; OK, read file, resize and display
READ_JPEG , filename , icon
;icon_resized = CONGRID(icon,3,160,80)
icon_resized = CONGRID(icon,3,280,140)
TVSCL,icon_resized , true = 1

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_splash__define

    struct   = { eis_splash                                          ,     $
                   tlbID                : 0L                         ,     $
                   group_leader         : 0L                         ,     $
                   parentClass          : OBJ_NEW()                  ,     $
                   xySize               : [0L,0L]                    ,     $
                   drawID               : 0L                         ,     $
                   progID               : 0L                         ,     $
                   offset               : 0.                               $
               }


END
