function propedit(varargin)
%PROPEDIT Edit property.
%   PROPEDIT edits all properties of any selected object through the 
%   use of a graphical interface.  PROPEDIT(HandleList) edits the 
%   properties for the object(s) in HandleList.  If HandleList is a 
%   vector, only similar object properties are listed.
%
%   See also GUIDE, ALIGN, CBEDIT, CTLPANEL, MENUEDIT.

%   Loren Dean
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.109 $ $Date: 1998/07/28 19:54:12 $

PropFig=findall(0,'Tag','Guide Property Editor');
Data=[];WatchFlag=0;
if ~isempty(PropFig),
  Data=get(PropFig,'UserData');
  if ~isempty(Data),  
    Data=get(Data.All.DataHandle,'UserData');      
    if nargin==1 & strcmp(varargin{1},'Resize'),    
      [Data,WatchFlag]=setwatch('on',Data,1);
    else,      
      [Data,WatchFlag]=setwatch('on',Data);
    end      
  end    
end  

% Wrap try catch around the callback area
%try,

switch nargin,
  %%%%%%%%%%%%%%%%%%%%%%%%
  %%% Peform an action %%%
  %%%%%%%%%%%%%%%%%%%%%%%%
  case 1,
    if isstr(varargin{1}),
      Action=varargin{1};
      
      switch Action,
        %%%%%%%%%%%%%%%%%%%%%%%%% 
        %%% BrowserButtonDown %%%
        %%%%%%%%%%%%%%%%%%%%%%%%%        
        case 'BrowserButtonDown',
          Data=objbrwser('ButtonDown',Data, ...
                         Data.PropFig.ListboxHandles(2),PropFig,'Complete');
          
        %%%%%%%%%%%%% 
        %%% Close %%%
        %%%%%%%%%%%%%        
        case 'Close',
          Data=guide('ToolUpdate',Data,PropFig,'delete');
          
        %%%%%%%%%%%%%%%%%%%% 
        %%% HandleUpdate %%%
        %%%%%%%%%%%%%%%%%%%%        
        case 'HandleUpdate',
          [UpdateType,Data]=LocalSetValue(Data,PropFig);
          Data=LocalGetPropList(Data);                  
          
          if Data.PropFig.PropListFlag,
            Data=LocalCreateString(Data);            
            Data=LocalUpdatePropertyField(Data,PropFig,'list','New');
          else,
            Data=LocalUpdatePropertyField(Data,PropFig,'edit','New');
          end            
          Data=LocalUpdateValueField(Data,PropFig);  

        %%%%%%%%%%%% 
        %%% Help %%%
        %%%%%%%%%%%%        
        case 'Help',
          helpfun('Property Editor',Data)
        
        %%%%%%%%%%%%%%%%
        %%% MenuCall %%%
        %%%%%%%%%%%%%%%%        
        case 'MenuCall',
          helpfun(get(gcbo,'Label'),Data);
          
        %%%%%%%%%%%%%%%%%%%%%% 
        %%% PropertyUpdate %%%
        %%%%%%%%%%%%%%%%%%%%%%        
        case 'PropertyUpdate',
          if Data.PropFig.PropListFlag,
            Data=LocalCreateString(Data);            
          end            
          Data=LocalUpdateValueField(Data,PropFig);  
          
        %%%%%%%%%%%%%%%%%%%%%%%%%% 
        %%% PropListButtonDown %%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%        
        case 'PropListButtonDown',
          if strcmp(get(PropFig,'SelectionType'),'open'),
            [Data,UpdateType]=LocalListOpen(Data);
            switch UpdateType,
              case 'Selection',            
                Data=guide('SelectionUpdate',Data,[]);
              case 'Property',            
                Data=guide('PropertyUpdate',Data);
              case 'Browser',          
                Data=guide('BrowserUpdate',Data);
            end % switch
            
          else,              
            [UpdateType,Data]=LocalSetValue(Data,PropFig);            
            Data=LocalUpdatePropertyField(Data,PropFig,'list','');
            Data=LocalUpdateValueField(Data,PropFig);
          end
          
        %%%%%%%%%%%%%%
        %%% Resize %%%
        %%%%%%%%%%%%%%
        case 'Resize',
          Data=LocalResize(Data,PropFig);
          
        %%%%%%%%%%%%%%%%%%%%%%% 
        %%% SelectionUpdate %%%
        %%%%%%%%%%%%%%%%%%%%%%%        
        case 'SelectionUpdate',
          [UpdateType,Data]=LocalSetValue(Data,PropFig);
          Data=LocalGetPropList(Data);                  
          
          if Data.PropFig.PropListFlag,
            Data=LocalCreateString(Data);            
            Data=LocalUpdatePropertyField(Data,PropFig,'list','New');
          else,
            Data=LocalUpdatePropertyField(Data,PropFig,'edit','New');
          end            
          Data=LocalUpdateValueField(Data,PropFig);  

        %%%%%%%%%%%%%%%% 
        %%% SetValue %%%
        %%%%%%%%%%%%%%%%       
        case 'SetValue',
          [UpdateType,Data]=LocalSetValue(Data,PropFig);
          switch UpdateType,
            case 'Property',          
              Data=guide('PropertyUpdate',Data);
            case 'Handle',          
              Data=guide('HandleUpdate',Data);
            case 'Browser',          
              Data=guide('PropertyUpdate',Data);
              Data=guide('BrowserUpdate',Data);
          end
  
        %%%%%%%%%%%%%%%%%%% 
        %%% ShowBrowser %%%
        %%%%%%%%%%%%%%%%%%%        
        case 'ShowBrowser',
          Data=LocalShowBrowser(Data,PropFig);
          
        %%%%%%%%%%%%%%%%%%%% 
        %%% ShowPropList %%%
        %%%%%%%%%%%%%%%%%%%%        
        case 'ShowPropList',
          Data=LocalShowPropList(Data,PropFig);
                    
        %%%%%%%%%%%%%%%%%%%%%
        %%% ToolsMenuCall %%%
        %%%%%%%%%%%%%%%%%%%%%        
        case 'ToolsMenuCall',
          Data=gnrlfun('ToolsMenuCall',Data);        
          
        %%%%%%%%%%%%%% 
        %%% Update %%%
        %%%%%%%%%%%%%%        
        case 'Update',
          %%% V5 LPD This doesn't work right if Tag or Style is set        
          [UpdateType,Data]=LocalSetValue(Data,PropFig);
          Data=LocalGetPropList(Data);        
          
          if Data.PropFig.PropListFlag,
            Data=LocalCreateString(Data);            
            Data=LocalUpdatePropertyField(Data,PropFig,'list','New');
          else,
            Data=LocalUpdatePropertyField(Data,PropFig,'edit','New');
          end            
          Data=LocalUpdateValueField(Data,PropFig);  

        %%%%%%%%%%%%%%%%%%%%%%%%%%% 
        %%% UpdatePropertyField %%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%        
        case 'UpdatePropertyField',
          [UpdateType,Data]=LocalSetValue(Data,PropFig);
          Data=LocalUpdatePropertyField(Data,PropFig,'edit','');
          Data=LocalUpdateValueField(Data,PropFig);  
          
        %%%%%%%%%%%%%%%%%%%%%%%% 
        %%% WindowButtonDown %%%
        %%%%%%%%%%%%%%%%%%%%%%%%        
        case 'WindowButtonDown',
          % Do nothing right now
          
      end % switch Action
      
      
    %%%%%%%%%%%%%%%%%%
    %%% Initialize %%%
    %%%%%%%%%%%%%%%%%%
    else,
      HandleList=varargin{1};
      Data=LocalInitFig(HandleList,0,PropFig);
      
    end % if isstr
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Custom Initialization %%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 2,
      Data=LocalInitFig(varargin{1:2},PropFig);
    
  %%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Initialize to Root %%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%
  case 0,
    
    HandleList=gnrlfun('InitializeHandleList',Data);    
    Data=LocalInitFig(HandleList,0,PropFig);
    
  %%%%%%%%%%%%%
  %%% Error %%%
  %%%%%%%%%%%%%
  otherwise,
    Data=setwatch('off',WatchFlag,Data);
    set(Data.All.DataHandle,'UserData',Data);
    error('Wrong number of input arguments for PROPEDIT');

end % switch nargin

%catch,
%  Data=gnrlfun('CatchErrors',Data); 
%end % try catch

Data=setwatch('off',WatchFlag,Data);
set(Data.All.DataHandle,'UserData',Data);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalCreateString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Data=LocalCreateString(Data)
% Create the Property List listbox string

if length(Data.All.HandleList>0),
  CurrentVal=gnrlfun('GetSafeVal',Data,Data.PropFig.PropList,'Prop');
  
  if length(Data.All.HandleList>1),
    for PropLp=1:size(Data.PropFig.PropList,1),
      CurFlag=gnrlfun('GetSameValFlag',[CurrentVal(PropLp,:)]);
      if ~CurFlag, % only one handle or all handles are equal  
        CurrentVal{PropLp,1}='Multiple Values';
      end % if Flag    
    end % for PropLp      
  end % if length ==1
  
  DispStruct=cell2struct(CurrentVal(:,1),Data.PropFig.PropList,1);
  ListString=evalc('disp(DispStruct)');
  ListString=strrep(ListString,'''','''''');
  LastLoc=max(find(ListString~=abs(sprintf('\n'))));
  ListString=[ 'char(''' ...
                  strrep(ListString(1:LastLoc),sprintf('\n'),''',''') ...
               ''')' ];
  ListString=eval(ListString);

  NewVal=get(Data.PropFig.ListboxHandles(1),'Value');

  if size(ListString,1)~=size(get(Data.PropFig.ListboxHandles(1),'String'),1),
    NewVal=1;
  end  
  
else,
  ListString={' '};NewVal=1;  
end % if length

TopDispValue=get(Data.PropFig.ListboxHandles(1),'ListboxTop');
if TopDispValue>NewVal,TopDispValue=1;end

set(Data.PropFig.ListboxHandles(1), ...
   'String'                   ,ListString  , ...
   'Value'                    ,NewVal      , ...
   'ListboxTop'               ,TopDispValue  ...
   );

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalGetDisableFlag %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DisableFlag=LocalGetDisableFlag(Data,CurrentProp)
% Find disabled property locations

TempTypeList=get(Data.All.HandleList,{'Type'});
TypeList=intersect(TempTypeList,TempTypeList);

DisableList=Data.PropFig.Disable.all;
for DisLp=1:size(TypeList,1),
  DisableList=[DisableList;getfield(Data.PropFig.Disable,TypeList{DisLp})];
end % for DisLp

DisableFlag=~isempty(strmatch(CurrentProp,DisableList,'exact'));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalGetEditString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [TypeFlag,ValString]=LocalGetEditString(Value,Caller)
% Get the correct string to be placed in the edit field

ValSize=size(Value);
ValString=['[ ' num2str(ValSize(1)) ];
for ValLp=2:length(ValSize),
  ValString=[ValString ' x ' num2str(ValSize(ValLp)) ];
end      
TypeFlag=1;

switch class(Value),
  case 'double',  
    if isempty(Value),
      ValString=['[ ]'];
      TypeFlag=0;
    else,      
      if length(size(Value))>2,
        ValString=[ValString '] double array']; 
      else,
                        % This is arbitrary      
        if prod(ValSize)>10,      
          ValString=[ValString '] double array']; 
        else,
          TypeFlag=0;        
          if Caller(1)=='l', % listbox
            ValString=mat2str(Value,5);
          else,
            ValString=mat2str(Value);
          end
          if ValString(1)=='[',
            ValString=['[ ' ValString(2:end-1) ' ]'];
            ValString=strrep(ValString,';',' ; ');
          end
        end % if ValSize
      end % if length
    end % if isempty      

  case 'struct',
    ValString=[ValString '] structure']; 
    
  case 'sparse',
    ValString=[ValString '] sparse matrix']; 

  case 'cell',
    ValString=[ValString '] cell array']; 
                 
  case 'char',
    % It's N-D  
    if length(size(Value))>2,
      ValString=[ValString '] character array']; 
  
    else,
                   % This is arbitrary      
      if ValSize(1)>1,      
        ValString=[ValString '] character array']; 
      
      else,
        if ~isempty(findstr(Value,sprintf('\n'))),
          ValString=[ValString '] character array with carriage returns']; 
        else,
          TypeFlag=0;
          ValString=quoting('Quotify',Value);        
        
        end
        
      end % if ValSize
    end % if length

  otherwise,    
    ValString=[ValString ']' class(Value)];        
          
end % switch
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalGetPossibleVal %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function PossibleVal=LocalGetPossibleVal(Type,CurrentProp,PossibleVal,PropFig)

switch CurrentProp{:},
  case 'Position',
    NewType=unique(char(Type),'rows');
    if size(NewType,1)==1,    
      switch NewType,
        case {'light','text'},
          statmsg(PropFig,'Position given as [x y z].');
        otherwise,        
          statmsg(PropFig,'Position given as [x y width height].');
      end
    else,
      statmsg(PropFig,' ');
    end      
  otherwise,    

    % Find disabled property locations
    Type=sortrows(char(Type));
    % The following comment out for speed.
    %Type=deblank(Type(1,:));  
    switch Type(1,1:2),
      case 'li', % line
        switch CurrentProp{:},
          case 'MarkerEdgeColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              'Possible values include ''none'',''auto'',A ColorSpec.');

          case 'MarkerFaceColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              'Possible values include ''none'',''auto'',A ColorSpec.');

        end    

      case 'pa', % patch
        switch CurrentProp{:},
          case 'MarkerEdgeColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              'Possible values include ''none'', ''auto'', A ColorSpec.');

          case 'MarkerFaceColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              'Possible values include ''none'', ''auto'', A ColorSpec.');

          case 'EdgeColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              ['Possible values include ''none'', ''flat'', ''interp'', ', ...
               'A ColorSpec.']);

          case 'FaceColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              ['Possible values include ''none'', ''flat'', ''interp'', ', ...
               'A ColorSpec.']);

        end    
      case 'su',  % surface
        switch CurrentProp{:},
          case 'MarkerEdgeColor',
            PossibleVal=[];
            statmsg(PropFig, ...
                ['Possible values include ''none'', ''auto'', ''flat'', ', ...
                 'A ColorSpec.']);

          case 'MarkerFaceColor',
            PossibleVal=[];
            statmsg(PropFig, ...
                ['Possible values include ''none'', ''auto'', ''flat'', ', ...
                 'A ColorSpec.']);

          case 'EdgeColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              ['Possible values include ''none'', ''flat'', ''interp'', ', ...
               'A ColorSpec.']);

          case 'FaceColor',
            PossibleVal=[];
            statmsg(PropFig, ...
              ['Possible values include ''none'', ''flat'', ''interp'', ', ...
               '''texturemap'', A ColorSpec.']);

        end    
    end      
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalGetPropList %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Data=LocalGetPropList(Data)
% Get the property list for the currently selected handles
switch length(Data.All.HandleList),
  case 0,
    Data.PropFig.PropList={};  
    
  case 1,
    TypeList=get(Data.All.HandleList,{'Type'});
    Info=get(Data.All.HandleList);
    Data.PropFig.PropList=cellstr(sortrows(char(fieldnames(Info))));  
    Data.PropFig.PropList= ...
      LocalRemoveProps(Data,Data.PropFig.PropList,TypeList);

  otherwise,    
    TypeList=get(Data.All.HandleList,{'Type'});
    TypeList=intersect(TypeList,TypeList);
    UniqueHandle=[];    
    for TypeLp=1:length(TypeList),
      TempHandle=findobj(Data.All.HandleList,'Type',TypeList{TypeLp});
      UniqueHandle=[UniqueHandle;TempHandle(1)];
    end      

    Info=get(UniqueHandle(1));
    Data.PropFig.PropList=fieldnames(Info);
    Data.PropFig.PropList= ...
      LocalRemoveProps(Data,Data.PropFig.PropList,TypeList);

    for HLp=2:length(UniqueHandle),
      NewInfo=get(UniqueHandle(HLp));
      NewProps=fieldnames(NewInfo);
      NewProps=LocalRemoveProps(Data,NewProps,TypeList);
      Data.PropFig.PropList=intersect(Data.PropFig.PropList,NewProps);
    end % for HLp
    Data.PropFig.PropList=cellstr(sortrows(char(Data.PropFig.PropList)));
  
end % switch  

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalListOpen %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
function [Data,UpdateType]=LocalListOpen(Data)
% Descend or climb through children or parents

Prop=get(Data.PropFig.PropTypeHandles(1),{'String'});
HandleList=[];
UpdateType='Selection';            

switch Prop{:},
  case 'XLabel',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=cat(1,HandleList{:});
    
  case 'YLabel',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=cat(1,HandleList{:});
    
  case 'ZLabel',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=cat(1,HandleList{:});
    
  case 'Title',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=cat(1,HandleList{:});
    
  case 'Children',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=cat(1,HandleList{:});
    
  case 'Parent',
    HandleList=gnrlfun('GetSafeVal',Data,Prop,'Prop');
    HandleList=unique(cat(1,HandleList{:}));
    if Data.All.GuideFlag,
      if any(HandleList==0),HandleList(HandleList==0)=[];end
    end % if
    
  otherwise,
    UpdateType='none';    
    %% Check to see if the popup menu is visible              
    if strcmp(get(Data.PropFig.PropTypeHandles(3),'Visible'),'on'),
      ValInfo=get(Data.PropFig.PropTypeHandles(3),{'Value';'String'});
      NumVal=size(ValInfo{2},1);
      if ValInfo{1}==NumVal,
        ValInfo{1}=1;
      else,
        ValInfo{1}=ValInfo{1}+1;
      end                    
      set(Data.PropFig.PropTypeHandles(3),'Value',ValInfo{1});
      set(Data.All.DataHandle,'UserData',Data);      
      propedit SetValue                  
      Data=get(Data.All.DataHandle,'UserData');      
      UpdateType='Property';            
    end % if strcmp
    return              
                
end % switch
            
if ~isempty(HandleList),
  set(Data.All.HandleList,'Selected','off');  
  Data.All.HandleList=HandleList;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalRemoveProps %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function PropList=LocalRemoveProps(Data,PropList,TypeList)
% Remove properties from list

RemoveList=Data.PropFig.Remove.all;
for TypeLp=1:size(TypeList,1),
  RemoveList=[RemoveList;getfield(Data.PropFig.Remove,TypeList{TypeLp})];
end % for TypeLp

for RmLp=1:size(RemoveList,1),
  RemoveLoc=strmatch(RemoveList(RmLp),PropList,'exact');
  PropList(RemoveLoc)=[];
end % for RmLp

%%%%%%%%%%%%%%%%%%% 
%%% LocalResize %%%
%%%%%%%%%%%%%%%%%%%        
function Data=LocalResize(Data,PropFig,varargin)
PropListHandle=Data.PropFig.ButtonHandles(2);
BrowserHandle=Data.PropFig.ButtonHandles(4);

set([Data.PropFig.PropTypeHandles Data.PropFig.ButtonHandles  ...
     Data.PropFig.ListboxHandles PropFig],'Units','points');

FigPos=get(PropFig,'Position');
TempFigPos=FigPos;

% Property, Value(4), Type, Tag, Frame
PropTypePos=get(Data.PropFig.PropTypeHandles,{'Position'});
PropTypePos=cat(1,PropTypePos{:});

ListPos=get(Data.PropFig.ListboxHandles,{'Position'});
ListPos=cat(1,ListPos{:});

% Status, Check 1, Close, Checks 2, Help, Frame
ButtonPos=get(Data.PropFig.ButtonHandles,{'Position'});
ButtonPos=cat(1,ButtonPos{:});

NumListOpen=get(PropListHandle,'Value')+get(BrowserHandle,'Value');

HOffset=ButtonPos(6,1);
VOffset=ButtonPos(6,2);

ButtonWidth=Data.PropFig.ButtonWidth;
ButtonHeight=Data.PropFig.ButtonHeight;  

ButtonPos(1:5,4)=ButtonHeight;
ButtonPos([3 5],1)=ButtonPos(3,1)+ButtonPos(3,3)-ButtonWidth(2);
ButtonPos([2 4],3)=ButtonWidth(1);
ButtonPos([3 5],3)=ButtonWidth(2);
ButtonPos(6,2)=VOffset;
ButtonPos(1,2)=ButtonPos(6,2)+VOffset;
ButtonPos([2 3],2)=sum(ButtonPos(1,[2 4]))+VOffset;
ButtonPos([4 5],2)=sum(ButtonPos(2,[2 4]))+VOffset;
ButtonPos(6,4)=sum(ButtonPos(4,[2 4]))+VOffset-ButtonPos(6,2);

PropTypePos(7,2)=sum(ButtonPos(6,[2 4]))+VOffset;

PropTypeWidth=(PropTypePos(7,3)-3*HOffset)/2;
PropTypePos([2:5],1)=sum(PropTypePos(3,[1 3]))-PropTypeWidth;
PropTypePos(1:5,3)=PropTypeWidth;
PropTypePos(6,3)=PropTypePos(7,3)-2*HOffset;
PropTypePos(1:6,4)=ButtonHeight;

if strcmp(get(Data.PropFig.PropTypeHandles(5),'Visible'),'on'),
  PropTypePos(2,3)=3*PropTypeWidth/4;
  PropTypePos(5,1)=sum(PropTypePos(2,[1 3]));
  PropTypePos(5,3)=PropTypeWidth/4;
end

ListPos(1,2)=PropTypePos(7,2)+VOffset;

if get(PropListHandle,'Value'),
  if get(BrowserHandle,'Value'),
    ListPos(:,4)= ...
        max(50, ...
        (FigPos(4)-VOffset-PropTypePos(7,2)-ButtonHeight-4*VOffset)/2 ...
        );
  else,
    ListPos(:,4)= ...
        max(50, ...
        (FigPos(4)-VOffset-PropTypePos(7,2)-2*ButtonHeight-4*VOffset) ...
        );
    
  end    
  PropTypePos(1:6,2)=sum(ListPos(1,[2 4]))+VOffset;
  
else,
  if get(BrowserHandle,'Value'),
    ListPos(:,4) = ...
        max(50,(FigPos(4)-VOffset-PropTypePos(7,2)-ButtonHeight-3*VOffset));
  else,      
    ListPos(:,4)=50;
  end      
  
  PropTypePos(1:6,2)=ListPos(1,2);
  
end % if get  
  
ListPos(2,2)=sum(PropTypePos(6,[2 4]))+VOffset;
PropTypePos(6,2)=ListPos(2,2);

if get(BrowserHandle,'Value'),
  PropTypePos(7,4)=sum(ListPos(2,[2 4]))+VOffset-PropTypePos(7,2);
else,
  PropTypePos(7,4)=sum(PropTypePos(6,[2 4]))+VOffset-PropTypePos(7,2);
end
  


% It was called from the menus
% check to see if not menu call
% use existing frame height to determine list height
if ~isempty(varargin),
  FigPos(4)=sum(PropTypePos(7,[2 4]))+VOffset;
  FigPos(2)=FigPos(2)+Data.PropFig.OldFigPos(4)-FigPos(4);
  set(PropFig,'ResizeFcn','','Position',FigPos);  
  drawnow
  set(PropFig,'ResizeFcn','propedit Resize');  
end % if isempty

Data.PropFig.OldFigPos=FigPos;

ButtonPos=num2cell(ButtonPos,2);
ListPos=num2cell(ListPos,2);
PropTypePos=num2cell(PropTypePos,2);
 
set(Data.PropFig.ButtonHandles,{'Position'},ButtonPos);
set(Data.PropFig.PropTypeHandles,{'Position'},PropTypePos);
set(Data.PropFig.ListboxHandles,{'Position'},ListPos);

    
set([Data.PropFig.PropTypeHandles Data.PropFig.ButtonHandles  ...
     Data.PropFig.ListboxHandles ],'Units','normalized');

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalSetValue %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
function [UpdateType,Data]=LocalSetValue(Data,PropFig)
% Set value for specified property

Property=Data.PropFig.CurrentProp;
%get(Data.PropFig.PropTypeHandles(1),'String');
PropFlag=[];
if ~isempty(Data.PropFig.PropList) & ~isempty(Property),
  PropFlag=strmatch(Property,Data.PropFig.PropList,'exact');
end

UpdateType=' ';

%% The property name must be valid
if ~isempty(PropFlag),
  Data.All.CurrentHandles(~ishandle(Data.All.CurrentHandles))=[];
  %% Check to see if the togglebutton is visible
  if strcmp(get(Data.PropFig.PropTypeHandles(5),'Visible'),'on') & ...
     isequal(gcbo,Data.PropFig.PropTypeHandles(5)),
    set(Data.PropFig.PropTypeHandles(5),'Value',1);
    CurColor=get(Data.All.CurrentHandles(1),Data.PropFig.CurrentProp);
    if ischar(CurColor),
      CurColor=[1 1 1];
    end
    Color=uisetcolor(CurColor,['Set ' Data.PropFig.CurrentProp]);
    set(Data.PropFig.PropTypeHandles(5),'Value',0);
    if isequal(Color,CurColor)|isequal(Color,0),
      return
    else,
      set(Data.PropFig.PropTypeHandles(2),'String',mat2str(Color));
    end
  end
  %% Check to see if the edit field is visible
  EditHandle=Data.PropFig.PropTypeHandles(2);
  if strcmp(get(EditHandle,'Visible'),'on'),
    if Data.PropFig.WorkspaceFlag,
      % Check to see if towork is still the value
      % if not, take the current value and clear base workspace      
      if strcmp(Data.PropFig.VarName,get(EditHandle,'String')),      
        BaseVars=evalin('base','whos');
        BaseVars={BaseVars.name};
        Loc=strmatch(Data.PropFig.VarName,BaseVars,'exact');
        if isempty(Loc),
          Value=get(Data.All.CurrentHandles(1),Data.PropFig.CurrentProp);
        else,
          Value=evalin('base',Data.PropFig.VarName);
        end % if
      else,
        Value=quoting('DeQuotify',get(EditHandle,'String'));
        [EditFlag,StaticString]=LocalGetEditString(Value,'edit');
        evalin('base',['clear(''' Data.PropFig.VarName ''')']);
      end        
    else,      
      Value=quoting('DeQuotify',get(EditHandle,'String'));
    end    
    
    if isequal(get(EditHandle,'ForegroundColor'),[.5 .5 .5]),
      if ~isequal(quoting('DeQuotify',Data.PropFig.CurrentVal), ...
                  Value) & ~Data.PropFig.WorkspaceFlag,
        set(EditHandle,'ForegroundColor',[0 0 0]);
      end        
    end  
    if ~isequal(get(EditHandle,'ForegroundColor'),[.5 .5 .5]),    
      if ~isempty(Data.All.CurrentHandles),    
        TempHandles=Data.All.HandleList;        
        Data.All.HandleList=Data.All.CurrentHandles;    
        [UpdateType,Data]=gnrlfun('SafeSet',Data,Property,Value, ...
                                  'edit',EditHandle,'Prop');
        if isequal(get(EditHandle,'ForegroundColor'),[1 0 0]),
          statmsg(PropFig,'Invalid value for the given property.',[1 0 0]);
        else,            
          statmsg(PropFig,' ');
        end
        Data.All.HandleList=TempHandles;
      end            
    end % if isequal
  %%The popup is open  
  elseif strcmp(get(Data.PropFig.PropTypeHandles(3),'Visible'),'on'),
    
    ValInfo=get(Data.PropFig.PropTypeHandles(3),{'Value';'String'});
    Value=ValInfo{2}{ValInfo{1}};           
      
    if isequal(get(Data.PropFig.PropTypeHandles(3),'ForegroundColor'), ...
               [.5 .5 .5]),
      if ~isequal(Data.PropFig.CurrentVal,Value),
        set(Data.PropFig.PropTypeHandles(3),'ForegroundColor',[0 0 0]);
      end        
    end  
    
    if ~isequal(get(Data.PropFig.PropTypeHandles(3),'ForegroundColor'), ...
                [.5 .5 .5]),
      if ~isempty(Data.All.CurrentHandles),    
        TempHandles=Data.All.HandleList;
        Data.All.HandleList=Data.All.CurrentHandles;
        [UpdateType,Data]=gnrlfun('SafeSet',Data,Property,Value,'popup', ...
                                  [],'Prop');                              
        if ~strcmp(Property,'IntegerHandle'),                              
          Data.All.HandleList=TempHandles;
        else,
          Data.All.CurrentHandles=Data.All.HandleList;
        end          
      end      
    
    end % if isequal    
    
  end % if  
  
end % if ~isempty

%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%% LocalShowBrowser %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
function Data=LocalShowBrowser(Data,PropFig,Junk);
% Toggle object browser display on/off
% Toggle Property list display on/off
BrowserMenuHandle=findall(PropFig,'Tag','MenuOptionsShowObjectBrowser');
BrowserHandle=Data.PropFig.ButtonHandles(4);

if isequal(gcbo,BrowserMenuHandle),
  CheckFlag=strcmp(get(BrowserMenuHandle,'Checked'),'off');
else,
  CheckFlag=get(BrowserHandle,'Value');
end

if CheckFlag,
  BrowseFlag=1;  
  Vis='on';  
  ObjTagVis='off';  
  Checked='on';  
else,
  BrowseFlag=0;
  Vis='off';  
  ObjTagVis='on';  
  Checked='off';  
end % if strcmp  

set(BrowserHandle,'Value',BrowseFlag);
set(BrowserMenuHandle,'Checked',Checked);

set(Data.PropFig.ListboxHandles(2),'Visible',Vis);
set(Data.PropFig.PropTypeHandles(6),'Visible',ObjTagVis);

if nargin~=3,
  Data=LocalResize(Data,PropFig,'menu');
end  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%% LocalShowPropList %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
function Data=LocalShowPropList(Data,PropFig,Junk);
% Toggle Property list display on/off

PropListMenuHandle=findall(PropFig,'Tag','MenuOptionsShowPropertyList');
PropListHandle=Data.PropFig.ButtonHandles(2);
BrowserHandle=Data.PropFig.ButtonHandles(4);

if isequal(gcbo,PropListMenuHandle),
  CheckFlag=strcmp(get(PropListMenuHandle,'Checked'),'off');
else,
  CheckFlag=get(PropListHandle,'Value');
end


if CheckFlag,
  PropListFlag=1;  
  CheckVal='on';  
  Checked='on';  
else,
  PropListFlag=0;
  CheckVal='off';  
  Checked='off';  
end % if strcmp  


set(PropListHandle,'Value',PropListFlag);
set(PropListMenuHandle,'Checked',Checked);

set(Data.PropFig.ListboxHandles(1),'Visible',CheckVal);
Data.PropFig.PropListFlag=PropListFlag;

if nargin~=3,
  Data=LocalResize(Data,PropFig,'menu');
end

if PropListFlag & nargin~=3,
  Data=LocalCreateString(Data);            
  Data=LocalUpdatePropertyField(Data,PropFig,'edit','');
  Data=LocalUpdateValueField(Data,PropFig);
end  


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalUpdatePropertyField %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Data=LocalUpdatePropertyField(Data,PropFig,Caller,CallType)
% Update the property name in the edit field

if Data.PropFig.WorkspaceFlag,
  evalin('base',['clear(''' Data.PropFig.VarName ''')']);
end

if isempty(Data.All.HandleList),
  Property='';
  Data.PropFig.ValidProp=0;  
  statmsg(PropFig,'An object must be selected.');
  set(Data.PropFig.PropTypeHandles(1),'Enable','off');  
  set(Data.PropFig.ListboxHandles(1),'String',{' '});

else,  
  set(Data.PropFig.PropTypeHandles(1),'Enable','on');  
  statmsg(PropFig,' ');
        
  if strcmp(Caller,'edit'),    
    OldProp=get(Data.PropFig.PropTypeHandles(1),'String');
    if ~isempty(OldProp),
      [r,c]=find(OldProp~=' ' & OldProp~=0);      
      OldProp=OldProp(:,min(c):max(c));
      % High Speed Property Editing      
      if ~isempty(OldProp),
        [r,c]=find(OldProp==' ');      
        if ~isempty(c),      
          OldProp=OldProp(:,1:max(c)-1);
        end      
      end      
            
    else,
      OldProp=Data.PropFig.PropList{1};      
    end   
    Property=lower(OldProp);
    PropList = cell(size(Data.PropFig.PropList));
    for i=1:prod(size(PropList)),
      PropList{i} = lower(Data.PropFig.PropList{i});
    end
    Value=strmatch(Property,PropList);
    switch length(Value),
      case 0,    
        if strcmp(CallType,'New'),
          Value=1;
          Data.PropFig.ValidProp=1;
          Property=Data.PropFig.PropList{1};          
          statmsg(PropFig,' ');
        else,          
          Value=[];      
          Data.PropFig.ValidProp=0;        
          Property=OldProp;        
          statmsg(PropFig,'Invalid Property Name',[1 0 0]);
        end          
        
      case 1,
        Property=Data.PropFig.PropList{Value};      
        Data.PropFig.ValidProp=1;        
        statmsg(PropFig,' ');
        
      otherwise,
        if length(Value)<10, % This is a hack for speed      
          NewValue=strmatch(Property,PropList(Value),'exact');
          if ~isempty(NewValue), % The typed property is an exact match
            Value=Value(NewValue);
            Property=Data.PropFig.PropList{Value};      
            Data.PropFig.ValidProp=1;
            statmsg(PropFig,' ');
          end % if ~isempty
        end % if length
        
        if length(Value)>1,        
          Data.PropFig.ValidProp=0;             
          SubPropList=char(Data.PropFig.PropList(Value));
          MatchPoint=sum(SubPropList,1)==length(Value)*SubPropList(1,:);
          NoMatchLoc=find(~MatchPoint);
          Message='Multiple Properties Possible';
          if isempty(NoMatchLoc),
            Property='';
          else,            
            MatchLen=min(NoMatchLoc)-1;          
            Property=SubPropList(1,1:MatchLen);            
            for ValLp=1:length(Value),
              if MatchLen==length(Data.PropFig.PropList{Value(ValLp)}),
              % it's an exact match
                Value=Value(ValLp);
                Property=Data.PropFig.PropList{Value(ValLp)};
                Data.PropFig.ValidProp=1;              
                Message=' ';
                break;                
              end                
            end  % for ValLp              
          end            
          
          statmsg(PropFig,Message);
        end % if length
    end % switch        

    if Data.PropFig.PropListFlag,      
      set(Data.PropFig.ListboxHandles(1),'Value',Value);
    end % if Data.PropFig.PropListFlag
    
  else,
    Value=get(Data.PropFig.ListboxHandles(1),'Value');
    if length(Value)>1,
      Value=Value(1);
      set(Data.PropFig.ListboxHandles(1),'Value',Value);
    end      
    Property=Data.PropFig.PropList{Value};  
    Data.PropFig.ValidProp=1;        
    statmsg(PropFig,' ');
    
  end  % if strcmp
end % if isempty  

Data.PropFig.CurrentProp=Property;
set(Data.PropFig.PropTypeHandles(1),'String',Property);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalUpdateValueField %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Data=LocalUpdateValueField(Data,PropFig)
% Update the value field
BadFlag=0;
if Data.PropFig.ValidProp,
  CurrentProp=get(Data.PropFig.PropTypeHandles(1),{'String'});
  PossibleVal=[];
  try,
    ReadOnlyFlag=0;
    PossibleVal=set(Data.All.HandleList(1),CurrentProp{:});
  catch,
    ReadOnlyFlag=1;      
  end

  DisableFlag=LocalGetDisableFlag(Data,CurrentProp);
  Type=get(Data.All.HandleList,{'Type'});
  PossibleVal=LocalGetPossibleVal(Type,CurrentProp,PossibleVal,PropFig);  
  CurrentString=gnrlfun('GetSafeVal',Data,CurrentProp,'Prop');
  CurFlag=gnrlfun('GetSameValFlag',CurrentString);
  CurrentVal=CurrentString{1};
  if CurFlag,
    ForeColor=[0 0 0];
  else,
    ForeColor=[.5 .5 .5];
  end % if Flag     
      
else,
  CurrentVal='';BadFlag=1;
  ReadOnlyFlag=1;ForeColor=[0 0 0];
end  

if ReadOnlyFlag|DisableFlag,% It's read only or forced disabled
  if ~BadFlag,  
    [EditFlag,StaticString]=LocalGetEditString(CurrentVal,'edit');
    
  else,
    StaticString=CurrentVal;
  end    
  set(Data.PropFig.PropTypeHandles(4), ...
     'Visible'        ,'on'         , ...
     'ForegroundColor',ForeColor    , ...     
     'String'         , StaticString  ...
     );
  Data.PropFig.CurrentVal=StaticString; 
  set(Data.PropFig.PropTypeHandles([2:3 5]),'Visible','off'); 
  
else,  
  if size(PossibleVal,1)>1, % bring the popup menu forward
    %CurrentString=gnrlfun('GetSafeVal',Data,CurrentProp,'Prop');
    CurrentString=CurrentString(1);
    CurrentVal=strmatch(CurrentString,PossibleVal,'exact');
    if CurFlag,
      ForeColor=[0 0 0];
    else,
      ForeColor=[.5 .5 .5];
    end % if Flag     
        
    set(Data.PropFig.PropTypeHandles(3), ...
       'Visible'                ,'on'       , ...
       'String'                 ,PossibleVal, ...
       'ForegroundColor'        ,ForeColor  , ...       
       'Value'                  ,CurrentVal   ...
       );    
    
    Data.PropFig.CurrentVal=CurrentVal;   
    set(Data.PropFig.PropTypeHandles([2 4:5]),'Visible','off');
    
  % Bring the color value field forward
  else,
    %%%%% Insert ? into position    
    if strcmp(CurrentProp{:},'Position'),
      EditFlag=0;      
      ForeColor=[0 0 0];      
      CurrentVal=get(Data.All.HandleList,{'Position'});
      if size(CurrentVal,1)>1,
        CurrentVal=cat(1,CurrentVal{:});
        diff(CurrentVal,1);        
        SameValFlag=find(~any(diff(CurrentVal,1),1));
        EditString(1:4)={' ? '};
        for lp=1:length(SameValFlag),
          EditString{SameValFlag(lp)}= ...
            [' ' num2str(CurrentVal(1,SameValFlag(lp)),16) ' '];
        end          
        EditString=strcat('[ ',EditString{:},' ]');        
        
      else,        
        EditString=mat2str(CurrentVal{:});        
        EditString=['[ ' EditString(2:end-1) ' ]'];
        EditString=strrep(EditString,';',' ; ');
      end  
      
    else,  
      [EditFlag,EditString]=LocalGetEditString(CurrentVal,'edit');
      
    end      
    
    
    if EditFlag,      
      BaseVars=evalin('base','whos');
      BaseVars={BaseVars.name};
      NameFlag=logical(0);
      BaseName=Data.PropFig.VarName;     
      Name=BaseName;     
      ct=0;     
      while ~NameFlag,
        Loc=strmatch(Name,BaseVars,'exact');
        if isempty(Loc),
          NameFlag=1;
        else,
          ct=ct+1;
          Name=[BaseName num2str(ct)];
        end % if
      end % while
      assignin('base',Name,CurrentVal);      
      Data.PropFig.VarName=Name;      
      Data.PropFig.WorkspaceFlag=1;      
      PropFig=findall(0,'Tag','Guide Property Editor');
      statmsg(PropFig,['Variable ' Name ' created in Workspace.']);
      EditString=Name;
      
    else,
      Data.PropFig.WorkspaceFlag=0;      
      
    end % if EditFlag    
    
    EditPos=get(Data.PropFig.PropTypeHandles(2),'Position');
    TogglePos=get(Data.PropFig.PropTypeHandles(5),'Position');
    ValWidth=sum(TogglePos(1,[1 3]))-EditPos(1);
    if length(CurrentProp{:})>4 & strcmp(CurrentProp{:}(end-4:end),'Color'),
      EditPos(3)=3*ValWidth/4;
      TogglePos(1)=sum(EditPos([1 3]));
      TogglePos(3)=ValWidth/4;
      CurColor=get(Data.All.HandleList(1),Data.PropFig.CurrentProp);
      if isstr(CurColor),
        CData=[];
        CurColor=get(0,'DefaultUicontrolBackgroundColor');
      else,
        CData=ones(100,100,3);
        CData(:,:,1)=CurColor(1);
        CData(:,:,2)=CurColor(2);
        CData(:,:,3)=CurColor(3);
      end
      
      Btn.Visible='on';
      Btn.Position=TogglePos;
      
      if isunix,
        Btn.BackgroundColor=CurColor;
      else,
        Btn.CData=CData;
      end
      
      set(Data.PropFig.PropTypeHandles(5),Btn);
      
    else,
      EditPos(3)=ValWidth;
      set(Data.PropFig.PropTypeHandles(5),'Visible','off');
    end

    set(Data.PropFig.PropTypeHandles(2), ...
        'Visible'        ,'on'       , ...
        'ForegroundColor',ForeColor  , ...              
        'Position'       ,EditPos    , ...
        'String'         , EditString  ...
        );
    Data.PropFig.CurrentVal=EditString;   
    set(Data.PropFig.PropTypeHandles(3:4),'Visible','off');
  end
end    

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LocalInitFig %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
function Data=LocalInitFig(HandleList,CustomList,PropFig)
% Initialize property editor

[HandleFlag,Data]=gnrlfun('InitializeHandles',PropFig,HandleList);

if strcmp(studio,'on'),
  %make call to Java
  % Try to open the inspector and object browser
  try
      java('com/mathworks/ide/inspector/Inspector', ...
          'activateInspector','()V');
      java('com/mathworks/ide/objectbrowser/ObjectBrowser', ...
          'activateObjectBrowser','()V');
  catch
    % Failed. Bail
    error('Failed to open Inspector and Object Browser');
  end
  delete(Data.All.HiddenFigure);
  return
end % if strcmp java


if HandleFlag==2,Data=guide('HandleUpdate',Data);return;end

CustomFlag=0;
CustomList={};

% Set up colors
LightGray=[192 192 192]/256 ; White=[1 1 1];
Black=[0 0 0]               ; MediumGray=[128 128 128]/256;

%%% Set up positions
Offset=3;
ButtonWidth(1)=130;ButtonHeight=20;
ButtonWidth(2)=80;
TextHeight=22;

% Property, Value(3), Type, Tag, Frame
PropTypePos=zeros(7,4);
PropTypePos(1,:)=[Offset Offset ButtonWidth(1) TextHeight];
PropTypePos(2,:)=[sum(PropTypePos(1,[1 3]))+Offset PropTypePos(1,2) ...
                  ButtonWidth(1) TextHeight];
PropTypePos(3:5,:)=PropTypePos(2*ones(3,1),:);
PropTypePos(6,:)=PropTypePos(1,:); 
PropTypePos(6,2)=PropTypePos(1,2)+TextHeight+Offset;
PropTypePos(6,3)=sum(PropTypePos(2,[1 3]))-PropTypePos(6,1);
PropTypePos(7,:)=[0 0 sum(PropTypePos(6,[1 3]))+Offset ...
                      sum(PropTypePos(6,[2 4]))+Offset];
PropTypePos(:,1:2)=PropTypePos(:,1:2)+Offset;

FigWidth=sum(PropTypePos(7,[1 3]))+Offset;

% Status, Check 1, Close, Checks 2, Help
ButtonPos=zeros(6,4);
ButtonPos(6,:)=PropTypePos(7,:)-[Offset Offset 0 0];
ListWidth=ButtonPos(6,3)-2*Offset;
ButtonPos(1,:)=[Offset Offset ListWidth TextHeight];
ButtonPos(2,:)=[ButtonPos(1,1) sum(ButtonPos(1,[2 4]))+Offset ...
                ButtonWidth(1) ButtonHeight];

ButtonPos(3,:)=[sum(ButtonPos(1,[1 3]))-ButtonWidth(2) ButtonPos(2,2) ...
                ButtonWidth(2) ButtonHeight];
ButtonPos(4:5,:)=ButtonPos(2:3,:);
ButtonPos(4:5,2)=ButtonPos(4:5,2)+ButtonPos(3,4)+Offset;
ButtonPos(6,4)=sum(ButtonPos(5,[2 4]))+Offset;
ButtonPos(:,1:2)=ButtonPos(:,1:2)+Offset;

PropTypePos(7,2)=sum(ButtonPos(6,[2 4]));

ListHeight=75;
ListPos=zeros(2,4);
ListPos(1,:)=[PropTypePos(7,1:2)+Offset ListWidth ListHeight];
ListPos(2,:)=ListPos(1,:);

PropTypePos(1:6,2)=sum(ListPos(1,[2 4]))+Offset;
ListPos(2,2)=sum(PropTypePos(6,[2 4]))+Offset;
PropTypePos(7,4)=sum(ListPos(2,[2 4]))+Offset-PropTypePos(7,2);

FigHeight=sum(PropTypePos(7,[2 4]))+Offset;
[FigHoriz,FigVert]=gnrlfun('GetFigPos',FigHeight,Data);
FigPos=[FigHoriz FigVert FigWidth FigHeight];

%%% Other Info
FigColor=get(0,'defaultuicontrolbackgroundcolor');

FontSize=get(0,'FactoryUIControlFontSize');
ButtonInfo={'Units'        ,'points'    ;'HandleVisibility'   ,'off'
            'FontUnits'    ,'points'    ;'FontSize'           ,FontSize
            'ForeGroundColor',Black
            'Interruptible','off'       ;'HorizontalAlignment','center' 
            'BusyAction'   ,'queue'            
           };
ButtonTags={'Status'       ;'Show Property List';'Close'
            'Show Object Browser';'Help'        ;'ButtonFrame'};
ButtonTips={'';'';'';'';'';''};

ButtonStrings={''                   ;'Show Property List';'Close'
               'Show Object Browser';'Help'              ;''};
ButtonStyle={'text';'checkbox';'pushbutton';'checkbox';'pushbutton';'frame'};
ButtonCall={''                    ;'propedit ShowPropList';'propedit Close';
            'propedit ShowBrowser';'propedit Help'        ;''};
ButtonColor=[White;FigColor;FigColor;FigColor;FigColor;FigColor];


            
PropTypeTags={'Property';'ValueEdit';'ValuePopup';
              'ValueText';'ValueToggle';
              'Object Type & Tag Information';'PropTypeFrame'
             };
PropTypeTips={'Property Name';'Property Value';'Property Value';
              'Property Value';'Property Value';'';''};
PropTypeStrings(1:7,1)={' '};
PropTypeStrings{5}='...';
PropTypeCalls={'propedit UpdatePropertyField';'propedit SetValue'
               'propedit SetValue'    ;'';'propedit SetValue';'';''};
PropTypeStyle={'edit';'edit';'popupmenu';'text';'togglebutton';'text';'frame'};
PropTypeColor=[White;White;White;White;FigColor;FigColor;FigColor];
PropTypeInfo=ButtonInfo;
PropTypeInfo{end-1,2}='left';


ListTags={'Property List';'Object Browser'};
ListTips={'';''};
ListCall={'propedit PropListButtonDown';'propedit BrowserButtonDown'};
ListInfo=[PropTypeInfo;{'Max',2;'Value',1;'FontName','FixedWidth'}];

ListVis={'on';'on'};
ListInfo=[{'Style','listbox'};ListInfo];
ListColor=[White;LightGray];


MenuInfo={'HandleVisibility','off'  ;'Interruptible' ,'off'    
          'BusyAction'      ,'queue'
         };
           
%%% Create the menu options
MenuFileLabels={'File'               
               '>Close Property Editor'
               };
MenuFileTags={'MenuFile'
              'MenuFileCloseTool'
             };
             
MenuFileCalls=[{''};{'propedit Close'}];
             
MenuOptionsLabels={'Options'               
               '>Show Object Browser'
               '>Show Property List'
               };
MenuOptionsTags={'MenuOptions'
              'MenuOptionsShowObjectBrowser'
              'MenuOptionsShowPropertyList'
             };
MenuOptionsCalls={'';'propedit ShowBrowser';'propedit ShowPropList'};


[MenuToolsLabels,MenuToolsCalls,MenuToolsTags]= ...
    gnrlfun('AddToolsMenu','Property Editor');

[MenuHelpLabels,MenuHelpCalls,MenuHelpTags]= ...
    gnrlfun('AddHelpMenu','Property Editor');


MenuInfoLabels=[MenuFileLabels ;MenuOptionsLabels; 
                MenuToolsLabels;MenuHelpLabels];
              
MenuInfoTags  =[MenuFileTags   ;MenuOptionsTags  ;
                MenuToolsTags  ;MenuHelpTags];
              
MenuInfoCalls =[MenuFileCalls  ;MenuOptionsCalls ; 
                MenuToolsCalls ;MenuHelpCalls];
                          
MenuInfoLabels=char(MenuInfoLabels);
MenuInfoTags=char(MenuInfoTags);
MenuInfoCalls=char(MenuInfoCalls);

% set up tool
MenuBar='none';
   
drawnow  
PropFig=figure(                     ...
              'Color'              ,FigColor                   , ...
              'CreateFcn'          ,''                         , ...
              'IntegerHandle'      ,'off'                      , ...
              'WindowButtonDownFcn','propedit WindowButtonDown', ...
              'CloseRequestFcn'    ,'propedit Close'           , ...
              'MenuBar'            ,MenuBar                    , ...
              'Name'               ,'Graphics Property Editor' , ...
              'Tag'                ,'Guide Property Editor'    , ...
              'NumberTitle'        ,'off'                      , ...
              'Units'              ,'points'                   , ...
              'Position'           ,FigPos                     , ...
              'Pointer'            ,'watch'                    , ...        
              'Resize'             ,'on'                       , ...
              'UserData'           ,[]                         , ...
              'Colormap'           ,[]                         , ...
              'Visible'            ,'off'                        ...
              );

MenuHandles=makemenu(PropFig,MenuInfoLabels,MenuInfoCalls,MenuInfoTags);
set(MenuHandles,MenuInfo(:,1),MenuInfo(:,2)');
set(MenuHandles(end-13),'Enable','off');


for ListLp=1:size(ListTags,1),
  ListboxHandle(ListLp)=uicontrol(ListInfo(:,1)   ,ListInfo(:,2)'     , ...
                                 'Parent'         ,PropFig            , ...
                                 'Position'       ,ListPos(ListLp,:)  , ...
                                 'Tag'            ,ListTags{ListLp}   , ...
                                 'TooltipString'  ,ListTips{ListLp}   , ...
                                 'Callback'       ,ListCall{ListLp}   , ...
                                 'String'         ,' '                , ...
                                 'Visible'        ,ListVis{ListLp}    , ...
                                 'BackgroundColor',ListColor(ListLp,:)  ...
                                 );
end % for ListLp

for BtnLp=size(ButtonTags,1):-1:1,
  ButtonHandles(BtnLp)=uicontrol(ButtonInfo(:,1) ,ButtonInfo(:,2)'      , ...
                                'Style'          ,ButtonStyle{BtnLp,1}  , ...  
                                'Parent'         ,PropFig               , ...
                                'Position'       ,ButtonPos(BtnLp,:)    , ...
                                'Tag'            ,ButtonTags{BtnLp,1}   , ...
                                'TooltipString'  ,ButtonTips{BtnLp,1}   , ...
                                'Callback'       ,ButtonCall{BtnLp,1}   , ...
                                'String'         ,ButtonStrings{BtnLp,1}, ...
                                'BackgroundColor',ButtonColor(BtnLp,:)    ...
                                );
end % BtnLp
set(ButtonHandles([2 4]),'Value',0,'HorizontalAlignment','left'); % Checkbox
set(ButtonHandles(1),'HorizontalAlignment','left');

for PLp=size(PropTypeTags,1):-1:1,
  PropTypeHandles(PLp)= ...
     uicontrol('Style'          ,PropTypeStyle{PLp,1}  , ...
               PropTypeInfo(:,1),PropTypeInfo(:,2)'    , ...
               'Parent'         ,PropFig               , ...
               'BackgroundColor',PropTypeColor(PLp,:)  , ...               
               'Position'       ,PropTypePos(PLp,:)    , ...
               'Tag'            ,PropTypeTags{PLp,1}   , ...
               'TooltipString'  ,PropTypeTips{PLp,1}   , ...
               'Callback'       ,PropTypeCalls{PLp,1}  , ...
               'String'         ,PropTypeStrings{PLp,1}  ...
               );
end % PLp
set([ListboxHandle ButtonHandles PropTypeHandles],'Units','normalized');

AllHandles=[ListboxHandle(1) ButtonHandles(5:-1:1)   ...
            ListboxHandle(2) PropTypeHandles([6 5 4 2 3 1]) ...
            ButtonHandles(6) PropTypeHandles(7) MenuHandles([13 6 3 1])'];
set(PropFig,'Children',AllHandles);
                
% Common UserData Settings
if isempty(Data.All.DataHandle),
  Data.All.DataHandle=PropFig;
end  

Data.All.CustomFlag=CustomFlag;
Data.All.CustomList=CustomList;

Data.All.Browser.Handles=[Data.All.Browser.Handles;ListboxHandle(2)];
Data.All.Browser.Complete=[Data.All.Browser.Complete;ListboxHandle(2)];
Data.All.ObjTypeTag=[Data.All.ObjTypeTag PropTypeHandles(6)];

Data.PropFig.PropTypeHandles=PropTypeHandles;
Data.PropFig.ButtonHandles=ButtonHandles;
Data.PropFig.ListboxHandles=ListboxHandle;

Data.PropFig.ButtonWidth=ButtonWidth;
Data.PropFig.ButtonHeight=ButtonHeight;

Data.PropFig.CurrentVal=[];
Data.PropFig.PropList={};
Data.PropFig.CurrentProp='';
Data.PropFig.OldFigPos=FigPos;
Data.PropFig.PropListFlag=1;
Data.PropFig.ValidProp=0;
Data.PropFig.VarName='towork';
Data.PropFig.WorkspaceFlag=0;

Data.PropFig.Remove.all={};
Data.PropFig.Remove.root={'CallbackObject';'CurrentFigure'};
Data.PropFig.Remove.figure={};
Data.PropFig.Remove.uicontextmenu={};
Data.PropFig.Remove.uimenu={};
Data.PropFig.Remove.uicontrol={};
Data.PropFig.Remove.axes={};
Data.PropFig.Remove.line={};
Data.PropFig.Remove.text={};
Data.PropFig.Remove.image={};
Data.PropFig.Remove.patch={};
Data.PropFig.Remove.surface={};
Data.PropFig.Remove.light={};
Data.PropFig.Remove.rectangle={};
Data.PropFig.Disable.all={'Children';'Parent'        ;'Type'
                          'CurrentProperty'          ;'UIContextMenu'
                         };
Data.PropFig.Disable.root={'ErrorMessage';'ScreenSize'};
Data.PropFig.Disable.figure={'CurrentAxes';'CurrentCharacter' ;'CurrentPoint'
                             'WaitStatus'
                            };                     
Data.PropFig.Disable.uicontextmenu={};
Data.PropFig.Disable.uimenu={};
Data.PropFig.Disable.uicontrol={};
Data.PropFig.Disable.axes={'AspectRatio';'XLabel';'YLabel';'ZLabel';'Title'};
                  
Data.PropFig.Disable.line={};
Data.PropFig.Disable.text={};
Data.PropFig.Disable.light={};
Data.PropFig.Disable.image={};
Data.PropFig.Disable.patch={};
Data.PropFig.Disable.surface={};
Data.PropFig.Disable.rectangle={};
                            
set(PropFig,'HandleVisibility','off');

Data=guide('ToolUpdate',Data,PropFig,'add');

if Data.All.DataHandle~=PropFig,
  DataFig.All.DataHandle=Data.All.DataHandle;
  set(PropFig,'UserData',DataFig);
  if length(Data.All.Browser.Complete)<2,% No other tool with a complete 
                                          % browser is open
    Data=objbrwser('CreateInitialMapping',Data);
  else,
    Data=objbrwser('SetBrowserString',Data,'Complete');
  end    
else, % This is the first open tool  
  Data=objbrwser('CreateInitialMapping',Data);
  Data=gnrlfun('TakeGeneralControl',Data);
end

BrowserHandle=Data.PropFig.ButtonHandles(4);
PropListHandle=Data.PropFig.ButtonHandles(2);
set([PropListHandle BrowserHandle],'Value',1);
Data=LocalShowBrowser(Data,PropFig,'ignore');

set(PropFig,'Visible','on');

Data=LocalGetPropList(Data);
if ~isempty(Data.PropFig.PropList),
  set(Data.PropFig.PropTypeHandles(1),'String',Data.PropFig.PropList{1});
end  
drawnow
Data=LocalShowPropList(Data,PropFig,'ignore');

if HandleFlag,
  Data=guide('SelectionUpdate',Data,[]);
end

drawnow
set(PropFig,'ResizeFcn','propedit Resize')
