www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgfeaturenode/private/pHistoryManager.m
function d = pHistoryManager( pFN, d, action, varargin ) %PHISTORYMANAGER Looks after the display of the features history % % VIEWDATA = PHISTORYMANAGER( NODE, VIEWDATA, ACTION, <ARGS> ) % % ACTIONS % DRAWLIST - Clears the list, and then adds all the history items, then % REFRESHDETAILS. (Called by cgfeaturenode/view) % % REFRESHDETAILS - Make sure the details pane is correct (string, color, % enabled) % % DETAILSEDIT - Updates history from new string in details pane % % ADD - Adds a new history item, and then call DRAWLIST % % REMOVE - Removes history itemm then call DRAWLIST, then set selects % correct item % % RENAME - Takes 4th argument - the new name. % Copyright 2000-2012 The MathWorks, Inc. and Ford Global Technologies, Inc. sc = xregGui.SystemColorsDbl; pF = pFN.getdata; Selected = i_getSelectedItem( d ); H = pF.get('History'); lengthH =length(H); switch action case 'drawlist' d = iDrawList(lengthH,H,pFN,d); case 'refreshdetails' iRefreshDetails(Selected,lengthH,H,d,sc); case 'detailsedit' if ~isempty( Selected ) index = i_ListIndex2HistoryIndex( Selected, lengthH ); H{index}.Details = get(d.Handles.Details,'String'); pF.info = pF.set('history',H); end case 'rename' index = i_ListIndex2HistoryIndex( varargin{2}, lengthH ); H{index}.Comment = varargin{1}; pF.info = pF.set('history',H); case 'add' comment = 'New'; details = ''; pF.info = pF.addhistoryitem(comment, details); d = pHistoryManager( pFN, d, 'drawlist' ); case 'remove' d = iRemove(lengthH,pF,H,pFN,d,Selected); end % ------------------------------------------- function i_setSelectedItem( d, index ) % ------------------------------------------- if index>1 d.Handles.History.selectRows(index); end % ------------------------------------------- function Selected = i_getSelectedItem( d ) % ------------------------------------------- % Refresh details display Selected = d.Handles.History.getSelectedRows; % ------------------------------------------- function historyIndex = i_ListIndex2HistoryIndex( listindex, lengthH ) % ------------------------------------------- indexmap = lengthH:-1:1; historyIndex = indexmap( listindex ); function d = iDrawList(lengthH,H,pFN,d) % Fill the history box Data = cell(lengthH,2); if ~isempty(H) set(d.Handles.HistoryDelete,'Enable','on'); for ind =1:lengthH Data{ind,1} = H{ind}.Comment; Data{ind,2} = H{ind}.Time; end % make sure the latest Item is Selected, and Visible d.Handles.History.setData(flipud(Data)); d.Handles.History.selectRows(1); pos = d.Handles.History.Position; H = pos(4)-2; W = pos(3)-2; if ((lengthH+1)*17) > H SCROLLBAR_WIDTH = javax.swing.UIManager.get('ScrollBar.width'); % Make room for the vertical scrollbar W = W - SCROLLBAR_WIDTH; end d.Handles.History.ColumnWidths = [W-120,120]; else d.Handles.History.Peer.setData(Data); end d = pHistoryManager( pFN, d, 'refreshdetails' ); function iRefreshDetails(Selected,lengthH,H,d,sc) if ~isempty(Selected) index = i_ListIndex2HistoryIndex( Selected, lengthH ); set(d.Handles.Details,'String',H{index}.Details,... 'Enable','on',... 'BackgroundColor',sc.WINDOW_BG); else set(d.Handles.Details,'String','',... 'Enable','off',... 'BackgroundColor',sc.CTRL_BG); end function d = iRemove(lengthH,pF,H,pFN,d,Selected) if isempty(Selected) d = pMessage(d,'Select one or more history record log numbers to remove'); return end index = i_ListIndex2HistoryIndex( Selected, lengthH ); H(index) = []; pF.info = pF.set('History',H); % now refresh the list d = pHistoryManager( pFN, d, 'drawlist' ); i_setSelectedItem( d, Selected - 1 );