www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprecfloat/generateEditorPages.m

    function hInfo = generateEditorPages(~, hPageGroup)
%GENERATEEDITORPAGES Generate a set of dialog pages for precision editing 
%
%  HINFO = GENERATEEDITORPAGES(OBJ, HPAGEGROUP) returns an array of
%  DialogPageInfo objects that describe a set a of panels for editing the
%  precision object.

%  Copyright 2006-2015 The MathWorks, Inc.


hInfo = mbcgui.dialog.PageInfo( ...
    'PageGroup', hPageGroup, ...
    'Name', 'General', ...
    'PreferredWidth', 380, ...
    'PreferredHeight', 420, ...
    'HelpHandler', 'cghelptool', ...
    'HelpCode', 'CGTABLEPROPSPRECISION', ...
    'CreateCallback', @i_createlyt);



function i_createlyt(hInfo, ~)

hParent = hInfo.Parent;
hGroup = hInfo.PageGroup;

ud.hRadios = xregGui.rbgroup('Parent', hParent, ...
    'Visible', 'off', ...
    'nx', 1, 'ny', 3, ...
    'String', {'IEEE double precision'; 'IEEE single precision'; 'Custom precision'}, ...
    'Callback', {@i_Radio, hInfo});
ud.hMantissa = mbcgui.widget.Spinner('Parent', hParent, ...
    'Visible', 'off', ...
    'Rule', 'int', ...
    'Min', 0, ...
    'Callback', {@i_EditBits, hInfo});
ud.hExponent = mbcgui.widget.Spinner('Parent', hParent, ...
    'Visible', 'off', ...
    'Rule', 'int', ...
    'Min', 0, ...
    'Callback', {@i_EditBits, hInfo});
ud.hManLabel = xregGui.labelcontrol('Parent', hParent, ...
    'Visible', 'off', ...
    'String', 'Number of bits for mantissa:', ...
    'LabelSizeMode', 'absolute', ...
    'ControlSizeMode', 'absolute', ...
    'LabelSize', 150, ...
    'ControlSize', 60, ...
    'Control', ud.hMantissa);
ud.hExpLabel = xregGui.labelcontrol('Parent', hParent, ...
    'Visible', 'off', ...
    'String', 'Number of bits for exponent:', ...
    'LabelSizeMode', 'absolute', ...
    'ControlSizeMode', 'absolute', ...
    'LabelSize', 150, ...
    'ControlSize', 60, ...
    'Control', ud.hExponent);

lyt = xreggridbaglayout(hGroup.Parent, ...
    'dimension', [3 2],...
    'rowsizes', [70 20 20],...
    'colsizes', [15 200],...
    'gap', 5, ...
    'mergeblock', {[1 1], [1 2]}, ...
    'elements',{ ud.hRadios, [], [], ...
    [], ud.hManLabel, ud.hExpLabel} );

ud.ObjList = event.listener(hGroup, 'ObjectChanged', @(h,evt) i_update(hInfo));
hInfo.UserData = ud;

i_update(hInfo);

hInfo.setUI(lyt);



function i_update(hInfo)
obj = hInfo.getObject;
ud = hInfo.UserData;

% Set radio button selection correctly
mbits = get(obj, 'mbits');
ebits = get(obj, 'ebits');
if mbits==52 && ebits==11
    ud.hRadios.Selected = 1;
elseif mbits==23 && ebits==8
    ud.hRadios.Selected = 2; 
else
    ud.hRadios.Selected = 3;
end
ud.hMantissa.Value = mbits;
ud.hExponent.Value = ebits;

% Enable/disable the mantissa and exponent
i_enableeditcontrols(hInfo);


function i_enableeditcontrols(hInfo)
obj = hInfo.getObject;
ud = hInfo.UserData;
if get(obj, 'Writable')
    set(ud.hRadios, 'Enable', 'on');
else
    set(ud.hRadios, 'Enable', 'off');
end
i_enablecustom(hInfo);


function i_enablecustom(hInfo)
ud = hInfo.UserData;
obj = hInfo.getObject;
if ud.hRadios.Selected==3 && get(obj, 'Writable')
    set([ud.hManLabel; ud.hExpLabel], 'Enable', 'on');
else
    set([ud.hManLabel; ud.hExpLabel], 'Enable', 'off');
end


function i_Radio(src, evt, hInfo)
i_enablecustom(hInfo);
i_EditBits(src, evt, hInfo);


function i_EditBits(~, ~, hInfo)
ud = hInfo.UserData;
obj = hInfo.getObject;

% Set exponent and mantissa bits
switch ud.hRadios.Selected
    case 1
        % Double
        obj = setPredefined(obj, 'IEEEDouble');
    case 2
        % Single
        obj = setPredefined(obj, 'IEEESingle');   
    otherwise
        obj = set(obj, 'mbits', ud.hMantissa.Value);
        obj = set(obj, 'ebits', ud.hExponent.Value);
end

ud.ObjList.Enabled = false;
hInfo.updateObject(obj);
ud.ObjList.Enabled = true;