www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+testplan/OptionsPanel.m
classdef OptionsPanel < mbcgui.widget.BasicContainer %mbccrosssectiongui.OptionsPanel Creates an options panel and connects % it with a message service % Copyright 2015 The MathWorks, Inc. properties (Access=private) %Control Contains all controls in the panel Control; %Layout Contains the layout for the panel Layout; %EventListener Holds listeners for the MessageService EventListener; end properties %MessageService Holds an instance of the MessageService MessageService; end events OptionChanged end methods function obj = OptionsPanel(varargin) %OptionsPanel Constructor for a cross section options panel obj@mbcgui.widget.BasicContainer(varargin{:}); obj.Control.confIntCheck = uicontrol('Parent',obj.Parent,... 'Style','checkbox',... 'Visible',obj.Visible,... 'Tag', 'ShowErrorLines', ... 'Callback',{@i_confCheck,obj}, ... 'String','Display confidence level (%):'); obj.Control.confIntValue= uicontrol('Parent',obj.Parent,... 'Visible',obj.Visible ,... 'Style','edit',... 'HorizontalAlignment', 'right', ... 'Callback',{@i_CILevel,obj},... 'BackgroundColor','w',... 'Tag', 'ConfidenceIntervalLevel'); addprop(obj.Control.confIntValue, 'OldValue'); obj.Control.DataPoints=uicontrol('Parent',obj.Parent,... 'Visible',obj.Visible,... 'Style','checkbox',... 'String','Display data points',... 'Tag', 'ShowDataPoints', ... 'Callback',{@i_OptionChanged,obj,'ShowDataPoints'}); obj.Control.ShowConstraints=uicontrol('Parent',obj.Parent,... 'Visible',obj.Visible,... 'Style','checkbox',... 'String','Display boundary constraint',... 'Tag', 'ShowConstraints', ... 'Callback',{@i_OptionChanged,obj,'ShowConstraints'}); obj.Control.ZoomConstraints=uicontrol('Parent',obj.Parent,... 'Visible',obj.Visible,... 'Style','checkbox',... 'String','Zoom to boundary constraint',... 'Tag', 'ZoomConstraints', ... 'Callback',{@i_OptionChanged,obj,'ZoomConstraints'}); obj.Control.ShowCommonYAxis=uicontrol('Parent',obj.Parent,... 'Visible',obj.Visible,... 'Style','checkbox',... 'String','Display common Y limits',... 'Tag', 'ShowCommonYAxis', ... 'Callback',{@i_OptionChanged,obj,'ShowCommonYAxis'}); % elements go in columns obj.Layout=xreggridbaglayout(obj.Parent,... 'border',[10 10 10 10],... 'rowsizes',[18,20,18,18,18,18,-1],... 'colsizes',[-1, 50],... 'Dimension', [7,2], ... 'mergeblock',{[1 1],[1 2]},... 'mergeblock',{[3 3],[1 2]},... 'mergeblock',{[4 4],[1 2]},... 'mergeblock',{[5 5],[1 2]},... 'mergeblock',{[6 6],[1 2]},... 'gapx',10,... 'elements',{... obj.Control.confIntCheck, [],obj.Control.DataPoints, obj.Control.ShowConstraints, obj.Control.ZoomConstraints,obj.Control.ShowCommonYAxis, [], ... [], obj.Control.confIntValue, [], [], [], [],[]}); set(obj.Parent,'LayoutComponent',{obj.Layout}); obj.ContentHandle = obj.Layout; updatePanelValuesFromMessageService(obj) end function updatePanelValuesFromMessageService(obj) %updatePanelValuesFromMessageService update the panel based on % the values in the message service ms = obj.MessageService; obj.Control.confIntCheck.Value = ms.ShowErrorLines; obj.Control.confIntValue.String = num2str(ms.ConfidenceIntervalLevel); obj.Control.confIntValue.OldValue = ms.ConfidenceIntervalLevel; obj.Control.DataPoints.Value = ms.ShowDataPoints; obj.Control.ShowConstraints.Value = ms.ShowConstraints; obj.Control.ZoomConstraints.Value = ms.ZoomConstraints; obj.Control.ShowCommonYAxis.Value = ms.ShowCommonYAxis; setConfIntervalEditEnableStatus(obj) end function setConfIntervalEditEnableStatus(obj) %setConfIntervalEditEnableStatus Sets the enable status of the % confidence interval edit box based on the status of the "show % error lines" checkbox if obj.MessageService.ShowErrorLines set(obj.Control.confIntValue, 'Enable', 'on') else set(obj.Control.confIntValue, 'Enable', 'off') end end function onOptionChanged(obj, ~, ~) %onOptionChanged Function that handles an OptionChanged event % from the message service indicating that a property in the % message service has changed updatePanelValuesFromMessageService(obj); end function set.MessageService(obj, ms) obj.MessageService = ms; obj.EventListener = event.listener(obj.MessageService,'OptionChanged',@obj.onOptionChanged); end end end function i_CILevel(src,~, obj) %i_CILevel callback for when confidence interval value has changed % Check that confidence interval is valid and use it otherwise revert the % value in the edit box newValue = str2double(src.String); confIntValue = obj.Control.confIntValue; if newValue > 0 && newValue <= 100 confIntValue.OldValue = newValue; obj.MessageService.ConfidenceIntervalLevel = newValue; else % reset the value to the previous value confIntValue.String = num2str(confIntValue.OldValue); end end function i_confCheck(src,~,obj) %i_confCheck callback for when the confidence checkbox has changed obj.MessageService.ShowErrorLines = src.Value; setConfIntervalEditEnableStatus(obj) end function i_OptionChanged(~,evt,obj,optionName) %i_OptionChanged callback for when an option changes obj.MessageService.(optionName) = evt.Source.Value; end