www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregdatagui/DataInfoView.m

    classdef DataInfoView < xregdatagui.AbstractDataView
%xregdatagui.DataInfoView class
%   xregdatagui.DataInfoView extends xregdatagui.AbstractDataView.
%
%    xregdatagui.DataInfoView 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'  
%       Display - Property is of type 'MATLAB array' (read only) 
%       MessageService - Property is of type 'handle' (read only) 
%       UIContextMenu - Property is of type 'MATLAB array'  
%       Listeners - Property is of type 'handle vector' (read only) 
%       InfoAxes - Property is of type 'MATLAB array' (read only) 
%       FileInfoList - Property is of type 'MATLAB array' (read only) 
%       RecordPatches - Property is of type 'MATLAB array' (read only) 
%       VariablePatches - Property is of type 'MATLAB array' (read only) 
%       TestPatches - Property is of type 'MATLAB array' (read only) 
%
%    xregdatagui.DataInfoView methods:
%       pCreateDisplay - A short description of the function
%       pssFilenameChangedUpdate - A short description of the function
%       pssNamesChangedUpdate - pNamesChangedUpdate updates the view on receipt of a "ssNamesChanged"
%       pssRecordsChangedUpdate - updates the view on receipt of a "RecordsChanged"
%       pssTestsChangedUpdate - PRECORDSCHANGEDUPDATE updates the view on receipt of a "RecordsChanged"


properties (Constant)
    %ViewInfo view description
    ViewInfo = { @xregdatagui.DataInfoView;
        '&Data Summary';
        xregrespath('surfviewer.bmp');
        'Data Summary';
        1};
end

properties (SetAccess=protected, AbortSet, SetObservable)
    %INFOAXES Property is of type 'MATLAB array' (read only)
    InfoAxes = [];
    %FILEINFOLIST Property is of type 'MATLAB array' (read only)
    FileInfoList = [];
    %RECORDPATCHES Property is of type 'MATLAB array' (read only)
    RecordPatches = [];
    %VARIABLEPATCHES Property is of type 'MATLAB array' (read only)
    VariablePatches = [];
    %TESTPATCHES Property is of type 'MATLAB array' (read only)
    TestPatches = [];
    TabLayout = [];
    %DataSummary summary statistics
    DataSummary
end


    methods  % constructor block
        function [obj] = DataInfoView(varargin)
        %DATAINFOVIEW A short description of the function
        %
        %  OUT = DATAINFOVIEW(VARARGIN)
        %  
        
        % Call the inherited constructor
        obj@xregdatagui.AbstractDataView(varargin{ : }); % converted super class constructor call

        % Construct the display
        obj.pCreateDisplay;
        
        % Update the display if we've just been created
        %obj.pUpdateDisplay;
        end  % datainfoview
        
    end  % constructor block

    methods 
    end   % set and get functions 

    methods  % public methods
        %----------------------------------------
       function pCreateDisplay(obj)
       %PCREATEDISPLAY A short description of the function
       %
       %  PCREATEDISPLAY(OBJ)
       %  
       
       f = mbcgui.container.layoutpanel('Parent',obj.Parent);
       
       

       % summary layout
       RED   = [0.8  0  0];
       GREEN = [0   .8 .4];
       BLUE  = [0    0  1];
       
       topLeftPanel = mbcgui.container.layoutpanel(...
           'Parent', f,...
           'BorderType', 'etchedin');
       
       if obj.MessageService.HasExtras
           tabLabels = {'Summary','Statistics','Variables','Filters','Test Variables','Test Filters','Test Notes'};
       else
           tabLabels = {'Summary','Statistics','Variables','Filters','Test Filters','Test Notes'};
       end

       tablyt = uitabgroup('Parent',topLeftPanel,'Units','pixels');
       tabs = gobjects(1,length(tabLabels));
       for i=1:length(tabLabels)
          tabs(i) = mbcgui.container.uitab('Parent',tablyt,...
              'Title',tabLabels{i});
       end
       
       obj.TabLayout = tablyt;
       
       btRed = uicontrol('Parent',tabs(1),...
           'Style','frame',...
           'Enable','off',...
           'BackgroundColor',RED);
       btGreen = uicontrol('Parent',tabs(1),...
           'Style','frame',...
           'Enable','off',...
           'BackgroundColor',GREEN);
       btBlue = uicontrol('Parent',tabs(1),...
           'Style','frame',...
           'Enable','off',...
           'BackgroundColor',BLUE);
       
       txRed = mbcgui.widget.Label('Parent',tabs(1),...
           'HorizontalAlignment','left',...
           'String', 'Data removed');
       txGreen = mbcgui.widget.Label('Parent',tabs(1),...
           'HorizontalAlignment','left',...
           'String','Data remaining');
       txBlue = mbcgui.widget.Label('Parent',tabs(1),...
           'HorizontalAlignment','left',...
           'String','Variables added');
       
       axesPanel = mbcgui.widget.AxesContainer(...
           'Parent',tabs(1),...
           'PositionSetting','outer');       
       
       obj.InfoAxes = axesPanel.AxesHandle;
       
       set(obj.InfoAxes,...
           'YTickLabel',{'' '' ''},...
           'Box','off',...
           'Color','none',...
           'Layer', 'top',...
           'TickLength', [0 0],...
           'YLim',[-2.5 2.5],...
           'XLim', [0 1],...
           'YTick', [-1.5 0 1.5],...
           'XLimMode','auto');
       
       % Create the patchs to display the information
       obj.RecordPatches = [ patch('Parent', obj.InfoAxes, ...
               'FaceColor', GREEN, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4); ...
               patch('Parent', obj.InfoAxes, ...
               'FaceColor', RED, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4) ];
       
       obj.VariablePatches = [ patch('Parent', obj.InfoAxes, ...
               'FaceColor', GREEN, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4); ...
               patch('Parent', obj.InfoAxes, ...
               'FaceColor', BLUE, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4) ];
       
       obj.TestPatches = [ patch('Parent', obj.InfoAxes, ...
               'FaceColor', GREEN, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4); ...
               patch('Parent', obj.InfoAxes, ...
               'FaceColor', RED, ...
               'EdgeColor', 'k', ...
               'Vertices', zeros(4, 2), ...
               'Faces', 1:4) ];
       
       topGridLayout = xreggridbaglayout(tabs(1),...
           'packgroup', 'xregdatagui.datainfoview',...
           'packstatus','off',...
           'dimension', [3 7],...
           'rowsizes', [80 15,-1],...
           'colsizes', [15 90 15 90 15 90 -1],...
           'gapx',3,...
           'border', [3 3 3 3], ...
           'mergeblock',{[1 1],[1 7]},...
           'elements', {axesPanel btGreen,[],...
               [] txGreen,[], ...
               [] btRed,[], ...
               [] txRed,[], ...
               [] btBlue,[], ...
               [] txBlue,[]});
           
       tabs(1).LayoutComponent = topGridLayout;    
      
       % summary statistics list
       obj.DataSummary = xregdatagui.SweepsetList('Parent', tabs(2),...
           'Editable', false);
       obj.DataSummary.MultiSelect = true;

       S = obj.DataSummary.getStandardColumnFunctions;
       obj.DataSummary.setColumnHeaders({S.Min S.Max S.Mean S.Std},...
           {'Min', 'Max', 'Mean', 'Std. Dev'}, [65 65 65 65]);
       
       tabs(2).LayoutComponent = obj.DataSummary;    
       
       % Variables, filters, etc.
       v = xregdatagui.VariableListView('Parent',tabs(3),...
           'MessageService',obj.MessageService);
       tabs(3).LayoutComponent = v;    
       % filters
       v = xregdatagui.FilterListView('Parent',tabs(4),...
           'MessageService',obj.MessageService);
       tabs(4).LayoutComponent = v;    

       if obj.MessageService.HasExtras
           % test variables
           pos = 5;
           v = xregdatagui.SweepVariableListView('Parent',tabs(pos),...
               'MessageService',obj.MessageService);
           tabs(pos).LayoutComponent = v;
       else
           pos = 4;
       end
       
       % Test filters
       v = xregdatagui.SweepFilterListView('Parent',tabs(pos+1),...
           'MessageService',obj.MessageService);
       tabs(pos+1).LayoutComponent = v;    

       % test notes
       v = xregdatagui.SweepNoteListView('Parent',tabs(pos+2),...
           'MessageService',obj.MessageService);
       tabs(pos+2).LayoutComponent = v;

       set(topLeftPanel, 'LayoutComponent', {tablyt});
       
       frame = mbcgui.container.layoutpanel(...
           'Parent', f,...
           'BorderType', 'etchedin', ...
           'LayoutBorder', [1 2 1 2]);
       sweepsetInfoText = mbcgui.widget.Label(...
           'Parent', frame,...
           'String', ' Source files',...
           'HorizontalAlignment', 'left');
       set(frame, 'LayoutComponent', {sweepsetInfoText});
       
       obj.FileInfoList = uicontrol('Style','list',...
           'Parent', f,...
           'Enable', 'inactive',...
           'BackgroundColor', [1 1 1]);
       
       grid = xreggridbaglayout(f,...
           'packgroup', 'xregdatagui.datainfoview',...
           'dimension', [2 2],...
           'rowsizes', [21 -1], ...
           'colratios', [0.65 0.35],...
           'gapx', 2, ...
           'gapy', -2, ...
           'mergeblock', {[1 2], [1 1]}, ...
           'elements', {topLeftPanel, [], frame, obj.FileInfoList},...    
           'visible', obj.Visible,...
           'position', obj.Position,...
           'packstatus', 'on');
       
       set(f,'LayoutComponent',grid)
       obj.ContentHandle = f;
       
       end  % pCreateDisplay
       
       %----------------------------------------
       function pssFilenameChangedUpdate(obj, ~,~)
       %PSSFILENAMECHANGEDUPDATE A short description of the function
       %  OUT = PSSFILENAMECHANGEDUPDATE(IN)
       
       % Get the sweepset
       ss = obj.MessageService.sweepset;
       % Set the filenames - make sure only the first is selected
       set(obj.FileInfoList, ...
           'String', get(ss, 'FileName'), ...
           'Value', 1);
       
       end  % pssFilenameChangedUpdate
       
       %----------------------------------------
       function pssNamesChangedUpdate(obj, ~,~)
       %pNamesChangedUpdate updates the view on receipt of a "ssNamesChanged"
       %event from the DMS
       %  pNamesChangedUpdate(OBJ)
       
       % Get the sweepset and sweepsetfilter
       ss  = obj.MessageService.Sweepset;
       ssf =  obj.MessageService.SweepsetFilter;
       
       % How many variables are there?
       numTotal = size(ss, 2);
       
       % How many come from the sweepsetfilter
       variables = get(ssf, 'variables');
       numFromSSF = sum([variables.OK]);
       
       numFromSS = numTotal - numFromSSF;
       
       Y_TOP = 0.6;
       Y_BOT = -0.6;
       
       % Lets plot these on the axes
       set(obj.VariablePatches, {'Vertices'}, ...
           {[0 Y_BOT; numFromSS Y_BOT; numFromSS Y_TOP; 0 Y_TOP];
           [numFromSS Y_BOT; numTotal Y_BOT; numTotal Y_TOP; numFromSS Y_TOP]});
       
       YL = get(obj.InfoAxes, 'YTickLabel');
       YL{2} = sprintf('%d + %d variables', numFromSS, numFromSSF);
       set(obj.InfoAxes, 'YTickLabel', YL);
       
       end  % pssNamesChangedUpdate
       
       %----------------------------------------
       function pssRecordsChangedUpdate(obj, ~,~)
       %PSSRECORDSCHANGEDUPDATE updates the view on receipt of a "RecordsChanged"
       %event from the DMS
       %  PSSRECORDSCHANGEDUPDATE(OBJ)
       
       % Get the sweepset and sweepsetfilter
       ss  = obj.MessageService.Sweepset;
       ssf = obj.MessageService.SweepsetFilter;
       [~, ~, originalSS] = getOriginal(ssf);
       
       % How many records are there?
       numFromSS = size(ss, 1);
       
       % How many in the original - note that for a sweepset data object this
       % would return zero and so we will take the max of numFromSS and the
       % original size
       numTotal = max(size(originalSS, 1), numFromSS);
       
       Y_TOP = 2.1;
       Y_BOT = 0.9;
       
       % Lets plot these on the axes
       set(obj.RecordPatches, {'Vertices'}, ...
           {[0 Y_BOT; numFromSS Y_BOT; numFromSS Y_TOP; 0 Y_TOP];
           [numFromSS Y_BOT; numTotal Y_BOT; numTotal Y_TOP; numFromSS Y_TOP]});
       
       YL = get(obj.InfoAxes, 'YTickLabel');
       YL{3} = sprintf('%d / %d records', numFromSS, numTotal);
       set(obj.InfoAxes, 'YTickLabel', YL);
       
       end  % pssRecordsChangedUpdate
       
       %----------------------------------------
       function pssTestsChangedUpdate(obj, ~, ~)
       %PRECORDSCHANGEDUPDATE updates the view on receipt of a "RecordsChanged"
       %event from the DMS
       %  PRECORDSCHANGEDUPDATE(OBJ)
 
       % Get the sweepset and sweepsetfilter
       ss  = obj.MessageService.Sweepset;
       ssf =  obj.MessageService.SweepsetFilter;
       
       % How many tests are there?
       numFromSS = size(ss, 3);
       
       % How many are removed by the sweepsetfilter
       numRemovedBySSF = length(get(ssf, 'removedsweeps'));
       % If its a tssf then we need to include the tests that have been excluded
       % in the tssf as well
       if obj.MessageService.isaTSSF
           numFromSSF = size(get(ssf, 'actualdata'), 3);
           numRemovedBySSF = numFromSSF - numFromSS + numRemovedBySSF;
       end
       
       numTotal = numFromSS + numRemovedBySSF;
       
       Y_TOP = -0.9;
       Y_BOT = -2.1;
       
       % Lets plot these on the axes
       set(obj.TestPatches, {'Vertices'}, ...
           {[0 Y_BOT; numFromSS Y_BOT; numFromSS Y_TOP; 0 Y_TOP];
           [numFromSS Y_BOT; numTotal Y_BOT; numTotal Y_TOP; numFromSS Y_TOP]});
       
       YL = get(obj.InfoAxes, 'YTickLabel');
       YL{1} = sprintf('%d / %d tests', numFromSS, numTotal);
       set(obj.InfoAxes, 'YTickLabel', YL);
       
       end  % pTestsChangedUpdate
       
       function pDataTransformed(obj,~,~)
       % update tab labels for filters, variables etc.
       
       obj.DataSummary.Sweepset = obj.MessageService.Sweepset;
       
       ssf =  obj.MessageService.SweepsetFilter;
       isTwoStage = ~obj.MessageService.isOneStage;
       Labels = {obj.TabLayout.Children.Title};
       Color = {obj.TabLayout.Children.ForegroundColor};
       [Labels{3},Color{3}] = getTabLabel(ssf,'Variables','variables');
       [Labels{4},Color{4}] = getTabLabel(ssf,'Filters','filters');
       if obj.MessageService.HasExtras
           pos = 5;
           [Labels{pos},Color{pos}] = getTabLabel(ssf,'Test Variables','sweepvariables',isTwoStage);
       else
           pos = 4;
       end
       [Labels{pos+1},Color{pos+1}] = getTabLabel(ssf,'Test Filters','sweepfilters',isTwoStage);
       [Labels{pos+2},Color{pos+2}] = getTabLabel(ssf,'Test Notes','sweepnotes',isTwoStage);

       
       [obj.TabLayout.Children.Title] = Labels{:};
       [obj.TabLayout.Children.ForegroundColor] = Color{:};
       
       
       end
       
end  % public methods 


    methods (Hidden) % possibly private or hidden
        %----------------------------------------
       function pPostSetDataMessageService(obj, ~)
       %PPOSTSETDATAMESSAGESERVICE 
       %  PPOSTSETDATAMESSAGESERVICE(OBJ, EVENT)
       
       % Call the super pPostSetDataMessageService
       pPostSetDataMessageService@xregdatagui.AbstractDataView(obj);
       dms = obj.MessageService;

       dmsListeners = [...
               event.listener(dms, 'ssfVariablesChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssfFiltersChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssfSweepVariablesChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssfSweepFiltersChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssfSweepNotesChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssDataChanged', @obj.pDataTransformed);...
               event.listener(dms, 'ssRecordsChanged', @obj.pssRecordsChangedUpdate);...
               event.listener(dms, 'ssNamesChanged',   @obj.pssNamesChangedUpdate);...
               event.listener(dms, 'ssTestsChanged',   @obj.pssTestsChangedUpdate);...
               event.listener(dms, 'ssFilenameChanged',@obj.pssFilenameChangedUpdate);...        
           ];
       
       obj.Listeners = [obj.Listeners(:); dmsListeners(:)];
       end  % pPostSetDataMessageService
       
end  % possibly private or hidden 

end  % classdef


function [Label,Color] = getTabLabel(ssf,Label,Property,isTwoStage)
%getTabLabel add number of items and error flag to tab label
if nargin<4
    % for expressions that don't depend on two-stage data 
    isTwoStage = true;
end
f = get(ssf,Property );
Color = 'k';
if ~isempty(f)
    % add number of items
    Label = sprintf('%s (%d)',Label,length(f));
    if ~all([f.OK]) || ~isTwoStage 
        % indicate that there is an error in one of the expressions
        Color = 'r';
    else
        Color = 'k';
    end
end

end