;------------------------------------------------------------------------------;
;+
; NAME
;           EIS_LINE_NAME_CUSTOM_GUI
;
; PURPOSE
;           This object
;
; INPUTS
;           parentClass - eis_mk_raster object id
;           line_name   -
;
; WRITTEN
;           John A Rainnie, RAL, Dec-2005
;
; HISTORY
;           V0.1 JAR, 16-Mar-2007
;               Added /ALL_EVENTS keyword to text widget. Removed QUIT
;               button. When APPLY button is selected, perform a bunch
;               of tests to verify the line name is;
;               (a) NOT zero length
;               (b) contains at most 2 words
;               (c) contains only 10 characters
;               (d) if only 1 word is supplied, then append " 0" to it
;
;-
;------------------------------------------------------------------------------;
FUNCTION eis_line_name_custom_gui::Init , parentClass , line_name

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

;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle   = "EIS Line Name" + pt_version
TLB_EVENT                   = {eis_line_name_custom_gui_Event}
TLB_EVENT.eis_line_name_custom_gui       = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE(                                  $
                                    TITLE       = widTitle,                 $
                                    COLUMN      = 1,                        $
                                    /FLOATING      ,                        $
                                    ;/MODAL         ,                        $
                                    GROUP_LEADER = Self.group_leader ,      $
                                    UValue      = TLB_EVENT)

;-------------------create the GUI------------------------------;

Self.line_name = line_name
Self->createGUI

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui::createGUI

event_pro = 'eis_line_name_custom_gui_EV'
; ______________________________________________________________________
;
; File base
;
; ______________________________________________________________________
nameBase                    = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1  ,                      $
                                    FRAME       = 1 )

aLabel                      = WIDGET_LABEL(nameBase ,                       $
                                    value       = 'Name:')

NAME_EVENT                  = {eis_line_name_custom_gui_Event}
NAME_EVENT.eis_line_name_custom_gui = Self
NAME_EVENT.Type             = "NAME"
value = Self.line_name
Self.nameTextID             = WIDGET_TEXT(nameBase                     ,    $
                                    value       = value                ,    $
                                    Event_Pro   = Event_Pro_update     ,    $
                                    /EDITABLE                          ,    $
                                    xSize       = 11                   ,    $
                                    uValue      = NAME_EVENT           ,    $
                                    /ALL_EVENTS)

aLabel                      = WIDGET_LABEL(nameBase ,                       $
                                    value       = '(max 10 chars)    ')
; ______________________________________________________________________
;
; Bottom base
;
; ______________________________________________________________________
bottomBase                  = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1  ,                      $
                                    frame       = 1  ,                      $
                                    /GRID_LAYOUT)


APPLY_EVENT                 = {eis_line_name_custom_gui_Event}
APPLY_EVENT.eis_line_name_custom_gui      = Self
APPLY_EVENT.Type            = "APPLY"
APPLYbutton                 = WIDGET_BUTTON(bottomBase,                     $
                                    value       = 'Apply',                   $
                                    Event_Pro   = event_pro       ,         $
                                    uValue      = APPLY_EVENT)


;QUIT_EVENT                  = {eis_line_name_custom_gui_Event}
;QUIT_EVENT.eis_line_name_custom_gui      = Self
;QUIT_EVENT.Type             = "QUIT"
;quitbutton                  = WIDGET_BUTTON(bottomBase,                     $
;                                    value       = 'Quit'                 ,  $
;                                    Event_Pro   = event_pro       ,         $
;                                    uValue      = QUIT_EVENT)


END

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_line_name_custom_gui_Event
OBJ_DESTROY    , eis_line_name_custom_gui_Event.eis_line_name_custom_gui

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_line_name_custom_gui::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui::setProperty, author  = author

IF (N_ELEMENTS(author) GT 0) THEN Self.eis_study.author = author

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui::GetProperty, tlbID   = tlbID

tlbID = Self.tlbID

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

    Return, Self.tlbID
End

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

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

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

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

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_line_name_custom_gui::Realize

Widget_Control, Self.tlbID, /Realize

End

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

XMANAGER , "eis_line_name_custom_gui" ,   Self.tlbID ,                      $
    Event_Handler  = "eis_line_name_custom_gui_EV",                         $
    cleanup        = "eis_line_name_custom_gui_Cleanup",                    $
    GROUP_LEADER   = Self.group_leader ,                                    $
    /NO_BLOCK

end

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui_Event__Define

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

;Get event handler structure containing eis_line_name_custom_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_line_name_custom_gui_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_line_name_custom_gui's class member procedure "Handler"
eis_line_name_custom_gui_Event.eis_line_name_custom_gui->Handler,Event

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

WIDGET_CONTROL, Event.ID, Get_UValue = eis_line_name_custom_gui_Event

CASE eis_line_name_custom_gui_Event.Type OF
    ;"QUIT"         : Self->Control, /Destroy
    "NAME"         : ;Self->verify_name
    "APPLY"        : Self->apply
    ELSE           : print,eis_line_name_custom_gui_Event.Type
ENDCASE
END
;______________________________________________________________________________
;
;______________________________________________________________________________
FUNCTION eis_line_name_custom_gui::verify_name

WIDGET_CONTROL , Self.nameTextID , get_value = widValue
;
; Test input
;
; It must not be the null string
IF (STRLEN(widValue) EQ 0) THEN BEGIN
    mText    = 'No name supplied. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

str_info = STRSPLIT(widValue[0] , ' ' , count = num_words)
IF (num_words GE 3) THEN BEGIN
    mText    = 'Only 2 words allowed. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

IF (STRLEN(widValue[0]) GT 10) THEN BEGIN
    mText    = 'Only 10 characters allowed. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

IF (num_words EQ 1) THEN widValue[0] = widValue[0] + " 0"

Self.line_name = widValue[0]

RETURN , 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_line_name_custom_gui::apply

IF (Self->verify_name() NE 1) THEN RETURN


Self.parentClass->update_line_name , Self.line_name


Self->Control, /Destroy

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_line_name_custom_gui__define

    struct          =	{ eis_line_name_custom_gui                      ,     $
                                    tlbID           : 0L              ,     $
                                    group_leader    : 0L              ,     $
                                    parentClass     : OBJ_NEW()       ,     $
                                    nameTextID      : 0L              ,     $
                                    line_name       : ''                    $
                      }

END
