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

    function doSetupCTable(obj)
%DOSETUPCTABLE Setup listeners
%
%  obj.doSetupCTable

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


obj.sharedAxisTable_Listeners = [...
        handle.listener(obj, obj.findprop('CurrentRow'), 'PropertyPostSet', {@i_setCurRow, obj.vSliderbar}); ...
        handle.listener(obj, obj.findprop('CurrentColumn'), 'PropertyPostSet', {@i_setCurCol, obj.hSliderbar}); ...
        handle.listener(obj, obj.findprop('ScrollRowLimits'), 'PropertyPostSet', {@i_setScrRowLims, obj.vSliderbar}); ...
        handle.listener(obj, obj.findprop('ScrollColumnLimits'), 'PropertyPostSet', {@i_setScrColLims, obj.hSliderbar}); ...
        handle.listener(obj, 'DisplayObjectsChanged', @i_setupGrid); ...
        handle.listener(obj, 'DataSizeChanged', @i_setupGrid); ...
        handle.listener(obj, obj.findprop('MinimumCellSize'), 'PropertyPostSet', @i_setCellSize); ...
        handle.listener(obj, obj.findprop('RowHeaderWidth'), 'PropertyPostSet', {@i_setRowHeaderWidth, obj.gridObject}); ...
        handle.listener(obj, obj.findprop('ColumnHeaderWidth'), 'PropertyPostSet', {@i_setColHeaderWidth, obj.gridObject}); ...
        handle.listener(obj, obj.findprop('ScrollbarWidth'), 'PropertyPostSet', {@i_setScrollWidth, obj.gridObject}); ...
        handle.listener(obj, obj.findprop('RowGap'), 'PropertyPostSet', {@i_setgap, obj.gridObject, 'gapy'}); ...
        handle.listener(obj, obj.findprop('ColumnGap'), 'PropertyPostSet', {@i_setgap, obj.gridObject, 'gapx'}); ...
        handle.listener(obj, obj.findprop('ScrollBarStyle'), 'PropertyPostSet', @i_setupGrid_InternalCall); ...
        handle.listener(obj, obj.findprop('TopLeftCorner'), 'PropertyPostSet', @i_setItemAtTL); ...
        handle.listener(obj, obj.findprop('TopRightCorner'), 'PropertyPostSet', @i_setItemAtTR); ...
        handle.listener(obj, obj.findprop('BottomLeftCorner'), 'PropertyPostSet', @i_setItemAtBL); ...
        handle.listener(obj, obj.findprop('BottomRightCorner'), 'PropertyPostSet', @i_setItemAtBR); ...
        handle.listener(obj, obj.findprop('EmptyTableComponent'), 'PropertyPostSet', @i_setupGrid_InternalCall); ...
        handle.listener(obj, obj.findprop('ColumnHeaderPosition'), 'PropertyPostSet', @i_setupGrid_InternalCall); ...
    ];


function i_setCellSize(src, evt)
evt.AffectedObject.pPostSetPosition([]);

function i_setCurCol(src, evt, hScroll)
set(hScroll, 'Value', evt.NewValue);


function i_setCurRow(src, evt, hScroll)
set(hScroll, 'Value', -evt.NewValue);


function i_setScrRowLims(src, evt, hScroll)
obj = evt.AffectedObject;
slims = obj.ScrollRowLimits;
if all(slims==0) || all(slims==1)
    set(hScroll, 'Min', -2, 'Max', -1, 'SliderStep', [1 1]);
else
    szData = obj.getVisibleSize;
    set(hScroll, 'Min', -slims(2), 'Max', -slims(1), 'SliderStep', [1,  szData(1)]/(slims(2)-slims(1)));
end


function i_setScrColLims(src, evt, hScroll)
obj = evt.AffectedObject;
slims = obj.ScrollColumnLimits;
if all(slims==0) || all(slims==1)
    set(hScroll, 'Min', 1, 'Max', 2, 'SliderStep', [1 1]);
else
    szData = obj.getVisibleSize;
    set(hScroll, 'Min', slims(1), 'Max', slims(2), 'SliderStep', [1,  szData(2)]/(slims(2)-slims(1)));
end


function i_setupGrid(src, evt)
src.doSetupGrid;


function i_setupGrid_InternalCall(src, evt)
evt.AffectedObject.doSetupGrid;


function i_setRowHeaderWidth(src, evt, hGrid)
obj = evt.AffectedObject;
if evt.NewValue<1
    obj.RowHeaderWidth = 1; 
end
newval = max(1, evt.NewValue);

sz = get(hGrid, 'colsizes');
if length(sz) && obj.ShowColumnHeaders
    if sz(1)>0
        sz(1) = newval;
    end
    set(hGrid, 'colsizes', sz);
end


function i_setColHeaderWidth(src, evt, hGrid)
obj = evt.AffectedObject;
if evt.NewValue<1
    obj.ColumnHeaderWidth = 1; 
end
newval = max(1, evt.NewValue);

sz = get(hGrid, 'rowsizes');
if length(sz) && obj.ShowColumnHeaders
    if strcmp(obj.ColumnHeaderPosition, 'top')
        if sz(1)>0
            sz(1) = newval;
        end
    else
        if sz(end-1)>0
            sz(end-1) = newval;
        elseif sz(end)>0
            sz(end) = newval;
        end
    end
    set(hGrid, 'rowsizes', sz);
end


function i_setScrollWidth(src, evt, hGrid)
obj = evt.AffectedObject;
if evt.NewValue<1
    obj.ScrollbarWidth = 1; 
end
newval = max(1, evt.NewValue);

szrow = get(hGrid, 'rowsizes');
szcol = get(hGrid, 'colsizes');
if length(szrow) && length(szcol)
    if strcmp(obj.ColumnHeaderPosition, 'top')
        if szrow(end)>0
            szrow(end) = newval;
        end
    else
        if (obj.ShowColumnHeaders && szrow(end-1)>0) || (~obj.ShowColumnHeaders && szrow(end)>0)
            szrow(end) = newval;
        end
    end
    if szcol(end)>0
        szcol(end) = newval;
    end
    set(hGrid, 'rowsizes', szrow, 'colsizes', szcol);
end


function i_setItemAtTL(src, evt)
evt.AffectedObject.doTLComp;

function i_setItemAtTR(src, evt)
evt.AffectedObject.doTRComp;

function i_setItemAtBL(src, evt)
evt.AffectedObject.doBLComp;

function i_setItemAtBR(src, evt)
evt.AffectedObject.doBRComp;


function i_setgap(src, evt, hGrid, prop)
set(hGrid, prop, evt.NewValue);
evt.AffectedObject.pPostSetPosition;