www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xreglistctrl/set.m

    function obj = set(obj, varargin)
%SET
%
%  set(xreglistctrl, 'Property', Value)
%  Property = {'numCells', 'position', 'controls', 'top'}
%
%  Also at this time only one parameter value pair per call can be used
%
%  This form of the set method return a modified form of the object

%  Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc.


sh = obj.slider;
ud = get(sh,'UserData');

d = length(varargin)/2;
nparam = floor(d);

% if 'full' required at all, flag > 0
redrawflag = 0;

for arg=1:2:nparam*2-1
    parameter = varargin{arg};
    value = varargin{arg+1};
    switch upper(parameter)

        case {'BORDER', 'INNERBORDER'}
            if isnumeric(value) && length(value)==1
                pos = ud.position;
                cellHeight = ud.cellHeight + 2*ud.cellBorder;
                if value < (pos(4)- cellHeight)/2 && value >= 3
                    ud.border = value;
                    redrawflag = 1;

                else
                    warning('mbc:xreglistctrl:InvalidPropertyValue', ...
                        'Inner border must be greater than 3 pixels and small enough to draw at least one Input object.');
                end
            end

        case 'CALLBACK'
            % is there a relistic check to do??
            ud.callback = value;
            
        case {'CELLBORDER', 'CONTROLBORDER', 'INPUTBORDER'}
            if isnumeric(value) && length(value)==1 && value >=0
                % min height available for drawing input objects is 15
                pos = ud.position;
                if pos(4)-2*ud.border-(15+2*value) >= 0
                    ud.cellBorder = value;
                    redrawflag = 1;
                else
                    warning(message('mbc:xreglistctrl:InvalidPropertyValue1'));
                    return
                end
            end

        case {'CELLHEIGHT', 'CELLHT', 'HEIGHT'}
            if isnumeric(value) && length(value)==1
                pos = ud.position;
                border = ud.border;
                cellBorder = ud.cellBorder;
                if value + 2*cellBorder <= pos(4)-2*border && value >= 10
                    ud.cellHeight = value;
                    redrawflag = 2;
                else
                    warning(message('mbc:xreglistctrl:InvalidPropertyValue2'));
                    return
                end
            end

        case {'CONTROLS','INPUTS','ELEMENTS'}
            if iscell(value)
                % changing controls => delete all current uicontrols
                for i = 1:length(ud.controls)
                    delete(ud.controls{i});
                end
                ud.controls = value;
                ud.top=1;
                if redrawflag<2, 
                    redrawflag = 1; 
                end
                    
                hP = get(obj.slider, 'Parent');
                for i = 1:length(ud.controls)
                    if get(ud.controls{i},'Parent')~=hP
                        set(ud.controls{i}, 'Parent', hP);
                    end
                    try
                        set(ud.controls{i},'Callback',  {@i_cellcb, obj, i});
                    end
                end
            end

        case 'NUMCELLS'
            % should use cell height property
            if isnumeric(value) && length(value)==1
                pos = ud.position;
                if floor((pos(4)-2*ud.border)/value)-2*ud.cellBorder > 15
                    try
                        set(obj,'cellHeight',floor((pos(4)-2*ud.border)/value)-2*ud.cellBorder ) ;
                    end
                end
                return
            end

        case 'FIXNUMCELLS'
            if isnumeric(value) && length(value)==1
                ud.fixnumcells = value;
                redrawflag = 2;
            else
                warning(message('mbc:xreglistctrl:InvalidPropertyValue'));
                return
            end

        case 'POSITION'
            position=value;
            if position == ud.position
                return
            end

            if position(3) < 40
                position(3) = 40;
            end
            if position(4) < 40
                position(4) = 40;
            end
            ud.position = position;
            redrawflag = 2;

        case 'SLIDERWIDTH'
            if isnumeric(value) && length(value)==1
                set(obj.layout, 'colsizes', [-1 value]);
                ud.sliderwidth = value;
            end

        case 'TOP'
            % should only be called from within methods
            ud.top = value;
            if redrawflag<2, redrawflag = 1; end;

        case {'USERDATA'}
            ud.userdata = value;


        case {'VALUE','VALUES'}
            % how many non-text Inputs?
            numVals =...
                length(ud.controls)-sum(cellfun('isclass',ud.controls,'xregtextinput'));

            if iscell(value) % check we've got a cell array of values
                switch length(value)
                    case length(ud.controls)
                        for i = 1:length(ud.controls)
                            try
                                set(ud.controls{i},'Value',value{i});
                            end
                        end

                    case numVals % cell array of new vals for non-text-inputs
                        inputNum=1;
                        for i = 1:length(ud.controls)
                            if ~isa(ud.controls{i},'xregtextinput')
                                try
                                    set(ud.controls{i},'Value',value{inputNum});
                                    inputNum = inputNum+1;
                                end
                            end
                        end

                end % switch
                if redrawflag<2, redrawflag = 1; end;
            end % if value is a cell array

        case 'VISIBLE'
            fr = obj.frame;
            set(fr,'Visible',value);
            for i=1:length(ud.controls)
               set( ud.controls{i},'Visible',value );
            end
            % visible on, need to redraw cells (not all 'on')
            if strcmp(value,'on') && redrawflag<2, redrawflag=1; end;
        case 'OBJECT'
            % sneaky way in for subclasses
            ud.object= value;
        case 'UICONTEXTMENU'
            set(obj.frame,'UIContextMenu',value);
            for i=1:length(ud.controls)
                set(ud.controls{i},'UIContextMenu',value);
            end

        otherwise
            % try calling set on individual controls
            for i = 1:length(ud.controls)
                try
                    set(ud.controls{i},parameter,value);
                end
            end

    end %switch

end


set(sh,'UserData',ud);

if redrawflag==1
    obj=redraw(obj,'cell');
elseif redrawflag==2
    obj=redraw(obj,'full');
end


function i_cellcb(src, evt, obj, idx)
callback(obj, idx);