www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbccrosssectiongui/ColumnHeader.m
classdef ColumnHeader < mbccrosssectiongui.AbstractCell %mbccrosssectiongui.ColumnHeader class % mbccrosssectiongui.ColumnHeader extends mbccrosssectiongui.AbstractCell. % % mbccrosssectiongui.ColumnHeader properties: % Parent - Property is of type 'MATLAB array' % Position - Property is of type 'rect' % Enable - Property is of type 'on/off' % Visible - Property is of type 'on/off' % Userdata - Property is of type 'MATLAB array' % Tag - Property is of type 'string' % Display - Property is of type 'MATLAB array' (read only) % DisplayYAxisTickMarks - Property is of type 'bool' % WideHeaderMode - Property is of type 'bool' % GraphView - Property is of type 'handle' (read only) % CurrentColumn - Property is of type 'int' (read only) % % mbccrosssectiongui.ColumnHeader methods: % pSetupWideMode - Configure the display according to "Wide Header" setting. % setGraphViewObject - Set the handle to the parent graph view % setInputValue - Display the given input value % update - Scrolling table interface function % Copyright 2014-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet) %WIDEHEADERMODE Property is of type 'bool' WideHeaderMode = false; %DISPLAYYAXISTICKMARKS Property is of type 'bool' DisplayYAxisTickMarks = false; end properties (Access=protected, AbortSet) %HAXIS Property is of type 'handle' hAxis = []; %HBORDER Property is of type 'MATLAB array' hBorder = []; %HVALUEEDITOR Property is of type 'MATLAB array' hValueEditor = []; %HVALUEHIGHLIGHTER Property is of type 'MATLAB array' hValueHighlighter = []; %HLABEL Property is of type 'handle' hLabel = []; %HLABELGRID Property is of type 'MATLAB array' hLabelGrid = []; end properties (Access=private) %GRID Grid = []; end properties (SetAccess=protected, AbortSet) %GRAPHVIEW Property is of type 'handle' (read only) GraphView = []; %CURRENTCOLUMN Property is of type 'int' (read only) CurrentColumn = 0; end methods % constructor block function obj = ColumnHeader(varargin) %ColumnHeader Constructor for RowHeader % % OUT = ColumnHeader(PROP, VAL) creates a new instance of a % ColumnHeader. This object is designed to be used as the column % header in the tradeoff grid of graphs. % Call the inherited constructor obj@mbccrosssectiongui.AbstractCell(varargin{:}); % converted super class constructor call obj.hBorder = mbcgui.container.layoutpanel(... 'Parent', obj.Parent,... 'Visible', obj.Visible, ... 'Position', obj.Position, ... 'BorderType','beveledout'); obj.hAxis = xregGui.axisslider('parent', obj.hBorder, ... 'orientation', 'horizontal'); obj.hValueEditor = mbcgui.widget.Spinner('Parent', obj.hBorder, ... 'Callback', {@i_editvalue, obj}); obj.hLabel = xregGui.labelcontrol('parent', obj.hBorder, ... 'LabelAlignment', 'Right', ... 'BaselineOffsetMode', 'manual', ... 'BaselineOffsetZero', 'middle', ... 'BaselineOffset', -4, ... 'Gap', 7, ... 'LabelSize',1,... 'ControlSize', 84, ... 'Control', obj.hValueEditor, ... 'Tag', 'CrossSectionHeaderLabel'); obj.hLabelGrid = xreggridbaglayout(obj.hBorder, ... 'dimension', [1 4], ... 'colsizes', [-1 80 80 -1], ... 'mergeblock', {[1 1] [1 3]}, ... 'elements', {obj.hLabel}); obj.Grid = xreggridbaglayout(obj.hBorder, ... 'dimension', [3 3], ... 'rowsizes', [1 -1 20], ... 'border', [4 6 4 7], ... 'mergeblock', {[3 3], [1 3]}, ... 'elements', {[], [], obj.hLabelGrid, obj.hAxis}); updateGridColSizes(obj); if obj.WideHeaderMode obj.pSetupWideMode; end set(obj.hBorder, 'LayoutComponent', {obj.Grid}); obj.ContentHandle = obj.hBorder; end % ColumnHeader end % constructor block methods function set.DisplayYAxisTickMarks(obj,value) obj.DisplayYAxisTickMarks=value; updateGridColSizes(obj); end function set.WideHeaderMode(obj,value) % Don't need to worry about getting strings right - the setTableData does % this anyway obj.WideHeaderMode = value; obj.pSetupWideMode; end function set.GraphView(obj,value) obj.GraphView = value; end function set.CurrentColumn(obj,value) value = round(value); % round to obtain an integer obj.CurrentColumn = value; end function set.hAxis(obj,value) obj.hAxis = value; end function set.hLabel(obj,value) obj.hLabel = value; end end % set and get functions methods % public methods %---------------------------------------- function pSetupWideMode(obj) %PSETUPWIDEMODE Configure the display according to "Wide Header" setting. % % PSETUPWIDEMODE(OBJ) configures the object display to match what is % specified by the WideHeaderMode property value. if obj.WideHeaderMode set(obj.hLabel, 'Gap', 1, 'LabelSize', 1); set(obj.hLabelGrid, ... 'dimension', [1 3], ... 'colsizes', [-1 80 -1], ... 'elements', {[], obj.hLabel}); else set(obj.hLabel, 'Gap', 7, 'LabelSize', 1); set(obj.hLabelGrid, ... 'dimension', [1 4], ... 'colsizes', [-1 80 80 -1], ... 'elements', {obj.hLabel}); end end % pSetupWideMode %---------------------------------------- function setGraphViewObject(obj, hView) %SETGRAPHVIEWOBJECT Set the handle to the parent graph view % % SETGRAPHVIEWOBJECT(OBJ, HVIEW) sets the reference to the parent graph % view object. This object is used when an input value is edited. obj.GraphView = hView; end % setGraphViewObject %---------------------------------------- function setInputValue(obj, val) %SETINPUTVALUE Display the given input value % % SETINPUTVALUE(OBJ, VAL) instructs the object to display the given value % as the current candidate input setting. In the case of the ColumnHeader, % this will update the editbox's value and the axis marker's position. set(obj.hValueEditor, 'Value', val); set(obj.hAxis,'Value', val); end % setInputValue end % public methods methods (Access=protected) %---------------------------------------- function update(obj) %update Scrolling table interface function % % update(OBJ,DM) sets up OBJ to display the information % from row R and column C of the data object DATA. dm = obj.DataModel; % Check whether to position object for a Y-axis per cell obj.DisplayYAxisTickMarks = ~dm.useCommonYAxis; % Check whether to use wider headers or not obj.WideHeaderMode = dm.WideHeaders; % Check whether to highlight the column header as the current fill item SC = xregGui.SystemColorsDbl; if dm.HighLightedColumn==obj.Column set(obj.hBorder, 'BackgroundColor', [0.784 1.0 0.737]); obj.hLabel.BackGroundColor = [0.784 1.0 0.737]; else set(obj.hBorder, 'BackgroundColor', SC.CTRL_BG); obj.hLabel.BackGroundColor = SC.CTRL_BG; end val = dm.ColumnItemValues(obj.Column); if dm.SelectedColumn==obj.Column fontw = 'bold'; else fontw = 'normal'; end % Get graphing x-limits from data model graphlims = dm.getGraphXLimits(obj.Row, obj.Column); % Check whether the input's value is outside its range if val<dm.XLimits(obj.Column,1) || val>dm.XLimits(obj.Column,2) % Turn edit box border red tt = sprintf('Value is outside the range of %s', dm.ColumnItemLabels{obj.Column}); hlcolor = 'r'; else % Use standard colours tt = ''; hlcolor = get(obj.hBorder, 'BackgroundColor'); end % Check whether the input value is outside the graphing range if val<graphlims(1) || val>graphlims(2) axisval = NaN; else axisval = val; end if obj.WideHeaderMode axisstr = dm.ColumnItemLabels{obj.Column}; labelstr = ''; else axisstr = ''; labelstr = [dm.ColumnItemLabels{obj.Column}, ':']; end set(obj.hAxis,'Value', axisval, ... 'Selected', dm.SelectedColumn==obj.Column, ... 'String', axisstr); obj.hAxis.setLimits(graphlims(1), graphlims(2)); set(obj.hLabel, 'String', labelstr, ... 'FontWeight', fontw); set(obj.hValueEditor, ... 'Min', min(dm.XLimits(obj.Column,1), val), ... 'Max', max(dm.XLimits(obj.Column,2), val), ... 'Value', dm.ColumnItemValues(obj.Column), ... 'TooltipString', tt, ... 'FontWeight', fontw); % set(obj.hValueHighlighter, 'HighlightColor', hlcolor); obj.hBorder.Tag = sprintf('ColumnHeader%d', obj.Column); % Save the column that is being displayed obj.CurrentColumn = obj.Column; end % update function dragSlice(~,~,~) %dragSlice default drag slice implementation that does nothing end end % protected methods methods (Access=private) function updateGridColSizes(obj) if ~isempty(obj.Grid) if obj.DisplayYAxisTickMarks set(obj.Grid, 'colsizes', [30, -1, 10]); else set(obj.Grid, 'colsizes', [10, -1, 10]); end end end end end % classdef function i_editvalue(src, ~, obj) if ~isempty(obj.GraphView) obj.GraphView.DataModel.setColumnItemValue(obj.CurrentColumn, src.Value); end end % i_editvalue