;------------------------------------------------------------------------------;
;+
; NAME: 
;		     eis_aec_widgets
; PURPOSE:
;		     This object
; INPUTS:
;		     GROUP -  
;-
;------------------------------------------------------------------------------;
FUNCTION eis_aec_widgets::Init , parentClass

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

;-------------------create the main base---------------------------------------;
TLB_EVENT                   = {eis_aec_widgets_Event}
TLB_EVENT.eis_aec_widgets = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE( Self.group_leader     ,          $
                                    COLUMN      = 1              ,          $
                                    FRAME       = 1)

;-------------------create the GUI------------------------------;
Self->createGUI

RETURN, 1

END
;______________________________________________________________________________
; 
;______________________________________________________________________________
PRO eis_aec_widgets::createGUI

Event_Pro = 'eis_aec_widgets_EV'


;
; Response Study Base
;
xy_thresholdBase            = WIDGET_BASE(Self.tlbID ,                      $
                                    COLUMN      = 1)

;
; Upper Threshold
;
upperThreshBase             = WIDGET_BASE(xy_thresholdBase ,                $
                                    ROW         = 1 )
upperThreshLabel            = WIDGET_LABEL(upperThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Upper Threshold (%):' ,  $
                                    xSize       = 180)

EISE_THR_X_EVENT            = {eis_aec_widgets_Event}
EISE_THR_X_EVENT.eis_aec_widgets = Self
EISE_THR_X_EVENT.Type       = "THR_U"
Self.threshUID              = WIDGET_SLIDER(upperThreshBase,                $
                                    value       = '0',                      $
                                    Event_Pro   = Event_Pro ,               $
                                    MINIMUM     = 0 ,                       $
                                    MAXIMUM     = 100 ,                     $
                                    uValue      = EISE_THR_X_EVENT)


;
; Lower Threshold
;
lowerThreshBase             = WIDGET_BASE(xy_thresholdBase ,               $
                                    ROW         = 1 )
lowerThreshLabel            = WIDGET_LABEL(lowerThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Lower Threshold (%):'  , $
                                    xSize       = 180)

EISE_THR_Y_EVENT            = {eis_aec_widgets_Event}
EISE_THR_Y_EVENT.eis_aec_widgets = Self
EISE_THR_Y_EVENT.Type       = "THR_L"
Self.threshLID              = WIDGET_SLIDER(lowerThreshBase,                $
                                    value       = '0',                      $
                                    Event_Pro   = Event_Pro ,               $
                                    MINIMUM     = 0 ,                       $
                                    MAXIMUM     = 100 ,                     $
                                    uValue      = EISE_THR_Y_EVENT)



;
; High Energy Pixel Count Limit
;
upperThreshBase             = WIDGET_BASE(xy_thresholdBase ,                $
                                    ROW         = 1 )
upperThreshLabel            = WIDGET_LABEL(upperThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Upper Pixel Count Limit (%):' ,  $
                                    xSize       = 180)

EISE_CNT_U_EVENT            = {eis_aec_widgets_Event}
EISE_CNT_U_EVENT.eis_aec_widgets = Self
EISE_CNT_U_EVENT.Type       = "CNT_U"
Self.cnt_uID                = WIDGET_SLIDER(upperThreshBase,                $
                                    value       = '0',                      $
                                    Event_Pro   = Event_Pro ,               $
                                    MINIMUM     = 0 ,                       $
                                    MAXIMUM     = 100 ,                     $
                                    uValue      = EISE_CNT_U_EVENT)

;
; Low Energy Pixel Count Limit
;
upperThreshBase             = WIDGET_BASE(xy_thresholdBase ,                $
                                    ROW         = 1 )
upperThreshLabel            = WIDGET_LABEL(upperThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Lower Pixel Count Limit (%):' ,  $
                                    xSize       = 180)

EISE_CNT_L_EVENT            = {eis_aec_widgets_Event}
EISE_CNT_L_EVENT.eis_aec_widgets = Self
EISE_CNT_L_EVENT.Type       = "CNT_L"
Self.cnt_lID                = WIDGET_SLIDER(upperThreshBase,                $
                                    value       = '0',                      $
                                    Event_Pro   = Event_Pro ,               $
                                    MINIMUM     = 0 ,                       $
                                    MAXIMUM     = 100 ,                     $
                                    uValue      = EISE_CNT_L_EVENT)


;
; Starting Exposure
;
upperThreshBase             = WIDGET_BASE(xy_thresholdBase ,                $
                                    ROW         = 1 )
upperThreshLabel            = WIDGET_LABEL(upperThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Starting Exposure:'   ,  $
                                    xSize       = 180)

EISE_EXP_EVENT              = {eis_aec_widgets_Event}
EISE_EXP_EVENT.eis_aec_widgets = Self
EISE_EXP_EVENT.Type         = "EXP"
value           = eis_get_aec_exposure_table()
formatted_value = STRING(format='(F7.3)',value/1000.)
Self.expID                  = WIDGET_DROPLIST(upperThreshBase,              $
                                    value       = formatted_value    ,      $
                                    Event_Pro   = Event_Pro ,               $
                                    uValue      = EISE_EXP_EVENT)

;
; Maximum Run Time
;
upperThreshBase             = WIDGET_BASE(xy_thresholdBase ,                $
                                    ROW         = 1 )
upperThreshLabel            = WIDGET_LABEL(upperThreshBase ,                $
                                    /ALIGN_LEFT  ,                          $
                                    value       = 'Starting Exposure:'   ,  $
                                    xSize       = 180)

EISE_MAX_EVENT              = {eis_aec_widgets_Event}
EISE_MAX_EVENT.eis_aec_widgets = Self
EISE_MAX_EVENT.Type         = "MAX_TIME"
Self.maxruntimeID           = WIDGET_TEXT(upperThreshBase    ,              $
                                    value       = '0'                ,      $
                                    Event_Pro   = Event_Pro ,               $
                                    /EDITABLE                         ,     $
                                    uValue      = EISE_MAX_EVENT)


; Get current values
Self.parentClass->getProperty , eis_aec_control = control_struct

; Set slider values
; Threshold
WIDGET_CONTROL , Self.threshUID , set_value = control_struct.upper_threshold
WIDGET_CONTROL , Self.threshLID , set_value = control_struct.lower_threshold
; Pixel Count Rate
WIDGET_CONTROL , Self.cnt_uID , set_value = control_struct.high_energy_pixel_count_limit
WIDGET_CONTROL , Self.cnt_lID , set_value = control_struct.low_energy_pixel_count_limit
; Starting Exposure
WIDGET_CONTROL , Self.expID   , set_droplist_select = control_struct.exposure_id
; Maximum Run Time
max_run_time = STRCOMPRESS(control_struct.run_time , /REMOVE_ALL)
WIDGET_CONTROL , Self.maxruntimeID   , set_value = max_run_time


END

;______________________________________________________________________________
; 
;______________________________________________________________________________
PRO eis_aec_widgets_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_aec_widgets_Event
OBJ_DESTROY    , eis_aec_widgets_Event.eis_aec_widgets

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_aec_widgets::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_aec_widgets::setProperty , raster_index = raster_index

IF (N_ELEMENTS(raster_index) GT 0) THEN BEGIN
    ;Self.parentClass->setProperty , raster_index = raster_index
    stop
ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_aec_widgets::GetProperty, acronymID = acronymID ,            $
                                         idID      = idID      ,            $
                                         ra_indexID = ra_indexID

acronymID  = Self.acronymID
idID       = Self.idID
ra_indexID = Self.ra_indexID

End
;______________________________________________________________________________
; Return widget id
;______________________________________________________________________________
Function eis_aec_widgets::tlbID

    Return, Self.tlbID
End

;______________________________________________________________________________
; Widget_Control wrapper
;______________________________________________________________________________
PRO eis_aec_widgets::Control, _Ref_Extra=Widget_Control_Keywords

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

;______________________________________________________________________________
; Widget_Info wrapper
;______________________________________________________________________________
Function eis_aec_widgets::Info, _Ref_Extra=Widget_Info_Keywords

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

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_aec_widgets::Realize

Widget_Control, Self.tlbID, /Realize
	
End

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

XMANAGER , "eis_aec_widgets" ,   Self.tlbID ,                        $
    Event_Handler  = "eis_aec_widgets_EV",                           $
    cleanup        = "eis_aec_widgets_Cleanup",                      $
    GROUP_LEADER   = Self.group_leader ,                                    $
    /NO_BLOCK

end

;______________________________________________________________________________
; 
;______________________________________________________________________________
PRO eis_aec_widgets_Event__Define

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

;Get event handler structure containing eis_aec_widgets type object
Widget_CONTROL,Event.ID,get_uvalue = eis_aec_widgets_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_aec_widgets's class member procedure "Handler"
eis_aec_widgets_Event.eis_aec_widgets->Handler,Event

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_aec_widgets_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_aec_widgets::Handler, Event

WIDGET_CONTROL, Event.ID, Get_UValue = eis_aec_widgets_Event
CASE eis_aec_widgets_Event.Type OF
    "THR_U"    :  Self->u_threshold
    "CNT_U"    :  Self->u_count
    "THR_L"    :  Self->l_threshold
    "CNT_L"    :  Self->l_count
    "EXP"      :  Self->exposure
    "MAX_TIME" : Self->max_run_time
    ELSE       :  print,eis_aec_widgets_Event.Type
ENDCASE
END
;______________________________________________________________________________
; Set Starting Exposure
;______________________________________________________________________________
PRO	eis_aec_widgets::max_run_time

; Get old value
Self.parentClass->getProperty , eis_aec_control = control_struct

; Get New Value
WIDGET_CONTROL , Self.maxruntimeID , get_value = new_value

; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Max Run Time' , new_value[0] ,                 $
                control_struct.run_time , 0 , 131071)

CASE valid.valid OF
    0:  BEGIN
            run_time = control_struct.run_time
            BEEP
        				complain = DIALOG_MESSAGE( valid.mText ,                        $
                             				DIALOG_PARENT = Self.tlbID,                $
                             				/ERROR )
        END
    1:  run_time = LONG(new_value[0])
ENDCASE

; Update widget value
WIDGET_CONTROL , Self.maxruntimeID ,                                        $
                        set_value = STRCOMPRESS( run_time , /REMOVE_ALL)

; Update value 
Self.parentClass->setProperty , run_time = run_time

END
;______________________________________________________________________________
; Set Starting Exposure
;______________________________________________________________________________
PRO	eis_aec_widgets::exposure

exposure_id = WIDGET_INFO(Self.expID , /DROPLIST_SELECT)
Self.parentClass->setProperty , exposure_id = exposure_id

END
;______________________________________________________________________________
; Set Upper Energy Pixel Count Limit
;______________________________________________________________________________
PRO	eis_aec_widgets::u_count

WIDGET_CONTROL , Self.cnt_uID , get_value = high_energy_pixel_count_limit
Self.parentClass->setProperty , high_energy_pixel_count_limit = high_energy_pixel_count_limit

END
;______________________________________________________________________________
; Set Lower Energy Pixel Count Limit
;______________________________________________________________________________
PRO	eis_aec_widgets::l_count

WIDGET_CONTROL , Self.cnt_lID , get_value = low_energy_pixel_count_limit
Self.parentClass->setProperty , low_energy_pixel_count_limit = low_energy_pixel_count_limit

END
;______________________________________________________________________________
; Set X Threshold
;______________________________________________________________________________
PRO	eis_aec_widgets::u_threshold

WIDGET_CONTROL , Self.threshUID , get_value = upper_threshold
Self.parentClass->setProperty , upper_threshold = upper_threshold

END
;______________________________________________________________________________
; Set Y Threshold
;______________________________________________________________________________
PRO	eis_aec_widgets::l_threshold

WIDGET_CONTROL , Self.threshLID , get_value = lower_threshold
Self.parentClass->setProperty , lower_threshold = lower_threshold

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO	eis_aec_widgets__Define

    struct          =	{ eis_aec_widgets                               ,     $
                                    tlbID           : 0L              ,     $
                                    group_leader    : 0L              ,     $
                                    parentClass     : OBJ_NEW()       ,     $
                                    threshUID       : 0L              ,     $
                                    threshLID       : 0L              ,     $
                                    cnt_uID         : 0L              ,     $
                                    cnt_lID         : 0L              ,     $
                                    expID           : 0L              ,     $
                                    maxruntimeID    : 0L                    $
                      }


END
