;$Id: db_legend.pro,v 1.7 2005/02/08 17:01:16 azuah Exp $
;###############################################################################
;
; NAME:
;   DB_Legend
;
; PURPOSE:
;   Widget dialog program (non-blocking) for editing the legend in a
;   1D multiplot.
;
; CATEGORY:
;   Data Browser
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Aug, 2003
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################



;===============================================================================
; DB_Legend_Cleanup
;
; PURPOSE:
;   Cleanup routine called when the main widget is destroyed
;
; PARAMETERS:
;   tlb [in] - the widget id of the top-level-base that is being
;              killed.
;
pro DB_Legend_Cleanup, tlb

widget_control, tlb, get_uvalue=sPtr

ptr_free, sPtr

end
;-------------------------------------------------------------------------------



;===============================================================================
; DB_Legend_Event
;
; PURPOSE:
;   Event handler for events originating from the main UI
;
; PARAMETERS:
;   event [in] - the event structure to be handled
;
pro DB_Legend_Event, event

widget_control,event.top,get_uvalue = sPtr
uname = widget_info(event.id,/uname)

switch uname of

    'LTITLE': begin
        widget_control, event.id, get_value=value
        (*sPtr).legend.title = strtrim(value,2)

        ((*sPtr).legObjRef)->GetProperty, title=oTitle
        oTitle->SetProperty, strings=(*sPtr).legend.title

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'TFONT': begin
        (*sPtr).legend.tfont = event.str

        ((*sPtr).legObjRef)->GetProperty, title=oTitle
        oTitle->GetProperty, font=oFont
        oFont->SetProperty, name=(*sPtr).legend.tfont

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'TFONTSIZE': begin
        (*sPtr).legend.tfontsize = float(event.str)

        ((*sPtr).legObjRef)->GetProperty, title=oTitle
        oTitle->GetProperty, font=oFont
        oFont->SetProperty, size=(*sPtr).legend.tfontsize

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'TCOLOR': begin
        widget_control, event.id, get_uvalue=colors
        (*sPtr).legend.tcolor = colors[*,event.index]

        ((*sPtr).legObjRef)->GetProperty, title=oTitle
        oTitle->SetProperty, color=(*sPtr).legend.tcolor 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'BCOLOR': begin
        widget_control, event.id, get_uvalue=colors
        (*sPtr).legend.bkgdcolor = colors[*,event.index]

        ((*sPtr).legObjRef)->SetProperty, fill_color=(*sPtr).legend.bkgdcolor 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'FCOLOR': begin
        widget_control, event.id, get_uvalue=colors
        (*sPtr).legend.outlcolor = colors[*,event.index]

        ((*sPtr).legObjRef)->SetProperty, outline_color=(*sPtr).legend.outlcolor 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'FTHICK': begin
        (*sPtr).legend.outlthick = float(event.str)

        ((*sPtr).legObjRef)->SetProperty, outline_thick=(*sPtr).legend.outlthick 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'IFONT': begin
        (*sPtr).legend.font = event.str

        ((*sPtr).legObjRef)->GetProperty, font=oFont
        oFont->SetProperty, name=(*sPtr).legend.font

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'IFONTSIZE': begin
        (*sPtr).legend.fontsize = float(event.str)

        ((*sPtr).legObjRef)->GetProperty, font=oFont
        oFont->SetProperty, size=(*sPtr).legend.fontsize

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'ICOLOR': begin
        widget_control, event.id, get_uvalue=colors
        (*sPtr).legend.textcolor = colors[*,event.index]

        ((*sPtr).legObjRef)->SetProperty, text_color=(*sPtr).legend.textcolor

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'ITHICK': begin
        (*sPtr).legend.itemthick[*] = float(event.str)

        nItems = (*sPtr).nItems
        ((*sPtr).legObjRef)->SetProperty, item_thick=(*sPtr).legend.itemthick[0:nItems-1]

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'GWIDTH': begin
        (*sPtr).legend.gwidth = float(event.str)

        ((*sPtr).legObjRef)->SetProperty, glyph_width=(*sPtr).legend.gwidth

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'GAP': begin
        (*sPtr).legend.gap = float(event.str)

        ((*sPtr).legObjRef)->SetProperty, gap=(*sPtr).legend.gap

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'INAME': begin
        widget_control, event.id, get_value=value, get_uvalue=index
        (*sPtr).legend.itemname[index] = strtrim(value,0)

        nItems = (*sPtr).nItems
        ((*sPtr).legObjRef)->SetProperty, item_name=(*sPtr).legend.itemname[0:nItems-1]

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'XLOC': begin
        ctm = ((*sPtr).legObjRef)->GetCTM() ; current transformation matrix

        (*sPtr).legend.location[0] = event.value
        x_new = (*sPtr).legend.location[0] * (*sPtr).vpdim[0]

        ((*sPtr).legObjRef)->Translate,-ctm[3,0],0.0,0.0 ; return to x-origin
        ;; translate legend to desired x-location, scaled by wieplane width.
        ((*sPtr).legObjRef)->Translate,x_new,0.0,0.0 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end

    'YLOC': begin
        ctm = ((*sPtr).legObjRef)->GetCTM() ; current transformation matrix

        (*sPtr).legend.location[1] = event.value
        y_new = (*sPtr).legend.location[1] * (*sPtr).vpdim[1]

        ((*sPtr).legObjRef)->Translate,0.0,-ctm[3,1],0.0 ; return to y-origin
        ;; translate legend to desired y-location, scaled by wieplane width.
        ((*sPtr).legObjRef)->Translate,0.0,y_new,0.0 

        ((*sPtr).widObjRef)->noRenew
        ((*sPtr).widObjRef)->refresh 
        break
    end


    'APPLY': begin
        void = ((*sPtr).daveGrRef)->set(legend = (*sPtr).legend)
        ((*sPtr).widObjRef)->Renew
        ((*sPtr).widObjRef)->refresh
        widget_control,event.top,/destroy
        break
    end

    'DEFAULT': begin
        void = ((*sPtr).davegrRef)->get(legend=origLegend)
        ((*sPtr).daveGrRef)->resetLegend
        void = ((*sPtr).davegrRef)->get(legend=legend)
        (*sPtr).legend = legend
        void = ((*sPtr).davegrRef)->set(legend=origLegend)
        
        ; update dialog
        wID = widget_info(event.top,find_by_uname='LTITLE')
        widget_control, wid, set_value=legend.title

        wID = widget_info(event.top,find_by_uname='TFONT')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.tfont, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]

        wID = widget_info(event.top,find_by_uname='TFONTSIZE')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.tfontsize, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]

        wID = widget_info(event.top,find_by_uname='TCOLOR')
        widget_control, wID, get_uvalue=options
        for i=0,(size(options))[2]-1 do begin
            void = where(options[*,i] eq legend.tcolor, count)
            if (count eq 3) then begin
                widget_control, wid, set_combobox_select=i
                break
            endif
        endfor

        wID = widget_info(event.top,find_by_uname='BCOLOR')
        widget_control, wID, get_uvalue=options
        for i=0,(size(options))[2]-1 do begin
            void = where(options[*,i] eq legend.bkgdcolor, count)
            if (count eq 3) then begin
                widget_control, wid, set_combobox_select=i
                break
            endif
        endfor

        wID = widget_info(event.top,find_by_uname='FCOLOR')
        widget_control, wID, get_uvalue=options
        for i=0,(size(options))[2]-1 do begin
            void = where(options[*,i] eq legend.outlcolor, count)
            if (count eq 3) then begin
                widget_control, wid, set_combobox_select=i
                break
            endif
        endfor

        wID = widget_info(event.top,find_by_uname='FTHICK')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.outlthick, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]

        wID = widget_info(event.top,find_by_uname='IFONT')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.font, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]
 
        wID = widget_info(event.top,find_by_uname='IFONTSIZE')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.fontsize, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]
 
        wID = widget_info(event.top,find_by_uname='ICOLOR')
        widget_control, wID, get_uvalue=options
        for i=0,(size(options))[2]-1 do begin
            void = where(options[*,i] eq legend.textcolor, count)
            if (count eq 3) then begin
                widget_control, wid, set_combobox_select=i
                break
            endif
        endfor
 
        wID = widget_info(event.top,find_by_uname='ITHICK')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.itemthick[0], count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]
 
        wID = widget_info(event.top,find_by_uname='GWIDTH')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.gwidth, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]
 
        wID = widget_info(event.top,find_by_uname='GAP')
        widget_control, wID, get_uvalue=options
        res = where(options eq legend.gap, count)
        if (count gt 0) then widget_control, wID, set_combobox_select=res[0]

        for i=0, n_elements((*sPtr).itemIDs)-1 do begin
            widget_control, (*sPtr).itemIDs[i], set_value=(legend.itemname)[i]
        endfor

        wID = widget_info(event.top,find_by_uname='XLOC')
        widget_control, wid, set_value=legend.location[0]
       
        wID = widget_info(event.top,find_by_uname='YLOC')
        widget_control, wid, set_value=legend.location[1]

        break
    end

    'EXIT': begin
        ((*sPtr).widObjRef)->Renew
        ((*sPtr).widObjRef)->refresh 
        widget_control,event.top,/destroy
        break
    end

    else: print, 'Unknown Event generated...'

endswitch


end
;-------------------------------------------------------------------------------



;===============================================================================
; DB_Legend
;
; PURPOSE:
;   Entry point and dialog builder for application.
;
; PARAMETERS
;   legObjRef [in;req] - Object reference for the legend to be
;                        modified.
;
;   widObjRef [in;req] - The object reference of the display (view)
;                        from which the edit request originated from.
;
; KEYWORDS:
;   group_leader [in] - the ID of the parent widget from which this
;                       dialog was launched.
;
pro DB_Legend, legObjRef,widObjRef,group_leader=glder

if (not obj_valid(legObjRef)) then return ; ensure legend is valid

if (not obj_valid(widObjRef)) then return ; ensure parent widget object is valid

; get the DaveGr ref from the legend object's uvalue
legObjRef->getProperty, uvalue=atomUval
daveGrRef = atomUval.objRef


if (vartype(daveGrRef) ne 'DAVEGR1D') then return

if (not daveGrRef->get(legend=legend)) then return

; top level base
title = 'DATABROWSER: Legend Properties'
if n_elements(glder) eq 0 then begin
    group_leader = 0L
    modal = 0
    tlb = widget_base(/col,title=title)
endif else begin
    modal = 1
    tlb = widget_base(group_leader=glder,/col,title=title);,modal=modal)
endelse

; Split the dialog base into
; - one tab base
; - one control base
tabBase = widget_tab(tlb)
ansBase = widget_base(tlb,/row,/align_center)

; Create two tab widgets
tab1 = widget_base(tabBase,title='General',/col)
tab2 = widget_base(tabBase,title='Item Attributes',/col)
tab3 = widget_base(tabBase,title='Item Labels',/col)
tab4 = widget_base(tabBase,title='Location',/col)

;=======================================================================
; Tab 1
dropSize = 150
labSize = 105
lab2Size = 110
textSize = 30
locSize = 17
gap0 = 10
gap1 = dropSize + labSize + gap0
gap2 = gap1 + labSize
; Create control bases for first tab
cb1 = widget_base(tab1,/col,/frame)
cb2 = widget_base(tab1,/col,/frame)

cb3 = widget_base(cb1,/row,/align_center)

cb4 = widget_base(cb1,/row)
cb41 = widget_base(cb4,/row)
cb42 = widget_base(cb4,/row,/align_left)

cb5 = widget_base(cb1,/row)
cb51 = widget_base(cb5,/row)
cb52 = widget_base(cb5,/row,/align_left)

cb6 = widget_base(cb1,/row)
cb61 = widget_base(cb6,/row)
cb62 = widget_base(cb6,/row,/align_left)

cb7 = widget_base(cb1,/row)
cb71 = widget_base(cb7,/row)
cb72 = widget_base(cb7,/row,/align_left)

cb8 = widget_base(cb2,/row)
cb81 = widget_base(cb8,/row)
cb82 = widget_base(cb8,/row,/align_left)

cb9 = widget_base(cb2,/row)
cb91 = widget_base(cb9,/row)
cb92 = widget_base(cb9,/row,/align_left)

cb10 = widget_base(cb2,/row)
cb101 = widget_base(cb10,/row)
cb102 = widget_base(cb10,/row,/align_left)

cb11 = widget_base(cb2,/row)
cb111 = widget_base(cb11,/row)
cb112 = widget_base(cb11,/row,/align_left)



; label
void = widget_label(cb3,value='Legend Title')

; title text field
void = widget_label(cb41,value='Text:',xsize=labSize,/align_right)
textID = widget_text(cb42,/editable,/all_events,value=legend.title,xsize=textSize,uname='LTITLE')

; Title Font
void = widget_label(cb51,value='Font:',xsize=labSize,/align_right)
fonts = ['HELVETICA','COURIER','TIMES','SYMBOL','HERSHEY']
fnameID = widget_combobox(cb52,value=fonts,uname='TFONT',uvalue=fonts,xsize=dropSize)
;if (strlen(axisFontName) gt 0) then begin
index = where(fonts eq legend.tfont)
widget_control, fnameID, set_combobox_select=index

; Title Font Size
void = widget_label(cb61,value='Fontsize:',xsize=labSize,/align_right)
sizes = [7,8,9,10,11,12,13,14,15,16,18,20]
fSizes = ['7','8','9','10','11','12','13','14','15','16','18','20']
tfsizeID = widget_combobox(cb62,value=fSizes,uname='TFONTSIZE',uvalue=sizes,xsize=dropSize)
res = where(sizes ge legend.tfontsize, count)
if (count gt 0) then widget_control, tfsizeID, set_combobox_select=res[0]

; Title Font Color
void = widget_label(cb71,value='Color:',xsize=labSize,/align_right)
colorNames = ['Aqua','Black','Blue','Fuchsia','Gray','Green','Lime','Maroon', $
              'Navy','Olive','Purple','Red','Silver','Teal','White','Yellow']
colorIndices = [[0,255,255],[0,0,0],[0,0,255],[255,0,255],$
                [128,128,128],[0,128,0],[0,255,0],[128,0,0], $
                [0,0,128],[128,128,0],[128,0,128],[255,0,0], $
                [192,192,192],[0,128,128],[255,255,255],[255,255,0]]
tcolorID = widget_combobox(cb72,value=colorNames,uname='TCOLOR',uvalue=colorIndices,xsize=dropSize)
for i=0,(size(colorIndices))[2]-1 do begin
    void = where(colorIndices[*,i] eq legend.tcolor, count)
    if (count eq 3) then begin
        widget_control, tcolorID, set_combobox_select=i
        break
    endif
endfor

; Bkgd Fill Color
void = widget_label(cb81,value='Bkgd Color:',xsize=labSize,/align_right)
bcolorID = widget_combobox(cb82,value=colorNames,uname='BCOLOR',uvalue=colorIndices,xsize=dropSize)
for i=0,(size(colorIndices))[2]-1 do begin
    void = where(colorIndices[*,i] eq legend.bkgdColor, count)
    if (count eq 3) then begin
        widget_control, bcolorID, set_combobox_select=i
        break
    endif
endfor

; Frame Color
void = widget_label(cb91,value='Frame Color:',xsize=labSize,/align_right)
fcolorID = widget_combobox(cb92,value=colorNames,uname='FCOLOR',uvalue=colorIndices,xsize=dropSize)
for i=0,(size(colorIndices))[2]-1 do begin
    void = where(colorIndices[*,i] eq legend.outlColor, count)
    if (count eq 3) then begin
        widget_control, fcolorID, set_combobox_select=i
        break
    endif
endfor

; Frame Thickness
void = widget_label(cb101,value='Frame Thickness:',xsize=labSize,/align_right)
tness = [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0]
tnesss = ['1.0','1.5','2.0','2.5','3.0','3.5','4.0','4.5','5.0']
tnessID = widget_combobox(cb102,value=tnesss,uname='FTHICK',uvalue=tness,xsize=dropSize)
res = where(tness ge legend.outlthick, count)
if (count gt 0) then widget_control, tnessID, set_combobox_select=res[0]


;=======================================================================
; Tab 2
dropSize = 150
labSize = 105
lab2Size = 110
textSize = 30
locSize = 17
gap0 = 10
gap1 = dropSize + labSize + gap0
gap2 = gap1 + labSize
; Create control bases for second tab
cb01 = widget_base(tab2,/col)
;cb02 = widget_base(tab2,/col,/frame,/align_center)

cb03 = widget_base(cb01,/row,/align_center)

cb04 = widget_base(cb01,/row)
cb041 = widget_base(cb04,/row)
cb042 = widget_base(cb04,/row,/align_left)

cb05 = widget_base(cb01,/row)
cb051 = widget_base(cb05,/row)
cb052 = widget_base(cb05,/row,/align_left)

cb06 = widget_base(cb01,/row)
cb061 = widget_base(cb06,/row)
cb062 = widget_base(cb06,/row,/align_left)

cb07 = widget_base(cb01,/row)
cb071 = widget_base(cb07,/row)
cb072 = widget_base(cb07,/row,/align_left)

cb08 = widget_base(cb01,/row)
cb081 = widget_base(cb08,/row)
cb082 = widget_base(cb08,/row,/align_left)

cb09 = widget_base(cb01,/row)
cb091 = widget_base(cb09,/row)
cb092 = widget_base(cb09,/row,/align_left)



; label
void = widget_label(cb03,value='Common Properties')

; Item Font
void = widget_label(cb041,value='Font:',xsize=labSize,/align_right)
void = widget_combobox(cb042,value=fonts,uname='IFONT',uvalue=fonts,xsize=dropSize)
index = where(fonts eq legend.font)
widget_control, void, set_combobox_select=index

; Item Font Size
void = widget_label(cb051,value='Fontsize:',xsize=labSize,/align_right)
void = widget_combobox(cb052,value=fSizes,uname='IFONTSIZE',uvalue=sizes,xsize=dropSize)
res = where(sizes ge legend.fontsize, count)
if (count gt 0) then widget_control, void, set_combobox_select=res[0]

; Item Font Color
void = widget_label(cb061,value='Color:',xsize=labSize,/align_right)
void = widget_combobox(cb062,value=colorNames,uname='ICOLOR',uvalue=colorIndices,xsize=dropSize)
for i=0,(size(colorIndices))[2]-1 do begin
    voidd = where(colorIndices[*,i] eq legend.textcolor, count)
    if (count eq 3) then begin
        widget_control, void, set_combobox_select=i
        break
    endif
endfor

; Item character Thickness
void = widget_label(cb071,value='Weight:',xsize=labSize,/align_right)
void = widget_combobox(cb072,value=tnesss,uname='ITHICK',uvalue=tness,xsize=dropSize)
res = where(tness ge (legend.itemthick)[0], count)
if (count gt 0) then widget_control, void, set_combobox_select=res[0]

; Item glyph width
void = widget_label(cb081,value='Glyph Width:',xsize=labSize,/align_right)
void = widget_combobox(cb082,value=tnesss,uname='GWIDTH',uvalue=tness,xsize=dropSize)
res = where(tness ge legend.gwidth, count)
if (count gt 0) then widget_control, void, set_combobox_select=res[0]

; Item spacing
void = widget_label(cb091,value='Spacing:',xsize=labSize,/align_right)
tness = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
tnesss = ['0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1.0']
void = widget_combobox(cb092,value=tnesss,uname='GAP',uvalue=tness,xsize=dropSize)
res = where(tness ge legend.gap, count)
if (count gt 0) then widget_control, void, set_combobox_select=res[0]

;=======================================================================
; Tab 3

nItems = daveGrRef->count()
itemIDs = lonarr(nItems)
for i = 0,nItems - 1 do begin
    itemIDs[i] = widget_text(tab3,/editable,/all_events,value=(legend.itemname)[i] $
                       ,xsize=40,uname='INAME',uvalue=i)
endfor


;=======================================================================
; Tab 4
res = widget_info(tab1,/geometry)
xsize = 0.90*res.xsize
void = cw_fslider(tab4,format='(F4.2)',/frame,minimum=0.00,maximum=1.00,xsize=xsize,/drag $
                  ,title='X location (horizontal)',uname='XLOC',value=(legend.location)[0])
void = cw_fslider(tab4,format='(F4.2)',/frame,minimum=0.00,maximum=1.00,xsize=xsize,/drag $
                  ,title='Y location (vertical)',uname='YLOC',value=(legend.location)[1])

; Action buttons
applTip = 'Save changes made and close this dialog'
dismTip = 'Close this dialog, discarding all chages made'
dfltTip = 'Revert all attributes to their default values'
void = widget_button(ansBase,value='Save',uname='APPLY',tooltip=applTip)
void = widget_button(ansBase,value='Dismiss',uname='EXIT',tooltip=dismTip)
void = widget_button(ansBase,value='Set Defaults',uname='DEFAULT',tooltip=dfltTip)

; tlb uvalue
sPtr = ptr_new({legend:legend, $
                legObjRef:legObjRef, $
                davegrRef:daveGrRef, $
                widObjRef:widObjRef, $
                nItems:nItems, $
                vpdim:atomUval.vpdim, $
                itemIDs:itemIDs $
               })

;----------------------------------------------------------------------------
; realize widgets
widget_control, tlb,/realize, set_uvalue=sPtr


registerName = 'db_legend'
xmanager,registerName,tlb,/no_block,event_handler='db_legend_event',cleanup='db_legend_cleanup'


end
