function GUI = axis_gui(h)
%AXIS_GUI  GUI for editing axis properties of h

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

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

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

%---Checkboxes
 s.AxisEqual = com.mathworks.mwt.MWCheckbox(sprintf('Equal'));
  s.AxisEqual.setFont(Prefs.JavaFontP);
  s.Main.add(s.AxisEqual);
  s.AxisEqualTT = com.mathworks.mwt.MWToolTip(s.AxisEqual,sprintf('Force equal X-Y data aspect ratio'));

%---Install GUI callbacks
 GUICallback = {@localWriteProp,h};
 set(s.AxisEqual,'Name','AxisEqual','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.AxisEqual = 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.rleditor')
     s.AxisEqualListener = handle.listener(t,findprop(t,'AxisEqual'),'PropertyPostSet',{@localReadProp,s.AxisEqual});
     %---Sync
      s.AxisEqual.setState(strcmpi(t.AxisEqual,'on'));
      s.Main.setVisible(1);
  else
     %---Clear
      s.AxisEqualListener = [];
      s.Main.setVisible(0);
  end
 %---Save structure
  set(eventSrc,'UserData',s);
