PRO gui_event, ev

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Event handler for the DI calibration GUI
;;
;; CALLING SEQUENCE:
;;	gui_event, ev
;;
;; REQUIRED INPUTS:
;;	ev - Event structure
;;
;; OUTPUTS:
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> gui_event, ev
;;
;; PROCEDURES USED (i.e. called directly!):
;;	gui_updateOptPane - Updates the option pane
;;	gui_openFile - Opens a FITS file for calibration
;;	gui_calibrate - Calibrates a file
;;
;; MODIFICATION HISTORY:
;;   2004-07-28  M. Desnoyer    Created
;;
;;-----------------------------------------------------------------------------

;; The different widgets that could produce an event
CASE widget_info(ev.ID, /UNAME) OF
'modlist': IF ev.clicks EQ 1 THEN gui_updateOptPane, ev.TOP
'openbut': gui_openFile, ev.TOP
'closebut': gui_closeFile, ev.TOP
'calbut': gui_calibrate, ev.TOP
'resetbut': BEGIN
	gui_reset, ev.TOP
	gui_updateoptpane, ev.TOP
END
'exitbut': widget_control, ev.TOP, /DESTROY
'colchangebut': BEGIN
	;; Get the program settings
	widget_control, ev.TOP, get_uvalue=data
	
	;; Create the array of widgetIDs that need to be updated
	wnds = -1
	IF data.previewWnd NE 0 THEN wnds = [wnds, data.previewWnd]
	IF data.calWnd[0] NE 0 THEN wnds = [wnds, data.calWnd[0]]
	IF data.calWnd[1] NE 0 THEN wnds = [wnds, data.calWnd[1]]
	IF max(wnds) EQ -1 THEN RETURN ;; No window to change color for
	wnds=wnds[1:*]

	;; Open the xloadct dialog
	xloadct, group=ev.TOP, updatecallback='gui_refreshPreviews', $
		updatecbdata=wnds
END
'modhelp': gui_modHelp, ev.TOP, $
	widget_info(widget_info(ev.TOP,find_by_uname='modlist'),/list_select)
'aboutbut': BEGIN
	nl = string(10B)
	trash = dialog_message('Deep Impact Image Calibration Utility'+nl+nl+$
		'Created for Deep Impact mission (NASA/JPL/UMD/BATC)'+nl+$
		'Copyright Cornell University 2004-2005'+nl+$
		'Author: Mark Desnoyer (md246@cornell.edu)', /information, $
		title='About', dialog_parent=ev.TOP)
END
ENDCASE

END