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

    classdef BdryPairwiseProjections < xregbdrygui.AbstractBdryView
    %xregbdrygui.BdryPairwiseProjections class
    %   xregbdrygui.BdryPairwiseProjections extends xregbdrygui.AbstractBdryView.
    %
    %    xregbdrygui.BdryPairwiseProjections 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'
    %       hTable - Property is of type 'handle' (read only)
    %       hData - Property is of type 'handle' (read only)
    %
    %    xregbdrygui.BdryPairwiseProjections methods:
    %       gettitle - Return a suitable title for a window
    
    % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (SetAccess=protected, AbortSet)
        %HTABLE Property is of type 'handle' (read only)
        hTable = [];
        %HDATA Property is of type 'handle' (read only)
        hData = [];
    end
    
    
    methods  % constructor block
        function obj = BdryPairwiseProjections( varargin )
        %BDRYPAIRWISEPROJECTIONS Class constructor
        
        % Call the inherited constructor
        obj@xregbdrygui.AbstractBdryView(varargin{ : }); % converted super class constructor call
        
        
        % Instantiate a new a data object for the pairwise projections
        obj.hData = xregbdrygui.BdryPairwiseData;
        obj.hData.MessageService = obj.MessageService;
        
        % Test to display when we can't display the plots
        nodisp = axestext( obj.Parent, ...
            'visible','off', ...
            'string', 'Too few factors for Pairwise Projections', ...
            'horizontalalignment', 'center', ...
            'verticalalignment', 'middle' );
        
        % The main tabel that drives the view
        obj.hTable = mbcgui.widget.ClassicTable( ...
            'Parent',obj.Parent,...
            'ShowRowHeaders',    true, ...
            'ShowColumnHeaders', true,...
            'RowHeaderWidth',    60,...
            'ColumnHeaderWidth', 45,...
            'UseVectorDrawMethod', false,...
            'MainConstructor',   @n_CreateMainObject,...
            'RowConstructor',    @i_CreateRowHeadObject,...
            'ColumnConstructor', @i_CreateColHeadObject, ...
            'MainData',         obj.hData, ...
            'RowHeaderData',    obj.hData,...
            'ColumnHeaderData', obj.hData,...
            'RowGap', 0, 'ColumnGap', 0, ...
            'ColumnHeaderPosition', 'bottom', ...
            'MaximumObjectCacheSize', 15 );
        
        obj.hTable.TopLeftCorner = obj.hTable.newCornerComponent( 'panel' );
        obj.hTable.BottomRightCorner = obj.hTable.newCornerComponent;
        obj.hTable.EmptyTableComponent = nodisp;
        
        % Setup some actions so that the user can change the graph size
        graphSize = mbcgui.actions.ActionGroup( '', '&Graph Size' );
        graphSize.MenuType = 'submenu';
        graphSize.Actions = [
            mbcgui.actions.ToggleAction( @(s, e)n_SetGraphSize( 1,   0 ), '&Display All Graphs' )
            mbcgui.actions.ToggleAction( @(s, e)n_SetGraphSize( 2, 100 ), '&Small' )
            mbcgui.actions.ToggleAction( @(s, e)n_SetGraphSize( 3, 150 ), '&Medium' )
            mbcgui.actions.ToggleAction( @(s, e)n_SetGraphSize( 4, 200 ), '&Large' )
            ];
        resolution = mbcgui.actions.StatefulAction({@i_EditResolution, obj}, 'Set &Resolution...');
        
        obj.Options.Actions = [graphSize resolution];
            function n_SetGraphSize( index, size )
            obj.hTable.MinimumCellSize = [size, size];
            set( graphSize.Actions, 'Selected', false );
            graphSize.Actions(index).Selected = true;
            end
        % Set the default graphs size to medium
        n_SetGraphSize( 3, 150 );
        
        % Set the message service
        obj.pPostSetMessageService;
        
        % Set the table as the main display item for this view
        obj.ContentHandle = obj.hTable;
        
        % We need to draw the constraint and update the table. This is done as a
        % "Post Constraint Change"
        obj.pPostConstraintChange;
        
        %--------------------------------------------------------------------------
        % Functions that construct the display objects
            function h = n_CreateMainObject( P )
            h = xregbdrygui.BdryPairwiseGraph( 'Parent', P, 'Visible', 'off' );
            h.addListener( event.listener( h, 'SelectHighlight', ...
                @(s, evt) obj.pSelectHighlight( evt ) ) );
            end
        
        end % of the main function
        
        
    end  % constructor block
    
    methods
    end   % set and get functions
    
    methods  % public methods
        %----------------------------------------
        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 = 'Pairwise Projections';
        end  % gettitle
        
    end  % public methods
    
    methods (Access=protected)
        %----------------------------------------
        function pPostConstraintChange(obj)
        %PPOSTCONSTRAINTCHANGE Respond to a change in the constraint
        %   PPOSTCONSTRAINTCHANGE(OBJ)
        
        
        PR = xregGui.PointerRepository;
        pID = PR.stackSetPointer(obj.Parent, 'watch');
        
        % Update the stored data
        obj.hData.pPostConstraintChange;
        
        % Update the table, i.e., redraw the graphs
        obj.hTable.update;
        
        PR.stackRemovePointer(obj.Parent, pID);
        
        end  % pPostConstraintChange
        
        %----------------------------------------
        function pPostSetMessageService(obj)
        %PPOSTSETMESSAGESERVICE Respond to change of MessageService
        %  PPOSTSETMESSAGESERVICE(OBJ) is called when the MessageService property
        %  is changed.
        %
        %  See also XREGBDRYGUI.ABSTRACTBDRYSLICE.
        
        
        % Clear the listeners
        obj.clearMessageServiceListeners;
        
        % Add new listeners
        obj.addMessageServiceListener( 'ConstraintChange',        @(src, evt) obj.pPostConstraintChange );
        obj.addMessageServiceListener( 'BoundaryPointsHighlight', @(src, evt) obj.pShowBoundaryPoints );
        obj.addMessageServiceListener( 'ValidationPointsToggled', @(src, evt) obj.pShowValidationPoints );
        
        % Make sure we update the plots
        % -- includes setting the message service in the table data
        obj.pUpdateGraph;
        
        end  % pPostSetMessageService
        
        %----------------------------------------
        function pSelectHighlight(obj, evt)
        %PSELECTHIGHLIGHT Highlights the selected region in all graphs of the view
        %   PSELECTHIGHLIGHT(OBJ, EVENT)
        
        D = evt.Data;
        R = D.YIndex;
        C = D.XIndex;
        D = rmfield(D, {'YIndex', 'XIndex'});
        
        % Update the stored data
        obj.hData.setHighlight(R+1, C, D);
        
        % Update the main part of the table, i.e., redraw the graphs
        obj.hTable.paintMain;
        
        end  % pSelectHighlight
        
        %----------------------------------------
        function pShowBoundaryPoints(obj)
        %PSHOWBOUNDARYPOINTS Set the visibilty of the boundary points in the graph obejcts.
        %   PSHOWBOUNDARYPOINTS(OBJ)
        
        BMS = obj.MessageService;
        hGraphs = obj.hTable.MainObjects;
        if ~isempty( hGraphs ),
            set( hGraphs, 'BoundaryPointsVisible', BMS.BoundaryPointHighlight )
        end
        
        
        end  % pShowBoundaryPoints
        
        %----------------------------------------
        function pShowValidationPoints(obj)
        %PSHOWVALIDATIONPOINTS Set the visibilty of the validation points in the graph obejcts.
        %   PSHOWVALIDATIONPOINTS(OBJ)
        
        BMS = obj.MessageService;
        hGraphs = obj.hTable.MainObjects;
        if ~isempty( hGraphs ),
            set( hGraphs, 'ValidationPointsVisible', BMS.ValidationPointHighlight )
        end
        end  % pShowValidationPoints
        
        %----------------------------------------
        function pUpdateGraph(obj)
        %PUPDATEGRAPH Update the pairwise graphs
        %  PUPDATEGRAPH(OBJ) updates the display
        
        PR = xregGui.PointerRepository;
        ptrID = PR.stackSetPointer(obj.Parent, 'watch');
        
        % Force a table update
        obj.hData.MessageService = obj.MessageService;
        obj.hTable.update;
        
        PR.stackRemovePointer(obj.Parent, ptrID);
        end  % pUpdateGraph 
    end
    
end  % classdef

function h = i_CreateRowHeadObject( P )
h = xregbdrygui.BdryPairwiseHeader( ...
    'Parent', P, ...
    'Visible', 'off', ...
    'Orientation', 'vertical', ...
    'AxisEdgeOffset', 10 );
end

function h = i_CreateColHeadObject( P )
h = xregbdrygui.BdryPairwiseHeader( ...
    'Parent', P, ...
    'Visible', 'off', ...
    'Orientation', 'horizontal', ...
    'AxisEdgeOffset', 15 );
end

function i_EditResolution(~,~,obj)
OK = obj.hData.guiEditResolution;
if OK
    sendEvent( obj.MessageService, 'ConstraintChange' );
end
end