www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@ColorBar/ColorBar.m
function obj = ColorBar(varargin) %COLORBAR Construct a new ColorBar object % % OBJ = COLORBAR(PROP, VALUE, ...) creates a new ColorBar object. % Copyright 2005-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin && isa(varargin{1}, 'mbcwidgets.ColorBar') obj = varargin{1}; varargin(1) = []; else obj = mbcwidgets.ColorBar; end % Call parent class constructor obj.abstractlayoutcomponent(varargin{:}); % Check a reasonable colormap is set - use current figure's one if not if size(obj.ColorMap,2)~=3 hFig = ancestor(obj.Parent, 'figure'); obj.ColorMap = get(hFig, 'Colormap'); end yl = [obj.Min, obj.Max]; obj.hAxesPanel = mbcgui.widget.AxesPanel(... 'Parent', obj.Parent, ... 'Border', [0 5 40 10]); obj.hAxes = obj.hAxesPanel.AxesHandle; set(obj.hAxes, ... 'HitTest', 'off', ... 'Units', 'pixels', ... 'Layer', 'Top', ... 'Box', 'on', ... 'XTick', [], ... 'XLim',[0 1], ... 'YLim',yl,... 'YAxisLocation', 'right'); obj.hPatch = patch('Parent', obj.hAxes, ... 'HitTest', 'off', ... 'Vertices',[0 yl(1) 0;0 yl(2) 0;1 yl(2) 0;1 yl(1) 0],... 'Faces',[1 2 3 4],... 'FaceVertexCData',[1 1 1],... 'EdgeColor','none',... 'FaceColor','flat'); if ~obj.RangeEditable % Force edit boxes to be invisible EditVis = 'off'; else EditVis = obj.Visible; end SC = xregGui.SystemColorsDbl; obj.hMin = uicontrol('Parent', obj.Parent, ... 'Visible', EditVis, ... 'Style', 'edit', ... 'BackgroundColor', SC.WINDOW_BG, ... 'HorizontalAlignment', 'right', ... 'String', obj.Min, ... 'Callback', {@i_cbmin, obj}); obj.hMax = uicontrol('Parent', obj.Parent, ... 'Visible', EditVis, ... 'Style', 'edit', ... 'BackgroundColor', SC.WINDOW_BG, ... 'HorizontalAlignment', 'right', ... 'String', obj.Max, ... 'Callback', {@i_cbmax, obj}); obj.pDrawColorBar; obj.pDoLayout; obj.addPropertyListeners({'ColorMap', 'Min', 'Max', 'RangeEditable'}, ... {{@i_setcolormap, obj}, ... {@i_setmin, obj}, ... {@i_setmax, obj}, ... {@i_setrngedit, obj}}); function i_setcolormap(~, ~, obj) obj.pDrawColorBar; function i_setmin(~, evt, obj) obj.setRange([evt.NewValue, obj.Max]); function i_setmax(~, evt, obj) obj.setRange([obj.Min, evt.NewValue]); function i_setrngedit(~, ~, obj) obj.pDoLayout; function i_cbmin(src, ~, obj) newval = str2double(get(src, 'String')); if newval<obj.Max obj.Min = newval; obj.send('RangeChanged', handle.EventData(obj,'RangeChanged')); else set(src, 'String', obj.Min); end function i_cbmax(src, ~, obj) newval = str2double(get(src, 'String')); if newval>obj.Min obj.Max = newval; obj.send('RangeChanged', handle.EventData(obj,'RangeChanged')); else set(src, 'String', obj.Max); end