function GUI = char_gui(h)
%CHAR_GUI  GUI for editing response characteristics of h

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

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

%---Top-level panel (MWGroupbox)
 s.Main = com.mathworks.mwt.MWGroupbox(sprintf('Response Characteristics'));
 s.Main.setLayout(java.awt.GridLayout(1,1,0,3));
 s.Main.setFont(Prefs.JavaFontB);
 s.Main.setVisible(0);

%---Checkboxes
 s.MarginVisible = com.mathworks.mwt.MWCheckbox(sprintf('Show stability margins'));
  s.MarginVisible.setFont(Prefs.JavaFontP);
  s.Main.add(s.MarginVisible);

%---Install GUI callbacks
 GUICallback = {@localWriteProp,h};
 set(s.MarginVisible,'Name','MarginVisible','ItemStateChangedCallback',GUICallback);

%---Install listner for target change
 s.TargetListener = handle.listener(h,findprop(h,'Target'),'PropertyPreSet',@localTargetPreSet);
 s.TargetListener.CallbackTarget = s.Main;

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

%---Return handle of top-level GUI
 GUI = s.Main;


%%%%%%%%%%%%%%%%%
% localReadProp %
%%%%%%%%%%%%%%%%%
function localReadProp(eventSrc,eventData,GUI)
% Target -> GUI
 h = cstprefs.sisoprops;
 if h.ListenerEnable
    GUI.setState(strcmpi(eventData.NewValue,'on'));
 end


%%%%%%%%%%%%%%%%%%
% localWriteProp %
%%%%%%%%%%%%%%%%%%
function localWriteProp(eventSrc,eventData,h)
% GUI -> Target
 h.Target.MarginVisible = get(eventSrc,'State');


%%%%%%%%%%%%%%%%%%%%%
% localTargetPreSet %
%%%%%%%%%%%%%%%%%%%%%
function localTargetPreSet(eventSrc,eventData)
% Update listeners when Target changes
 %---New target
  t = eventData.NewValue;
 %---Get structure
  s = get(eventSrc,'UserData');
 %---Update listener
  if isa(t,'sisogui.bodeditor')
     s.MarginVisibleListener = handle.listener(t,findprop(t,'MarginVisible'),'PropertyPostSet',{@localReadProp,s.MarginVisible});
     %---Sync
      s.MarginVisible.setState(strcmpi(t.MarginVisible,'on'));
      s.Main.setVisible(1);
  else
     %---Clear
      s.MarginVisibleListener = [];
      s.Main.setVisible(0);
  end
 %---Save structure
  set(eventSrc,'UserData',s);
