www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcfoundation/@DCTManager/guiJobParameterEditor.m
function [jobParams, OK] = guiJobParameterEditor(jobParams, varargin) %GUIJOBPARAMETEREDITOR Display a dialog for editing DCT Job Parameters. % % [S, OK] = GUIJOBPARAMETEREDITOR(S) displays a dialog that allow the % user to edit the parameters of a DCT job that are in the structure S. % The parameters that are currently supported are AttachedFiles and % AdditionalPaths. % % [...] = GUIJOBPARAMETEREDITOR(S, 'DepFindFcn', FCN) specifies a function % handle that can be called in order to automatically find file % dependencies. % Copyright 2006-2012 The MathWorks, Inc. % Process input options FindFcn = []; for n = 1:2:length(varargin) switch lower(varargin{n}) case 'depfindfcn' FindFcn = varargin{n+1}; end end hFig = xregdialog('Name', 'Parallel Computing Job Parameters'); xregcenterfigure(hFig, [500 300]); sc = xregGui.SystemColorsDbl; udh = xregGui.RunTimePointer; udh.LinkToObject(hFig); % Get existing file and path dependencies if ~isempty(jobParams) FD = jobParams.AttachedFiles; PD = jobParams.AdditionalPaths; else FD = {}; PD = {}; end hOK = uicontrol('Parent', hFig, ... 'String', 'OK', ... 'Style', 'pushbutton', ... 'Callback', @(src, evt) set(hFig, 'Tag', 'ok', 'Visible', 'off')); hCancel = uicontrol('Parent', hFig, ... 'String', 'Cancel', ... 'Style', 'pushbutton', ... 'Callback', @(src, evt) set(hFig, 'Visible', 'off')); % File dependency controls hFDLabel = uicontrol('Parent', hFig, ... 'Style', 'text', ... 'String', 'File dependencies:',... 'HorizontalAlignment', 'left'); hFDList = uicontrol('Parent', hFig, ... 'Style', 'listbox',... 'String', FD, ... 'BackgroundColor', sc.WINDOW_BG); hFDRemove = uicontrol('Parent', hFig, ... 'String', 'Remove', ... 'Style', 'pushbutton', ... 'Callback', {@i_RemoveFromList, hFDList}); hFDAdd = uicontrol('Parent', hFig, ... 'String', 'Add...', ... 'Style', 'pushbutton', ... 'Callback', {@i_AddToList, hFDList, 'file'}); if ~isempty(FindFcn) hFDFind = uicontrol('Parent', hFig, ... 'String', 'Find', ... 'Style', 'pushbutton', ... 'Callback', {@i_FindDependencies, hFDList, FindFcn}); else hFDFind = []; end % Path Dependency controls hPDLabel = uicontrol('Parent', hFig, ... 'Style', 'text', ... 'String', 'Path dependencies:',... 'HorizontalAlignment', 'left'); hPDList = uicontrol('Parent', hFig, ... 'Style', 'listbox',... 'String', PD,... 'BackgroundColor', sc.WINDOW_BG); hPDRemove = uicontrol('Parent', hFig, ... 'String', 'Remove', ... 'Style', 'pushbutton', ... 'Callback', {@i_RemoveFromList, hPDList}); hPDAdd = uicontrol('Parent', hFig, ... 'String', 'Add...', ... 'Style', 'pushbutton', ... 'Callback', {@i_AddToList, hPDList, 'path'}); L = xreggridbaglayout(hFig, ... 'packstatus', 'off', ... 'dimension', [19 3], ... 'rowsizes', [15, 2, 25, 7, 25, 7, 25, -1, 10, 15, 2, 25, 7, 25, 7, 25, -1, 10, 25], ... 'colsizes', [-1, 65, 65], ... 'gapx', 7, ... 'border', [7 7 7 7], ... 'mergeblock', {[3 8],[1,2]},... 'mergeblock', {[12,17],[1,2]},... 'elements', {hFDLabel,[],hFDList,[],[],[],[],[],[],hPDLabel,[],hPDList,[],[],[],[],[],[],[],... [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],hOK,... [],[],hFDAdd,[],hFDRemove,[],hFDFind,[],[],[],[],hPDAdd,[],hPDRemove,[],[],[],[],hCancel}); hFig.LayoutManager = L; set(L, 'packstatus', 'on'); % Disable the Remove buttons if there isn't anything in the list if isempty(get(hFDList,'String')) set(hFDRemove, 'Enable', 'off') end if isempty(get(hPDList, 'String')) set(hPDRemove, 'Enable', 'off') end % Set up listeners that will disable remove buttons when lists are empty List = [... mbcgui.hgclassesutil.proplistener(hFDList, 'String', 'PostSet', mbcutils.callback(@i_checkRemove, hFDRemove)); ... mbcgui.hgclassesutil.proplistener(hPDList, 'String', 'PostSet', mbcutils.callback(@i_checkRemove, hPDRemove)); ... ]; %#ok<NASGU> hFig.showDialog(hOK); OK = strcmpi(get(hFig, 'Tag'), 'ok'); if OK jobParams.AttachedFiles = get(hFDList, 'String'); jobParams.AdditionalPaths = get(hPDList, 'String'); end hFig.delete; function i_checkRemove(~, evt, hRemove) S = get(evt.AffectedObject, 'String'); if isempty(S) set(hRemove, 'Enable', 'off'); else set(hRemove, 'Enable', 'on'); end function i_AddToList(~, ~, list, type) currStr = get(list, 'String'); currInd = get(list, 'Value'); % If we've got an item selected then get it if ~isempty(currStr) currItem = currStr{currInd}; else currItem = ''; end % If we've got an item set the dialog's startpath to it if ~isempty(currItem) startpath = currItem; else startpath = ''; end % If we're adding file dependencies use the file selection dialog, else if % we are adding path dependencies use the directory selection dialog. if strcmp(type, 'file') [file, path] = uigetfile('', 'Select File Dependency', startpath, 'MultiSelect', 'on'); elseif strcmp(type, 'path') file = ''; path = uigetdir(startpath, 'Select Path Dependency'); end % If the user didn't hit cancel, add the dependency to the list if ~(isequal(file,0) || isequal(path,0)) if iscell(file) addStr = file; addStr = cellfun(@(str) [path str], addStr, 'UniformOutput', false); else addStr = {[path,file]}; end Keep = ~ismember(addStr, currStr); KeepStr = addStr(Keep); currStr = [currStr; KeepStr(:)]; if any(Keep) % Update list set(list, 'String', currStr); if (currInd==0) set(list, 'Value', 1); end end end function i_RemoveFromList(~, ~, list) currStr = get(list, 'String'); currInd = get(list, 'Value'); if ~isempty(currStr) % Make a new list from all the items other than the one we are removing currStr(currInd) = []; % Listbox doesn't like it's Value to be out of range, so make sure that it % isn't and set it to something sensible if isempty(currStr) currInd = 0; elseif currInd > length(currStr) currInd = length(currStr); end set(list, 'String', currStr, 'Value', currInd); end function i_FindDependencies(~, ~, list, FindFcn) Files = FindFcn(); currStr = get(list, 'String'); if ~isempty(Files) % Add file dependencies that are not already there currStr = [currStr; setdiff(Files(:), currStr)]; set(list, 'String', currStr); else h = warndlg('No file dependencies were found.', 'File Dependencies', 'modal'); waitfor(h); end