www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cgoptimgui/OutputList.m

    classdef OutputList < mbcgui.widget.BasicContainer
    %cgoptimgui.OutputList class
    %   cgoptimgui.OutputList extends mbcgui.widget.BasicContainer.
    %
    %    cgoptimgui.OutputList 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'
    %       OutputPointers - Property is of type 'MATLAB array'
    %       SelectedIndex - Property is of type 'MATLAB array'
    %       SelectedOutputs - Property is of type 'MATLAB array'
    %       SelectionStyle - Property is of type 'string'
    
    %  Copyright 2006-2015 The MathWorks, Inc.
    
    properties (AbortSet, SetObservable)
        %OUTPUTPOINTERS Property is of type 'MATLAB array'
        OutputPointers = mbcpointer( 1, 0 );
        %SELECTEDINDEX Property is of type 'MATLAB array'
        SelectedIndex = [];
        %SELECTEDOUTPUTS Property is of type 'MATLAB array'
        SelectedOutputs = [];
        %SELECTIONSTYLE Property is of type 'string'
        SelectionStyle = 'single';
    end
    
    properties (SetAccess=private)
        hTable
    end
    
    events
        SelectionChanged
    end  % events
    
    methods  % constructor block
        function obj = OutputList(varargin)
        %OUTPUTLIST Constructor for OutputList object
        %  OBJ = OUTPUTLIST(PROP, VAL, ...) creates a new OutputList object.  This
        %  object can be used for displaying and selecting lists of optimization
        %  outputs.
        
        % Call parent class constructor
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call
        
        hT = mbcwidgets.Table1D('list', ...
            'Parent', obj.Parent);
        props = {'Name', 'Rows', 'Solutions', ...
            'Free Variables', 'FixedVariables', 'Objectives', 'Constraints'};
        hT.Peer.setColumnData(props);
        hT.Peer.setColumnWidths([150, 60, 60, 100, 100, 100, 100]);
        hT.Peer.setIconBaseLocation(cgrespath);
        i_setTableSelectionStyle(hT, obj.SelectionStyle);
        obj.ContentHandle = hT;
        obj.hTable= hT;
        % Set up property listeners
        L = obj.addPropertyListeners( ...
            { ...
            'SelectionStyle', ...
            'SelectedIndex' ...
            }, ...
            { ...
            {@i_setSelectionStyle, hT}, ...
            {@i_setSelectedIndex, hT}, ...
            } ...
            );
        % need to disable SelectedIndex pointer
        L = obj.addPropertyListeners( 'OutputPointers', {@i_setItems, L{2}} );        
        % Set up listeners on Java list
        obj.addListeners( ...
            handle.listener(hT, 'SelectionChanged', {@i_listitemsel, obj, L{1}}) ...
            );
        
        obj.pDisplay(false);
        end  % OutputList
        
    end  % constructor block
    
    methods
        function set.SelectedIndex(obj,value)
        obj.SelectedIndex = i_setselindex(obj,value);
        end
        
        function value = get.SelectedOutputs(obj)
        value = i_getselitems(obj,obj.SelectedOutputs);
        end
        
        function set.SelectedOutputs(obj,value)
        obj.SelectedOutputs = i_setselitems(obj,value);
        end
        
        function set.SelectionStyle(obj,value)
        obj.SelectionStyle = i_setselectionstyle(obj,value);
        end
        
    end   % set and get functions
    
    methods (Access=protected) 
        %----------------------------------------
        function pDisplay(obj, FROMLIST)
        %PDISPLAY Regenerate list.
        %  PDISPLAY(OBJ) recreates the list from the current OutputObjects property
        %  value.
        
        hT = obj.hTable;
        
        % Get information for items
        info = obj.pListDisplayDetails;
        
        % Default for FROMLIST is true
        if nargin==1
            FROMLIST = true;
        end
        
        obj.pSetListDetails( info );
        
        if FROMLIST
            % Make sure the sorting is re-applied
            hT.Peer.sort();
        else
            % Clear the sorting
            hT.Peer.clearSort();
        end
        
        % Select any selected items
        if ~isempty( obj.SelectedIndex )
            hT.selectRows(obj.SelectedIndex);
        else
            hT.clearSelection();
        end
        
        end  % pDisplay
        
        %----------------------------------------
        function info = pListDisplayDetails(obj)
        %PLISTDISPLAYDETAILS Get the display information for the list
        %  INFO = PLISTDISPLAYDETAILS(OBJ) is called when the list needs
        %  regenerating.  INFO must be a (n-by-8) cell array containing strings
        %  that will be used to construct the list, where n is the length of
        %  obj.OutputObjects.
        
        if ~isempty(obj.OutputPointers)
            Outputs = infoarray(obj.OutputPointers);
        else
            Outputs = {};
        end
        
        info = cell(length(Outputs), 7);
        
        if ~isempty(Outputs)
            % Icons
            info(:, 1) = cellfun(@iconfile, Outputs, 'UniformOutput', false);
            
            % Names
            info(:, 2) = cellfun(@getname, Outputs, 'UniformOutput', false);
            
            % Number of runs and solutions
            info(:, 3) = cellfun(@getNumRuns, Outputs, 'UniformOutput', false);
            info(:, 4) = cellfun(@getNumSolutions, Outputs, 'UniformOutput', false);
            
            % Strings listing names of each type of data column
            info(:, 5) = cellfun(@(x) i_GetContentString(x, 'FreeVars'), Outputs, 'UniformOutput', false);
            info(:, 6) = cellfun(@(x) i_GetContentString(x, 'FixedVars'), Outputs, 'UniformOutput', false);
            info(:, 7) = cellfun(@(x) i_GetContentString(x, 'Objectives'), Outputs, 'UniformOutput', false);
            info(:, 8) = cellfun(@(x) i_GetContentString(x, 'Constraints'), Outputs, 'UniformOutput', false);
        end
        end  % pListDisplayDetails
        
        %----------------------------------------
        function pSetListDetails(obj, info)
        %PSETLISTDETAILS Updates the peer with the list information.
        %   PSETLISTDETAILS(OBJ, INFO)
        
        icons = info(:,1);
        
        % update the Peer
        obj.hTable.Peer.setData( info(:,2:end), icons );
        
        end  % pSetListDetails
        
    end  
    
end  % classdef

function val = i_getselitems(obj, ~)
val = obj.OutputPointers(obj.SelectedIndex);
end  % i_getselitems

function val = i_setselitems(obj, val)
[~, idx] = intersect(obj.OutputPointers, val);
obj.SelectedIndex = idx;
val = [];
end  % i_setselitems

% SelectedIndex property must be a row vector for multiple selection
% SelectedIndex property must be a scalar for single selection
function val = i_setselindex(obj, val)
if ~isempty(val)
    if strcmp(obj.SelectionStyle, 'single')
        val = val(1);
    else
        val = val(:)';
    end
    val = val(val<=length(obj.OutputPointers));
end
end  % i_setselindex

% SelectionStyle must be one of 'single' or 'multiple'
function val = i_setselectionstyle(obj, val)
if ~any(strcmp(val, {'single', 'multiple'}))
    val = obj.SelectionStyle;
end
end  % i_setselectionstyle

function i_setSelectionStyle(~, evt, hT)
i_setTableSelectionStyle(hT, evt.AffectedObject.SelectionStyle);
end  % i_setSelectionStyle

function i_setTableSelectionStyle(hT, SelSetting)
multiSelect = strcmp(SelSetting, 'multiple');
if multiSelect
    hT.SelectionMode = 'MultiRegion';
else
    hT.SelectionMode = 'SingleRow';
end
end  % i_setTableSelectionStyle

function i_setSelectedIndex(~, evt, hT)

NewValue = evt.AffectedObject.SelectedIndex;
if ~isempty( NewValue )
    hT.Peer.selectModelRows( NewValue-1 );
else
    hT.Peer.clearSelection();
end
end  % i_setSelectedIndex

function i_setItems(~, evt, hSelectL)
obj = evt.AffectedObject;
hSelectL.Enabled = false;
obj.SelectedIndex = [];
hSelectL.Enabled = true;
obj.pDisplay(false);
end  % i_setItems

function i_listitemsel(~, evt, obj, hSelectL)
hSelectL.Enabled = false;
obj.SelectedIndex = double(evt.data.SelectedDataRows);
hSelectL.Enabled = true;
obj.notify('SelectionChanged');
end  % i_listitemsel

function S = i_GetContentString(obj, ContentType)
ColNames = getColumnNames(obj, ...
    'OutputFormat', 'cell', 'OutputContents', {ContentType});

S = sprintf('%s, ', ColNames{:});
if ~isempty(S)
    S = S(1:end-2);
end
end  % i_GetContentString