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

    classdef SharedAxisHeader < mbcgui.widget.BasicContainer
    %mbcgui.widget.SharedAxisHeader class
    %   mbcgui.widget.SharedAxisHeader extends mbcgui.widget.BasicContainer.
    %
    %    mbcgui.widget.SharedAxisHeader 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'
    %       UserData - Property is of type 'MATLAB array'
    %       Tag - Property is of type 'string'
    %       Min - Property is of type 'double'
    %       Max - Property is of type 'double'
    %       Value - Property is of type 'double'
    %       Label - Property is of type 'ustring'
    %       Orientation - Property is of type 'string'
    %       AxisEdgeOffset - Property is of type 'int'
    %       AxisFrontOffset - Property is of type 'int'
    %       BackgroundColor - Property is of type 'color'
    %
    %    mbcgui.widget.SharedAxisHeader methods:
    %       doPosition - Redraw sharedAxisHeader control
    %       doSetup - Setup listeners for object
    %       setLimits - Set the min and max properties of the object
    %       setTableData - Table drawing interface function
    
    %  Copyright 2015-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (AbortSet, SetObservable)
        %MIN Property is of type 'double'
        Min = 0;
        %MAX Property is of type 'double'
        Max = 1;
        %VALUE Property is of type 'double'
        Value = NaN;
        %LABEL Property is of type 'ustring'
        Label = ''
        %ORIENTATION Property is of type 'string'
        Orientation = 'horizontal';
        %AXISEDGEOFFSET Property is of type 'int'
        AxisEdgeOffset = 5;
        %AXISFRONTOFFSET Property is of type 'int'
        AxisFrontOffset = 5;
        %BACKGROUNDCOLOR Property is of type 'color'
        BackgroundColor = get( xregGui.SystemColorsDbl, 'CTRL_BACK' );
    end
    
    properties (Access=protected, AbortSet)
        %AXIS Property is of type 'handle'
        axis = [];
        %GRID Property is of type 'MATLAB array'
        grid = [];
    end
    
    methods  % constructor block
        function obj= SharedAxisHeader(varargin)
        %SHAREDAXISHEADER Constructor function for SharedAxisHeader objects
        %  OBJ = SHAREDAXISHEADER(PROP, VAL, ...)
        
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call
        
        pnl = mbcgui.container.layoutpanel(...
            'Parent', obj.Parent, ...
            'BorderType', 'beveledout', ...
            'BackgroundColor', obj.BackgroundColor);
        obj.axis = mbcgui.widget.AxisSlider('Parent', pnl, ...
            'Orientation', obj.Orientation, ...
            'Min', obj.Min, ...
            'Max', obj.Max, ...
            'Value', obj.Value, ...
            'String', obj.Label);
        obj.grid = xreggridbaglayout(pnl);
        set(pnl, 'LayoutComponent', {obj.grid});
        obj.ContentHandle = pnl;
        obj.doPosition;
        obj.doSetup;
        
        end  % sharedAxisHeader
        
    end  % constructor block
    
    methods  % public methods
        %----------------------------------------
        function doPosition( obj )
        %DOPOSITION Redraw sharedAxisHeader control
        %  DOPOSITION(OBJ);
        
        if strcmp(obj.Orientation, 'vertical')
            set(obj.grid, ...
                'dimension', [1 2], ...
                'rowsizes', -1, ...
                'colsizes', [-1 1], ...
                'border', [0 obj.AxisEdgeOffset-1 obj.AxisFrontOffset-1 obj.AxisEdgeOffset-1], ...
                'elements', {[], obj.axis});
        else
            set(obj.grid, ...
                'dimension', [2 1], ...
                'rowsizes', [1 -1], ...
                'colsizes', -1, ...
                'border', [obj.AxisEdgeOffset-1 0 obj.AxisEdgeOffset-1 obj.AxisFrontOffset-1], ...
                'elements', {obj.axis});
        end
        
        end  % doPosition
        
        %----------------------------------------
        function doSetup(obj)
        %DOSETUP Setup listeners for object
        %  DOSETUP(OBJ)
        
        addListeners(obj,[ ...
            event.proplistener(obj, obj.findprop('Min'), 'PostSet', @(h,evt) i_setaxprops(h,evt,'Min')); ...
            event.proplistener(obj, obj.findprop('Max'), 'PostSet', @(h,evt) i_setaxprops(h,evt,'Max')); ...
            event.proplistener(obj, obj.findprop('Label'), 'PostSet', @i_setaxlabel); ...
            event.proplistener(obj, obj.findprop('Orientation'), 'PostSet', @i_setorient); ...
            event.proplistener(obj, obj.findprop('AxisEdgeOffset'), 'PostSet', @i_setpos); ...
            event.proplistener(obj, obj.findprop('AxisFrontOffset'), 'PostSet', @i_setpos); ...
            event.proplistener(obj, obj.findprop('Value'), 'PostSet', @(h,evt) i_setaxprops(h,evt,'Value')); ...
            event.proplistener(obj, obj.findprop('BackgroundColor'), 'PostSet', @(h,evt) i_setbg(h,evt,obj.ContentHandle)); ...
            ]);
        
        end  % doSetup
        
        %----------------------------------------
        function setLimits( obj, mn, mx )
        %SETLIMITS Set the min and max properties of the object
        %  SETLIMITS(OBJ, MIN, MAX)
        
        % Disable property listeners during operation
        disableListeners(obj)
        set(obj, 'Min', mn, 'Max', mx);
        obj.axis.setLimits(mn, mx);
        enableListeners(obj)
        end  % setLimits
        
        %----------------------------------------
        function setTableData(obj, R, C, data)
        %SETTABLEDATA Table drawing interface function
        %  SETTABLEDATA(OBJ, ROW, COL, DATA) where DATA should be a structure
        %  containing the fields Limits, Value and Label.
        
        if isa(data, 'mbcgui.widget.ScrollTableData')
            % Use standard interface to get the structure of information
            if R==0
                data = data.getStandardColumnHeaderData(C);
            else
                data = data.getStandardRowHeaderData(R);
            end
        end
        
        if (data.Value < data.Limits(1)) || (data.Value > data.Limits(2))
            val = NaN;
        else
            val = data.Value;
        end
        set(obj, 'Label', data.Label, ...
            'Value', val);
        obj.setLimits(data.Limits(1), data.Limits(2));
        
        if isfield(data, 'Color')
            obj.BackgroundColor = data.Color;
        end
        
        end  % setTableData
        
    end  % public methods
    
    
    methods(Access=protected)
        function setPosition(obj,newpos)
        setPosition@mbcgui.widget.BasicContainer(obj,newpos);
        obj.doPosition();
        end
        
        
    end
    
end  % classdef

function i_setpos(~, evt)
evt.AffectedObject.doPosition;
end  % i_setpos


function i_setaxprops(~, evt, prop)
obj = evt.AffectedObject;
set(obj.axis, prop, obj.(prop));
end  % i_setaxprops

function i_setaxlabel(~, evt)
obj = evt.AffectedObject;
set(obj.axis, 'String', obj.Label);
end  % i_setaxprops


function i_setorient(~, evt)
obj = evt.AffectedObject;
set(obj.axis, 'Orientation', obj.Orientation);
obj.doPosition;
end  % i_setorient


function i_setbg(~, evt, pnl)
set(pnl, 'BackgroundColor', evt.AffectedObject.BackgroundColor);
end  % i_setbg