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

root/gliderproc/trunk/MATLAB/util/suspend.m

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

Initial import of Stark code.

Line 
1 function theResult = suspend(theValue)
2
3 % suspend -- Control for suspending any process.
4 %  suspend('demo') demonstrates itself.
5 %  suspend (no arguments) creates or activates a pushbutton
6 %   control labeled "Suspend" that can be used to guide the
7 %   suspension of activities.
8 %  suspend(0 or 1) sets/gets the state of the control.
9 %   If the control-value is 1, suspend execution by using
10 %   "keyboard" from within your procedure.  After resuming,
11 %   reset the control with "suspend(0)".
12 %  suspend([]) deletes the control.
13 %
14 % Also see: keyboard.
15  
16 % Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO.
17 %  All Rights Reserved.
18 %   Disclosure without explicit written consent from the
19 %    copyright owner does not constitute publication.
20  
21 % Version of 26-Jul-2000 13:57:27.
22 % Updated    27-Jul-2000 13:45:47.
23
24 persistent theControl
25
26 % Constants.
27
28 RED = [1 0 0];
29 GREEN = [0 1 0];
30 THE_TAG = '__Suspend__';
31 N_DEMO = 3;
32
33 % Demonstration.
34
35 if nargin > 0 & isequal(theValue, 'demo')
36         disp([' ## Suspend this process ' int2str(N_DEMO) ...
37                         ' times by clicking "Suspend".'])
38         suspend(0)
39         count = 0;
40         while count < N_DEMO
41                 drawnow   % Very important.
42                 if suspend
43                         count = count + 1;
44                         disp([' ## Suspended at ' datestr(now)])
45                         disp([' ## Now entering "keyboard" mode ...'])
46                         disp([' ## Type "r-e-t-u-r-n" to continue.'])
47                         keyboard
48                         disp(' ## Resuming ...')
49                         suspend(0)
50                 end
51         end
52         suspend([])
53         disp(' ## Done')
54         return
55 end
56
57 % Create or activate the control.
58
59 if ~any(gcbo)
60         theFigure = findobj('Type', 'figure', 'Tag', THE_TAG);
61         if isempty(theFigure)
62                 theFigure = figure('Name', 'Suspend', 'Visible', 'off', ...
63                                                         'Tag', THE_TAG, ...
64                                                         'CloseRequestFcn', 'suspend([])');
65                 theControl = uicontrol(theFigure, 'Style', 'PushButton', ...
66                                         'String', 'Suspend', 'BackgroundColor', GREEN, ...
67                                         'Callback', mfilename);
68                 pos = get(theControl, 'Position');
69                 set(theControl, 'Position', [0 0 1 1] .* pos);
70                 pos = [1 1 0 0] .* get(theFigure, 'Position') + ...
71                                 [0 0 1 1] .* get(theControl, 'Position');
72                 pos(1:2) = 20;
73                 p = get(theFigure, 'Position');
74                 set(theFigure, 'Position', pos, 'Resize', 'off', 'Visible', 'on')
75         end
76         figure(theFigure)
77 end
78
79 % Toggle the color-state via callback.
80
81 if any(gcbo) & isequal(theControl, gcbo)
82         theColor = get(gcbo, 'BackGroundColor');
83         if isequal(theColor, RED)
84                 set(gcbo, 'BackgroundColor', GREEN)
85         else
86                 set(gcbo, 'BackgroundColor', RED)
87         end
88         return
89 end
90
91 % Set the color-state.
92
93 if nargin > 0
94         if ischar(theValue), theValue = eval(theValue); end
95         if isempty(theValue)
96                 theFigure = findobj('Type', 'figure', 'Tag', THE_TAG);
97                 delete(theFigure)
98                 theControl = [];
99                 return
100         elseif isequal(theValue, 0)
101                 set(theControl, 'BackgroundColor', GREEN)
102         else
103                 set(theControl, 'BackgroundColor', RED)
104         end
105 end
106
107 % Get the color-state.
108
109 if nargout > 0
110         theColor = get(theControl, 'BackgroundColor');
111         theResult = isequal(theColor, RED);
112         return
113 end
Note: See TracBrowser for help on using the browser.