This is a static copy of a profile reportHome
graphics/private/prepareui (40 calls, 0.557 sec)
Generated 05-Aug-2011 13:03:07 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/graphics/private/prepareui.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
46 | if (isa(hc, 'uicontrol') || is... | 9984 | 0.350 s | 62.7% |  |
45 | hc = handle(uichandles(i)); | 9984 | 0.120 s | 21.6% |  |
43 | uichandles = findall(Fig, 'Vis... | 40 | 0.044 s | 7.8% |  |
50 | end | 9984 | 0.033 s | 5.9% |  |
54 | return | 40 | 0 s | 0% |  |
All other lines | | | 0.011 s | 2.0% |  |
Totals | | | 0.557 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
117 | The variable 'CapturedImages' appears to change size on every loop iteration. Consider preallocating for speed. |
118 | The variable 'CapturedImages' appears to change size on every loop iteration. Consider preallocating for speed. |
120 | The variable 'Frame' appears to change size on every loop iteration. Consider preallocating for speed. |
121 | The variable 'Frame' appears to change size on every loop iteration. Consider preallocating for speed. |
133 | The variable 'CapturedImages' appears to change size on every loop iteration. Consider preallocating for speed. |
135 | The variable 'Frame' appears to change size on every loop iteration. Consider preallocating for speed. |
142 | The variable 'CapturedImages' appears to change size on every loop iteration. Consider preallocating for speed. |
144 | The variable 'CapturedImages' appears to change size on every loop iteration. Consider preallocating for speed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 182 |
Non-code lines (comments, blank lines) | 98 |
Code lines (lines that can run) | 84 |
Code lines that did run | 14 |
Code lines that did not run | 70 |
Coverage (did run/can run) | 16.67 % |
Function listing
time calls line
1 function pj = prepareui( pj, Fig )
2 %PREPAREUI Method to draw Uicontrol objects in output.
3 % Mimics user interface objects as Images so they appear in output.
4 % Takes screen captures of user interface objects and creates true
5 % color Images in the same location as the user interface objects so
6 % the uicontrols themselves seem to print (which they can not because
7 % they are drawn by the windowing system, not MATLAB).
8 %
9 % Ex:
10 % pj = PREPAREUI( pj, h ); %modifies PrintJob object pj and creates
11 % %Images of Uicontrols in Figure h
12 %
13 % See also PREPARE, RESTORE, PREPAREHG, RESTOREUI.
14
15 % Copyright 1984-2009 The MathWorks, Inc.
16 % $Revision: 1.8.4.13 $ $Date: 2009/02/18 02:18:41 $
17
40 18 error( nargchk(2,2,nargin) );
19
40 20 if (~useOriginalHGPrinting())
21 error('MATLAB:Print:ObsoleteFunction', 'The function %s should only be called when original HG printing is enabled.', upper(mfilename));
22 end
23
24 %Early exit if the user has requested not to see controls in output.
40 25 if ~pj.PrintUI
26 return
27 end
28
29 % Check if we have a valid java figure handle to proceed.
40 30 if ~isequal(size(Fig), [1 1]) || (~isempty(Fig) && ~isfigure(Fig))
31 error('MATLAB:UIControl:PrintingNotSupported', ...
32 'Need a handle to a Figure object.')
33 end
34
35 %Bail if device doesn't support TC images.
40 36 if strcmp( pj.Driver, 'hpgl' ) || strcmp( pj.Driver, 'ill' )
37 pj.UIData = [];
38 return
39 end
40
41 % Get handles to all visible uicontrols and java component containers.
40 42 pj.UIData.UICHandles = [];
0.04 40 43 uichandles = findall(Fig, 'Visible', 'on');
40 44 for i = 1:length(uichandles)
0.12 9984 45 hc = handle(uichandles(i));
0.35 9984 46 if (isa(hc, 'uicontrol') || isa(hc, 'uitable') || isa(hc, 'hgjavacomponent'))
47 % don't want to make a copy/image this
48 pj.UIData.UICHandles = [pj.UIData.UICHandles; uichandles(i)];
49 end
0.03 9984 50 end
51
40 52 if isempty(pj.UIData.UICHandles)
40 53 pj.UIData = [];
40 54 return
55 end
56
57 % If we did find uicontrols and intend to proceed, make sure we are in java
58 % figures.
59 if (usejava('awt') ~= 1)
60 error('MATLAB:UIControl:PrintingNotSupported', ...
61 'Printing of uicontrols is not supported on this platform.');
62 end
63
64 pj.UIData.OldRootUnits=get(0,'Units');
65 pj.UIData.OldFigUnits=get(Fig,'Units');
66 pj.UIData.OldFigPosition=get(Fig,'Position');
67 pj.UIData.OldFigVisible=get(Fig,'Visible');
68 set( Fig, 'units', 'points' )
69 if ~strcmp('docked', get(Fig, 'windowstyle'))
70 pj.UIData.MovedFigure = screenpos( Fig, get( Fig, 'position' ) );
71 else
72 pj.UIData.MovedFigure = false;
73 end
74 pj.UIData.OldFigCMap=get(Fig,'Colormap');
75
76 set([0 Fig],'Units','pixels');
77
78 %%% UI Controls %%%
79
80 pj.UIData.AxisHandles = [];
81 Frame = [];
82
83 % Making the assumption that the bottom uicontrol is usually
84 % created first and underneath the others.
85 pj.UIData.UICHandles=flipud(pj.UIData.UICHandles);
86 pj.UIData.UICUnits=get(pj.UIData.UICHandles,{'Units'});
87
88 % This should not be necessary anymore since we depend on the
89 % getpixelposition API for uicontrol position. But, printing popupmenu
90 % uicontrol on the Mac (native) causes a hang if this is not done.
91 % Keep this for now till that issue is resolved of Mac supports java
92 % figures. Corresponding restore in restoreui.m
93 set(pj.UIData.UICHandles,'Units','pixels');
94
95 % Create images %
96 CapturedImages = [];
97 CaptureCount = 0;
98
99 % Ensure all changes are flushed before getting the component images.
100 drawnow; % drawnow;
101
102 for lp = 1:length(pj.UIData.UICHandles)
103 h = pj.UIData.UICHandles(lp);
104 hh = handle(h);
105 himage = hh.getPrintImage;
106
107 if isempty(himage)
108 % uicontrol did not return a bitmap. This should be an error, but
109 % currently there is a bug due to which an unrealized uicontrol
110 % does not print. So, ignore it silently for now. Downstream code
111 % depends on an image of valid (>0) size.
112 % TODO: This condition should error when G#291605 is fixed.
113 continue;
114 end
115
116 CaptureCount = CaptureCount+1;
117 CapturedImages{CaptureCount}.cdata = himage;
118 CapturedImages{CaptureCount}.colormap = [];
119
120 Frame{CaptureCount}.Pos = rectaroundcontrol(h);
121 Frame{CaptureCount}.Units = pj.UIData.UICUnits{lp};
122
123 % Take the min of the size of uicontrol (stored in Frame above) and the
124 % size of the bitmap image returned by Java. This is so that we get the
125 % correct segment of image out of the bitmap for popupmenu uicontrols
126 % if the size of the control is smaller or bigger than what is on
127 % screen.
128 hc = size(CapturedImages{CaptureCount}.cdata); hc = [hc(2) hc(1)];
129 minrect = min(hc, ceil(Frame{CaptureCount}.Pos(3:4)));
130
131 % Clamp down the image and the Frame size to the minrect so that the
132 % image is not clipped in unpleasant ways (under OpenGL).
133 CapturedImages{CaptureCount}.cdata = CapturedImages{CaptureCount}.cdata(...
134 1:minrect(2), 1:minrect(1), :);
135 Frame{CaptureCount}.Pos(3:4) = minrect;
136 end
137
138 % Draw each image to stand in for the uicontrols
139 for lp=1:length(Frame)
140 if ~isempty(CapturedImages{lp})
141 if ~isempty( CapturedImages{lp}.colormap )
142 CapturedImages{lp}.cdata = ind2rgb(CapturedImages{lp}.cdata, ...
143 CapturedImages{lp}.colormap);
144 CapturedImages{lp}.colormap = [];
145 end
146
147 pj.UIData.AxisHandles(lp)=axes('Parent',Fig, ...
148 'Units' ,'pixels' , ...
149 'Position' ,Frame{lp}.Pos, ...
150 'Tag' ,'PrintUI' ...
151 );
152 %call low level command so NextPlot has no affect, fix Axes.
153 image('cdata',CapturedImages{lp}.cdata, ...
154 'Parent',pj.UIData.AxisHandles(lp));
155 set(pj.UIData.AxisHandles(lp), ...
156 'Units' ,Frame{lp}.Units, ...
157 'Visible' ,'off' , ...
158 'ColorOrder' ,[0 0 0] , ...
159 'XTick' ,[] , ...
160 'XTickLabelMode' ,'manual' , ...
161 'YTick' ,[] , ...
162 'YTickLabelMode' ,'manual' , ...
163 'YDir' ,'reverse' , ...
164 'XLim' ,[0.5 (Frame{lp}.Pos(3))+0.5], ...
165 'YLim' ,[0.5 (Frame{lp}.Pos(4))+0.5] ...
166 );
167 else
168 pj.UIData.AxisHandles(lp) = -1;
169 warning('MATLAB:Print:UIcontrolScreenCaptureFailed', ...
170 'Screen capture failed - UIcontrol will not appear in output.');
171 end %if ~isempty(capturedimages)
172 end % for lp
173
174 set(Fig, 'Units', pj.UIData.OldFigUnits );
175 set(0, 'Units', pj.UIData.OldRootUnits);
176
177 % Make uicontrols invisible because Motif on Sol2 sometimes seg-v's
178 % if the uicontrols are visible while resizing in normalized units.
179 % note we don't store the old visible state since we searched for visible
180 % uicontrols in the findobj above.
181 set(pj.UIData.UICHandles,'visible','off');
182 drawnow;
Other subfunctions in this file are not included in this listing.