www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@classicTable/doSetupAxesGrid.m

    function doSetupAxesGrid(obj)
%DOSETUPAXESGRID Set the table elements into the grid layout
%
%  SETUPGRID(OBJ) sets up the grid layout to correctly contain the table
%  display objects and the scrollbars.  This configuration is well-suited
%  for arrays of axes.

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


if obj.isCreatedCorrect && obj.canPaint
    % Flags to indicate that various components should be visible or not
    SHOW_HSCROLL = (diff(obj.ScrollColumnLimits)>0);
    SHOW_VSCROLL = (diff(obj.ScrollRowLimits)>0);
    SHOW_TL = false; SHOW_TR = false; SHOW_BL = false;
    SHOW_BR = SHOW_HSCROLL && SHOW_VSCROLL;
    
    [nR_obj, nC_obj] = size(obj.MainObjects);
    nR = nR_obj; nC = nC_obj;
    if SHOW_HSCROLL
        nR = nR+1;
    end
    if obj.ShowColumnHeaders
        nR = nR+1;
    else
    end
    if SHOW_VSCROLL
        nC = nC+1;
    end
    if obj.ShowRowHeaders
        nC = nC+1;
    end
    
    rowsizes = repmat(-1, 1, nR);
    colsizes = repmat(-1, 1, nC);
    els = cell(nR, nC);
    
    if obj.ShowRowHeaders && obj.ShowColumnHeaders
        els{nR_obj+1} = obj.TopLeftCorner;
        els = i_convert_to_cell(els, obj.ColumnHeaderObjects, nR_obj+1, 2);
        els = i_convert_to_cell(els, obj.RowHeaderObjects, 1, 1);
        els = i_convert_to_cell(els, obj.MainObjects, 1, 2);
        SHOW_TL = true;
        rowsizes(nR_obj+1) = obj.ColumnHeaderWidth;
        colsizes(1) = obj.RowHeaderWidth;
    elseif obj.ShowRowHeaders 
        els = i_convert_to_cell(els, obj.RowHeaderObjects, 1, 1);
        els = i_convert_to_cell(els, obj.MainObjects, 1, 2);
        colsizes(1) = obj.RowHeaderWidth;
    elseif obj.ShowColumnHeaders
        els = i_convert_to_cell(els, obj.ColumnHeaderObjects, nR_obj+1, 1);
        els = i_convert_to_cell(els, obj.MainObjects, 1, 1);
        rowsizes(nR_obj+1) = obj.ColumnHeaderWidth;
    else
        els = i_convert_to_cell(els, obj.MainObjects, 1, 1);
    end
    
    % variable for holding marge settings for the scrollbars
    mergeargs = {};
    if SHOW_HSCROLL
        if obj.ScrollbarStyle==1 && obj.ShowRowHeaders
            els{end, 2} = obj.hSliderbar;
            SHOW_BL = true;
            els{end, 1} = obj.BottomLeftCorner;
            if SHOW_BR
                mergeargs = [mergeargs, {'mergeblock', {[nR nR],[2 nC-1]}}];
            else
                mergeargs = [mergeargs, {'mergeblock', {[nR nR],[2 nC]}}];
            end
        else
            els{end, 1} = obj.hSliderbar;
            if SHOW_BR
                mergeargs = [mergeargs, {'mergeblock', {[nR nR],[1 nC-1]}}];
            else
                mergeargs = [mergeargs, {'mergeblock', {[nR nR],[1 nC]}}];
            end
        end
        rowsizes(end) = obj.ScrollbarWidth;
    end
    if SHOW_VSCROLL
        if obj.ScrollbarStyle==1 && obj.ShowColumnHeaders
            els{1, end} = obj.vSliderbar;
            SHOW_TR = true;
            els{nR_obj+1, end} = obj.TopRightCorner;
            if SHOW_BR
                mergeargs = [mergeargs, {'mergeblock', {[1 nR-2],[nC nC]}}];
            else
                mergeargs = [mergeargs, {'mergeblock', {[1 nR-1],[nC nC]}}];
            end
        else
            els{1, end} = obj.vSliderbar;
            if SHOW_BR
                mergeargs = [mergeargs, {'mergeblock', {[1 nR-1],[nC nC]}}];
            else
                mergeargs = [mergeargs, {'mergeblock', {[1 nR],[nC nC]}}];
            end
        end
        colsizes(end) = obj.ScrollbarWidth;
    end
    if SHOW_BR
        els{end, end} = obj.BottomRightCorner;
    end
    
    
    set(obj.gridObject, ...
        'clearmerge', [], ...
        'dimension', [nR, nC], ...
        'rowsizes', rowsizes, ...
        'colsizes', colsizes, ...
        'elements', els, ...
        mergeargs{:});
    
    set(obj.EmptyTableComponent, 'Visible', 'off');
    i_setvisible(obj.hSliderbar, obj.Visible, SHOW_HSCROLL);
    i_setvisible(obj.vSliderbar, obj.Visible, SHOW_VSCROLL);
    i_setvisible(obj.TopLeftCorner, obj.Visible, SHOW_TL);
    i_setvisible(obj.TopRightCorner, obj.Visible, SHOW_TR);
    i_setvisible(obj.BottomLeftCorner, obj.Visible, SHOW_BL);
    i_setvisible(obj.BottomRightCorner, obj.Visible, SHOW_BR);
    
else
    sz_D = obj.pGetDataSize;
    if all(sz_D==0)
        set(obj.gridObject, 'clearmerge', [], ...
            'dimension', [1 1], ...
            'rowsizes', [], ...
            'colsizes', [], ...
            'elements', {obj.EmptyTableComponent});
        set(obj.EmptyTableComponent, 'Visible', obj.Visible);
    else
        set(obj.gridObject, 'dimension', [0 0], 'elements', {});
        set(obj.EmptyTableComponent, 'Visible', 'off');
    end
    set([obj.hSliderbar; obj.vSliderbar], 'Visible', 'off');
    set(obj.TopLeftCorner, 'Visible', 'off');
    set(obj.TopRightCorner, 'Visible', 'off');
    set(obj.BottomLeftCorner, 'Visible', 'off');
    set(obj.BottomRightCorner, 'Visible', 'off');
end





function hcell = i_convert_to_cell(hcell, h, Rstart, Cstart)
[nR_h, nC_h] = size(h);
Rstart_adj = Rstart-1;
Cstart_adj = Cstart-1;
for n = Rstart:(Rstart_adj+nR_h)
    n_hindex = n-Rstart_adj;
    for m = Cstart:(Cstart_adj+nC_h)
        hcell{n, m} = h(n_hindex, m-Cstart_adj);
    end
end


function i_setvisible(hObject, onstate, boolvalue)
if boolvalue
    set(hObject, 'Visible', onstate);
else
    set(hObject, 'Visible', 'off');
end