function s = create(h)
%CREATE  Create Response Property Editor, returns java handles in structure s

%   Author(s): A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.13 $  $Date: 2000/08/28 23:02:58 $

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

%---Frame
 s.Frame = com.mathworks.mwt.MWFrame(sprintf('Property Editor'));
 s.Frame.setLayout(com.mathworks.mwt.MWBorderLayout(0,0));
 s.Frame.setFont(Prefs.JavaFontP);
 set(s.Frame,'WindowActivatedCallback',{@localRefresh,h},'WindowClosingCallback',{@localClose,h});
%---Open an empty Frame with some status text
 s.Frame.setSize(java.awt.Dimension(360,280));
 centerfig(s.Frame);
 s.Status = com.mathworks.mwt.MWLabel(sprintf('Opening Property Editor...'),com.mathworks.mwt.MWLabel.CENTER);
 s.Frame.add(s.Status,com.mathworks.mwt.MWBorderLayout.CENTER);
 s.Frame.setVisible(1);
 s.Frame.toFront;
 xypos1 = s.Frame.getLocation;

%---ButtonPanel
 s.ButtonPanel = com.mathworks.mwt.MWPanel(java.awt.FlowLayout(java.awt.FlowLayout.RIGHT,7,0));
 s.ButtonPanel.setInsets(java.awt.Insets(2,5,5,-2));
    %---Close
     s.Close = com.mathworks.mwt.MWButton(sprintf('Close')); s.ButtonPanel.add(s.Close);
     s.Close.setFont(Prefs.JavaFontP);
     set(s.Close,'ActionPerformedCallback',{@localClose,h});
    %---Help
     s.Help = com.mathworks.mwt.MWButton(sprintf('Help')); s.ButtonPanel.add(s.Help);
     s.Help.setFont(Prefs.JavaFontP);
     set(s.Help,'ActionPerformedCallback','ctrlguihelp(''response_properties'');');

%---TabPanel
 s.TabPanel = com.mathworks.mwt.MWTabPanel;
 s.TabPanel.setInsets(java.awt.Insets(5,5,5,5));
 s.TabPanel.setMargins(java.awt.Insets(12,8,8,8));
 s.TabPanel.setFont(Prefs.JavaFontP);
    %---Labels
     s.Text = text_gui(h.Data);
     s.LabelsTab = localMakeTab(s.Text);
     s.TabPanel.addPanel(sprintf('Labels'),s.LabelsTab);
    %---Limits
     s.XLimits = limit_gui(h.Data,'X');
     s.YLimits = limit_gui(h.Data,'Y');
     s.LimitsTab = localMakeTab(s.XLimits,s.YLimits);
     s.TabPanel.addPanel(sprintf('Limits'),s.LimitsTab);
    %---Units
     s.Units = unit_gui(h.Data); 
     s.UnitsTab = localMakeTab(s.Units);
     s.TabPanel.addPanel(sprintf('Units'),s.UnitsTab);
    %---Style
     s.Grid  = grid_gui(h.Data);
     s.Font  = font_gui(h.Data);
     s.Color = clr_gui(h.Data);
     s.StyleTab = localMakeTab(s.Grid,s.Font,s.Color);
     s.TabPanel.addPanel(sprintf('Style'),s.StyleTab);
    %---Characteristics
     s.Characteristics = char_gui(h.Data);
     s.PhaseWrapping = wrap_gui(h.Data);
     s.CharacteristicsTab = localMakeTab(s.Characteristics,s.PhaseWrapping);
     s.TabPanel.addPanel(sprintf('Characteristics'),s.CharacteristicsTab);
%---Start on the first tab panel
 s.TabPanel.selectPanel(0);

%---Remove the status text, add the real components and pack
 s.Frame.remove(s.Status);
 s.Frame.add(s.ButtonPanel,com.mathworks.mwt.MWBorderLayout.SOUTH);
 s.Frame.add(s.TabPanel,com.mathworks.mwt.MWBorderLayout.CENTER);
 s.Frame.pack;
 xypos2 = s.Frame.getLocation;
 if abs(xypos1.x-xypos2.x)<5 & abs(xypos1.y-xypos2.y)<5
    centerfig(s.Frame);
 end


%%%%%%%%%%%%%%%%
% localMakeTab %
%%%%%%%%%%%%%%%%
function Tab = localMakeTab(varargin)
% Combine panels into a single panel for use in a tab dialog
%---Top-level Panel
Tab = com.mathworks.mwt.MWPanel(com.mathworks.mwt.MWBorderLayout(0,0));
for n=1:nargin
   if n<nargin
      %---Not last element, leave 5-pixel spacing
      tmp = com.mathworks.mwt.MWPanel(com.mathworks.mwt.MWBorderLayout(0,5));
   else
      %---Last element, leave 0-pixel spacing
      tmp = com.mathworks.mwt.MWPanel(com.mathworks.mwt.MWBorderLayout(0,0));
   end
   %---Pack towards top
   tmp.add(varargin{n},com.mathworks.mwt.MWBorderLayout.NORTH);
   %---Add java handle to structure
   s(n,1) = tmp;
   %---Add first panel to Tab
   if n==1
      Tab.add(tmp,com.mathworks.mwt.MWBorderLayout.CENTER);
   %---Nest other panels
   else
      tmp2 = s(n-1,1);
      tmp2.add(tmp,com.mathworks.mwt.MWBorderLayout.CENTER);
   end
end
%---Store java handles
set(Tab,'UserData',s);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pass these callbacks to class methods %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localRefresh(eventSrc,eventData,h)
 h.refresh;

function localClose(eventSrc,eventData,h)
 h.close;
