www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+project/ButtonPanel.m
classdef ButtonPanel < mbcgui.multiview.View %ButtonPanel MBCMODEL project button panel % Copyright 2016-2016 The MathWorks, Inc. properties (SetAccess=private) %NextAction uicontrol to display next action NextAction %Buttons array of buttons Buttons end properties (Constant) %AppName name of app (on app toolstrip) AppName = 'MBC Model Fitting'; %AppDescription description of app (on app toolstrip) AppDescription = 'Create experimental designs and statistical models for model-based calibration.'; end properties %Browser browser handle (xregtools.MBrowser) Browser %ShowBrowserButton true=Browser button, false=Home button ShowBrowserButton = true; end methods function obj = ButtonPanel(varargin) %ButtonPanel constructor obj@mbcgui.multiview.View(varargin{:}) % setup actions obj.Actions = mbcmodelview.project.StartActions(obj.Browser,obj.MessageService); create(obj); obj.addListeners(handle.listener(obj.Browser,obj.Browser.findprop('CurrentNode'),'PropertyPostSet',@obj.onNodeUpdated)) obj.addListeners(handle.listener(obj.Browser,obj.Browser.findprop('RootNode'),'PropertyPostSet',@obj.onNodeUpdated)) obj.addListeners(event.listener(obj.MessageService,'NodeUpdated',@obj.onNodeUpdated)) end function update(obj) %update update NextAction String if ~isempty(obj.Browser) && ~isempty(obj.Browser.RootNode) proj = info(obj.Browser.RootNode); if isBlank(proj) % new project - nothing done yet obj.NextAction.String = 'Your project is empty. Design an experiment or import data for modeling.'; elseif numChildren(proj)==0 && ~isempty(dataptrs(proj)) % data but no test plan yet obj.NextAction.String = 'Your project contains data. Now fit models to data.'; else % test plans exist obj.NextAction.String = 'Your project contains test plans. Browse the project to view designs and models, or generate a calibration using models.'; end end end end methods (Access=private) function create(obj) %create create component col = 'w'; pane = mbcgui.container.layoutpanel('Parent',obj.Parent, ... 'BackgroundColor', col, ... 'BorderType', 'beveledin'); obj.NextAction = uicontrol('Parent',pane,... 'Style','text',... 'FontSize',10,... 'BackgroundColor',col,... 'HorizontalAlignment','center',... 'String',''); [hTitleLyt,hDescription] = createTitle(obj,pane); % create mbcImageButtons for each action btnSize = 130; createButtons(obj,pane); hButtonLyt = xreggridbaglayout(pane,... 'dimension',[1 ,length(obj.Buttons)+2],... 'colsizes',[-1 btnSize*ones(1,length(obj.Buttons)) -1],... 'elements',[{[]},obj.Buttons,{[]}],... 'border',[0 0 0 10],... 'gapx',1); hBrowseLyt = createHomeButton(obj,pane); rowSizes = [30 30 20 -1 32 btnSize+20 55 30 -1]; getStartedLyt = xreggridbaglayout(pane,... 'dimension',[length(rowSizes),1],... 'rowsizes',rowSizes,... 'gapy',2,... 'elements',{[],hTitleLyt,hDescription,[],... obj.NextAction,hButtonLyt,hBrowseLyt,... [],[]}); pane.LayoutComponent = getStartedLyt; obj.ContentHandle = pane; end function [buttons] = createButtons(obj,pane) %createButtons create image buttons buttons = obj.Actions.ActionList; obj.Buttons = cell(1,length(buttons)); for i=1:length(buttons) obj.Buttons{i} = mbcImageButton('Parent',pane,... 'Action',buttons(i),... 'Browser',obj.Browser); end end function [hTitleLyt,hDescription] = createTitle(obj,pane) %createTitle create title % title and description ic = mbcgui.widget.IconText('Parent',pane,... 'ImageFile',xregrespath('mbc_app_24.bmp'),... 'String',obj.AppName); hTitleText = uicontrol('Parent',pane,... 'Style','text',... 'BackgroundColor','w',... 'String',obj.AppName,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'FontSize',14); hTitleLyt = xreggridbaglayout(pane,... 'dimension',[1 ,4],... 'colsizes',[-1 24 200 -1],... 'elements',{[],ic,hTitleText,[]},... 'gapx',5); hDescription = uicontrol('Parent',pane,... 'Style','text',... 'BackgroundColor','w',... 'FontSize',10,... 'String',obj.AppDescription); end function hBrowseLyt = createHomeButton(obj,pane) if obj.ShowBrowserButton % Browse Project button browseBtn = uicontrol('Parent',pane,... 'Style','pushbutton',... 'FontSize',10,... 'HorizontalAlignment','center',... 'Callback',@obj.onBrowse,... 'String','Browse Project'); hBrowseLyt = xreggridbaglayout(pane,... 'dimension',[1 ,3],... 'colsizes',[-1 200 -1],... 'elements',{[],browseBtn,[]},... 'border',[0 30 0 0],... 'gapx',1); else % add Home button browseBtn = xregGui.iconuicontrol('Parent',pane,... 'Style','pushbutton',... 'HorizontalAlignment','center',... 'ImageFile',xregrespath('mbc_app_24.bmp'),... 'TransparentColor',[0 255 0],... 'Callback',@obj.onHome,... 'TooltipString','Home'); hBrowseLyt = xreggridbaglayout(pane,... 'dimension',[1 ,3],... 'colsizes',[-1 45 -1],... 'elements',{[],browseBtn,[]},... 'border',[0 0 0 10],... 'gapx',1); end end function onNodeUpdated(obj,~,~) %onNodeUpdated update button panel update(obj); %make sure IsRunning is false on refresh reset(obj.Actions); end function onBrowse(obj,~,~) %onBrowse select brower pane selectHome(obj.Browser,2) end function onHome(obj,~,~) %onHome select home pane selectHome(obj.Browser,1) end end end