www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/+xregdesgui/DesignTable.m
classdef DesignTable < xregdesgui.DesignView %xregdesgui.DesignTable class % xregdesgui.DesignTable extends xregdesgui.DesignView. % % xregdesgui.DesignTable properties: % Parent - Property is of type 'MATLAB array' % Position - Property is of type 'rect' % Enable - Property is of type 'on/off' % Visible - Property is of type 'on/off' % UserData - Property is of type 'MATLAB array' % Tag - Property is of type 'string' % MessageService - Property is of type 'handle' % Options - Property is of type 'handle vector' % Actions - Property is of type 'handle vector' % UIContextMenu - Property is of type 'MATLAB array' % % xregdesgui.DesignTable methods: % canPrint - Check whether component can be printed % gettitle - Return a suitable title for a window % showFilterEditor - display GUI for editing the table's filter % Copyright 2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (Access=public, AbortSet, Hidden) %HTABLE Property is of type 'handle' hTable = []; end methods % constructor block function obj = DesignTable(varargin) %DESIGNTABLE Constructor for designtable object % % H = DESIGNTABLE(PROP, VAL, ...) creates a new designtable object. obj@xregdesgui.DesignView(varargin{ : }); % converted super class constructor call obj.Options.Actions = mbcgui.actions.StatefulAction(@obj.i_valfilter, '&Value Filter...', ... 'Specify filter on values displayed'); jP = com.mathworks.toolbox.mbc.gui.peer.DesignEditorTablePeer; obj.hTable = mbcwidgets.Table2D(jP, ... 'Parent', obj.Parent, ... 'UIContextMenu', obj.UIContextMenu); obj.hTable.ValueChangedCallback = @obj.i_cellchange; obj.Actions.Actions = obj.hTable.CopyPasteActions; pPostSetMessageService(obj) obj.addListeners(handle.listener(obj.hTable.Peer, 'MousePressed', @obj.i_passonbtndown)); obj.ContentHandle = obj.hTable; end end % constructor block methods (Access=private) function i_valfilter(obj, ~, ~) obj.showFilterEditor; end function i_cellchange(obj, ~, evt) obj.pDesignUpdate(evt.data.Rows, evt.data.Columns, evt.data.NewValue); end function i_passonbtndown(obj, ~, ~) obj.notify('ButtonDown', event.EventData); end end methods (Access=protected) % protected methods function setUIContextMenu(obj) if ~isempty(obj.hTable) obj.hTable.UIContextMenu = obj.UIContextMenu; end end end methods % public methods %---------------------------------------- function out = canPrint(obj) %#ok<MANU> %CANPRINT Check whether component can be printed % CANPRINT(OBJ) returns false for the designtable object. out = false; end % canPrint %---------------------------------------- function s = gettitle(obj) %#ok<MANU> %GETTITLE Return a suitable title for a window % GETTITLE(OBJ) returns a string that can be used as a title for the view. s = 'Design Table'; end % gettitle %---------------------------------------- function pDesignUpdate(obj, row, col, newvalue) %PDESIGNUPDATE Update design from table edit % PDESIGNUPDATE(OBJ, row, col, value) executes an edit callback from a % table cell or cells. if obj.hasData Dnew = obj.MessageService.getdesign; Dnew(row, col) = code(model(Dnew), newvalue, col(:)'); obj.disableMessageServiceListeners; obj.MessageService.setdesign(Dnew,'design'); obj.enableMessageServiceListeners; end end % pDesignUpdate %---------------------------------------- function pUpdateData(obj,~, ~) %PUPDATEDATA Update numbers in the table % PUPDATEDATA(OBJ) updates the table display. if obj.hasData d = obj.MessageService.getdesign; fs = invcode(model(d), factorsettings(d)); obj.hTable.Peer.setDesignData(fs, getuserfixed(d), getdatapoint(d), factors(d)); else obj.hTable.Peer.setDesignData([], [], [], {}); end end % pUpdateData %---------------------------------------- function pUpdateLock(obj,~,~) %PUPDATELOCK Update table lock setting % PUPDATELOCK(OBJ) updates the table's editable setting if obj.hasData d = obj.MessageService.getdesign; obj.hTable.Editable = ~getlock(d); else obj.hTable.Editable = false; end end % pUpdateLock %---------------------------------------- function showFilterEditor(obj) %SHOWFILTEREDITOR display GUI for editing the table's filter % % SHOWFILTEREDITOR(OBJ) displays a dialog that allows the user to change % the filter being used on the table cells. sc = xregGui.SystemColorsDbl; figh = xregdialog('name','Table Filter', ... 'resize','off', ... 'tag', 'tableFilterEditor'); xregcenterfigure(figh, [350, 240], obj.Parent); pUD = xregGui.RunTimePointer; pUD.LinkToObject(figh); ud.tablyt = uitabgroup(figh, 'Units', 'pixels', 'Tag', 'TabGroup'); ud.tabBasic = mbcgui.container.uitab('Parent', ud.tablyt, ... 'Title', 'Basic', ... 'LayoutBorder', [15,10,10,10],... 'Tag', 'basicTab'); ud.tabAdvanced = mbcgui.container.uitab('Parent', ud.tablyt, ... 'Title', 'Advanced', ... 'LayoutBorder', [15,10,10,10],... 'Tag', 'advancedTab'); % text fields describing the opptions basictext = uicontrol('Parent', ud.tabBasic, 'Style','text',... 'String',['The "Basic" option will construct a filter which prevents cells',... ' in the table which are equal to the specified value, within the specified',... ' tolerance, from being displayed.'],... 'HorizontalAlignment','left'); advancedtext = uicontrol('Parent', ud.tabAdvanced, 'Style','text',... 'String',['The "Advanced" option will construct a filter using the settings',... ' below. Cells which test true by the filter will not have their values',... ' displayed.'],... 'HorizontalAlignment','left'); divBasic = xregGui.dividerline(ud.tabBasic); divAdvanced = xregGui.dividerline(ud.tabAdvanced); % Basic options ud.basicvalue = mbcgui.widget.Spinner('Parent', ud.tabBasic, ... 'Value', obj.hTable.Peer.getFilterValue); ud.basictol = mbcgui.widget.Spinner('Parent', ud.tabBasic, ... 'Value', obj.hTable.Peer.getFilterTol); basicvalLabel = xregGui.labelcontrol('Parent', ud.tabBasic, ... 'Control', ud.basicvalue, ... 'String', 'Value to filter out:', ... 'Tag', 'filterValue'); basictolLabel = xregGui.labelcontrol('Parent', ud.tabBasic, ... 'Control', ud.basictol, ... 'String', 'Tolerance level:', ... 'Tag', 'filterTol'); % Advanced options ud.advancedvalue = mbcgui.widget.Spinner('Parent', ud.tabAdvanced, ... 'Value', obj.hTable.Peer.getFilterValue,... 'Tag', 'advancedValue'); ud.advancedtol = mbcgui.widget.Spinner('Parent', ud.tabAdvanced, ... 'Value', obj.hTable.Peer.getFilterTol); popval = find( strcmp( obj.hTable.Peer.getFilterType,{ '==', '~=', '<', '<=', '>', '>=' } ) ); if isempty(popval) popval = 1; end ud.advancedtype = uicontrol('Parent', ud.tabAdvanced,'Style','popupmenu',... 'String',{'==','~=','<','<=','>','>='},... 'Value',popval, ... 'BackgroundColor', sc.WINDOW_BG, ... 'Callback',{@i_enabletol, pUD}, ... 'Tag', 'advancedType'); advancedLabel1 = xregGui.labelcontrol('Parent', ud.tabAdvanced, ... 'Control', ud.advancedtype, ... 'ControlSize', 40, ... 'String', 'Exclude values:'); ud.advancedLabel2 = xregGui.labelcontrol('Parent', ud.tabAdvanced, ... 'Control', ud.advancedtol, ... 'String', char(177)); basicGrid = xreggridbaglayout(ud.tabBasic, 'packstatus', 'off', ... 'dimension', [5 2], ... 'rowsizes', [45 2 0 20 20], ... 'gapy', 5, ... 'colsizes', [165 -1], ... 'mergeblock', {[1 1], [1 2]}, ... 'mergeblock', {[2 2], [1 2]}, ... 'elements', {basictext, divBasic, [], basicvalLabel, basictolLabel}); set(basicGrid, 'Visible', 'on'); ud.tabBasic.LayoutComponent = basicGrid; advancedGrid = xreggridbaglayout(ud.tabAdvanced, ... 'dimension',[4 4], ... 'rowsizes', [45 2 10 20], ... 'gapy', 5, ... 'gapx', 5, ... 'colsizes', [130 60 72 -1], ... 'mergeblock', {[1 1], [1 4]}, ... 'mergeblock', {[2 2], [1 4]}, ... 'elements', {advancedtext, divAdvanced, [], advancedLabel1, ... [],[],[], ud.advancedvalue, ... [],[],[], ud.advancedLabel2}); set(advancedGrid, 'Visible', 'on'); ud.tabAdvanced.LayoutComponent = advancedGrid; % Add ok, cancel, apply and a remove filter buttons cancbtn=uicontrol('Parent', figh,'Style','pushbutton',... 'String','Cancel',... 'Callback','set(gcbf, ''visible'', ''off'')'); okbtn=uicontrol('Parent', figh,'Style','pushbutton',... 'String','OK',... 'Callback','set(gcbf, ''tag'', ''ok'', ''visible'', ''off'')'); applybtn=uicontrol('Parent', figh,'Style','pushbutton',... 'String','Apply',... 'Callback',{@i_apply, pUD, obj.hTable}); rembtn=uicontrol('Parent', figh,'Style','pushbutton',... 'String','Remove Filter',... 'Callback',{@i_remove, obj.hTable.Peer}); lyt = xreggridbaglayout(figh, ... 'dimension', [2 5], ... 'rowsizes', [-1 25], ... 'gapy', 10, ... 'border', [7 7 7 7], ... 'gapx', 7, ... 'colsizes', [90 -1 65 65 65], ... 'mergeblock', {[1 1], [1 5]}, ... 'elements', {ud.tablyt, rembtn, [] , [], [], applybtn, [], okbtn, [], cancbtn}); pUD.info = ud; i_enabletol(ud.advancedtype, [], pUD) figh.LayoutManager = lyt; set(lyt, 'packstatus', 'on'); figh.showDialog(okbtn); % get output tg=get(figh,'Tag'); if strcmp(tg, 'ok'); % Apply changes before deleting figure i_apply(applybtn, [], pUD, obj.hTable); end delete(figh); end % showFilterEditor end % public methods methods(Access=protected) %---------------------------------------- function pPostSetMessageService(obj) %PPOSTSETMESSAGESERVICE Respond to change of MessageService % PPOSTSETMESSAGESERVICE(OBJ) is called when the MessageService property % is changed. % Clear the listeners and add new ones obj.clearMessageServiceListeners; if ~isempty(obj.MessageService) obj.addMessageServiceListener( ... [event.listener(obj.MessageService,'DesignChange',@obj.pUpdateData), ... event.listener(obj.MessageService,'LockChange',@obj.pUpdateLock)] ... ); end obj.pUpdateData; obj.pUpdateLock; end % pPostSetMessageService end end % classdef function i_enabletol(src, ~, pUD) ud = pUD.info; if get(src, 'Value') > 2 set(ud.advancedLabel2, 'Enable', 'off'); else set(ud.advancedLabel2, 'Enable', 'on'); end end % i_enabletol function i_apply(~, ~, pUD, tbl) ud = pUD.info; if ud.tablyt.SelectedTab == ud.tabBasic % Basic tbl.Peer.setFilterData('==', ud.basicvalue.Value, ud.basictol.Value); else % Advanced str = get(ud.advancedtype, 'String'); popval = get(ud.advancedtype, 'Value'); tbl.Peer.setFilterData(str{popval}, ud.advancedvalue.Value, ud.advancedtol.Value); end end % i_apply function i_remove(src, ~, tbl) tbl.removeFilter; % Close figure set(get(src, 'Parent'), 'Visible', 'off'); end % i_remove