www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/+mbcgui/+dialog/PageGroup.m

    classdef PageGroup < mbcgui.widget.BasicContainer
    %mbcgui.widget.PageGroup class
    %   mbcgui.widget.PageGroup extends mbcgui.widget.BasicContainer.
    %
    %    mbcgui.widget.PageGroup properties:
    %       Parent - Property is of type 'MATLAB array'
    %       Position - Property is of type 'rect'
    %       Enable - Property is of type 'on/off'
    %       Visible - Property is of type 'on/off'
    %       Tag - Property is of type 'string'
    %       Object - Property is of type 'MATLAB array' (read only)
    %       PageInfoFunction - Property is of type 'MATLAB array'
    %       DisplaySinglePageAsTab - Property is of type 'bool'
    %       CurrentPage - Property is of type 'int' (read only)
    %       UserData - Property is of type 'MATLAB array'
    %
    %    mbcgui.widget.PageGroup methods:
    %       cancel - Cancel the UI editing
    %       finalize - Complete the UI editing
    %       getCurrentHelpCode - Return help code for current page
    %       getCurrentHelpHandler - Return help handler function for current page
    %       getObject - Return the dialog's displaying object
    %       getPreferredSize - Returns a size vector for the group
    %       hasAnyHelp - Check whether any of the pages require a help button
    %       initialize - Initializes the group's display
    %       updateObject - Update the display object in the dialog
    
    %  Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (AbortSet)
        %PAGEINFOFUNCTION Property is of type 'MATLAB array'
        PageInfoFunction = [];
        %DISPLAYSINGLEPAGEASTAB Property is of type 'bool'
        DisplaySinglePageAsTab = false;
    end
    
    properties (SetAccess=protected, AbortSet)
        %HPAGEOBJECTS Property is of type 'handle vector'
        hPageObjects = [];
        %SENDCHANGEEVENTS Property is of type 'bool'
        SendChangeEvents = true;
    end
    
    properties (SetAccess=protected, AbortSet)
        %CURRENTPAGE Property is of type 'int' (read only)
        CurrentPage
    end
    
    properties (SetAccess=protected, AbortSet, SetObservable)
        %OBJECT Property is of type 'MATLAB array' (read only)
        Object = [];
    end
    
    
    events
        ObjectChanged
        Finalize
        Cancel
        PageChanged
    end  % events
    
    methods  % constructor block
        function obj = PageGroup(varargin)
        %PageGroup Construct a new DialogPageGroup object
        %  OBJ = PageGroup(Prop, Value, ...) constructs a new DialogPageGroup
        %  object.  This object manages vectors of DialogPageInfo objects and the
        %  layouts that they are displayed within.
        %
        %  You must call the INITIALIZE method at some point after creation.
        
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call

        obj.initialize;
        
        end  % DialogPageGroup
        
    end  % constructor block
    
    methods  % public methods
        %----------------------------------------
        function cancel(obj)
        %CANCEL Cancel the UI editing
        %  CANCEL(OBJ) sends a cancel event that notifies pages that they should
        %  undo any permanent edits that have been made.  During this time, object
        %  changes are not broadcast.  Edits that have been made in the object
        %  being directly edited do not need to be undone; this event is useful
        %  when edits have been made to other objects via a reference.
        
        obj.SendChangeEvents = false;
        obj.notify('Cancel');
        obj.SendChangeEvents = true;
        
        end  % cancel
        
        %----------------------------------------
        function finalize(obj)
        %FINALIZE Complete the UI editing
        %  FINALIZE(OBJ) sends a finalize event that notifies pages that they
        %  should commit any outstanding edits.  During this time, object changes
        %  are not broadcast.
        
        obj.SendChangeEvents = false;
        obj.notify('Finalize');
        obj.SendChangeEvents = true;
        
        end  % finalize
        
        %----------------------------------------
        function hc = getCurrentHelpCode(obj)
        %GETCURRENTHELPCODE Return help code for current page
        %  HC = GETCURRENTHELPCODE(OBJ) returns the help code for the
        %  currently-displayed page.
        
        if obj.CurrentPage>0
            hc = obj.hPageObjects(obj.CurrentPage).HelpCode;
        else
            hc = '';
        end
        end  % getCurrentHelpCode
        
        %----------------------------------------
        function hh = getCurrentHelpHandler(obj)
        %GETCURRENTHELPHANDLER Return help handler function for current page
        %  HH = GETCURRENTHELPHANDLER(OBJ) returns the help handler for the
        %  currently-displayed page.
        
        if obj.CurrentPage>0
            hh = obj.hPageObjects(obj.CurrentPage).HelpHandler;
        else
            hh = '';
        end
        
        end  % getCurrentHelpHandler
        
        %----------------------------------------
        function DispObj = getObject(obj)
        %GETOBJECT Return the dialog's displaying object
        %  DISPOBJ = GETOBJECT(OBJ) returns the object that this page group was
        %  created for.
        
        DispObj = obj.Object;
        
        end  % getObject
        
        %----------------------------------------
        function sz = getPreferredSize(obj)
        %GETPREFERREDSIZE Returns a size vector for the group
        %  SZ = GETPREFERREDSIZE(OBJ) returns a 2-element vector containing the
        %  preferred width and height of the group of pages.
        
        if ~isempty(obj.hPageObjects)
            W = get(obj.hPageObjects, {'PreferredWidth'});
            figW = max([W{:}]);
            H = get(obj.hPageObjects, {'PreferredHeight'});
            figH = max([H{:}]);
            sz = [figW figH];
        else
            sz = [380 400];
        end
        
        end  % getPreferredSize
        
        %----------------------------------------
        function hasHelp = hasAnyHelp(obj)
        %HASANYHELP Check whether any of the pages require a help button
        %  HASANYHELP(OBJ) returns true if any of the DialogPageInfo objects in
        %  this group have non-empty help handlers and help codes.
        
        % Check whether to show the help button
        hasHelp = ~all( ...
            cellfun('isempty', get(obj.hPageObjects, {'HelpCode'})) ...
            & cellfun('isempty', get(obj.hPageObjects, {'HelpHandler'})) ...
            );
        
        end  % hasAnyHelp
        
        %----------------------------------------
        function initialize(obj)
        %INITIALIZE Initializes the group's display
        %  INITIALIZE(OBJ) creates the display for the group.
        
        if ~isempty(obj.ContentHandle)
            % Destroy the old UI
            delete(obj.ContentHandle);
            obj.hPageObjects = [];
        end
        
        % Create the PageInfo objects
        genFcn = obj.PageInfoFunction;
        if ~isempty(genFcn) && (isobject(obj.Object) || ~isempty(obj.Object))
            hInfo = genFcn(obj.Object, obj);

            obj.hPageObjects = hInfo;
            
            % Create the appropriate layout
            obj.ContentHandle = obj.pCreateTabPanel;
        end
        end  % initialize
        
        %----------------------------------------
        function hComp = pCreateTabPanel(obj)
        %PCREATETABPANEL Create the layout that contains dialog pages
        %  HCOMP = PCREATETABPANEL(OBJ) creates and returns the layout that
        %  contains the pages of information defined by the DialogPageInfo objects.
        
        if isempty(obj.hPageObjects)
            hComp = uicontrol('Parent', obj.Parent, ...
                'Position', obj.Position, ...
                'Style', 'text', ...
                'Visible', obj.Visible, ...
                'String', '<No information available>');
            
        elseif length(obj.hPageObjects)==1 && ~obj.DisplaySinglePageAsTab
            % Do not put single page in a tab
            hComp = i_createUI(obj.Parent, obj.hPageObjects);
            set(hComp, 'Position', obj.Position, ...
                'Visible', obj.Visible);
            obj.CurrentPage = 1;
        else
            % Create a tablayout to put the components in.
            inf = obj.hPageObjects;
            hComp = uitabgroup('Parent',obj.Parent,...
                'SelectionChangedFcn',@i_tabselect,...
                'Units','pixels');
            
            hTabs = gobjects(1,length(inf));
            for i=1:length(inf)
                % create the tabs
                hTabs(i) = mbcgui.container.uitab('Parent',hComp,...
                    'LayoutBorder', [7 7 7 7],...
                    'Title',inf(i).Name);
            end
            % create the first tab
            hTabs(1).LayoutComponent = i_createUI(hTabs(1), inf(1));
            
            obj.CurrentPage = 1;
        end
        
        
            function i_tabselect(~, ~)
            tabNumber = find(hComp.SelectedTab == hComp.Children);
            
            if ~inf(tabNumber).IsCreated
                hTabs(tabNumber).LayoutComponent = i_createUI(hTabs(tabNumber), inf(tabNumber));
            end
            obj.pSetPage(tabNumber);
            obj.notify('PageChanged');
            end
        
        end
        
        %----------------------------------------
        function pSetPage(obj, page)
        %PSETPAGE Sets the current page for the object
        %  PSETPAGE(OBJ, PAGE) sets the CurrentPage property to be PAGE.
        
        obj.CurrentPage = page;
        
        end  % pSetPage
        
        %----------------------------------------
        function updateObject(obj, DispObj)
        %UPDATEOBJECT Update the display object in the dialog
        %  UPDATEOBJECT(OBJ, DISPOBJ) calls the dialog's updateObject method with
        %  DISPOBJ.  This will cause an ObjectChanged event to be sent on this
        %  group and the dialog if this group is being shown.
        
        obj.Object = DispObj;
        if obj.SendChangeEvents
            obj.notify('ObjectChanged');
        end
        
        end  % updateObject
        
    end  % public methods
    
end  % classdef

function L = i_createUI(hParent, hInfo)

L = hInfo.createUI(hParent);

end