NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/prstuff/PrintSetup.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function PrintSetup(command,subcommand,comnum);
2 %
3 % PRINTSETUP creates an interactive printed-page layout editor.
4 %
5 %             Creates a dialog box which allows the user
6 %             to customize the printing options for the
7 %             current figure.  Most of the items should
8 %             be self explanatory. A picture is drawn at
9 %             the bottom of the figure showing the page
10 %             and the positioning of the figure's contents
11 %             on it.  Click and drag on the edges of the
12 %             inner rectangle to resize, and in the center
13 %             to reposition the figure on the printed page.
14 %
15 % Call as: >> PrintSetup
16 %
17 % Keith Rogers 12/94
18 % Minor Mods by Brian Blanton, Mar 95.
19
20 %Copyright (c) 1995 by Keith Rogers
21 figs=get(0,'Children');
22 Pfig=findobj(figs,'flat','Type','figure','Tag','FEDAR Plot F');
23 Pax=findobj(Pfig,'Type','axes','Tag','FEDAR Plot A');
24 Ofig=findobj(figs,'flat','Type','figure','Tag','FEDAR Opt F');
25 Oax=findobj(Ofig,'Type','axes','Tag','FEDAR Opt A');   
26
27 PSFigure=findobj(figs,'flat','Type','figure','Tag','PrintSetup');
28 if ~isempty(PSFigure)&nargin<1,return,end
29
30 if(nargin<1)
31         ShrinkFactor = 3.7;                                     
32         Background = 'b';
33         Foreground = 'w';
34         if isempty(Pfig)
35            fig = gcf;
36         else
37            fig = Pfig;
38         end
39         PSFigure = figure('Name','Print Setup',...
40                           'NumberTitle','off',...
41                           'Position',[100 40 380 420],...
42                           'NextPlot','Add',...
43                           'Color',Background,...
44                           'Tag','PrintSetup');
45         PaperPosition = get(fig,'PaperPosition');
46         PaperSize = get(fig,'PaperSize');
47         uicontrol(PSFigure,'Style','Text',...
48                            'BackGr',Background,...
49                            'ForeGr',Foreground,...
50                            'String','Margins',...
51                            'Position',[25 400 60 20]);
52         uicontrol(PSFigure,'Style','Text',...
53                            'BackGr',Background,...
54                            'ForeGr',Foreground,...
55                            'String','Bottom',...
56                            'HorizontalAlignment','Right',...
57                            'Position',[5 380 60 20]);
58         uicontrol(PSFigure,'Style','Edit',...
59                            'BackGr',Background,...
60                            'ForeGr',Foreground,...
61                            'String',num2str(PaperPosition(2)),...
62                            'Position',[70 380 60 20],...
63                            'Tag','Bottom',...
64                            'Callback','PrintSetup(''Margins'',''Bottom'')');
65         uicontrol(PSFigure,'Style','Text',...
66                            'BackGr',Background,...
67                            'ForeGr',Foreground,...
68                            'String','Left',...
69                            'HorizontalAlignment','Right',...
70                            'Position',[5 355 60 20]);
71         uicontrol(PSFigure,'Style','Edit',...
72                            'BackGr',Background,...
73                            'ForeGr',Foreground,...
74                            'String',num2str(PaperPosition(1)),...
75                            'Position',[70 355 60 20],...
76                            'Tag','Left',...
77                            'Callback','PrintSetup(''Margins'',''Left'')');
78         uicontrol(PSFigure,'Style','Text',...
79                            'BackGr',Background,...
80                            'ForeGr',Foreground,...
81                            'String','Top',...
82                            'HorizontalAlignment','Right',...
83                            'Position',[5 330 60 20]);
84         uicontrol(PSFigure,'Style','Edit',...
85                            'BackGr',Background,...
86                            'ForeGr',Foreground,...
87                            'String',num2str(PaperSize(2)-PaperPosition(2)-PaperPosition(4)),...
88                            'Position',[70 330 60 20],...
89                            'Tag','Top',...
90                            'Callback','PrintSetup(''Margins'',''Top'')');
91         uicontrol(PSFigure,'Style','Text',...
92                            'BackGr',Background,...
93                            'ForeGr',Foreground,...
94                            'String','Right',...
95                            'HorizontalAlignment','Right',...
96                            'Position',[5 305 60 20]);
97         uicontrol(PSFigure,'Style','Edit',...
98                            'BackGr',Background,...
99                            'ForeGr',Foreground,...
100                            'String',num2str(PaperSize(1)-PaperPosition(1)-PaperPosition(3)),...
101                            'Position',[70 305 60 20],...
102                            'Tag','Right',...
103                            'Callback','PrintSetup(''Margins'',''Right'')');     
104         uicontrol(PSFigure,'Style','Text',...
105                            'BackGr',Background,...
106                            'ForeGr',Foreground,...
107                            'String','Paper Type',...
108                            'HorizontalAlignment','Left',...
109                            'Position',[150 400 100 20]);
110         PaperType = get(fig,'PaperType');
111         if(strcmp(PaperType,'usletter'))
112                 val = 1;
113         elseif(strcmp(PaperType,'uslegal'))
114                 val = 2;
115         elseif(strcmp(PaperType,'a3'))
116                 val = 3;
117         elseif(strcmp(PaperType,'a4letter'))
118                 val = 4;
119         elseif(strcmp(PaperType,'a5'))
120                 val = 5;
121         elseif(strcmp(PaperType,'b4'))
122                 val = 6;
123         else
124                 val = 7;
125         end
126         uicontrol(PSFigure,'Style','popupmenu',...
127                            'BackGr',Background,...
128                            'ForeGr',Foreground,...
129                            'String','usletter|uslegal|a3|a4letter|a5|b4|tabloid',...
130                            'Value',val,...
131                            'Tag','PaperType',...
132                            'Callback','PrintSetup(''PaperType'')',...
133                            'Position',[150 380 120 20]);
134         uicontrol(PSFigure,'Style','Text',...
135                            'BackGr',Background,...
136                            'ForeGr',Foreground,...
137                            'HorizontalAlignment','left',...
138                            'String','Paper Orientation',...
139                            'Position',[150 355 120 20]);
140         Orient = get(fig,'PaperOrientation');
141         if(strcmp(Orient,'portrait'))
142                 val = 1;
143         elseif(strcmp(Orient,'landscape'))
144                 val = 2;
145         else
146                 val = 3;
147         end
148         uicontrol(PSFigure,'Style','popupmenu',...
149                            'BackGr',Background,...
150                            'ForeGr',Foreground,...
151                            'String','Portrait|Landscape|Tall',...
152                            'Tag','Orient',...
153                            'Value',val,...
154                            'Callback','PrintSetup(''Orient'')',...
155                            'Position',[150 335 120 20]);
156         uicontrol(PSFigure,'Style','checkbox',...
157                            'BackGr',Background,...
158                            'ForeGr',Foreground,...
159                            'String','Invert Hardcopy',...
160                            'Tag','Invert',...
161                            'Value',strcmp(get(fig,'InvertHardCopy'),'on'),...
162                            'Callback','PrintSetup(''Invert'')',...
163                            'Position',[150 305 130 20]);
164         uicontrol(PSFigure,'Style','Text',...
165                            'BackGr',Background,...
166                            'ForeGr',Foreground,...
167                            'String','PaperUnits',...
168                            'HorizontalAlignment','Left',...
169                            'Position',[270 400 90 20]);
170                                                
171         PaperUnits = get(fig,'PaperUnits');
172         if(strcmp(PaperUnits,'inches'))
173                 val = 1;
174         elseif(strcmp(PaperUnits,'centimeters'))
175                 val = 2;
176         elseif(strcmp(PaperUnits,'normalized'))
177                 val = 3;
178         else
179                 val = 4;
180         end
181        
182         uicontrol(PSFigure,'Style','popupmenu',...
183                            'BackGr',Background,...
184                            'ForeGr',Foreground,...
185                            'String','inches|centimeters|normalized|points',...
186                            'Tag','PaperUnits',...
187                            'Value',val,...
188                            'Callback','PrintSetup(''PaperUnits'')',...
189                            'Position',[280 380 90 20]);
190         uicontrol(PSFigure,'Style','pushbutton',...
191                            'BackGr','g',...
192                            'ForeGr','k',...
193                            'String','APPLY',...
194                            'Tag','APPLY',...
195                            'Callback','PrintSetup(''APPLY'')',...
196                            'Position',[290 340 80 25]);
197         uicontrol(PSFigure,'Style','pushbutton',...
198                            'BackGr','r',...
199                            'ForeGr','k',...
200                            'String','Cancel',...
201                            'Tag','Cancel',...
202                            'Callback','PrintSetup(''Cancel'')',...
203                            'Position',[290 305 80 25]);
204        
205         axes('Units',PaperUnits,...
206                  'Position',[.7 .25 PaperSize(1)/ShrinkFactor PaperSize(2)/ShrinkFactor],...
207                  'box','on')
208         axis('equal');
209         axis([0 PaperSize(1) 0 PaperSize(2)]);
210         PlotRect = [PaperPosition(1) PaperPosition(2);
211                     PaperPosition(1)+PaperPosition(3) PaperPosition(2);
212                                 PaperPosition(1)+PaperPosition(3) PaperPosition(2)+PaperPosition(4);                     
213                                 PaperPosition(1) PaperPosition(2)+PaperPosition(4)];
214         PatchObj = patch('XData',PlotRect(:,1),...
215                                                  'YData',PlotRect(:,2),...
216                                                  'EdgeColor','w',...
217                                                  'FaceColor',Background);
218         set(PatchObj,'ButtonDownFcn','PrintSetup(''Resize'')');
219         UserData = [fig;PatchObj;ShrinkFactor];
220         set(gcf,'UserData',UserData);
221         set(gcf,'PaperPosition',PaperPosition,...
222                         'PaperType',PaperType,...
223                         'PaperOrientation',Orient,...
224                         'PaperUnits',PaperUnits);
225         axis(axis);
226         hold on;
227
228 elseif(strcmp(command,'DrawPage'))
229
230         UserData = get(gcf,'UserData');
231         fig = UserData(1);
232         PatchObj = UserData(2);
233         ShrinkFactor = UserData(3);
234        
235         PaperPosition = get(gcf,'PaperPosition');
236         PaperUnits = get(gcf,'PaperUnits');
237         if(strcmp(get(gca,'Units'),'normalized'))
238                 set(gca,'units',PaperUnits);   
239         else
240                 set(gcf,'PaperUnits',get(gca,'Units'));
241                 set(fig,'PaperUnits',get(gca,'Units'));
242         end
243         PaperSize = get(gcf,'PaperSize');
244         set(gcf,'PaperUnits',PaperUnits);
245         AxPos = get(gca,'Position');
246         set(gca,'Position',[AxPos(1) AxPos(2) PaperSize(1)/ShrinkFactor PaperSize(2)/ShrinkFactor]);
247         set(gca,'Units',PaperUnits);
248         if(strcmp(PaperUnits,'normalized'))
249                 axis('normal');
250                 axis([0 1 0 1]);
251         else
252                 axis('equal');
253                 PaperSize = get(gcf,'PaperSize');
254                 axis([0 PaperSize(1) 0 PaperSize(2)]);
255         end
256         PlotRect = [PaperPosition(1) PaperPosition(2);
257                     PaperPosition(1)+PaperPosition(3) PaperPosition(2);
258                                 PaperPosition(1)+PaperPosition(3) PaperPosition(2)+PaperPosition(4);                     
259                                 PaperPosition(1) PaperPosition(2)+PaperPosition(4)];
260        
261         set(PatchObj,'EraseMode','Xor',...
262                                 'XData',PlotRect(:,1),...
263                                 'YData',PlotRect(:,2));
264         set(PatchObj,'EraseMode','Normal');
265         axis(axis);
266         hold on;
267 elseif(strcmp(command,'Resize'))
268         UserData = get(gcf,'UserData');
269         PatchObj = UserData(2);
270         if(nargin<2)
271                 cp = get(gca,'CurrentPoint');
272                 XData = get(PatchObj,'XData');
273                 YData = get(PatchObj,'YData');
274                 minx = min(XData);
275                 miny = min(YData);
276                 ext = [minx miny max(XData)-minx max(YData)-miny];
277                 set(PatchObj,'UserData',ext);
278                 if(cp(1,1)<ext(1)+.2*ext(3))
279                         if(cp(1,2)<ext(2)+.2*ext(4))            % Lower Left Corner
280                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Corner'',1)');
281                         elseif(cp(1,2)>ext(2)+.8*ext(4))        % Upper Left Corner
282                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Corner'',2)');
283                         else                                                            % Left Side
284                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Side'',1)');
285                         end
286                 elseif(cp(1,1)>ext(1)+.8*ext(3))
287                         if(cp(1,2)<ext(2)+.2*ext(4))            % Lower Right Corner
288                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Corner'',4)');
289                         elseif(cp(1,2)>ext(2)+.8*ext(4))        % Upper Right Corner
290                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Corner'',3)');
291                         else                                                            % Right Side
292                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Side'',3)');
293                         end
294                 elseif(cp(1,2)>ext(2)+.8*ext(4))                % Top Side
295                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Side'',2)')
296                 elseif(cp(1,2)<ext(2)+.2*ext(4))                % Bottom Side
297                                 set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Side'',4)')
298                 else                                                                    % Center
299                         set(gca,'UserData',cp);
300                         set(gcf,'WindowButtonMotionFcn','PrintSetup(''Resize'',''Move'')');
301                 end
302                 set(PatchObj,'erasemode','xor');
303                 set(gcf,'WindowButtonUpFcn','PrintSetup(''Resize'',''Up'')');
304         elseif(strcmp(subcommand,'Corner'))
305                 cp = get(gca,'CurrentPoint');
306                 ext = get(PatchObj,'UserData');
307                 if(comnum == 1)
308                         ext = [cp(1,1:2) ext(1:2)+ext(3:4)-cp(1,1:2)];
309                 elseif(comnum == 2)
310                         ext = [cp(1,1) ext(2) ext(1)+ext(3)-cp(1,1) cp(1,2)-ext(2)];
311                 elseif(comnum == 3)
312                         ext(3:4) = cp(1,1:2)-ext(1:2);
313                 else
314                         ext(2:4) = [cp(1,2) cp(1,1)-ext(1) ext(2)+ext(4)-cp(1,2)];
315                 end
316                 XData = ext(1)+[0 ext(3) ext(3) 0];
317                 YData = ext(2)+[0 0 ext(4) ext(4)];
318                 set(PatchObj,'XData',XData,'YData',YData);
319         elseif(strcmp(subcommand,'Side'))
320                 cp = get(gca,'CurrentPoint');
321                 ext = get(PatchObj,'UserData');
322                 if(comnum == 1)
323                         ext = [cp(1,1) ext(2) ext(1)+ext(3)-cp(1,1) ext(4)];
324                 elseif(comnum == 2)
325                         ext = [ext(1) ext(2) ext(3) cp(1,2)-ext(2)];
326                 elseif(comnum == 3)
327                         ext = [ext(1) ext(2) cp(1,1)-ext(1) ext(4)];
328                 else
329                         ext = [ext(1) cp(1,2) ext(3) ext(2)+ext(4)-cp(1,2)];
330                 end
331                 XData = ext(1)+[0 ext(3) ext(3) 0];
332                 YData = ext(2)+[0 0 ext(4) ext(4)];
333                 set(PatchObj,'XData',XData,'YData',YData);
334         elseif(strcmp(subcommand,'Move'))
335                 startpoint = get(gca,'UserData');
336                 cp = get(gca,'CurrentPoint');
337                 XData = get(PatchObj,'XData');
338                 YData = get(PatchObj,'YData');
339                 XData = XData+cp(1,1)-startpoint(1,1);
340                 YData = YData+cp(1,2)-startpoint(1,2);
341                 set(PatchObj,'XData',XData,'YData',YData);
342                 set(gca,'UserData',cp);
343         else
344                 PaperSize = get(gcf,'PaperSize');
345                 set(PatchObj,'EraseMode','normal');
346                 set(gcf,'WindowButtonMotionFcn','',...
347                                 'WindowButtonUpFcn','');
348                 XData = get(PatchObj,'XData');
349                 YData = get(PatchObj,'YData');
350                 ext = [XData(1) YData(1) XData(2)-XData(1) YData(3)-YData(2)];
351                 set(gcf,'PaperPosition',ext);
352                 set(findobj(gcf,'Tag','Bottom'),'String',num2str(ext(1)));
353                 set(findobj(gcf,'Tag','Left'),'String',num2str(ext(2)));
354                 set(findobj(gcf,'Tag','Top'),'String',num2str(PaperSize(2)-ext(2)-ext(4)));
355                 set(findobj(gcf,'Tag','Right'),'String',num2str(PaperSize(1)-ext(1)-ext(3)));
356                 set(PatchObj,'UserData',ext);
357         end
358 elseif(strcmp(command,'Margins'))
359         PaperPosition = get(gcf,'PaperPosition');
360         PaperSize = get(gcf,'PaperSize');
361         Bottom = str2num(get(findobj(gcf,'Tag','Bottom'),'String'));
362         Left = str2num(get(findobj(gcf,'Tag','Left'),'String'));
363         Top = str2num(get(findobj(gcf,'Tag','Top'),'String'));
364         Right = str2num(get(findobj(gcf,'Tag','Right'),'String'));
365         set(gcf,'PaperPosition',[Left ...
366                                  Bottom ...
367                                  PaperSize(1)-Left-Right ...
368                                  PaperSize(2)-Bottom-Top]);
369         PrintSetup('DrawPage');
370 elseif(strcmp(command,'Invert'))
371         if(get(findobj(gcf,'Tag','Invert'),'Value'))
372                 set(gcf,'InvertHardCopy','on');
373         else
374                 set(gcf,'InvertHardCopy','off');
375         end
376 elseif(strcmp(command,'PaperUnits'))
377         units = get(findobj(gcf,'Tag','PaperUnits'),'Value');
378         if(units == 1)
379                 set(gcf,'PaperUnits','Inches');
380         elseif(units == 2)
381                 set(gcf,'PaperUnits','Centimeters');
382         elseif(units == 3)
383                 set(gcf,'PaperUnits','Normalized');
384         elseif(units == 4)
385                 set(gcf,'PaperUnits','Points');
386         end
387         PaperSize = get(gcf,'PaperSize');
388         PaperPosition = get(gcf,'PaperPosition');
389         set(findobj(gcf,'Tag','Left'),'String',...
390                 num2str(PaperPosition(1)));
391         set(findobj(gcf,'Tag','Right'),'String',...
392                 num2str(PaperSize(1)-PaperPosition(1)-PaperPosition(3)));
393         set(findobj(gcf,'Tag','Top'),'String',...
394                 num2str(PaperSize(2)-PaperPosition(2)-PaperPosition(4)));
395         set(findobj(gcf,'Tag','Bottom'),'String',...
396                 num2str(PaperPosition(2)));
397         PrintSetup('DrawPage');
398 elseif(strcmp(command,'PaperType'))
399         UserData = get(gcf,'UserData');
400         val = get(findobj(gcf,'Tag','PaperType'),'Value');
401         if(val == 1)
402                 set(gcf,'PaperType','usletter');
403                 UserData(3) = 3.5;
404                 set(gcf,'UserData',UserData);
405         elseif(val == 2)
406                 set(gcf,'PaperType','uslegal');
407                 UserData(3) = 4;
408                 set(gcf,'UserData',UserData);
409         elseif(val == 3)
410                 set(gcf,'PaperType','a3');
411                 UserData(3) = 5;
412                 set(gcf,'UserData',UserData);
413         elseif(val == 4)
414                 set(gcf,'PaperType','a4letter');
415                 UserData(3) = 3.5;
416                 set(gcf,'UserData',UserData);
417         elseif(val == 5)
418                 set(gcf,'PaperType','a5');
419                 UserData(3) = 2.5;
420                 set(gcf,'UserData',UserData);
421         elseif(val == 6)
422                 set(gcf,'PaperType','b4');
423                 UserData(3) = 4;
424                 set(gcf,'UserData',UserData);
425         else
426                 set(gcf,'PaperType','tabloid');
427                 UserData(3) = 5;
428                 set(gcf,'UserData',UserData);
429         end
430         PrintSetup('Margins');
431 elseif(strcmp(command,'Orient'))
432         val = get(findobj(gcf,'Tag','Orient'),'Value');
433         if(val == 1)
434                 orient portrait;
435         elseif(val == 2)
436                 orient landscape;
437         else
438                 orient tall;
439         end
440         ext = get(gcf,'PaperPosition');
441         PaperSize = get(gcf,'PaperSize');
442         set(findobj(gcf,'Tag','Bottom'),'String',num2str(ext(1)));
443         set(findobj(gcf,'Tag','Left'),'String',num2str(ext(2)));
444         set(findobj(gcf,'Tag','Top'),'String',num2str(PaperSize(2)-ext(2)-ext(4)));
445         set(findobj(gcf,'Tag','Right'),'String',num2str(PaperSize(1)-ext(1)-ext(3)));
446         PrintSetup('DrawPage');
447 elseif(strcmp(command,'APPLY'))
448         UserData = get(gcf,'UserData');
449         fig = UserData(1);
450         set(fig,'PaperUnits',get(gcf,'PaperUnits'));
451         set(fig,'PaperType',get(gcf,'PaperType'));
452         set(fig,'PaperOrientation',get(gcf,'PaperOrientation'));
453         set(fig,'PaperPosition',get(gcf,'PaperPosition'));
454         set(fig,'InvertHardCopy',get(gcf,'InvertHardCopy'));
455 %       delete(gcf);
456 elseif(strcmp(command,'Cancel'))
457         delete(gcf);           
458 end
Note: See TracBrowser for help on using the browser.