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

    classdef TabMotionManager < mbcgui.motion.ContainerMotionManager
    %mbcgui.motion.TabMotionManager class
    %   mbcgui.motion.TabMotionManager extends mbcgui.motion.ContainerMotionManager.
    %
    %    mbcgui.motion.TabMotionManager properties:
    %       Figure - Property is of type 'MATLAB array'
    %       Mode - Property is of type 'string'
    %       Enable - Property is of type 'on/off'
    %       MouseMoveFcn - Property is of type 'MATLAB callback'
    %       MouseInFcn - Property is of type 'MATLAB callback'
    %       MouseOutFcn - Property is of type 'MATLAB callback'
    %       EnableTree - Property is of type 'bool'
    %       Region - Property is of type 'rect'
    %       UseExternalRef - Property is of type 'on/off'
    %       ExternalRef - Property is of type 'MATLAB array'
    %       Handle - Property is of type 'MATLAB array'
    %
    %    mbcgui.motion.TabMotionManager methods:
    %       AttachToPanel - Attach Motion Manager to uipanel
    %       ExecuteMovement - Execute MotionManager callbacks
    %       enableManager - determine whether to enable manager
    
    %  Copyright 2016 The MathWorks, Inc.
    
    methods  % constructor block
        function obj = TabMotionManager(varargin)
        %UiTabMotionManager Window Motion management class
        %  OBJ = UiTabMotionManager(PROP, VALUE, ...)
        
        % obj = mbcgui.motion.PanelMotionManager;
        
        % Call superclass constructor
        obj@mbcgui.motion.ContainerMotionManager(varargin{ : }); % converted super class constructor call
        
        end  % PanelMotionManager
        
    end  % constructor block

    
    methods  % public methods
        
        %----------------------------------------
        function en = enableManager(obj)
        %enableManager determine whether to enable manager
        %   en = enableManager(obj)
        
        % selected tab
        en = obj.Handle == obj.Handle.Parent.SelectedTab;
        end  % enableManager
        
    end  % public methods
    
    methods (Access=protected)
        
        function onSelectTab(M,~,evt)
        %onSelectTab select tab with buttons
        
        hTab = M.Handle;
        M.Enable = mbconoff(isParentEnabled(M) && evt.NewValue == hTab);
        end  % iSelectionChanged
        
        function onSetSelectedTab(M,~,evt)
        %onSetSelectedTab set SelectedTab listener on uitabgroup
        hTab = M.Handle;
        hTabGroup = evt.AffectedObject;
        % enable if tab is the selected tab
        if ~isempty(hTabGroup.SelectedTab)
            M.Enable = mbconoff( isParentEnabled(M) && hTabGroup.SelectedTab == hTab);
        end
        end  % iSelectionChanged
        
        
        function onSetParent(obj,hPanel, evt)
        % Attach to MotionManager in panel's new parent
        OldParent = obj.Parent;
        if ~isempty(OldParent);
            OldParent.UnregisterManager(obj);
        end
        NewParentMM = MotionManager(get(evt.AffectedObject, 'Parent'));
        NewParentMM.RegisterManager(obj);
        % replace listener to tab parent set
        % this code also deletes the previous listener
        hTabGroup = hPanel.Parent;
        
        obj.PMMListeners(1) = event.proplistener(hTabGroup,hTabGroup.findprop('SelectedTab'),'PostSet',@obj.onSetSelectedTab);
        obj.PMMListeners(2) = event.listener(hTabGroup,'SelectionChanged',@obj.onSelectTab);
        
        obj.Enable = mbconoff(strcmpi(NewParentMM.Enable,'on') && enableManager(obj));
        end  % iParentPostSet
        
        function  createContainerListeners(obj)
        %createContainerListeners create listeners for container state 
        
        hPanel = obj.Handle;
        hTabGroup = hPanel.Parent;
        obj.PMMListeners = {...
            event.proplistener(hTabGroup,hTabGroup.findprop('SelectedTab'),'PostSet',@obj.onSetSelectedTab),...
            event.listener(hTabGroup,'SelectionChanged',@obj.onSelectTab),...
            event.proplistener(hPanel, hPanel.findprop('Parent'), ...
            'PostSet', @obj.onSetParent) ...
            event.listener(hPanel, 'ObjectBeingDestroyed',@obj.onDeletePanel);
            };
        end
        
    end
    
end  % classdef