1 |
function [newvalue] = EditValue(titlestr, labelstr, value) |
---|
2 |
%function [newvalue] = EditValue(titlestr, labelstr, value) |
---|
3 |
% |
---|
4 |
% Abstract: |
---|
5 |
% Pop-up window with editable text control that allows user |
---|
6 |
% to interactively change a floating point value. |
---|
7 |
% |
---|
8 |
% Usage: |
---|
9 |
% Intended to be used from another program that requires user |
---|
10 |
% input or user requests change. The window stays open and |
---|
11 |
% consequently the function is in a wait state until user |
---|
12 |
% completes requested change. |
---|
13 |
% |
---|
14 |
% >> option = EditValue('Edit Value', 'Marker Size:', 1); |
---|
15 |
% |
---|
16 |
|
---|
17 |
% History: |
---|
18 |
% o 11 August 1995 create function, window, by Sara Haines |
---|
19 |
% |
---|
20 |
|
---|
21 |
if nargin < 3 |
---|
22 |
disp('EditValue: error! Not enough input arguments'); |
---|
23 |
return; |
---|
24 |
end |
---|
25 |
|
---|
26 |
|
---|
27 |
Wpos = [130 300 125 100]; |
---|
28 |
EditWin = figure('Position', [Wpos], ... |
---|
29 |
'NumberTitle','off',... |
---|
30 |
'Name', titlestr,... |
---|
31 |
'NextPlot','new',... |
---|
32 |
'Userdata', [1], ... |
---|
33 |
'Tag','EditWin'); |
---|
34 |
|
---|
35 |
LabelText = uicontrol('Parent', EditWin, ... |
---|
36 |
'CallBack','', ... |
---|
37 |
'Style','text',... |
---|
38 |
'String', labelstr, ... |
---|
39 |
'ForeGround', 'w', ... |
---|
40 |
'BackGround', 'k', ... |
---|
41 |
'Horiz', 'center', ... |
---|
42 |
'Units', 'normal', ... |
---|
43 |
'Position',[0.1 0.7 0.8 0.3], ... |
---|
44 |
'Tag','LabelText'); |
---|
45 |
|
---|
46 |
EditText = uicontrol('Parent', EditWin, ... |
---|
47 |
'CallBack','set(findobj(0,''Tag'',''EditWin''), ''Userdata'', -1)', ... |
---|
48 |
'Style','edit',... |
---|
49 |
'String', num2str(value), ... |
---|
50 |
'ForeGround', 'r', ... |
---|
51 |
'BackGround', 'w', ... |
---|
52 |
'Horiz', 'center', ... |
---|
53 |
'Units', 'normal', ... |
---|
54 |
'Position',[0.2 0.4 0.6 0.3], ... |
---|
55 |
'Tag','EditText'); |
---|
56 |
|
---|
57 |
% set userdata to original value |
---|
58 |
set(EditText, 'Userdata', value); |
---|
59 |
newvalue = value; % until user changes it! |
---|
60 |
|
---|
61 |
CancelButton = uicontrol('Parent',EditWin,... |
---|
62 |
'Callback','set(findobj(0,''Tag'',''EditWin''), ''Userdata'', 0)',... |
---|
63 |
'BackgroundColor',[1;0;0],... |
---|
64 |
'Style','pushbutton',... |
---|
65 |
'String','Cancel',... |
---|
66 |
'Units', 'normal', ... |
---|
67 |
'Position',[0.3 0.1 0.4 0.2],... |
---|
68 |
'Tag','CancelButton'); |
---|
69 |
|
---|
70 |
% purposefully suspend other action until user finishes edit change |
---|
71 |
% or presses the cancel button |
---|
72 |
figure(EditWin); |
---|
73 |
while get(EditWin, 'Userdata')==1 |
---|
74 |
figure(EditWin); |
---|
75 |
pause(1); |
---|
76 |
end |
---|
77 |
|
---|
78 |
newvalue = str2num(get(EditText, 'String')); |
---|
79 |
close(EditWin); |
---|