www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@itemList/itemList.m

    function obj = itemList(varargin)
%ITEMLIST Constructor for itemList object
%
%  OBJ = ITEMLIST(PROP, VAL, ...)

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


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

% Call parent class constructor
if ~isempty(varargin)
    obj.abstractlayoutcomponent( varargin{:} );
else
    obj.abstractlayoutcomponent;
end

% Create the Table
obj.Display = mbcwidgets.List(...
    'Parent',   obj.Parent,...
    'Position', obj.Position,...
    'Visible',  obj.Visible,...
    'Enable',   obj.Enable );

% We need to push itemList proerties into the Table1d/Peer.
properties = {...
    'BorderStyle','DisplayChecks',...
    'DisplayHeaderRow', 'DisplayTypeColumn',...
    'ItemColumnWidth', 'ItemHeaderText',...
    'TypeHeaderText', 'Items',...
    'SelectedIndex', 'SelectionStyle',...
    'UIContextMenu'};

% Keep the itemList and Table1D properties in sync.
listeners = repmat( {@iUpdate}, size( properties ) );
L = obj.addPropertyListeners( properties, listeners );

% Store the listener on SelectedIndex so we can disable it.
obj.SelectedIndexListener = L( strcmp( properties, 'SelectedIndex' ) );

% Update the Table and Peer with the initial properties.
obj.pUpdateTable( properties );
obj.Display.Peer.setIconBaseLocation( obj.pListResourceLocation );

% Listen for the Table1D SelectionChanged event
obj.addListeners( handle.listener( obj.Display,      'SelectionChanged', {@i_TableSelectionChanged, obj, obj.SelectedIndexListener} ) );
% Listen for the Peer's ActionPerformed event.
obj.addListeners( handle.listener( obj.Display.Peer, 'ActionPerformed',  {@i_SendOpenEvent, obj} ) );

% Draw the Table.
obj.pDisplay(false);

%--------------------------------
function iUpdate( obj, evt )
obj.pUpdateTable( evt.Source.Name );

%--------------------------------
function i_SendOpenEvent(peer, evt, obj)
% Would prefer to use SelectedIndex here, but it may not have been updated
% yet.
openedIndex = obj.Display.getSelectedRows();
openedItem = obj.Items(openedIndex);
obj.send('Open', xregGui.xregEventData(obj, 'Open', struct('ItemOpened', openedItem)));
    
%--------------------------------
function i_TableSelectionChanged(table1d, evt, obj, hSelectL)

hSelectL.Enabled = 'off';
obj.SelectedIndex = double(evt.data.SelectedDataRows);
hSelectL.Enabled = 'on';

% Fire our own event.
evt = xregGui.xregEventData(obj, 'SelectionChanged', evt.data);
send( obj, 'SelectionChanged', evt );