;+
; NAME:
;	Overplot Texts
; PURPOSE: 
;	Allows creation of texts which will be overplotted in 
;	the plot window, when "Data_Display"
;	is used for plotting.
; CALLING SEQUENCE:
;	Overplot_Texts
; SIDE EFFECTS
;	The texts and their position in the plot window
;	are kept in a special data structure.
; MODIFICATION HISTORY:
;	Created by A.Csillaghy in June 1991
;		Inst. of Astronomy, ETH Zurich
;       Modified for IDL5/SSW/Ragview in March 98 -- ACs
;-

PRO Add_Text
    
text = ''

IF !d.name EQ 'X' THEN BEGIN
    displ = !d.window
    wnr = WMesg('Click where you want the text','Texts',300,200)
    WSet,displ
    WShow,displ
    Cursor, x, y
    WDelete, wnr
    wnr = WMesg('Insert now your text on the keyboard','Texts',300,200)
    Read, 'Your text: ',text
    Read_Test,'Its size ', 1.0, sizeText
    WDelete, wnr
    XYOuts, x, y, text, CHARSIZE = sizeText
    Store_Text, x, y, text, sizeText
    WSet, displ
ENDIF ELSE BEGIN
    Data_Display
    Print, 'Move the cursor where you want the text...'
    Cursor, x, y
    Read, 'Insert the text to write: ',text
    Read_Test,'Insert the size of the text',1.0,sizeText
    XYOuts, x, y, text, CHARSIZE = sizeText
    Store_Text, x, y, text, sizeText
END

END
 
  
PRO Remove_Text

  nbTexts = N_Texts()
  IF nbTexts GE 1 THEN BEGIN
    menuMove = ''
    FOR i = 1, nbTexts DO BEGIN
      Get_Text, i, dum1, dum2, text, dum3
      menuMove = [menuMove, text ]
    ENDFOR

    menuMove = menuMove( 1:N_Elements(menuMove)-1)
    choice = General_Menu(menuMove, 'Choose the text to remove ... ')
    Take_Away, choice
  ENDIF ELSE Print,'No texts displayed ... '

END


PRO Move_Text

nbTexts = N_Texts()
IF nbTexts GE 1 THEN BEGIN
  menuMove =  ''
  FOR i = 1, nbTexts DO BEGIN
      Get_Text, i,d1,d2 , text, d3
      menuMove = [menuMove, text ]
  ENDFOR
  menuMove = menuMove( 1:N_Elements(menuMove)-1)
  choice = General_Menu(menuMove, 'Choose the text to move ... ')
  Get_Text, choice, x, y, text, siz
  Take_Away, choice
  IF !d.name EQ 'X' THEN BEGIN
    imageWin = !d.window
    wnr = WMesg('Click to the new position ', 'Move Text' ,200, 500)
    WSet, imageWin
  ENDIF ELSE $
    Print, 'Click on the new position ...'
  Cursor, x, y
  IF !d.name EQ 'X' THEN WDelete, wnr
  Store_Text, x, y, text, siz
ENDIF 

END


PRO Overplot_Texts
  
  mainMenuLength = 4
  
  mainMenu = StrArr(mainMenuLength)
  mainMenu(0) = 'Add Text'
  mainMenu(1) = 'Remove Text'
  mainMenu(2) = 'Move Text'
  mainMenu(3) = 'Return to Customize Menu'

  REPEAT BEGIN
    
    choice = General_Menu(mainMenu,$
	'Texts: Choose Option or Exit')

    CASE choice OF
      1: Add_Text
      2: Remove_Text
      3: Move_Text
      ELSE:
    END

    IF choice NE mainMenuLength THEN $
      Data_Display, /MDISP
    IF !d.name NE 'X' THEN Wait,3

  END UNTIL choice EQ mainMenuLength

END
