function h_out = sisoprops(Target)
%SISOPROPS  SISO Tool properties object contructor

%   Author(s): A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.6 $  $Date: 2000/06/30 17:33:36 $

mlock

persistent h;  

if nargout==0
   %---Register class
    c = schema.class(findpackage('cstprefs'),'sisoprops');
   %---Define properties
    p = schema.prop(c,'Target',        'handle');
    p = schema.prop(c,'PlotType',      'String');
    p = schema.prop(c,'EditorFrame',   'mxArray');
    p = schema.prop(c,'TargetPreSet',  'handle');  p.set('AccessFlags.PublicGet','off','AccessFlags.PublicSet','off');
    p = schema.prop(c,'TargetPostSet', 'handle');  p.set('AccessFlags.PublicGet','off','AccessFlags.PublicSet','off');
    p = schema.prop(c,'FigureListener','handle');  p.set('AccessFlags.PublicGet','off');
    p = schema.prop(c,'ListenerEnable','mxArray'); p.set('AccessFlags.Init','on','FactoryValue',1);
else
   %---Abort if Java MWT is unsupported (make sure to return an instance of the class)
    if ~usejava('MWT'), h=cstprefs.sisoprops; h_out = h; return; end
   %---Create single class instance
    if isempty(h)
       h = cstprefs.sisoprops;
       h.TargetPreSet  = handle.listener(h,findprop(h,'Target'),'PropertyPreSet', @localTargetPreSet);
       h.TargetPostSet = handle.listener(h,findprop(h,'Target'),'PropertyPostSet',@localTargetPostSet);
    end
   %---If Target is provided, set Target property
    if nargin>0
       open(h);
       h.Target = Target;
    end
end
h_out = h;


%%%%%%%%%%%%%%%%%%%%%
% localTargetPreSet %
%%%%%%%%%%%%%%%%%%%%%
function localTargetPreSet(eventSrc,eventData)
% PreSet
 h = eventData.AffectedObject;
 old = h.Target;
 if isa(old,'sisogui.grapheditor')
    %---De-deselect old Target's plots
     set(old.HG.PlotAxes,'Selected','off');
 end
 new = eventData.NewValue;
 if isa(new,'sisogui.grapheditor')
    %---Show which axes are being modfied
     set(new.HG.PlotAxes,'Selected','on');
    %---Listen for SISO Tool deletion
     h.FigureListener = handle.listener(new.LoopData,'ObjectBeingDestroyed',{@localClose,h});
    %---Update PlotType and figure title
     switch class(new)
     case 'sisogui.rleditor'
        h.PlotType = 'rleditor';
        h.EditorFrame.setTitle(sprintf('Property Editor: Root Locus'));
     case 'sisogui.bodeditor'
        h.PlotType = 'bodeditor';
        h.EditorFrame.setTitle(sprintf('Property Editor: Bode Diagram'));
     end
 else
    %---Target cleared: close
     close(h);
 end


%%%%%%%%%%%%%%%%%%%%%%
% localTargetPostSet %
%%%%%%%%%%%%%%%%%%%%%%
function localTargetPostSet(eventSrc,eventData)
% PostSet
 if isa(eventData.NewValue,'sisogui.grapheditor')
   %---Pack EditorFrame
    eventData.AffectedObject.EditorFrame.pack;
    eventData.AffectedObject.EditorFrame.toFront;
 end


%%%%%%%%%%%%%%
% localClose %
%%%%%%%%%%%%%%
function localClose(eventSrc,eventData,h)
%---Call close method
 close(h);
