time | Calls | line |
---|
| | 1 | function updateLegendMenuToolbar(hProp,eventData,hObj) %#ok
|
| | 2 | %updateLegendMenuToolbar Update menu and toolbar controls for legend and colorbar
|
| | 3 |
|
| | 4 | % Copyright 2011-2014 The MathWorks, Inc.
|
| | 5 |
|
| | 6 | % determine which figure and axes are interested in
|
< 0.001 | 38 | 7 | if ~isempty(eventData)
|
< 0.001 | 8 | 8 | fig = eventData.AffectedObject;
|
< 0.001 | 30 | 9 | else
|
0.002 | 30 | 10 | fig = ancestor(hObj,'figure');
|
< 0.001 | 38 | 11 | end
|
| | 12 |
|
| | 13 | %bail out early, if the figure cannot be found
|
< 0.001 | 38 | 14 | if(isempty(fig))
|
| | 15 | return
|
< 0.001 | 38 | 16 | end
|
| | 17 |
|
0.002 | 38 | 18 | cax = fig.CurrentAxes;
|
| | 19 |
|
| | 20 | % update controls only for default figure menubar or toolbar
|
| | 21 | % figure Toolbar == 'auto' follows the value of figure Menubar
|
| | 22 | % Also, we can leave early if the figure is being deleted, which could
|
| | 23 | % cause the CurrentAxes listener to fire (see below)
|
0.001 | 38 | 24 | if ~(strcmp(fig.MenuBar,'figure') || strcmp(fig.ToolBar,'figure'))
|
| | 25 | return
|
0.003 | 38 | 26 | elseif strcmp(fig.BeingDeleted,'on')
|
< 0.001 | 16 | 27 | return
|
< 0.001 | 22 | 28 | end
|
| | 29 |
|
| | 30 | % create MenuToolbarInfo object and store in a transient, hidden
|
| | 31 | % dynamic prop on the figure.
|
< 0.001 | 22 | 32 | if ~isprop(fig,'LegendColorbarMenuToolbarInfo')
|
< 0.001 | 8 | 33 | hP = addprop(fig,'LegendColorbarMenuToolbarInfo');
|
< 0.001 | 8 | 34 | hP.Hidden = true;
|
< 0.001 | 8 | 35 | hP.Transient = true;
|
0.004 | 8 | 36 | fig.LegendColorbarMenuToolbarInfo = matlab.graphics.illustration.internal.MenuToolbarInfo(fig);
|
< 0.001 | 8 | 37 | hP.SetAccess = 'private';
|
< 0.001 | 22 | 38 | end
|
| | 39 |
|
| | 40 |
|
| | 41 | % determine which menubar/toolbar to update
|
< 0.001 | 22 | 42 | updateMenubar = false;
|
< 0.001 | 22 | 43 | updateToolbar = false;
|
< 0.001 | 22 | 44 | if strcmp(fig.MenuBar,'figure')
|
< 0.001 | 22 | 45 | updateMenubar = true;
|
< 0.001 | 22 | 46 | if strcmp(fig.ToolBar,'auto')
|
< 0.001 | 22 | 47 | updateToolbar = true;
|
< 0.001 | 22 | 48 | end
|
< 0.001 | 22 | 49 | end
|
< 0.001 | 22 | 50 | if strcmp(fig.ToolBar,'figure')
|
| | 51 | updateToolbar = true;
|
< 0.001 | 22 | 52 | end
|
| | 53 |
|
| | 54 | % check if legend is on for the current axes
|
< 0.001 | 22 | 55 | legon = false;
|
< 0.001 | 22 | 56 | if ~isempty(cax) && isvalid(cax)
|
| | 57 | % Check for a 'LegendVisible' property first (for charts that expose
|
| | 58 | % a LegendVisible property)
|
< 0.001 | 22 | 59 | if isprop(cax,'LegendVisible')
|
| | 60 | legon = strcmp(cax.LegendVisible,'on');
|
< 0.001 | 22 | 61 | elseif isprop(cax,'Legend')
|
0.004 | 22 | 62 | if isValidLegendHandleObject(cax.Legend)
|
< 0.001 | 22 | 63 | legon = true;
|
| | 64 | else
|
| | 65 | % An HG1 fig file may contain a double handle to a deleted legend
|
| | 66 | % If so, clear the property. This axes has no legend.
|
| | 67 | cax.setLegendExternal([]);
|
< 0.001 | 22 | 68 | end
|
< 0.001 | 22 | 69 | end
|
< 0.001 | 22 | 70 | end
|
| | 71 |
|
| | 72 | % check if colorbar is on for the current axes
|
< 0.001 | 22 | 73 | cbaron = false;
|
< 0.001 | 22 | 74 | if ~isempty(cax) && isvalid(cax)
|
| | 75 | % Check for a 'ColorbarVisible' property first (for charts that expose
|
| | 76 | % a ColorbarVisible property)
|
< 0.001 | 22 | 77 | if isprop(cax,'ColorbarVisible')
|
| | 78 | cbaron = strcmp(cax.ColorbarVisible,'on');
|
< 0.001 | 22 | 79 | elseif isprop(cax,'Colorbar')
|
0.002 | 22 | 80 | if isValidColorBarHandleObject(cax.Colorbar)
|
| | 81 | cbaron = true;
|
< 0.001 | 22 | 82 | else
|
| | 83 | % An HG1 fig file may contain a double handle to a deleted colorbar
|
| | 84 | % If so, clear the property. This axes has no colorbar.
|
0.002 | 22 | 85 | cax.setColorbarExternal([]);
|
< 0.001 | 22 | 86 | end
|
< 0.001 | 22 | 87 | end
|
< 0.001 | 22 | 88 | end
|
| | 89 |
|
0.002 | 22 | 90 | info = fig.LegendColorbarMenuToolbarInfo;
|
| | 91 |
|
< 0.001 | 22 | 92 | if updateMenubar
|
< 0.001 | 22 | 93 | if isempty(info.LegendMenu)
|
0.073 | 8 | 94 | info.LegendMenu = findall(fig,'Tag','figMenuInsertLegend');
|
< 0.001 | 22 | 95 | end
|
< 0.001 | 22 | 96 | if isempty(info.ColorbarMenu)
|
0.073 | 8 | 97 | info.ColorbarMenu = findall(fig,'Tag','figMenuInsertColorbar');
|
< 0.001 | 22 | 98 | end
|
| | 99 |
|
< 0.001 | 22 | 100 | lmenu = info.LegendMenu;
|
< 0.001 | 22 | 101 | if ~isempty(lmenu) && isvalid(lmenu)
|
< 0.001 | 22 | 102 | if legon
|
0.001 | 22 | 103 | lmenu.Checked = 'on';
|
| | 104 | else
|
| | 105 | lmenu.Checked = 'off';
|
< 0.001 | 22 | 106 | end
|
< 0.001 | 22 | 107 | end
|
| | 108 |
|
< 0.001 | 22 | 109 | cbmenu = info.ColorbarMenu;
|
< 0.001 | 22 | 110 | if ~isempty(cbmenu) && isvalid(cbmenu)
|
< 0.001 | 22 | 111 | if cbaron
|
| | 112 | cbmenu.Checked = 'on';
|
< 0.001 | 22 | 113 | else
|
< 0.001 | 22 | 114 | cbmenu.Checked = 'off';
|
< 0.001 | 22 | 115 | end
|
< 0.001 | 22 | 116 | end
|
< 0.001 | 22 | 117 | end
|
| | 118 |
|
< 0.001 | 22 | 119 | if updateToolbar
|
< 0.001 | 22 | 120 | if isempty(info.LegendToggle)
|
0.036 | 8 | 121 | info.LegendToggle = uigettool(fig,'Annotation.InsertLegend');
|
< 0.001 | 22 | 122 | end
|
< 0.001 | 22 | 123 | if isempty(info.ColorbarToggle)
|
0.027 | 8 | 124 | info.ColorbarToggle = uigettool(fig,'Annotation.InsertColorbar');
|
< 0.001 | 22 | 125 | end
|
| | 126 |
|
< 0.001 | 22 | 127 | ltoggle = info.LegendToggle;
|
< 0.001 | 22 | 128 | if ~isempty(ltoggle) && isvalid(ltoggle)
|
< 0.001 | 22 | 129 | if legon
|
0.001 | 22 | 130 | ltoggle.State = 'on';
|
| | 131 | else
|
| | 132 | ltoggle.State = 'off';
|
< 0.001 | 22 | 133 | end
|
< 0.001 | 22 | 134 | end
|
| | 135 |
|
< 0.001 | 22 | 136 | cbtoggle = info.ColorbarToggle;
|
< 0.001 | 22 | 137 | if ~isempty(cbtoggle) && isvalid(cbtoggle)
|
< 0.001 | 22 | 138 | if cbaron
|
| | 139 | cbtoggle.State = 'on';
|
< 0.001 | 22 | 140 | else
|
0.001 | 22 | 141 | cbtoggle.State = 'off';
|
< 0.001 | 22 | 142 | end
|
< 0.001 | 22 | 143 | end
|
< 0.001 | 22 | 144 | end
|
Other subfunctions in this file are not included in this listing.