1 | function out = uigetdate(varargin) |
---|
2 | % UIGETDATE date selection dialog box |
---|
3 | % T = UIGETDATE(D) displays a dialog box in form of a calendar |
---|
4 | % |
---|
5 | % UIGETDATE expects serial date number or standard MATLAB Date |
---|
6 | % format (see DATESTR) as input data und returns serial date number |
---|
7 | % for the selected date and time. |
---|
8 | % |
---|
9 | % UIGETDATE by itself uses the current date and time as input data |
---|
10 | % |
---|
11 | % Example: |
---|
12 | % t = datestr( uigetdate('16-Aug-1974 03:00') ) |
---|
13 | % |
---|
14 | % See also datevec, datestr, datenum |
---|
15 | |
---|
16 | % version: v1.0 |
---|
17 | % author: Elmar Tarajan [MCommander@gmx.de] |
---|
18 | |
---|
19 | if nargin == 0 |
---|
20 | varargin{1} = now; |
---|
21 | end% if |
---|
22 | |
---|
23 | if ~ishandle(varargin{1}) |
---|
24 | % |
---|
25 | datvec = datevec(varargin{1}); |
---|
26 | % |
---|
27 | scr = get(0,'ScreenSize'); |
---|
28 | h.units = 'pixels'; |
---|
29 | h.parent = figure(h,'menubar','none', ... |
---|
30 | 'numbertitle','off', ... |
---|
31 | 'resize','off', ... |
---|
32 | 'handlevisibility','on', ... |
---|
33 | 'visible','off', ... |
---|
34 | 'WindowStyle','modal', ... |
---|
35 | 'Tag','uigetdate', ... |
---|
36 | 'position',[ (scr(3:4)- [197 199])/2 197 199 ]); |
---|
37 | % |
---|
38 | pos = [5 5 0 0]; |
---|
39 | uicontrol(h,'style','edit','position',pos+[0 0 104 26]) |
---|
40 | uicontrol('style','slider','units','pixels','position',pos+[3 2 100 20], ... |
---|
41 | 'sliderstep',[.0005 .0005],'min',-10,'max',10,'value',0, ... |
---|
42 | 'callback','uigetdate(gcbo,''time'')','UserData',0) |
---|
43 | % |
---|
44 | h.style = 'edit'; |
---|
45 | h.fontweight = 'bold'; |
---|
46 | h.foregroundcolor = [.2 .2 .2]; |
---|
47 | uicontrol(h,'enable','inactive','position',pos+[ 17 2 73 20],'Tag','time', ... |
---|
48 | 'String',sprintf('%02d:%02d',datvec(4:5))) |
---|
49 | % |
---|
50 | % textbanners |
---|
51 | tmp = [2 20 101 4 ; 2 2 101 3 ; 2 2 3 22 ; 17 2 2 22 ; 88 2 2 22 ; 101 2 2 22 ]; |
---|
52 | for i=1:6 ; uicontrol(h,'style','text','position',pos+tmp(i,:)) ; end% for |
---|
53 | % |
---|
54 | uicontrol(h,'style','edit','position',pos+[105 0 84 26],'visible','on') |
---|
55 | uicontrol(h,'style','pushbutton','position',pos+[108 2 78 21],'Tag','ok', ... |
---|
56 | 'CData',repmat(repmat([0.3:0.01:1 1:-0.01:0.3],18,1),[1 1 3]), ... |
---|
57 | 'string','ok','Callback','uigetdate(gcbo,''ok'')') |
---|
58 | % |
---|
59 | pos = [5 32 0 0]; |
---|
60 | uicontrol(h,'style','edit','position',pos+[0 0 189 136],'enable','inactive','Tag','cday', ... |
---|
61 | 'UserData',datvec(3)) |
---|
62 | h.style = 'pushbutton'; |
---|
63 | h.fontweight = 'normal'; |
---|
64 | for i=95:-19:0 |
---|
65 | for j=0:26:156 |
---|
66 | uicontrol(h,'position',pos+[j+3 i+2 27 20],'Enable','off', ... |
---|
67 | 'foregroundcolor',[.2 .2 .2],'Tag','day', ... |
---|
68 | 'callback','uigetdate(gcbo,''day'')') |
---|
69 | end% for |
---|
70 | end% for |
---|
71 | % |
---|
72 | tmp = {'Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun'}; |
---|
73 | for j=0:6 |
---|
74 | uicontrol(h,'style','text','position',pos+[j*26+4 119 25 13],'string',tmp{j+1}, ... |
---|
75 | 'backgroundcolor',[0.4 0.4 0.4],'foregroundcolor',[.9 .9 .9]) |
---|
76 | end% for |
---|
77 | % |
---|
78 | pos = [5 169 0 0]; |
---|
79 | uicontrol(h,'style','edit','position',pos+[0 0 189 26]) |
---|
80 | h.style = 'slider'; |
---|
81 | uicontrol(h,'position',pos+[3 2 100 20],'sliderstep',[0.00025 1], ... |
---|
82 | 'min',-2000,'max',2000,'Value',datvec(2), ... |
---|
83 | 'callback','uigetdate(gcbo,''months'')') |
---|
84 | uicontrol(h,'position',pos+[112 2 74 20],'sliderstep',[0.00025 1], ... |
---|
85 | 'min',0,'max',4000,'value',datvec(1), ... |
---|
86 | 'callback','uigetdate(gcbo,''year'')') |
---|
87 | % |
---|
88 | h.style = 'edit'; |
---|
89 | h.enable = 'inactive'; |
---|
90 | h.fontweight = 'bold'; |
---|
91 | h.foregroundcolor = [.2 .2 .2]; |
---|
92 | tmp = {'Januar' 'Februar' 'March' 'April' 'May' 'Juni' 'Juli' ... |
---|
93 | 'August' 'September' 'October' 'November' 'December'}; |
---|
94 | uicontrol(h,'position',pos+[ 17 2 73 20],'Tag','months','String',tmp{datvec(2)},'Userdata',tmp) |
---|
95 | uicontrol(h,'position',pos+[126 2 47 20],'Tag','year','String',num2str(datvec(1))) |
---|
96 | % |
---|
97 | % textbanners |
---|
98 | h.style = 'text'; |
---|
99 | tmp = [2 20 185 4 ; 2 2 185 3 ; 2 2 3 22 ; 17 2 2 22 ; 88 2 2 22 ; ... |
---|
100 | 101 2 13 22 ; 126 2 2 22 ; 171 2 2 22 ; 184 2 3 22]; |
---|
101 | for i=1:9 |
---|
102 | uicontrol(h,'position',pos+tmp(i,:)) |
---|
103 | end% for |
---|
104 | % |
---|
105 | set(h.parent,'visible','on') |
---|
106 | setday(varargin{1}) |
---|
107 | % |
---|
108 | set(findobj(gcf,'string',num2str(datvec(3))),'CData',geticon) |
---|
109 | % |
---|
110 | uiwait |
---|
111 | try |
---|
112 | out = datenum([num2str( ... |
---|
113 | get(findobj(gcf,'Tag','cday'),'UserData')) '-' ... |
---|
114 | get(findobj(gcf,'Tag','months'),'String') '-' ... |
---|
115 | get(findobj(gcf,'Tag','year'),'String') ' ' ... |
---|
116 | get(findobj(gcf,'Tag','time'),'String') ':00']); |
---|
117 | delete(findobj(0,'Tag','uigetdate')) |
---|
118 | catch |
---|
119 | out = []; |
---|
120 | closereq |
---|
121 | end% try |
---|
122 | |
---|
123 | return |
---|
124 | end% if |
---|
125 | |
---|
126 | switch varargin{2} |
---|
127 | case 'months' |
---|
128 | h = findobj(gcbf,'Tag','months'); |
---|
129 | months = get(h,'UserData'); |
---|
130 | set(h,'String',months{mod(get(gcbo,'Value')-1,12)+1}) |
---|
131 | set(findobj(gcbf,'Tag','ok'),'Enable','off') |
---|
132 | % |
---|
133 | case 'year' |
---|
134 | set(findobj(gcbf,'Tag','year'),'String',get(gcbo,'Value')) |
---|
135 | set(findobj(gcbf,'Tag','ok'),'Enable','off') |
---|
136 | % |
---|
137 | case 'day' |
---|
138 | h= findobj(gcf,'Tag','day'); |
---|
139 | set(h,'CData',[]) |
---|
140 | |
---|
141 | set(varargin{1},'CData',geticon) |
---|
142 | set(findobj(gcbf,'Tag','cday'),'Userdata',get(varargin{1},'String')) |
---|
143 | set(findobj(gcbf,'Tag','ok'),'Enable','on') |
---|
144 | try ; uicontrol(h(3)) ; end% try |
---|
145 | return |
---|
146 | % |
---|
147 | case 'time' |
---|
148 | try |
---|
149 | if toc<0.1 |
---|
150 | step = get(gcbo,'UserData'); |
---|
151 | set(gcbo,'UserData',step+1) |
---|
152 | step = floor(step*sign(get(gcbo,'value'))/2); |
---|
153 | else |
---|
154 | set(gcbo,'UserData',1) |
---|
155 | step = sign(get(gcbo,'value')); |
---|
156 | set(gcbo,'value',0) |
---|
157 | end% if |
---|
158 | % |
---|
159 | handles.time = findobj(gcbf,'Tag','time'); |
---|
160 | time = sum(sscanf(get(handles.time,'String'),'%d:%d').*[60;1]); |
---|
161 | time = time+step; |
---|
162 | if time<0 |
---|
163 | time = 1439; |
---|
164 | elseif time>1439 |
---|
165 | time = 0; |
---|
166 | end% if |
---|
167 | time = sprintf('%02.f:%02.f',floor(time/60),(time/60-floor(time/60))*60); |
---|
168 | set(handles.time,'String',time) |
---|
169 | % |
---|
170 | tic |
---|
171 | return |
---|
172 | catch |
---|
173 | tic |
---|
174 | end% try |
---|
175 | drawnow |
---|
176 | % |
---|
177 | case 'ok' |
---|
178 | uiresume |
---|
179 | return |
---|
180 | % |
---|
181 | end% switch |
---|
182 | setday(['1-' get(findobj(gcbf,'Tag','months'),'String') '-' ... |
---|
183 | get(findobj(gcbf,'Tag','year'),'String')]) |
---|
184 | % |
---|
185 | % |
---|
186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
187 | function setday(datvec) |
---|
188 | %------------------------------------------------------------------------------- |
---|
189 | datvec = datevec(datvec); |
---|
190 | datvec(3) = 1; |
---|
191 | % |
---|
192 | day = [7 1 2 3 4 5 6]; |
---|
193 | day = day(weekday(datestr(datvec))); |
---|
194 | % |
---|
195 | monthend = eomday(datvec(1),datvec(2)); |
---|
196 | % |
---|
197 | ind = [zeros(1,42-monthend-day+1) monthend:-1:1 zeros(1,day-1)]; |
---|
198 | % |
---|
199 | enable = repmat({'on'},42,1); |
---|
200 | enable(ind==0) = {'off'}; |
---|
201 | % |
---|
202 | count = strrep(strrep(cellstr(num2str(ind')),' 0',''),' ',''); |
---|
203 | % |
---|
204 | h = findobj(gcf,'Tag','day'); |
---|
205 | set(h,{'String'},count,{'Enable'},enable,'backgroundcolor',[0.7 0.7 0.7],'CData',[]) |
---|
206 | set(h(ind~=0),'backgroundcolor',[.925 .922 .9002]); |
---|
207 | set(h(ind~=0&repmat([1 1 0 0 0 0 0],1,6)),'backgroundcolor',[1 .8 .8]) |
---|
208 | % |
---|
209 | % |
---|
210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
211 | function icon = geticon |
---|
212 | %------------------------------------------------------------------------------- |
---|
213 | tmp = [0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ; |
---|
214 | 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 ; ... |
---|
215 | 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 ; ... |
---|
216 | 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 ; ... |
---|
217 | 1 1 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 ; ... |
---|
218 | 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 ; ... |
---|
219 | 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 ; ... |
---|
220 | 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 ; ... |
---|
221 | 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 ; ... |
---|
222 | 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 ; ... |
---|
223 | 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 ; ... |
---|
224 | 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 ; ... |
---|
225 | 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 ; ... |
---|
226 | 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 ; ... |
---|
227 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 ]; |
---|
228 | tmp(tmp==1)=NaN; |
---|
229 | tmp(tmp==0)=1; |
---|
230 | icon(:,:,1) = tmp; |
---|
231 | tmp(tmp==1)=0.25; |
---|
232 | icon(:,:,2) = tmp; |
---|
233 | tmp(tmp==.25)=0; |
---|
234 | icon(:,:,3) = tmp; |
---|