function agents(action);
%AGENTS	Show international distributors' locations and contact information.

%	Ned Gulley, 6-21-93
%	Copyright (c) 1984-94 by The MathWorks, Inc.

if nargin<1,
    action='initialize';
end;

if strcmp(action,'initialize'),
    figNumber=figure( ...
	'Name','Internat''l Distributors for The MathWorks, Inc.', ...
        'NumberTitle','off', ...
	'Visible','off');

    axes( ...
	'Units','normalized', ...
        'Position',[0.05 0.40 0.70 0.50]);

    %===================================
    % Set up the Comment Window
    top=0.35;
    left=0.05;
    right=0.75;
    bottom=0.05;
    labelHt=0.05;
    spacing=0.005;
    promptStr=str2mat(' ','  Click on the map''s red dots to see distributors', ...
	'  for The MathWorks around the world.');

    % First, the Comment Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',[0.5 0.5 0.5]);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',[0.5 0.5 0.5], ...
	'ForegroundColor',[1 1 1], ...
        'String','Distributor Information');
    % Then the editable text field
    txtPos=[left bottom (right-left) top-bottom-labelHt-spacing];
    txtHndl=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'Max',10, ...
        'BackgroundColor',[1 1 1], ...
        'Position',txtPos, ...
	'Callback','agents(''eval'')', ...
        'String',promptStr);

    %====================================
    % Information for all buttons
    labelColor=[0.8 0.8 0.8];
    top=0.95;
    left=0.80;
    btnWid=0.15;
    btnHt=0.08;
    % Spacing between the button and the next command's label
    spacing=0.04;

    %====================================
    % The CONSOLE frame
    frmBorder=0.02;
    yPos=0.05-frmBorder;
    frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',[0.5 0.5 0.5]);
    
    %====================================
    % The INFO button
    uicontrol( ...
	'Style','push', ...
        'Units','normalized', ...
        'Position',[left bottom+btnHt+spacing btnWid btnHt], ...
        'String','Info', ...
        'Callback','agents(''info'')');

    %====================================
    % The CLOSE button
    uicontrol( ...
	'Style','push', ...
        'Units','normalized', ...
        'Position',[left bottom btnWid btnHt], ...
        'String','Close', ...
        'Callback','close(gcf)');

    load topo
    world=[topo(30:180,180:360) topo(30:180,1:179)];
    imageHndl=imagesc(world);
    set(gca, ...
	'XLim',[1 360],'YLim',[1 150], ...
	'XTick',[],'YTick',[], ...
 	'YDir','normal', ...
	'Box','on');
    colormap((topomap1+white)/2);
    title('Click on a dot to see the name of a distributor');

    % These are latitude and longitude pairs in degrees/minutes
    % Berlin, Stockholm, Tokyo, Jerusalem, Boston, London, Taipei, Seoul
    agentList=[];
    % Scientific Computers, Aachen (Bonn)
    agentList(1,:)=[50.44 7.06];
    % Cambridge Control, Cambridge (London)
    % fudged north for separation from Rapid Data
    agentList(2,:)=[53.00 -0.10];
    % CEANET, Sydney
    agentList(3,:)=[-33.52 151.13];
    % Computer Solutions, Stockholm
    agentList(4,:)=[59.20 18.03];
    % COMSOL AG, Bern
    agentList(5,:)=[46.57 7.30];
    % Cranes, Bangalore
    agentList(6,:)=[13.00 77.00];
    % Cybernet, Tokyo
    agentList(7,:)=[35.42 139.46];
    % Green Hills, Taipei
    agentList(8,:)=[25.04 121.29];
    % Kimhua, Seoul
    agentList(9,:)=[37.33 126.58];
    % Omikron Delta
    agentList(10,:)=[31.47 35.14];
    % OpenCADD, Sao Paulo
    agentList(11,:)=[-23.33 -46.39];
    % Rapid Data, Sussex (London)
    agentList(12,:)=[51.30 0.10];
    % SSG, Sevres (Paris)
    agentList(13,:)=[48.52 2.20];
    % Teoresi, Turin (Rome)
    agentList(14,:)=[41.53 12.30];
    % The MathWorks, Natick (Boston)
    agentList(15,:)=[42.20 -71.05];
    % AddLink, Barcelona, Spain
    agentList(16,:)=[42.00 2.00];

    % Convert from degrees/minutes to degrees/decimal degrees
    agentList=fix(agentList)+(agentList-fix(agentList))/.6;
    hold on

    for count=1:size(agentList,1),
        lat=agentList(count,1);
        long=agentList(count,2);
    	plot(long+180,lat+60,'w.', ...
	    'MarkerSize',20)

    	plot(long+180,lat+60,'r.', ...
	    'MarkerSize',11)

    	hndlList(count)=plot(long+180,lat+60,'ko', ...
	    'MarkerSize',8, ...
	    'UserData',count, ...
	    'ButtonDownFcn','agents(''agentinfo'');');
    end;

    set(gca,'UserData',agentList(:,1)+sqrt(-1)*agentList(:,2));
    set(imageHndl,'ButtonDownFcn','agents(''agentinfo'');');
    drawnow;
    set(figNumber,'UserData',txtHndl);
    % Now uncover the figure
    set(figNumber,'Visible','on');

elseif strcmp(action,'agentinfo'),
    complexAgentList=get(gca,'UserData');
    currPos=get(gca,'CurrentPoint');
    complexCurrPos=(currPos(1,2)-60)+sqrt(-1)*(currPos(1,1)-180);
    distList=abs(complexCurrPos-complexAgentList);
    [minDistance,index]=min(distList);
    if minDistance>20, index=[]; end;
    txtHndl=get(gcf,'UserData');
    if index==1,
    	str= ...                                 
	[' Scientific Computers GmbH  '
	 ' Federal Republic of Germany'
	 ' Phone: +49-89-995901-1     '
	 ' Fax: +49-89-995901-11      '];
	set(txtHndl,'String',str);
    elseif index==2,
    	str= ...                                 
        [' Cambridge Control Limited         '  
         ' Jeffreys Building, Cowley Road    '  
         ' Cambridge, CB4 4WS, United Kingdom' 
	 ' Phone: +44-223-424-200            '
	 ' Fax: +44-223-423-255              '];
	set(txtHndl,'String',str);
    elseif index==3,
    	str= ...                               
        [' CEANET Pty., Ltd.               '  
         ' 4th Floor, 56 Berry Street      '  
         ' North Sydney NSW 2060, Australia'  
         ' Phone: +61-2-922-6311           '  
         ' Fax: +61-2-922-5118             '  
         ' Email: ceanet@tmx.mhs.oz.au     '];
	set(txtHndl,'String',str);
    elseif index==4,
	str= ...
        [' Computer Solutions Europe AB'  
         ' Bjornnasvagen 21            '  
         ' S-113 47 Stockholm, Sweden  '  
         ' Phone: +46-8-15-30-22       '  
         ' Fax: +46-8-15-76-35         '  
         ' Email: info@comsol.se       '];
	set(txtHndl,'String',str);
    elseif index==5,
   	str= ...
        [' COMSOL AG                      '  
         ' Technology Park, Morgenstr. 129'  
         ' 3018 Bern, Switzerland         '  
         ' Phone: +41-31-998-44-11        '  
         ' Fax: +41-31-998-44-18          '  
         ' Email: cosol@clients.switch.ch '];
	set(txtHndl,'String',str);
    elseif index==6,
 	str= ...
        [' Cranes Software International        '  
         ' 35/1, Cunningham Rd, Alappat Building'  
         ' Bangalore 560 052, India             '  
 	 ' Phone: +91-802-260-260               '  
 	 ' Fax: +91-802-216-165                 '];
	set(txtHndl,'String',str);
    elseif index==7,
 	str= ...
        [' Cybernet Systems Co., Ltd.                '  
         ' Sunshine 60, 27F, 3-1-1, Higashi-Ikebukuro'  
         ' Toshima-ku, Tokyo, 170, Japan             '  
	 ' Phone: +81-3-5978-5410                    '
	 ' Fax: +81-3-5978-5440                      '];
	set(txtHndl,'String',str);
    elseif index==8,
 	str= ...
        [' Green Hills Technology, Inc.     '  
         ' 5th Floor, 354-1 Fu-Shin N. Road '  
         ' Taipei, Taiwan, Republic of China'  
         ' Phone: +886-2-501-8787           '  
         ' Fax: +886-2-502-4478             '];
	set(txtHndl,'String',str);
    elseif index==9,
 	str= ...
        [' Kimhua Technologies, Inc.            '  
         ' 740-18, Sungmi B/D                   '  
         ' Banpo 1 Dong Suh Cho-Gu, Seoul, Korea'  
         ' Phone: +82-2-517-1257                '  
         ' Fax: +82-2-517-1259                  '];
	set(txtHndl,'String',str);
    elseif index==10,
 	str= ...
        [' Omikron Delta (1927) Ltd.   '  
         ' 10 Carlebach Street         '  
         ' Tel-Aviv 67132, Israel      '  
         ' Phone: +972-3-561-5151      '  
         ' Fax: +972-3-561-2962        '  
         ' Email: baruchp@datasrv.co.il'];
	set(txtHndl,'String',str);
    elseif index==11,
 	str= ...
        [' OpenCADD Computacao Grafica         '  
         ' Av. Brig. Faria Lima 1544-4 And.    '  
         ' Cep 01452-001 Sao Paulo - SP, Brasil'  
         ' Phone: +55-11-816-3144              '  
         ' Fax: +55-11-816-7864                '];
	set(txtHndl,'String',str);
    elseif index==12,
 	str= ...
        [' Rapid Data Ltd.                          '  
         ' Crescent House, Crescent Road, Worthing, '  
         ' West Sussex, BN11 5RW, United Kingdom    '  
         ' Phone: +44-903-821-266                   '  
         ' Fax: +44-903-820-762                     '  
         ' Email: radata@ibmpcug.co.uk              '];
	set(txtHndl,'String',str);
    elseif index==13,
 	str= ...
        [' Scientific Software Group'  
         ' 72-78 Grand Rue          '  
         ' 92310 - Sevres, France   '  
         ' Phone: +33-1-45-34-23-91 '  
         ' Fax: +33-1-45-07-08-06   '  
         ' Email: alain@ssg.fr      '];
	set(txtHndl,'String',str);
    elseif index==14,
 	str= ...
        [' Teoresi s.r.l.         '  
         ' via Foggia, 30         '  
         ' 10152 Turin, Italy     '  
         ' Phone: +39-11-24-85-332'  
         ' Fax: +39-11-24-84-698  '];
	set(txtHndl,'String',str);
    elseif index==15,
 	str= ...
        [' The MathWorks, Inc.            '  
         ' 24 Prime Park Way              '  
         ' Natick, Massachusetts 01760 USA'  
         ' Phone: +508-653-1415           '  
         ' Fax: +508-653-6284             '  
         ' Email: info@mathworks.com      '];
	set(txtHndl,'String',str);
    elseif index==16,
 	str= ...
	[' AddLink Software Cientifico'
	 ' Cl. Rosellon, 205, 4, 1R   '
	 ' 08008 Barcelona, Spain     '
	 ' Phone: +93-415-49-04       '
	 ' Fax: +93-415-72-68         '];
	set(txtHndl,'String',str);
    end;

elseif strcmp(action,'info'),
    ttlStr=get(gcf,'Name');
    hlpStr= ...                                                
        ['                                                    '  
         ' This demo allows you to find the contact           '  
         ' information for any of The MathWorks'' distributors '  
         ' around the world.                                  '  
         '                                                    '  
         ' Simply click on any of the dots you see, and       '  
         ' the information corresponding to the distributor   '  
         ' at that location will appear in the text field at  '  
         ' the bottom of the window.                          '   
         '                                                    '  
         ' File name: agents.m                                '];
    helpfun(ttlStr,hlpStr);                                    

end;    % if strcmp(action, ...
