www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph1d/prefsgui.m
function gr=prefsgui(gr) %PREFSGUI GUI for altering graph1d appearance % % GR=PREFSGUI(GR) opens up a modal dialog offering a range of options % for altering the appearance of the 1D graph object GR. Options available % include: General colours, optional histogram, histogram colours and % histogram gridline style. % Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc. gr=i_createfig(gr); function gr=i_createfig(gr) figh = xregdialog('name','1D Graph Options',... 'resize','off'); xregcenterfigure(figh, [290 360]); [lyt, pUD] = i_createlyt(figh,gr); % ok and cancel buttons okbtn = uicontrol('Style','pushbutton',... 'Parent',figh,... 'Position',[0 0 65 25],... 'String','OK',... 'Callback', {@i_ok, pUD}); cancbtn = uicontrol('Style','pushbutton',... 'Parent',figh,... 'Position',[0 0 65 25],... 'String','Cancel',... 'Callback',@(s,e) set(figh, 'Tag', 'cancel', 'Visible', 'off')); applybtn = uicontrol('Style','pushbutton',... 'Parent',figh,... 'Position',[0 0 65 25],... 'String','Apply',... 'Callback',@(s,e) i_apply(pUD)); flw=xregflowlayout(figh, ... 'orientation','right/center',... 'elements',{applybtn,cancbtn,okbtn}, ... 'gap',7, ... 'border',[0 0 -7 0]); main=xregborderlayout(figh, ... 'center',lyt, ... 'south',flw, ... 'innerborder',[10 45 10 10]); figh.LayoutManager = main; set(main, 'packstatus', 'on'); figh.showDialog(okbtn); % output is simply the input object delete(figh); function i_ok(src, evt, pUD) i_apply(pUD); ud = pUD.info; set(ud.figure, 'Tag', 'ok', 'Visible', 'off'); function [lyt,pUD]=i_createlyt(figh,gr) pUD = xregGui.RunTimePointer; pUD.LinkToObject(figh); objud = get(gr.axes, 'UserData'); % general options frm1=mbcgui.container.layoutpanel(... 'Parent', figh, ... 'Title','General',... 'BorderType', 'etchedin', ... 'LayoutBorder',[10 7 10 2]); txt(1)=uicontrol('Style','text',... 'Parent',frm1,... 'Position',[0 0 100 15],... 'String','Axes color:',... 'HorizontalAlignment','left'); 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)) ']'],... 'Position',[0 0 75 20],... 'Callback',{@i_editchcol, pUD, 'gen.axcol.push'}); ud.gen.axcol.push=uicontrol('Style','togglebutton',... 'Value',0,... 'Position',[0 0 30 20],... 'BackgroundColor',ud.axcol,... 'Callback',{@i_interactivechcol, pUD, 'gen.axcol.edit'},... 'Parent',frm1); txt(2)=uicontrol('Style','text',... 'Parent',frm1,... 'Position',[0 0 100 15],... 'String','Plot color:',... 'HorizontalAlignment','left'); ud.lncol=get(gr.line,'MarkerFaceColor'); ud.gen.lncol.edit=uicontrol('Style','edit',... 'Parent',frm1,... 'BackgroundColor','w',... 'String',['[' num2str(ud.lncol(1)) ' ' num2str(ud.lncol(2)) ' ' num2str(ud.lncol(3)) ']'],... 'Position',[0 0 75 20],... 'Callback',{@i_editchcol, pUD, 'gen.lncol.push'}); ud.gen.lncol.push=uicontrol('Style','togglebutton',... 'Value',0,... 'Position',[0 0 30 20],... 'BackgroundColor',ud.lncol,... 'Callback',{@i_interactivechcol, pUD, 'gen.lncol.edit'},... 'Parent',frm1); % set up layouts for general frame flw2=xregflowlayout(frm1,'orientation','left/center','gap',5,... 'elements',{txt(1) ud.gen.axcol.edit ud.gen.axcol.push}); flw3=xregflowlayout(frm1,'orientation','left/center','gap',5,... 'elements',{txt(2) ud.gen.lncol.edit ud.gen.lncol.push}); grd=xreggridbaglayout(frm1,'dimension',[2 1],'elements',{flw2 flw3}); set(frm1, 'LayoutComponent', {grd}); % histogram options frm2=mbcgui.container.layoutpanel(... 'Parent', figh, ... 'Title','Histogram',... 'BorderType', 'etchedin', ... 'LayoutBorder',[10 10 10 5]); ud.hist.usehist=uicontrol('Style','checkbox',... 'Parent',frm2,... 'String','Show degeneracy histogram',... 'Position',[0 0 200 20],... 'Value',objud.HistOptions.Show); txt(1)=uicontrol('Style','text',... 'Parent',frm2,... 'Position',[0 0 80 15],... 'String','Number of bars:',... 'HorizontalAlignment','left'); numbars = objud.HistOptions.NumBars; if isempty(numbars) auto=1; str='50'; else auto=0; str=num2str(numbars); end ud.hist.numbars=uicontrol('Style','edit',... 'Parent',frm2,... 'Position',[0 0 50 20],... 'String',str,... 'UserData',str,... 'BackgroundColor','w',... 'Callback',{@i_checknumbars, pUD}); ud.hist.autobars=uicontrol('Style','togglebutton',... 'Parent',frm2,... 'Position',[0 0 40 20],... 'String','Auto',... 'Value',auto,... 'Callback',{@i_autobars, pUD}); if auto set(ud.hist.numbars,'Enable','off'); end div1=xregGui.dividerline(frm2); if strcmp(get(gr.hist.axes,'YGrid'),'on') val=1; else val=0; end ud.hist.usegrid=uicontrol('Style','checkbox',... 'Parent',frm2,... 'String','Show gridlines',... 'Position',[0 0 200 20],... '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:',... 'Position',[0 0 80 15],... 'Enable',en); val=zeros(2,2); st=get(gr.hist.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, ... 'string',{'solid','dashed';'dotted','dash-dot'},... 'value',val,'position',[0 0 140 40]); div2=xregGui.dividerline(frm2); txt(2)=uicontrol('Style','text',... 'Parent',frm2,... 'HorizontalAlignment','left',... 'String','Bar colors:',... 'Position',[0 0 70 15]); ud.barcol = objud.HistOptions.Colours; val=zeros(1,2); if size(ud.barcol,1)==1 val(1)=1; vis='off'; str='Color:'; ud.barcol=[ud.barcol;0 0 0]; else val(2)=1; vis='on'; str='Top color:'; end ud.hist.barcolor.radios=xregGui.rbgroup(frm2,'nx',2,'ny',1,'value',val,'string',{'Solid','Gradient'},... 'callback',{@i_filltype, pUD},... 'position',[0 0 120 20]); ud.hist.barcolor.text1=uicontrol('Style','text',... 'Parent',frm2,... 'HorizontalAlignment','left',... 'String',str,... 'Position',[0 0 70 15]); ud.hist.barcolor.text2=uicontrol('Style','text',... 'Parent',frm2,... 'HorizontalAlignment','left',... 'String','Bottom color:',... 'Position',[0 0 70 15],... 'Visible',vis); ud.hist.barcolor.edit1=uicontrol('Style','edit',... 'Parent',frm2,... 'BackgroundColor',[1 1 1],... 'String',['[' num2str(ud.barcol(1,1)) ' ' num2str(ud.barcol(1,2)) ' ' num2str(ud.barcol(1,3)) ']'],... 'Position',[0 0 75 20],... 'Callback',{@i_editchcol, pUD, 'hist.barcolor.push1'}); ud.hist.barcolor.edit2=uicontrol('Style','edit',... 'Parent',frm2,... 'BackgroundColor',[1 1 1],... 'String',['[' num2str(ud.barcol(2,1)) ' ' num2str(ud.barcol(2,2)) ' ' num2str(ud.barcol(2,3)) ']'],... 'Position',[0 0 75 20],... 'Callback',{@i_editchcol, pUD, 'hist.barcolor.push2'},... 'Visible',vis); ud.hist.barcolor.push1=uicontrol('Style','toggle',... 'Value',0,... 'Position',[0 0 30 20],... 'BackgroundColor',ud.barcol(1,:),... 'Callback',{@i_interactivechcol, pUD, 'hist.barcolor.edit1'},... 'Parent',frm2); ud.hist.barcolor.push2=uicontrol('Style','toggle',... 'Value',0,... 'Position',[0 0 30 20],... 'BackgroundColor',ud.barcol(2,:),... 'Callback',{@i_interactivechcol, pUD, 'hist.barcolor.edit2'},... 'Parent',frm2,... 'Visible',vis); flw1=xregflowlayout(frm2,'orientation','left/center','gap',5,... 'elements',{txt(1) ud.hist.numbars ud.hist.autobars}); flw2=xregflowlayout(frm2,'orientation','left/top','gap',5,... 'elements',{ud.hist.gridstyletext ud.hist.gridstyle}); flw3=xregflowlayout(frm2,'orientation','left/center','gap',5,... 'elements',{txt(2) ud.hist.barcolor.radios}); flw4=xregflowlayout(frm2,'orientation','left/center','gap',5,... 'elements',{ud.hist.barcolor.text1 ud.hist.barcolor.edit1 ud.hist.barcolor.push1}); flw5=xregflowlayout(frm2,'orientation','left/center','gap',5,... 'elements',{ud.hist.barcolor.text2 ud.hist.barcolor.edit2 ud.hist.barcolor.push2}); grd=xreggridbaglayout(frm2,'dimension',[9 1],... 'rowratios',[1 1 .33 1 1.7 .33 1 1 1],... 'elements',{ud.hist.usehist flw1 div1 ud.hist.usegrid flw2 div2 flw3 flw4 flw5}); set(frm2, 'LayoutComponent', {grd}); lyt=xreggridbaglayout(figh,'dimension',[2 1],... 'rowsizes',[70 -1],'elements',{frm1 frm2},'gap',5); ud.graph = gr; ud.figure = figh; pUD.info = ud; function i_apply(pUD) ud=pUD.info; gr=ud.graph; % update object vis=get(gr,'Visible'); set(gr,'Visible','off'); col=get(ud.gen.axcol.push,'BackgroundColor'); set([gr.axes;gr.hist.axes],{'XColor','YColor','ZColor'},{col,col,col}); set(get(gr.hist.axes,'Title'),'Color',col); set(gr.factortext,'ForegroundColor',col); set(gr.line,'MarkerFaceColor',get(ud.gen.lncol.push,'BackgroundColor')); if get(ud.hist.usehist,'Value') hist='on'; else hist='off'; end set(gr,'histogram',hist); if get(ud.hist.autobars,'Value') nbars='auto'; else nbars=str2num(get(ud.hist.numbars,'String')); end set(gr,'histogrambars',nbars); if get(ud.hist.usegrid,'Value') grid='on'; else grid='off'; end grids={'-',':','--','-.'}; val=get(ud.hist.gridstyle,'Selected'); set(gr.hist.axes,'YGrid',grid,'GridLineStyle',grids{val}); val=get(ud.hist.barcolor.radios,'Selected'); if val==1 % solid col=get(ud.hist.barcolor.push1,'BackgroundColor'); else % gradient col=get([ud.hist.barcolor.push1;ud.hist.barcolor.push2],'BackgroundColor'); col=cat(1,col{:}); end set(gr,'histogramcolor',col); set(gr,'Visible',vis); 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_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_filltype(src, evt, pUD) ud = pUD.info; % make 2 radiobuttons mutually exclusive, change options below sel = ud.hist.barcolor.radios.Selected; if sel==1 str = 'Color:'; vis = 'off'; else str = 'Top color:'; vis = 'on'; end set(ud.hist.barcolor.text1,'String',str) set([ud.hist.barcolor.text2;ud.hist.barcolor.edit2;ud.hist.barcolor.push2],'Visible',vis); function i_autobars(src, evt, pUD) ud = pUD.info; % need to switch number of bars to auto/or normal auto=get(ud.hist.autobars,'Value'); if auto en='off'; else en='on'; end set(ud.hist.numbars,'Enable',en); function i_checknumbars(src, evt, pUD) ud = pUD.info; % check input on numbars edit field n=str2double(get(ud.hist.numbars,'String')); if isnan(n) || n<0 || floor(n)~=n % bad user input. return to previous input set(ud.hist.numbars,'String',get(ud.hist.numbars,'UserData')); else set(ud.hist.numbars,'UserData',num2str(n)); end %======================================================================== % 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