function updateCoords(this)
% One of the vertices has changed, synchronise other vertices based on 
% 'Linked' and orientation settings.

%   Author: A. Stothert 
%   Copyright 1986-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $ $Date: 2004/12/10 19:32:30 $

nConstr = size(this.getData('xCoords'),1);

%Check that we have a valid constraint to update
if ~all(size(this.getData('xCoords')) == size(this.getData('yCoords'))) || ...
      size(this.Linked,1) ~= nConstr-1 
   return
else
   %Make sure we've a valid selected edge
   SE = this.getData('SelectedEdge');
   if any(SE > nConstr)
      SE = SE(SE <= nConstr);
      this.setData('SelectedEdge',SE);
   end
   %Disable listeners for this constraint, prevents recursion
   set(this.Listeners,'Enable','off');
end

%Constraint property has been updated
switch this.Orientation
   case 'vertical'
      fldNormal = {'yCoords'};
      fldGlue   = 'xCoords';
      idxOrientation = 1;      %x-coordinate is free
   case 'horizontal'
      fldNormal = {'xCoords'};
      fldGlue   = 'yCoords';
      idxOrientation = 2;      %y-coordinate is free
   case 'both'
      fldNormal = {'yCoords','xCoords'};
      idxOrientation = [];     %neither coordinate is free
end

%Based on orientation update neighouring elements
iElement = this.SelectedEdge;
if iElement < nConstr
   for iNormal = 1:numel(fldNormal)
      this.(fldNormal{iNormal})(iElement+1,1) = this.(fldNormal{iNormal})(iElement,2);
      if ~isempty(idxOrientation)&&...
            this.Linked(iElement,idxOrientation)
         this.(fldGlue)(iElement+1,1) = this.(fldGlue)(iElement,2);
      end
   end
end
if iElement > 1
   for iNormal = 1:numel(fldNormal)
      this.(fldNormal{iNormal})(iElement-1,2) = this.(fldNormal{iNormal})(iElement,1);
      if ~isempty(idxOrientation)&&...
            this.Linked(iElement-1,idxOrientation)
         this.(fldGlue)(iElement-1,2) = this.(fldGlue)(iElement,1);
      end
   end
end

%Enable listeners for this constraint
set(this.Listeners,'Enable','on');

