www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/+xregdesgui/DesignList.m
classdef DesignList < mbcgui.widget.Component %xregdesgui.DesignList class extends mbcgui.widget.Component % xregdesgui.DesignList properties: % Parent - Property is of type 'MATLAB array' (read only) % Position - Property is of type 'rect' % Visible - Property is of type 'on/off' % Designs - Property is of type 'MATLAB array' % SelectedIndex - Property is of type 'MATLAB array' % SelectedDesigns - Property is of type 'MATLAB array' (read only) % Copyright 2015-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet, SetObservable) %DESIGNS Property is of type 'MATLAB array' Designs = { }; %SELECTEDINDEX Property is of type 'MATLAB array' SelectedIndex = [ ]; end properties (Access=protected, AbortSet) %HLIST Property is of type 'handle' hList = []; %HIL Property is of type 'handle' hIL = []; %HLISTENERS Property is of type 'handle vector' hListeners = []; end properties (SetAccess=protected, AbortSet) %SELECTEDDESIGNS Property is of type 'MATLAB array' (read only) SelectedDesigns = { }; end events DesignSelected end % events methods % constructor block function obj = DesignList(varargin) %DESIGNLIST Constructor for designList object % % OBJ = DESIGNLIST(PROP, VAL, ...) constructs a designList object which is % used for presenting a flat list of design objects in GUIs. obj@mbcgui.widget.Component(varargin{:}) obj.hList= mbcwidgets.List('Parent',obj.Parent,... 'IconLocation',xregrespath,... 'Grid',true,... 'IconTransparentColor',[0 255 0],... 'SelectionMode','MultiRow',... 'SelectionChangedCallback',{@i_listSelectionCallback, obj}); heads = {'Name','Design Type','Number of Points'}; w = [150 200 100]; obj.hList.setColumnData(heads); obj.hList.setColumnWidths(w); % Update selected designs field obj.pSelectDesigns; % Initialize list obj.pDrawList; % Set up listeners obj.hListeners = [... event.proplistener(obj, obj.findprop('Designs'), 'PostSet', @i_setDesigns); ... event.proplistener(obj, obj.findprop('SelectedIndex'), 'PostSet', @i_setSelectedIdx); ... ]; end % designList end % constructor block methods function set.Designs(obj,value) obj.Designs = i_ensurecell(obj,value); end function set.SelectedIndex(obj,value) obj.SelectedIndex = i_ensurevect(obj,value); end function set.hList(obj,value) % DataType = 'handle' validateattributes(value,{'handle'}, {'scalar'},'','hList') obj.hList = value; end function set.hIL(obj,value) % DataType = 'handle' validateattributes(value,{'handle'}, {'scalar'},'','hIL') obj.hIL = value; end function set.hListeners(obj,value) % DataType = 'handle vector' validateattributes(value,{'handle'}, {'vector'},'','hListeners') obj.hListeners = value; end end % set and get functions methods % public methods %---------------------------------------- function pCheckSelection(obj) %PCHECKSELECTION Make sure that selected indices are valid % PCHECKSELECTION(OBJ) private method to check that the selection indices % are correct. [obj.hListeners.Enabled]=deal(false); obj.SelectedIndex = obj.SelectedIndex(obj.SelectedIndex<=length(obj.Designs)); [obj.hListeners.Enabled]=deal(true); end % pCheckSelection %---------------------------------------- function pDrawList(obj) %PDRAWLIST Refresh the list % PDRAWLIST(OBJ) is a private method that redraws the list of designs. % add each design Data = cell(length(obj.Designs),3); Icons = cell(length(obj.Designs),1); for n=1:length(obj.Designs) d=setlock(obj.Designs{n},0); Icons{n} = iconfile(d); Data{n,1}=name(d); Data{n,2} = getstyleinfo(d); Data{n,3} = npoints(d); end obj.hList.Peer.setData(Data,Icons); obj.hList.selectRows(obj.SelectedIndex); end % pDrawList %---------------------------------------- function pSelectDesigns(obj) %PSELECTDESIGNS Update selected designs property % PSELECTDESIGNS(OBJ) is a private method for updating the SelectedDesigns % property. obj.SelectedDesigns = obj.Designs(obj.SelectedIndex); end % pSelectDesigns %---------------------------------------- function pSetSelection(obj, idx) %PSETSELECTION Set new selection in object % PSETSELECTION(OBJ, IDX) is a private method to set a new selection in % the object without firing any actions as a result of this. [obj.hListeners.Enabled]=deal(false); obj.SelectedIndex = idx(idx<=length(obj.Designs)); [obj.hListeners.Enabled]=deal(true); end % pSetSelection end % public methods methods(Access=protected) function setPosition(obj,pos) obj.hList.Position = pos; end function setVisible(obj,vis) obj.hList.Visible = vis; end end end % classdef function val = i_ensurecell(~, val) if isempty(val) val = {}; elseif iscell(val) val = val(:)'; else error(message('mbc:xregdesgui:designList:InvalidPropertyValue')); end end % i_ensurecell function val = i_ensurevect(obj, val) if isnumeric(val) val = double(val(:)'); if isempty(obj.Designs) if ~isempty(val) error(message('mbc:xregdesgui:designList:InvalidPropertyValue1')); end else if ~(all(val<=length(obj.Designs)) && all(val>=1)) error(message('mbc:xregdesgui:designList:InvalidPropertyValue2')); end end else error(message('mbc:xregdesgui:designList:InvalidPropertyValue3')); end end % i_ensurevect function i_listSelectionCallback(src, ~, obj) idx = src.getSelectedRows; obj.pSetSelection(idx); obj.pSelectDesigns; notify(obj, 'DesignSelected',xregEventData(idx)); end % i_listSelectionCallback function i_setDesigns(~, evt) % Make sure that all selections are in the correct range obj = evt.AffectedObject; obj.pCheckSelection; obj.pSelectDesigns; obj.pDrawList; end % i_setDesigns function i_setSelectedIdx(~, evt) % Update the selected design list obj = evt.AffectedObject; obj.pSelectDesigns; obj.pDrawList; end % i_setSelectedIdx