www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/cgDatasetList.m
classdef cgDatasetList < handle %CGDATASETLIST Java list for use in CAGE Data Sets % L = cgDatasetList(fig,tag,MultiSelect) % Copyright 2009-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetAccess=private) %List mbcwidgets.List Java table object (read only) List %Layout surrounding panel layout (read only) Layout %Tag label to tag object (read only) Tag %Indices indices used to reference CAGE items within data set code (read only) Indices end properties %SelectionCallback selection callback function handle for data sets SelectionCallback %MultiSelect multiple row selection in list MultiSelect=true; end properties(Dependent) %ContextMenu conext menu for main table ContextMenu %Selected selected items in list in Indices basis Selected %SelectedRows row numbers selected in list (read only) SelectedRows %RowCount number of rows in list (read only) RowCount %ColumnCount number of columns in list (read only) ColumnCount %SelectedLabels labels (first column) of selected items in list (read only) SelectedLabels end methods function L = cgDatasetList(parent,tag,MultiSelect) %cgDatasetList constructor % L = cgDatasetList(parent,tag,MultiSelect) if nargin<2 tag = ''; end P = mbcgui.container.titlebarpanel(... 'Parent', parent, ... 'Visible', 'off'); L.List = mbcwidgets.List('Parent',P,... 'SelectionMode','MultiRow',... 'SelectionChangedCallback',{@cbSelection,L},... 'Grid',true,... 'UserData',tag); L.List.Peer.setBorder([]); if nargin>2 L.MultiSelect = MultiSelect; end L.List.Peer.setIconBaseLocation(cgrespath); set(P,'ContentHandle',L.List); L.Layout = P; L.Tag = tag; end function r=get.RowCount(L) r = L.List.getRowCount; end function r=get.ColumnCount(L) r = L.List.getColumnCount; end function sel = get.SelectedRows(L) sel = L.List.getSelectedRows(); end function sel = get.Selected(L) ind = L.List.getSelectedRows(); sel = L.Indices(ind); end function set.ContextMenu(L,um) L.List.TableContextMenu = um; end function um = get.ContextMenu(L) um = L.List.TableContextMenu; end function set.Selected(L,ind) [~,sel]= ismember(ind,L.Indices); L.List.selectRows(sel(sel~=0)); end function labs = get.SelectedLabels(L) ind = L.SelectedRows; if ~isempty(ind) Data = L.List.getData; labs = Data(ind,1); else labs = cell(0,1); end end function set.MultiSelect(L,Mode) L.MultiSelect = Mode; if ~isempty(L.List) if Mode L.List.SelectionMode = 'MultiRow'; %#ok<*MCSUP> else L.List.SelectionMode = 'SingleRow'; %#ok<*MCSUP> end end end function old_sel=deselect(L) %deselect deselect all items in list % old_sel=deselect(L) old_sel=L.Selected; L.Selected = []; end function configureList(L, cols, widths, title, tt) %configureList configure list columns % configureList(L, cols, widths, title, tt) % configureList(L, cols, widths, title) % configureList(L, cols, widths) if nargin<4 title = ''; end if nargin<5 tt = ''; end configureTitle(L,title,tt) L.List.Peer.setStoreSwingCalls(true); L.List.Peer.setColumnData(cols); L.List.Peer.setColumnWidths(widths); if L.MultiSelect L.List.SelectionMode = 'MultiRow'; else L.List.SelectionMode = 'SingleRow'; end L.List.Peer.setStoreSwingCalls(false); % sort by first column sortList(L,1); end function configureExprList(L) %configureExprList main expression list % configureExprList(L) configureList(L,... {'Expression','Type','Information'},... [200,150,400],... ''); end function configureEmptyList(L, msg, title, tt) %configureEmptyList Empty list with message % configureEmptyList(L, msg, title, tt) L.List.Peer.setStoreSwingCalls(true); L.List.Peer.setColumnData(' '); L.List.Peer.setColumnWidths(400); % make sure there are no icons either L.List.Peer.setData({msg},{''}); if nargin>=4 configureTitle(L,title,tt) else configureTitle(L,'','') end % no selection L.List.SelectionMode = 'None'; L.List.Peer.setStoreSwingCalls(false); end function clearList(L) %clearList clear all items in list % clearList(L) if L.List.getRowCount>0 Data = cell(0,L.List.getColumnCount); L.List.Peer.setData(Data,cell(0,1)); end end function configureTitle(L, title, ~) %configureTitle configure title and tooltip in panel layout % configureTitle(L, title, tooltip) % Note that tooltip is no longer used set(L.Layout, 'BarTitle', title); end function refreshList(L, ListData, IconData, Indices, select_index) %refrehList display new data in list % refreshList(L, ListData, IconData, ind, select_index) % ListData: cell array of data % IconData: cell array of icon files for first n columns % Indices: indices used by data set % selected_index: items to select if nargin<4 select_index = []; end if ~L.MultiSelect && isempty(select_index) && ~isempty(ListData) % select first item for non-empty lists select_index = 1; end L.List.Peer.setStoreSwingCalls(true); clearList(L) L.Indices = Indices; L.List.Peer.setData(ListData); for i=1:size(IconData,2) L.List.Peer.setIconData(IconData(:,i),i-1); end L.List.Peer.setStoreSwingCalls(false); if ~isempty(select_index) L.Selected = select_index; end end function sortList(L, col) %sortList sort list by column % sortList(L, col) sortBy(L.List,col); end end end function cbSelection(~,~,L) %cbSelection main selection callback for list d= getViewData(cgbrowser); d.currentlist = L.Tag; if ~isempty(L.SelectionCallback) % call user-defined function d = feval(L.SelectionCallback,d,L.Tag); end setViewData(cgbrowser,d); end