www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgconstraint/editordialog.m

    function [obj, ok] = editordialog(obj, PROJ)
%EDITORDIALOG Create an editor dialog for the constraint
%
%  [OBJ, OK] = EDITORDIALOG(OBJ, PROJ) opens a dialog that lets you edit
%  the settings of this constraint and change the type of constraint to
%  another one.

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


fact = cgexprfactory;
connames = getConstraintNames(fact);
confunc = getConstraintFuncs(fact, address(PROJ));
factoryfuncs = cell(size(confunc));
for n =1:length(factoryfuncs)
    % Absorb argument passed to object creation func
    factoryfuncs{n} = @(dlg) confunc{n}();
end

thisidx = find( strcmp( getconstrainttype( obj ),connames ) );
if isempty(thisidx)
    thisidx = length(connames)+1;
    connames{end+1} = getconstrainttype(obj);
    factoryfuncs{end+1} = obj;
else
    factoryfuncs{thisidx} = obj;
end

hDlg = mbcgui.dialog.MultiObjectDialog( ...
    'Title', 'Edit Constraint', ...
    'ChooserLabel', 'Constraint type:', ...
    'ChooserLabelWidth', 90, ...
    'PageInfoFunction', @(obj, grp) generateEditorPages(obj, grp, PROJ), ...
    'OptionStrings', connames, ...
    'OptionFunctions', factoryfuncs, ...
    'CurrentOption', thisidx, ...
    'DialogPanelSize', [600 360], ...
    'LayoutFunction', @i_createlayout);

ok = hDlg.show;
if ok
    obj = hDlg.Object;
end
delete(hDlg);
end


function L = i_createlayout(hDlg, hChooser, hCards)
hDescrip = axestext(hDlg.Figure, ...
    'visible', 'off', ...
    'verticalalignment','top');
hIcon = mbcgui.widget.Image('Parent', hDlg.Figure, ...
    'Visible', 'off');
hDiv = xregGui.dividerline('parent', hDlg.Figure, ...
    'visible', 'off');
L = xreggridbaglayout(hDlg.Figure, ...
    'dimension', [5 4], ...
    'rowsizes', [0 20 0 2 -1], ...
    'colsizes', [-1 20 330 40], ...
    'gapy', 10, ...
    'mergeblock', {[1 3] [3 3]}, ...
    'mergeblock', {[1 3] [4 4]}, ...
    'mergeblock', {[4 4] [1 4]}, ...
    'mergeblock', {[5 5] [1 4]}, ...
    'elements', {[], hChooser, [], hDiv, hCards, ...
    [], [], [], [], [], ....
    hDescrip, [], [], [], [], ...
    hIcon});

hList = event.listener(hDlg, 'OptionChanged', @i_updateui);
set(L, 'UserData', hList);
    function i_updateui(~, ~)
        if isobject(hDlg.Object)
            hIcon.ImageFile = largeiconfile(hDlg.Object);
            set(hDescrip, 'String', texdescription(hDlg.Object));
        else
            hIcon.ImageFile = '';
            set(hDescrip, 'String', '');
        end
    end
end