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

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

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

Initial import of Stark code.

Line 
1 function EditLabel(command, subcommand)
2 % function EditLabel(command, subcommand)
3 %
4 % Abstract:
5 %   Edit labels of current axes
6 %
7 %
8 % Commands and subcommands:
9 %   initialize
10 %   editlabel
11 %     title
12 %     xlabel
13 %     ylabel
14 %     zlabel
15 %     gtext
16 %   reset
17 %     done
18 %     reset
19 %     cancel
20 %     show
21 %     newaxestouched
22 %   info
23 %
24 %
25 % History:
26 %
27 %
28
29 global LASTAXIS
30 axestr = ['XYZ'];
31
32
33 if nargin < 1
34   command = 'initialize';
35 end
36
37
38 if strcmp(command, 'initialize')
39  
40   EditLabelFig=findobj(0,'Type','figure','Tag','EditLabelFig');
41   if ~isempty(EditLabelFig),return,end
42  
43   curfig=gcf;
44   curfig = watchon;
45   if isempty(LASTAXIS)
46     curaxes=gca;
47   else
48     curaxes=LASTAXIS;
49   end
50    
51   EditLabelFig = figure('Position',[150 350 335 250],...
52       'NumberTitle','off',...
53       'Name','Edit Labels',...
54       'NextPlot','new',...
55       'Tag','EditLabelFig');
56
57  
58   LabelFrame=uicontrol('Parent',EditLabelFig, ...
59       'CallBack','', ...         
60       'Style','frame',...
61       'String','Axes Limits', ...
62       'Horiz', 'center', ...
63       'Position',[13 63 310 175], ...
64       'Tag','LabelFrame');
65
66   LabText1=uicontrol('Parent',EditLabelFig,...
67       'Style', 'text', ...
68       'Position',[13+5 63+150 300 20],...
69       'String','LABELS',...
70       'Horiz','center',...
71       'Tag','LabText1');
72   TLabO=uicontrol('Parent',EditLabelFig,...
73       'Style', 'text', ...
74       'Position',[13+5 63+125 50 20],...
75       'String','Title: ',...
76       'Horiz','Right',...
77       'Tag','TLabO');
78   XLabO=uicontrol('Parent',EditLabelFig,...
79       'Style', 'text', ...
80       'Position',[13+5 63+100 50 20],...
81       'String','X-Axis: ',...
82       'HorizontalAlignment','Right',...
83       'Tag','XLabO');
84   YLabO=uicontrol('Parent',EditLabelFig,...
85       'Style', 'text', ...
86       'Position',[13+5 63+75 50 20],...
87       'String','Y-Axis: ',...
88       'Horiz','Right',...
89       'Tag','YLabO');
90   ZLabO=uicontrol('Parent',EditLabelFig,...
91       'Style', 'text', ...
92       'Position',[13+5 63+50 50 20],...
93       'String','Z-Axis: ',...
94       'Horiz','Right',...
95       'Tag','ZLabO');
96   GLabO=uicontrol('Parent',EditLabelFig,...
97       'Style', 'text', ...
98       'Position',[13+5 63+25 50 20],...
99       'String','Gtext: ',...
100       'Horiz','Right',...
101       'Tag','GLabO');
102      
103   TLabOe=uicontrol('Parent',EditLabelFig,...
104       'CallBack','EditLabel(''editlabel'',''title'')',...
105       'BackgroundColor','w',...
106       'ForegroundColor','r',...
107       'Position',[13+5+50 63+125 247 20],...
108       'String',get(get(curaxes,'title'),'string'),...
109       'Style','edit',...
110       'Tag','TLabOe');
111   XLabOe=uicontrol('Parent',EditLabelFig,...
112       'CallBack','EditLabel(''editlabel'',''xlabel'')',...
113       'BackgroundColor','w',...
114       'ForegroundColor','r',...
115       'Position',[13+5+50 63+100 247 20],...
116       'String',get(get(curaxes,'xlabel'),'string'),...
117       'Style','edit',...
118       'Tag','XLabOe');
119   YLabOe=uicontrol('Parent',EditLabelFig,...
120       'CallBack','EditLabel(''editlabel'',''ylabel'')',...
121       'BackgroundColor','w',...
122       'ForegroundColor','r',...
123       'Position',[13+5+50 63+75 247 20],...
124       'String',get(get(curaxes,'ylabel'),'string'),...
125       'Style','edit',...
126       'Tag','YLabOe');
127   ZLabOe=uicontrol('Parent',EditLabelFig,...
128       'CallBack','EditLabel(''editlabel'',''zlabel'')',...
129       'BackgroundColor','w',...
130       'ForegroundColor','r',...
131       'Position',[13+5+50 63+50 247 20],...
132       'String',get(get(curaxes,'zlabel'),'string'),...
133       'Style','edit',...
134       'Tag','ZLabOe');
135   GLabOe=uicontrol('Parent',EditLabelFig,...
136        'CallBack','EditLabel(''editlabel'',''gtext'')',...
137        'BackgroundColor','w',...
138        'ForegroundColor','r',...
139        'Position',[13+5+50 63+25 247 20],...
140        'String','',...
141        'Style','edit',...
142        'Tag','GLabOe');
143
144   % Done, cancel, and reset buttons
145   DoneButton = uicontrol('Parent',EditLabelFig,...   
146       'BackgroundColor',[0;1;0],...
147       'Style','pushbutton',...
148       'String','Done',...
149       'Position',[23 35 50 20],...
150       'Callback','EditLabel(''reset'',''done'')',...
151       'Tag','DoneButton');
152
153   ResetButton = uicontrol('Parent',EditLabelFig,...   
154       'BackgroundColor',[1;1;0],...
155       'Style','pushbutton',...
156       'String','Reset',...
157       'Position',[23+63 35 50 20],...
158       'Callback','EditLabel(''reset'',''reset'')',...
159       'Tag','ResetButton');
160  
161   CancelButton = uicontrol('Parent',EditLabelFig,...   
162       'BackgroundColor',[1;0;0],...
163       'Style','pushbutton',...
164       'String','Cancel',...
165       'Position',[23+63+63 35 50 20],...
166       'Callback','EditLabel(''reset'',''cancel'')',...
167       'Tag','CancelButton');
168
169   HelpButton = uicontrol('Parent',EditLabelFig,...   
170       'BackgroundColor',[1;1;1],...
171       'ForegroundColor',[0;0;0],...
172       'Style','pushbutton',...
173       'String','HELP',...
174       'Position',[23+63 10 50 20],...
175       'Callback','EditLabel(''info'')',...
176       'Tag','HelpButton');
177  
178   % Use hidden axes (non-visible) to store original data about the limits
179   % so that original limits can be restored by user if it is desired
180   HiddenLabels = axes('Parent',EditLabelFig,...
181       'Visible', 'off', ...
182       'Tag', 'HiddenLabels');
183
184   title=get(get(curaxes, 'Title'), 'String');
185   set(get(HiddenLabels, 'Title'), 'String', title);
186  
187   % for each axis get label and set in Hidden Axes
188   for i=1:3
189     label=get(get(curaxes, [axestr(i) 'Label']), 'String');
190     set(get(HiddenLabels, [axestr(i) 'Label']), 'String', label);
191   end                                   % for each axis
192  
193   watchoff(curfig);
194    
195  elseif strcmp(command, 'editlabel')
196    
197    EditLabelFig=findobj(0,'Type','figure','Tag','EditLabelFig');
198
199    XLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'XLabOe');
200    YLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'YLabOe');
201    ZLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'ZLabOe');
202    
203    TLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'TLabOe');
204    GLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'GLabOe');
205
206    if isempty(LASTAXIS)
207      curaxes=gca;
208    else
209      curaxes=LASTAXIS;
210    end
211
212    if strcmp(subcommand, 'xlabel')
213      
214       XLabOe=findobj(EditLabelFig,'Type','uicontrol','Tag','XLabOe');
215       str=get(XLabOe,'String');
216       set(get(curaxes,'Xlabel'),'String',str);
217      
218    elseif strcmp(subcommand, 'ylabel')
219      
220       YLabOe=findobj(EditLabelFig,'Type','uicontrol','Tag','YLabOe');
221       str=get(YLabOe,'String');
222       set(get(curaxes,'Ylabel'),'String',str);
223      
224    elseif strcmp(subcommand, 'zlabel')
225      
226       YLabOe=findobj(EditLabelFig,'Type','uicontrol','Tag','ZLabOe');
227       str=get(ZLabOe,'String');
228       set(get(curaxes,'Zlabel'),'String',str);
229      
230    elseif strcmp(subcommand, 'title')
231      
232       TLabOe=findobj(EditLabelFig,'Type','uicontrol','Tag','TLabOe');
233       str=get(TLabOe,'String');
234       set(get(curaxes,'Title'),'String',str);
235      
236    elseif strcmp(subcommand, 'gtext')
237      
238       GLabOe=findobj(EditLabelFig,'Type','uicontrol','Tag','GLabOe');
239       str=get(GLabOe,'String');
240       axes(curaxes);
241       h=gtext(str);
242      
243    end
244
245  elseif strcmp(command, 'reset')
246  
247    EditLabelFig=findobj(0,'Type','figure','Tag','EditLabelFig');
248
249    XLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'XLabOe');
250    YLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'YLabOe');
251    ZLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'ZLabOe');
252    
253    TLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'TLabOe');
254    GLabOe = findobj(0,'Type', 'uicontrol', 'Tag', 'GLabOe');
255
256    HiddenLabels=findobj(0,'Type','axes','Tag','HiddenLabels');
257
258    if isempty(LASTAXIS)
259      curaxes=gca;
260    else
261      curaxes=LASTAXIS;
262    end
263
264
265    if strcmp(subcommand, 'done')
266      
267      %close Edit Label Figure and retain changes made
268      delete(EditLabelFig);
269      
270    elseif strcmp(subcommand, 'reset')
271      
272      % get data from hidden axes
273      title=get(get(HiddenLabels, 'title'), 'String');
274      set(get(curaxes, 'title'), 'String', title);
275
276      % for each axis set Hidden label back to curaxes
277      for i=1:3
278        label=get(get(HiddenLabels, [axestr(i) 'Label']), 'String');
279        set(get(curaxes, [axestr(i) 'Label']), 'String', label);
280      end                                % for each axis
281  
282      % show reset data back in Edit Labels
283      EditLabel('reset','show');
284      
285    elseif strcmp(subcommand, 'cancel')
286      
287      title=get(get(HiddenLabels, 'title'), 'String');
288      set(get(curaxes, 'title'), 'String', title);
289
290      % for each axis set Hidden label back to curaxes
291      for i=1:3
292        label=get(get(HiddenLabels, [axestr(i) 'Label']), 'String');
293        set(get(curaxes, [axestr(i) 'Label']), 'String', label);
294      end                                % for each axis
295      
296      
297      delete(EditLabelFig);
298      
299    elseif strcmp(subcommand, 'show')
300      set(TLabOe, 'String', get(get(curaxes, 'title'), 'String'));
301      
302      set(XLabOe, 'String', get(get(curaxes, 'xlabel'), 'String'));
303      set(YLabOe, 'String', get(get(curaxes, 'ylabel'), 'String'));
304      set(ZLabOe, 'String', get(get(curaxes, 'zlabel'), 'String'));
305      
306    elseif strcmp(subcommand, 'newaxestouched')
307      title=get(get(curaxes, 'Title'), 'String');
308      set(get(HiddenLabels, 'Title'), 'String', title);
309  
310      % for each axis get label and set in Hidden Axes
311      for i=1:3
312        label=get(get(curaxes, [axestr(i) 'Label']), 'String');
313        set(get(HiddenLabels, [axestr(i) 'Label']), 'String', label);
314      end                                % for each axis
315
316  
317      EditLabel('reset', 'show');
318      
319    end
320    
321    
322  elseif strcmp(command,'info');
323     ttlStr='Edit Labels Help';
324     hlpStr= ...                                           
325         ['                                              ' 
326          '                                              ' 
327          '                                              '];
328     PrHelp(ttlStr,hlpStr);                               
329  
330  end
Note: See TracBrowser for help on using the browser.