/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_misc/gcmfaces_caption.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_misc/gcmfaces_caption.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Sun Mar 13 15:41:48 2016 UTC (9 years, 4 months ago) by gforget
Branch: MAIN
Changes since 1.1: +27 -19 lines
- revised handling of temporary variables.

1 gforget 1.1 function []=gcmfaces_caption(myCaption);
2     % GCMFACES_CAPTION(myCaption) adds an editable
3     % caption to the current figure and menu buttons
4     % to show or hide it, or return its handle.
5 gforget 1.2 %
6     % Notes:
7     % 1) the added menu functionalities only support one
8     % caption per figure.
9     % 2) the added menu functionalities operate with two
10     % temporary variables (capTmp, capTmppp) that get
11     % deleted after each callback.
12 gforget 1.1
13     gcmfaces_global;
14    
15     %the on/off button callback in text form
16     capOnOff=[...
17 gforget 1.2 'capTmp.h=findall(gcf,''type'',''uipanel'');' ...
18     'capTmp.nh=length(capTmp.h);' ...
19     'capTmp.captionHandle=[];' ...
20     'for capTmppp=1:length(capTmp.h);' ...
21     ' capTmp.tag=get(capTmp.h(capTmppp),''Tag'');' ...
22     ' if ~isempty(strfind(capTmp.tag,''gfCap''));' ...
23     ' capTmp.captionHandle=capTmp.h(capTmppp);' ...
24 gforget 1.1 ' end;' ...
25     'end;' ...
26 gforget 1.2 'capTmp.tmp1=get(capTmp.captionHandle,''Visible'');' ...
27     'if strcmp(capTmp.tmp1,''on'');' ...
28     ' capTmp.tmp1=''off'';' ...
29 gforget 1.1 'else;' ...
30 gforget 1.2 ' capTmp.tmp1=''on''; ' ...
31 gforget 1.1 'end;' ...
32 gforget 1.2 'set(capTmp.captionHandle,''Visible'',capTmp.tmp1);' ...
33     'clear capTmp capTmppp;' ...
34 gforget 1.1 ];
35    
36     capHandle=[...
37 gforget 1.2 'capTmp.h=findall(gcf,''type'',''uipanel'');' ...
38     'capTmp.nh=length(capTmp.h);' ...
39 gforget 1.1 'captionHandle=[];' ...
40 gforget 1.2 'for capTmppp=1:length(capTmp.h);' ...
41     ' capTmp.tag=get(capTmp.h(capTmppp),''Tag'');' ...
42     ' if ~isempty(strfind(capTmp.tag,''gfCap''));' ...
43     ' captionHandle=capTmp.h(capTmppp);' ...
44 gforget 1.1 ' end;' ...
45     'end;' ...
46 gforget 1.2 'clear capTmp capTmppp;' ...
47 gforget 1.1 'evalin(''base'',''captionHandle'');' ...
48     ];
49    
50     %use call back for example:
51     if isempty(who('myCaption'));
52     myCaption='';
53     %use call back for example:
54     %myCaption=['example: ' capOnOff];
55     end;
56    
57     %create and tag panel:
58     hp = uipanel('Title','Caption','FontSize',12,...
59     'BackgroundColor','white',...
60     'Position',[.05 0.85 .9 .1]);
61     set(hp,'Tag','gfCap');
62    
63     %add the caption text in panel:
64     txt = uicontrol('Parent',hp,'Style', 'edit','Max',2,'Min',0, 'String', myCaption);
65     set(txt,'FontSize',14,'units','normalized');
66     set(txt,'Position',[0.05 0.1 0.9 0.8])
67    
68     %add menu button:
69     mn=uimenu('Label','Caption');
70     uimenu(mn,'Label','Hide/Show','Callback',capOnOff);
71     uimenu(mn,'Label','captionHandle','Callback',capHandle);
72    

  ViewVC Help
Powered by ViewVC 1.1.22