function movescale(action,delta,direction)

%ORIGINUI  Tool for interactively modifying a map origin
%
%  ORIGINUI provides a tool to modify the origin of a displayed map
%  projection.  A marker (dot) is displayed where the origin is
%  currently located.  This dot can be moved and the map reprojected with
%  the identified point as the new origin.
%
%  ORIGINUI automatically toggles the current axes into a mode where
%  only actions recognized by ORIGINUI are executed.  Upon exit of
%  this mode, all prior ButtonDown functions are restored to the
%  current axes and its children.
%
%  ORIGINUI ON activates origin tool.  ORIGINUI OFF de-activates
%  the tool.  ORIGINUI will toggle between these two states.
%
%  ORIGINUI recognizes the following keystrokes.  RETURN will reproject
%  the map with the identified origin and remain in the originui mode.
%  ENTER reprojects the map with the identified origin and exits the
%  originui mode.  DELETE and ESCAPE will exit the origin mode
%  (same as ORIGINUI OFF).  N,S,E,W Keys move the marker North, South,
%  East or West by 10.0 degrees for each keystroke.  n,s,e,w keys move
%  the marker in the respective directions by 1 degree per keystroke.
%
%  ORIGINUI recognizes the following mouse actions when the cursor is on
%  the origin marker.  Single click and hold moves the origin marker.
%  Double click on the marker reprojects the map with the specified
%  map origin and remains in the origin mode (same as ORIGINUI RETURN).
%  Extended click moves the marker along the cartesian X or Y direction
%  only (depending on the direction of greatest movement).  Alternative
%  click exits the origin tool (same as ORIGINUI OFF).
%
%  For Macintosh:   Extend click - Shift click mouse button
%                   Alternate click - Option click mouse button
%
%  For MS-Windows:  Extend click - Shift click left button or both buttons
%                   Alternate click - Control click left button or right button
%
%  For X-Windows:   Extend click - Shift click left button or middle button
%                   Alternate click - Control click left button or right button
%
%  See also  SETM, AXESM

%  Copyright 1996-1998 by Systems Planning and Analysis, Inc. and The MathWorks, Inc.
% $Revision: 1.2 $
%  Written by:  W. Stumpf, E. Byrns, E. Brown





%  Ensure that the plot is in a 2D view

if any(get(gca,'view') ~= [0 90])
    btn = questdlg( strvcat('Must be in 2D view for operation.',...
	                        'Change to 2D view?'),...
				    'Incorrect View','Change','Cancel','Change');

    switch btn
	    case 'Change',      view(2);
		case 'Cancel',      return
    end
end

%  Switch yard

switch action
case 'downscale'    %  Mouse clicks on the scale baseline

		pt = get(gca,'CurrentPoint');

	    set(gcf,'WindowButtonMotionFcn','movescale(''movescale'')',...
	            'WindowButtonUpFcn','movescale(''upscale'')',...
				'pointer','fleur')

	    hobject = get(gcf,'CurrentObject');
		s = get(hobject,'UserData');
		t.oldUD = s;
		t.pt = pt;
		set(hobject,'UserData',t)
		set(hobject,'selected','on')

		childtag = s.Children; % Tag of all elements of scale ruler
		hidem(childtag);
		set(hobject,'Visible','on','erasemode','xor')
		


case 'movescale'    %  Move the origin marker by the mouse

     hobject = get(gcf,'CurrentObject');
     t = get(hobject,'UserData');
     lastpt = t.pt;
     pt = get(gca,'CurrentPoint');

     x  = get(hobject,'Xdata');
	 y  = get(hobject,'Ydata');

     delx = pt(1,1) - lastpt(1,1);
	 dely = pt(1,2) - lastpt(1,2);

     set(hobject,'Xdata',x+delx,'Ydata',y+dely);

	 t.pt = pt;
	 set(hobject,'UserData',t)
	 
% Handles of all elements of scale ruler

	 	s = t.oldUD;



case 'upscale'   %  Mouse release of the origin marker
    hobject   = get(gcf,'CurrentObject');
	set(gcf,'WindowButtonMotionFcn','',...
	         'WindowButtonUpFcn','',...
			 'pointer','arrow')

	set(hobject,'selected','on')

% Restore UserData

	t = get(hobject,'UserData');
	s = t.oldUD;
	set(hobject,'UserData',s) % need this?

% Update location of scaleruler 

     x  = get(hobject,'Xdata');
	 y  = get(hobject,'Ydata');

     s.XLoc = x(1);
	 s.YLoc = y(1);
	 
% Handles of all elements of scale ruler

	childtag = s.Children; % Tag of all elements of scale ruler
	hchild = findall(gca,'tag',childtag);
	delete([hobject; hchild(:)]);

% Redraw scale

	scaleruler(s,'plot');
	
end
