gusucode.com > vision工具箱matlab源码程序 > vision/+vision/+internal/+cascadeTrainer/+tool/CategoryDlg.m
% Copyright 2014 The MathWorks, Inc. classdef CategoryDlg < vision.internal.uitools.OkCancelDlg properties VarName; end properties(Access=private) Prompt = getString(message('vision:trainingtool:CategoryPrompt'));; EditBox; PromptX = 10; EditBoxX = 110; end methods %------------------------------------------------------------------ % CategoryDlg create a dialog to for creating or renaming an ROI label % CategoryDlg(groupName, dlgType) returns a dialog for creating % or renaming an ROI label. groupName is the app toolgroup used % for positioning the dialog. dlgType is the type of the dialog % specified as a string. Possible values are 'add' and 'rename'. function this = CategoryDlg(groupName, dlgType) switch dlgType case 'add' dlgTitle = vision.getMessage('vision:trainingtool:CategoryTitle'); case 'rename' dlgTitle = vision.getMessage('vision:trainingtool:RenameCategoryTitle'); end this = this@vision.internal.uitools.OkCancelDlg(... groupName, dlgTitle); this.DlgSize = [250, 90]; createDialog(this); addParamsVarPrompt(this); addParamsVarEditBox(this); % Set focus to the edit box. uicontrol(this.EditBox); end end methods(Access=private) %------------------------------------------------------------------ function addParamsVarPrompt(this) % Prompt uicontrol('Parent',this.Dlg,'Style','text',... 'Position',[this.PromptX, 48, 200, 20], ... 'HorizontalAlignment', 'left',... 'String', this.Prompt); end %------------------------------------------------------------------ function addParamsVarEditBox(this) this.EditBox = uicontrol('Parent', this.Dlg,'Style','edit',... 'String',this.VarName,... 'Position', [this.EditBoxX, 47, 125, 25],... 'HorizontalAlignment', 'left',... 'BackgroundColor',[1 1 1], ... 'Tag', 'varEditBox'); % Handle pressing of 'return' or 'escape' key while typing into % the edit box. this.EditBox.KeyPressFcn = @this.onKeyPressEditBox; end end methods(Access=protected) %------------------------------------------------------------------ function onKeyPressEditBox(this, ~, evd) switch(evd.Key) case 'return' onOK(this); case 'escape' onCancel(this); end end %------------------------------------------------------------------ function onOK(this, ~, ~) drawnow(); this.VarName = get(this.EditBox, 'String'); if ~isvarname(this.VarName) errordlg(getString(message('vision:uitools:invalidCategoryVariable'))); else this.IsCanceled = false; close(this); end end end end