www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgexprgui/@InputSelector/InputSelector.m

    function obj = InputSelector(varargin)
%INPUTSELECTOR Create a new InputSelector object
%
%  OBJ = INPUTSELECTOR(Prop, Value, ...) creates a new InputSelector
%  object.  This object lets the user match up available expression objects
%  to a set list of named slots.
%
%  The InputSelector object allows several ways of specifying lists of
%  items to choose from.  These are spcified by using one of the following
%  in a cell of the ListPointers property:
%
%  + String         : One of 'models', 'variables', 'tables',
%                     'normalizers'.
%  + Pointer vector : A list of expressions to display for this option.
%  + Callback       : A callback that takes a handle to the object as the
%                     source and returns a list of expression pointers.
%                     Note that the source object contains a reference to a
%                     project which can be used to provide customized
%                     lists.

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


if nargin && isa(varargin{1}, 'cgexprgui.InputSelector')
   obj = varargin{1};
   varargin(1) = [];
else
   obj = cgexprgui.InputSelector;
end

% Call parent class constructor
obj.abstractlayoutcomponent(varargin{:});

SC = xregGui.SystemColorsDbl;
obj.hSelList = cgexprgui.NamedList('Parent', obj.Parent, ...
    'Visible', obj.Visible, ...
    'Items', obj.InputNames, ...
    'ExpressionPointers', obj.InputPointers, ...
    'SelectedIndex', 1, ...
    'ItemHeaderText', 'Input Name');
obj.hAvailList = cgtools.exprList('Parent', obj.Parent, ...
    'Visible', obj.Visible, ...
    'ItemColumnWidth', 0.6);
obj.hSelButton = uicontrol('Parent', obj.Parent, ...
    'Style', 'Pushbutton', ...
    'Visible', obj.Visible, ...
    'String', '< Select', ...
    'Callback', {@i_select, obj, obj.hAvailList, obj.hSelList});
obj.hDeselButton = uicontrol('Parent', obj.Parent, ...
    'Style', 'Pushbutton', ...
    'Visible', obj.Visible, ...
    'String', 'Deselect', ...
    'Callback', {@i_deselect, obj, obj.hSelList});
obj.hFilterPopup = uicontrol('Parent', obj.Parent, ...
    'Style', 'Popupmenu', ...
    'Visible', obj.Visible, ...
    'BackgroundColor', SC.WINDOW_BG, ...
    'String', {' '}, ...
    'Value', 1, ...
    'Callback', {@i_filterchange, obj});

lyt = xreggridbaglayout(obj.Parent, ...
    'dimension', [7, 3], ...
    'rowsizes', [20 2 -1 25 7 25 -1], ...
    'colsizes', [-1 70 -1], ...
    'colratios', [4 0 5], ...
    'gapx', 10, ...
    'position', obj.Position, ...
    'mergeblock', {[1 7], [1 1]}, ...
    'mergeblock', {[3 7], [3 3]}, ...
    'elements', {obj.hSelList, [], [], [], [], [], [], ...
    [], [], [], obj.hSelButton, [], obj.hDeselButton, [], ...
    obj.hFilterPopup, [], obj.hAvailList});
obj.Display = lyt;

obj.pSetFilters;
obj.pFillSourceList;
obj.pEnableButtons;

L = obj.addPropertyListeners( ...
    { ...
    'InputNames', ...
    'InputPointers', ...
    'ListNames', ...
    'ListPointers', ...
    'Project', ...
    }, ...
    { ...
    {@i_setsellist, obj.hSelList, 'Items'}, ...
    {@i_setsellist, obj.hSelList, 'ExpressionPointers'}, ...
    @i_setfilterstr, ...
    @i_setfiltervals, ...
    @i_setfiltervals, ...
    } ...
    );
set(L, 'CallbackTarget', obj);


L = [ ...
    handle.listener(obj.hSelList, 'SelectionChanged', {@i_sellistclick, obj.hAvailList, obj.hSelList}), ...
    handle.listener(obj.hAvailList, 'SelectionChanged', @i_availlistclick), ...
    handle.listener(obj.hAvailList, 'Open', {@i_listselect, obj, obj.hAvailList, obj.hSelList}), ...
    ];
set(L, 'CallbackTarget', obj);
obj.addListeners(L);



function i_setsellist(obj, evt, hList, ListProp)
set(hList, ListProp, evt.NewValue);
obj.pEnableButtons;

function i_setfilterstr(obj, evt)
obj.pSetFilters;
obj.pFillSourceList;
obj.pEnableButtons;

function i_setfiltervals(obj, evt)
obj.pFillSourceList;
obj.pEnableButtons;

function i_sellistclick(obj, evt, hAvail, hSel)
% Update selection in source list and check enable state of buttons
hAvail.SelectedItems = hSel.getCurrentExpression;
obj.pEnableButtons;

function i_availlistclick(obj, evt)
obj.pEnableButtons;


function i_select(src, evt, obj, hAvail, hSel)
idx = hSel.SelectedIndex;
if ~isempty(hAvail.SelectedItems)
    obj.InputPointers(idx) = hAvail.SelectedItems(1);
end

function i_deselect(src, evt, obj, hSel)
idx = hSel.SelectedIndex;
obj.InputPointers(idx) = mbcpointer(1);

function i_filterchange(src, evt, obj)
obj.pFillSourceList;

function i_listselect(src, evt, obj, hAvail, hSel)
% On a double click, do a selection then also move the list selection down
i_select(src, evt, obj, hAvail, hSel);
hSel.incrementSelection;