www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/mv_designlist.m

    function [out,ok]=mv_designlist(des,str)
% MV_DESIGNLIST   GUI for selecting a subset of designs
%
%   [OUT,OK] = MV_DESIGNLIST(IN,STR) displays a listbox containing the
%   list of designs in IN and allows the user to select a subset
%   which is returned in OUT.  The optional STR is a string to display
%   above the list of designs.  OK indicates whether the OK button was
%   pressed (OK=1) or Cancel (OK=0).
%
%   IN must be an array of xregGui.RunTimePointer's to designs.

%   Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.

% Default outputs
out = [];
ok = 0;

if nargin<2
    str = 'Select the designs by Shift-clicking and Ctrl-clicking:';
end

% ensure des is a cell
if isempty(des)
    des=[];
end

% screen des list to allow only linear designs
keep=false(1,length(des));
for n=1:length(des)
    keep(n)=isoptimcapable(des(n).info);
end
des=des(keep);

% if des is empty then popup a warning dialog.
if isempty(des)
    h=warndlg('There are no designs to choose from!','Warning','modal');
    waitfor(h);
    return
end

dlg = mbcgui.container.Dialog(...
    'Name','Select Designs',...
    'Tag','DesignChooser',...
    'Buttons', 'OK_CANCEL',...
    'Size', [560  230] );
figh = dlg.Figure;

% controls: just a text item and a list
text=uicontrol('Parent',figh,...
    'Style','text',...
    'HorizontalAlignment','left',...
    'String',str);

% list box is set up with icons and multiple columns
list = mbcwidgets.Table1D( 'list', 'Parent', figh, 'SelectionMode', 'MultiRow' );
list.Peer.setColumnData( {'Name','Design Type','Number of Points'} );
list.Peer.setColumnWidths( [150 200 100]);

% add each design
icons = cell( length(des), 1 );
listData = cell( length(des), 3 );
for n=1:length(des)
    % dereference the pointer
    d=des(n).info;
    d=setlock(d,0);
    icons{n} = xregrespath( iconfile(d) );
    listData(n,:) = {name(d), getstyleinfo(d), npoints(d)};
end
list.Peer.setData( listData, icons );

% Sort by design name
list.Peer.setSortBy( 0, 1 );

% And select the first one
list.selectRows( 1 );

dlg.Content = xreggridbaglayout( figh,...
    'Dimension', [2 1],...
    'RowSizes', [25, -1],...
    'Elements', {text; list} );

closeMode = dlg.showDialog();

if strcmp(closeMode,'OK')
    % get selected indices
    inds = list.getSelectedRows();
    if ~isempty( inds )
        out = des(inds);
        ok = 1;
    end
end
delete(dlg);