www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph2d/prefsgui.m

    function gr=prefsgui(gr)
%PREFSGUI Preferences GUI for mvgraph2d objects
%   GUI function for altering general preferences in the mvgraph2d object
%   Usage:
%   PREFSGUI(GR)

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


objud = gr.DataPointer.info;
figh = xregdialog('name','2D Graph Options',...
    'resize','off');
xregcenterfigure(figh, [290 255]);

pUD = xregGui.RunTimePointer;
pUD.LinkToObject(figh);

frm1=mbcgui.container.layoutpanel(...
    'Parent', figh, ...
    'Title','General',...
    'BorderType', 'etchedin', ...
    'LayoutBorder',[10 0 10 5]);
ud.axcol=get(gr.axes,'XColor');
ud.gen.axcol.edit=uicontrol('Style','edit',...
    'Parent',frm1,...
    'BackgroundColor',[1 1 1],...
    'String',['[' num2str(ud.axcol(1)) ' ' num2str(ud.axcol(2)) ' ' num2str(ud.axcol(3)) ']'],...
    'Callback', {@i_editchcol, pUD, 'gen.axcol.push'});
ud.gen.axcol.push=uicontrol('Style','toggle',...
    'Value',0,...
    'BackgroundColor',ud.axcol,...
    'Callback',{@i_interactivechcol, pUD, 'gen.axcol.edit'}, ...
    'Parent',frm1);
txt(1) = xregGui.labelcontrol('parent', frm1, ...
    'string', 'Axes color:', ...
    'controlsize', 75, ...
    'Control', ud.gen.axcol.edit);

ud.lncol=get(gr.line,'MarkerFaceColor');
ud.gen.lncol.edit=uicontrol('Style','edit',...
    'Parent',frm1,...
    'BackgroundColor',[1 1 1],...
    'String',['[' num2str(ud.lncol(1)) ' ' num2str(ud.lncol(2)) ' ' num2str(ud.lncol(3)) ']'],...
    'Callback',{@i_editchcol, pUD, 'gen.lncol.push'});
ud.gen.lncol.push=uicontrol('Style','toggle',...
    'Value',0,...
    'BackgroundColor',ud.lncol,...
    'Callback',{@i_interactivechcol, pUD, 'gen.lncol.edit'},...
    'Parent',frm1);
txt(2) = xregGui.labelcontrol('parent', frm1, ...
    'string', 'Plot color:', ...
    'controlsize', 75, ...
    'Control', ud.gen.lncol.edit);

ud.gen.lnsize.edit=mbcgui.widget.Spinner('Parent', frm1,...
    'Min',1, ...
    'Rule','int',...
    'ClickIncrement',1,...
    'Value',get(gr,'MarkerSize'));
txt(3) = xregGui.labelcontrol('parent', frm1, ...
    'string', 'Plot marker size:', ...
    'controlsize', 75, ...
    'Control', ud.gen.lnsize.edit);


frm2=mbcgui.container.layoutpanel(...
    'Parent', figh, ...
    'Title','Scatter plot',...
    'BorderType', 'etchedin', ...
    'LayoutBorder',[10 7 10 5]);
if objud.grid
    val=1;
else
    val=0;
end
ud.hist.usegrid=uicontrol('Style','checkbox',...
    'Parent',frm2,...
    'String','Show gridlines',...
    'Value',val,...
    'Callback',{@i_usegrid, pUD});
if val
    en='on';
else
    en='off';
end
ud.hist.gridstyletext=uicontrol('Style','text',...
    'HorizontalAlignment','left',...
    'Parent',frm2,...
    'String','Gridline style:',...
    'Enable',en);
val=zeros(2,2);
st=get(gr.axes,'GridLineStyle');
switch lower(st)
    case '-'
        val(1)=1;
    case ':'
        val(2)=1;
    case '--'
        val(3)=1;
    case '-.'
        val(4)=1;
    otherwise
        val(1)=1;
end
ud.hist.gridstyle=xregGui.rbgroup(frm2,'nx',2,'ny',2,'value',val,'string',...
    {'solid','dashed';'dotted','dash-dot'},...
    'enable',en);

% ok and cancel buttons
okbtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'Position',[145 7 65 25],...
    'String','OK',...
    'Callback',{@i_ok, pUD, gr});
cancbtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'Position',[218 7 65 25],...
    'String','Cancel',...
    'Callback',{@i_cancel, figh});
applybtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'Position',[218 7 65 25],...
    'String','Apply',...
    'Callback',{@i_apply, pUD, gr});


grd1 = xreggridbaglayout(frm1, 'packstatus', 'off', ...
    'dimension', [3 2], ...
    'rowsizes', [20 20 20], ...
    'colsizes', [180 30], ...
    'gapx', 5, ...
    'gapy', 3, ...
    'elements', {txt(1), txt(2), txt(3), ud.gen.axcol.push, ud.gen.lncol.push});
set(frm1, 'LayoutComponent', {grd1});
grd2 = xreggridbaglayout(frm2, 'dimension', [2 2], ...
    'rowsizes', [20 40], ...
    'colsizes', [80 -1], ...
    'mergeblock', {[1 1], [1 2]}, ...
    'elements', {ud.hist.usegrid, ud.hist.gridstyletext, [], ud.hist.gridstyle});
set(frm2, 'LayoutComponent', {grd2});
mainlyt = xreggridbaglayout(figh, 'dimension', [3 4], ...
    'rowsizes', [95 -1 25], ...
    'colsizes', [-1 65 65 65], ...
    'gapx', 7, ...
    'gapy', 10, ...
    'border', [10 10 10 10], ...
    'mergeblock', {[1 1], [1 4]}, ...
    'mergeblock', {[2 2], [1 4]}, ...
    'elements', {frm1, frm2, [], [], [], okbtn, [], [], cancbtn, [], [], applybtn});

figh.LayoutManager = mainlyt;
set(mainlyt, 'packstatus', 'on');

ud.figure = figh;
pUD.info = ud;

figh.showDialog(okbtn);

delete(figh);


function i_cancel(src, evt, figh)
set(figh, 'Tag','finished', 'Visible', 'off');

function i_ok(src, evt, pUD, gr)
i_applydata(gr,pUD);
ud = pUD.info;
set(ud.figure,'Tag','finished', 'Visible', 'off');

function i_apply(src, evt, pUD, gr)
i_applydata(gr,pUD);



function i_usegrid(src, evt, pUD)
ud = pUD.info;
% need to enable/disable stuff
if get(ud.hist.usegrid,'Value')
    en='on';
else
    en='off';
end
set(ud.hist.gridstyletext,'Enable',en);
set(ud.hist.gridstyle,'Enable',en);


function i_editchcol(src, evt, pUD, field)
ud = pUD.info;
changeobj=i_getfield(ud,field);
% grab string
str=get(src,'String');
if strcmp(str,'none')
    set(changeobj,'BackgroundColor',get(0,'DefaultUicontrolBackgroundColor'));
else
    col=str2num(str);
    if length(col(:))~=3 || any(col>1 | col<0)
        col = get(changeobj,'BackgroundColor');
        set(src,'String',['[' num2str(col(1)) ' ' num2str(col(2)) ' ' num2str(col(3)) ']']);
    else
        set(changeobj,'BackgroundColor',col);
    end
end


function i_interactivechcol(src, evt, pUD, field)
ud = pUD.info;
changeobj=i_getfield(ud,field);
col=get(src,'BackgroundColor');
col2=uisetcolor(col);
if ~all(col2==col)
    set(src,'BackgroundColor',col2,'Value',0);
    set(changeobj,'String',['[' num2str(col2(1),2) ' ' num2str(col2(2),2) ' ' num2str(col2(3),2) ']']);
else
    set(src,'Value',0);
end


function i_applydata(gr,pUD)
ud = pUD.info;

vis = get(gr, 'Visible');
set(gr,'Visible','off');

col=get(ud.gen.axcol.push,'BackgroundColor');
set([gr.axes;gr.colorbar.axes],{'XColor','YColor','ZColor'},{col,col,col});
set([gr.xtext;gr.ytext],'ForegroundColor',col);
set(gr.line,'MarkerFaceColor',get(ud.gen.lncol.push,'BackgroundColor'));
set(gr.line,'MarkerSize',get(ud.gen.lnsize.edit,'Value'));

if get(ud.hist.usegrid,'Value')
    grd='on';
else
    grd='off';
end
set(gr,'Grid',grd);
grids={'-',':','--','-.'};
val=get(ud.hist.gridstyle,'Selected');
set(gr.axes,'GridLineStyle',grids{val});

set(gr,'Visible',vis);



%========================================================================
% i_getfield......replacement for external getfield
%========================================================================
function [out]=i_getfield(base,ext)
fields = regexp(ext, '(\w+)', 'tokens');
out = base;
for n = 1:length(fields)
    out = out.(fields{n}{1});
end