function h_out = tbxprefs
%TBXPREFS  Toolbox preferences object contructor

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

mlock

persistent h; 
           
a = findpackage('cstprefs');

if nargout==0
   %---Register class
   c = schema.class(a,'tbxprefs');

   %---Default FontSizes are system-dependent
   if isunix
      SysFontSize  = 10;
      UIFontSize   = 10;
      JavaFontSize = 12;
   else
      SysFontSize  = 8;
      UIFontSize   = 8;
      JavaFontSize = 11;
   end

   %---Define properties

    %---Units/Scales
    localCreateProp(c, 'FrequencyUnits',        'String',  'rad/sec'     );
    localCreateProp(c, 'FrequencyScale',        'String',  'log'         );
    localCreateProp(c, 'MagnitudeUnits',        'String',  'dB'          );
    localCreateProp(c, 'MagnitudeScale',        'String',  'linear'      );
    localCreateProp(c, 'PhaseUnits',            'String',  'deg'         );

    %---Grids
    localCreateProp(c, 'Grid',                  'String',  'off'         );

    %---Fonts
    localCreateProp(c, 'TitleFontSize',         'mxArray', SysFontSize   );
    localCreateProp(c, 'TitleFontWeight',       'String',  'normal'      );
    localCreateProp(c, 'TitleFontAngle',        'String',  'normal'      );
    localCreateProp(c, 'XYLabelsFontSize',      'mxArray', SysFontSize   );
    localCreateProp(c, 'XYLabelsFontWeight',    'String',  'normal'      );
    localCreateProp(c, 'XYLabelsFontAngle',     'String',  'normal'      );
    localCreateProp(c, 'AxesFontSize',          'mxArray', SysFontSize   );
    localCreateProp(c, 'AxesFontWeight',        'String',  'normal'      );
    localCreateProp(c, 'AxesFontAngle',         'String',  'normal'      );
    localCreateProp(c, 'IOLabelsFontSize',      'mxArray', SysFontSize   );
    localCreateProp(c, 'IOLabelsFontWeight',    'String',  'normal'      );
    localCreateProp(c, 'IOLabelsFontAngle',     'String',  'normal'      );

    %---Colors
    localCreateProp(c, 'AxesForegroundColor',   'mxArray', [0.4 0.4 0.4] );

    %---Response Characteristics
    localCreateProp(c, 'SettlingTimeThreshold', 'mxArray', 0.02          );
    localCreateProp(c, 'RiseTimeLimits',        'mxArray', [0.1 0.9]     );

    %---Phase Wrapping
    localCreateProp(c, 'UnwrapPhase',           'String',  'on'          );

    %---Siso Tool Options
    localCreateProp(c, 'CompensatorFormat',     'String',  'TimeConstant');
    % Options are: [{TimeConstant}|ZeroPoleGain]
    localCreateProp(c, 'ShowSystemPZ',          'String',  'on'          );
    localCreateProp(c, 'SISOToolStyle',         'mxArray', localSISOToolStyle);

    %---UI Preferences
    localCreateProp(c, 'UIFontSize',            'mxArray', UIFontSize    );
    localCreateProp(c, 'JavaFontSize',          'mxArray', JavaFontSize  );
    %---Only define java fonts if the system supports Java
    if usejava('AWT')
       localCreateProp(c, 'JavaFontP',          'mxArray', java.awt.Font('Dialog',java.awt.Font.PLAIN,JavaFontSize));
       localCreateProp(c, 'JavaFontB',          'mxArray', java.awt.Font('Dialog',java.awt.Font.BOLD,JavaFontSize));
       localCreateProp(c, 'JavaFontI',          'mxArray', java.awt.Font('Dialog',java.awt.Font.ITALIC,JavaFontSize));
    end

    %---Preference file version control
    localCreateProp(c, 'Version',               'mxArray', 1             );

else
   if isempty(h)
      %---Create class instance (w/default values)
      h = cstprefs.tbxprefs;
      h.reset;  %---This may not be neccessary as of beta5
      %---Load default user preference file (if it exists)
      h.load;
   end

end
h_out = h;

%%%%%%%%%%%%%%%%%%%
% localCreateProp %
%%%%%%%%%%%%%%%%%%%
function localCreateProp(Class,PropName,DataType,FactoryValue)
% Add property to class and install default value
%---Add property to class
 p = schema.prop(Class,PropName,DataType);
%---Set Factory Value for property and use it upon initialization
 p.set('AccessFlags.Init','on','FactoryValue',FactoryValue);


%%%%%%%%%%%%%%%%%%%%%%
% localSISOToolStyle %
%%%%%%%%%%%%%%%%%%%%%%
function s = localSISOToolStyle
% Create the default SISO Tool style structure
s = struct(...
   'Color',[],...
   'Marker',[]);
s.Color = struct(...
   'ClosedLoop',[1 0 0.8],...
   'Compensator',[1 0 0],...
   'Margin',[.8 .5 0],...
   'PreFilter',[0.6 0.6 0.4],...
   'Response',[0 0 1],...
   'System',[0 0 1]);
s.Marker = struct(...
   'ClosedLoop','s');
