www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbccrosssectiongui/AbstractCell.m
classdef AbstractCell < mbcgui.widget.BasicContainer %mbccrosssection.AbstractCell AbstractCell class for a ClassicTable, % contains listeners for Refresh and SliceDragged events % Copyright 2015 The MathWorks, Inc. properties (Access=protected) %Row Row that the cell is in Row = 0; %Column Column that the cell is in Column = 0; %DataModelEventListeners Holds listeners for data model events DataModelEventListeners = []; %DataModel The data model DataModel = []; end events Refresh; SliceDragged; end methods (Abstract, Access=protected) update(obj); dragSlice(obj,src,evt) end methods function obj = AbstractCell(varargin) %AbstractCell Constructor for AbstractCell class, passes % andy input arguments to superclass obj@mbcgui.widget.BasicContainer(varargin{:}); % super class constructor call end function setTableData(obj, R, C, dm) %setTableData Method called by ClassicTable to setup a cell % with its position and data, will also create listeners on % data model and update the cell obj.Row = R; obj.Column = C; obj.DataModel = dm; addDataModelEventListeners(obj); update(obj); end end methods (Access=private) function doUpdate = shouldUpdate(obj,evt) %shouldUpdate Only do update if the object is visible, if the event data % contained a specific row or column this has to match too doUpdate=false; if strcmp(obj.Visible,'on') if any(strcmp(properties(evt),'Data')) if (isfield(evt.Data,'Row') && evt.Data.Row~=obj.Row) ... || (isfield(evt.Data,'Column') && evt.Data.Column~=obj.Column) % don't update if there was a Row/Column specified % that does not match with the current Row/Column doUpdate = false; else doUpdate = true; end else % update if there was no event data doUpdate=true; end end end function onRefresh(obj,~,evt) %onRefresh Handles a Refresh event if shouldUpdate(obj,evt) update(obj); end end function onSliceDragged(obj,src,evt) %onSliceDragged Handles a SliceDragged event if shouldUpdate(obj,evt) obj.dragSlice(src,evt) end end function addDataModelEventListeners(obj) %addDataModelEventListeners Adds listeners for DataModel events dm = obj.DataModel; if isobject(dm) obj.DataModelEventListeners = [... event.listener(dm,'Refresh',@obj.onRefresh),... event.listener(dm,'SliceDragged',@obj.onSliceDragged),... ]; end end end end