www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetgui/@table/table.m

    function obj = table(varargin)
%TABLE Constructor for cgdatasetgui.table object
%
%  OBJ = TABLE(PROP, VAL, ...)

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


if length(varargin) && isa(varargin{1}, 'cgdatasetgui.table')
    obj = varargin{1};
    varargin(1) = [];
else
    obj = cgdatasetgui.table;
end

% Call super-class constructor
obj.Table2D(com.mathworks.toolbox.mbc.gui.peer.DatasetTablePeer, varargin{:});

% Attach listener for column header highlighting.
obj.addListeners(handle.listener(obj.Peer, 'HighlightRequested',  {@i_highlight, obj}));

% Attach to data edited callback
obj.addListeners(handle.listener(obj, 'ValueChanged', {@i_datachanged, obj}));

% Attach to asynchronous data requests
obj.addListeners(handle.listener(obj.Peer, 'DataRequested',  {@i_sendnewdata, obj}));
obj.addListeners(handle.listener(obj.Peer, 'CopyRequested',  {@i_copydata, obj}));
obj.addListeners(handle.listener(obj.Peer, 'PasteRequested', {@i_pastedata, obj}));

% Check whether the dataset pointer field has been set
if ~isempty(obj.DatasetPointer)
    setDataset(obj.DatasetPointer);
end



function i_sendnewdata(src, evt, obj)
obj.asyncDataRequest(evt.JavaEvent);

function i_copydata(src, evt, obj)
obj.copyRequest(evt.JavaEvent);

function i_pastedata(src, evt, obj)
obj.pasteRequest(evt.JavaEvent);


function i_highlight(src, evt, obj)
column = evt.JavaEvent.getSourceColumn+1;
if length(column)==1 && column>0
    obj.highlightInputs(obj.pConvertDisplayToDataset(column));
else
    % Remove all highlights
    obj.highlightInputs(0);
end


function i_datachanged(src, evt, obj)
% The dataset needs to re re-evaluated and then the table updated
pDataset = obj.DatasetPointer;
hDataset = pDataset.info;

% Set a watch pointer to fill the time before the table visibly updates
P = xregGui.PointerRepository;
ptrID = P.stackSetPointer(obj.Parent, 'watch');

rows = evt.Data.Rows;
cols = obj.pConvertDisplayToDataset(evt.Data.Columns);
hDataset = setValueAt(hDataset, rows, cols, evt.Data.NewValue);
pDataset.info = hDataset;

% Tell table to reload its data
obj.refresh;

P.stackRemovePointer(obj.Parent, ptrID);

data = struct('Row', rows, ...
    'Column', cols, ...
    'NewValue', evt.Data.NewValue);
obj.send('DataChanged', xregGui.xregEventData(obj, 'DataChanged', data));