function Main = wrap_gui(h)
%WRAP_GUI  GUI for editing phase wrap properties of h

%   Author(s): A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $  $Date: 2000/08/02 16:05:55 $

%---Get Toolbox Preferences
Prefs = cstprefs.tbxprefs;

%---Top-level panel (MWGroupbox)
Main = com.mathworks.mwt.MWGroupbox(sprintf('Phase Wrapping'));
Main.setLayout(com.mathworks.mwt.MWBorderLayout(0,0));
Main.setFont(Prefs.JavaFontB);
s.Main = Main;

%---Checkbox
s.UnwrapPhase = com.mathworks.mwt.MWCheckbox(sprintf('Unwrap phase'));
s.UnwrapPhase.setFont(Prefs.JavaFontP);
Main.add(s.UnwrapPhase,com.mathworks.mwt.MWBorderLayout.WEST);

%---Install listeners and callbacks
CLS = findclass(findpackage('cstprefs'),'respprop');
s.UnwrapPhaseListener = handle.listener(h,CLS.findprop('UnwrapPhase'),'PropertyPostSet',{@localReadProp,s});
set(s.UnwrapPhase,'Name','UnwrapPhase','ItemStateChangedCallback',{@localWriteProp,h});

%---Store java handles
set(Main,'UserData',s);


%%%%%%%%%%%%%%%%%
% localReadProp %
%%%%%%%%%%%%%%%%%
function localReadProp(eventSrc,eventData,s)
% Update GUI when property changes
if eventData.AffectedObject.ListenerEnable
   if isempty(eventData.NewValue)
      s.Main.setVisible(0);
   else
      s.Main.setVisible(1);
      s.UnwrapPhase.setState(strcmpi(eventData.NewValue,'on'));
   end
end


%%%%%%%%%%%%%%%%%%
% localWriteProp %
%%%%%%%%%%%%%%%%%%
function localWriteProp(eventSrc,eventData,h)
% Update property when GUI changes
h.ListenerEnable = 1;  %---Keep PropObj listener enabled here !!!
h.UnwrapPhase = get(eventSrc,'State');
h.LastChange = 'UnwrapPhase';
h.ListenerEnable = 1;  %---Re-enable PropObj listeners
