1 | function newList = locoeditlist(List, ListName, CheckList) |
---|
2 | %LOCOEDITLIST - Device list editor |
---|
3 | % newList = locoeditlist(List) |
---|
4 | % newList = locoeditlist(List, InfoString) |
---|
5 | % newList = locoeditlist(List, InfoString, CheckList) |
---|
6 | % |
---|
7 | % Allows one to easily edit a element or device list |
---|
8 | % Inputs: List = list to edit |
---|
9 | % InfoString = informational string {optional} |
---|
10 | % CheckList = 0 - don't check, else check |
---|
11 | % |
---|
12 | % Note: Closing the window will result in no change to the list |
---|
13 | % |
---|
14 | % Writen by Greg Portmann |
---|
15 | |
---|
16 | if nargin < 1 |
---|
17 | error('At least 1 input is required.') |
---|
18 | end |
---|
19 | |
---|
20 | if nargin < 2 |
---|
21 | ListName = ''; |
---|
22 | end |
---|
23 | |
---|
24 | if isstr(List) |
---|
25 | error('First input cannot be a string'); |
---|
26 | return |
---|
27 | end |
---|
28 | |
---|
29 | if nargin < 3 |
---|
30 | CheckList = ones(max(size(List)),1); |
---|
31 | end |
---|
32 | if ~isstr(ListName) |
---|
33 | CheckList = ListName; |
---|
34 | ListName = ''; |
---|
35 | end |
---|
36 | |
---|
37 | if length(CheckList) ~= max(size(List)) |
---|
38 | error('List and CheckList must have the same max(size).'); |
---|
39 | end |
---|
40 | |
---|
41 | |
---|
42 | if isunix |
---|
43 | ScaleFactor = 8; |
---|
44 | ButtonHeight = 20; |
---|
45 | Offset = 6; |
---|
46 | else |
---|
47 | ScaleFactor = 6.5; |
---|
48 | ButtonHeight = 16; |
---|
49 | Offset = 6; |
---|
50 | end |
---|
51 | |
---|
52 | |
---|
53 | if size(List,2) == 2 |
---|
54 | % Column vector |
---|
55 | RowVectorFlag = 0; |
---|
56 | ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d), RingData(%d)', ListName, max(List(:,1)), max(List(:,1))))+Offset); |
---|
57 | elseif size(List,1) == 1 |
---|
58 | % Row vector |
---|
59 | List = List'; |
---|
60 | RowVectorFlag = 1; |
---|
61 | ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d)', ListName, max(List)))+Offset); |
---|
62 | elseif size(List,2) == 1 |
---|
63 | % Column vector |
---|
64 | RowVectorFlag = 0; |
---|
65 | ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d)', ListName, max(List)))+Offset); |
---|
66 | elseif size(List,2) > 2 |
---|
67 | % More than 2 columns is a problem |
---|
68 | error('Input list must be 1 or 2 columns.') |
---|
69 | end |
---|
70 | if ButtonWidth < 75 |
---|
71 | ButtonWidth = 75; |
---|
72 | end |
---|
73 | |
---|
74 | % Add a buffer to ButtonWidth |
---|
75 | ButtonWidth = 1.15*ButtonWidth; |
---|
76 | |
---|
77 | n = size(List,1); |
---|
78 | col = ceil(n/40); |
---|
79 | row = ceil(n/col); |
---|
80 | |
---|
81 | |
---|
82 | FigWidth = col*ButtonWidth + (col-1)*3 + 6; |
---|
83 | FigHeight = 3+(row+1)*ButtonHeight; |
---|
84 | |
---|
85 | |
---|
86 | % Change figure position |
---|
87 | set(0,'Units','pixels'); |
---|
88 | p=get(0,'screensize'); |
---|
89 | |
---|
90 | h0 = figure( ... |
---|
91 | 'Color',[0.8 0.8 0.8], ... |
---|
92 | 'HandleVisibility','On', ... |
---|
93 | 'Interruptible', 'on', ... |
---|
94 | 'MenuBar','none', ... |
---|
95 | 'Name',['Edit ', ListName, ' List'], ... |
---|
96 | 'NumberTitle','Off', ... |
---|
97 | 'Units','pixels', ... |
---|
98 | 'Position',[30 p(4)-FigHeight-40 FigWidth FigHeight], ... |
---|
99 | 'Resize','on', ... |
---|
100 | 'Userdata', [], ... |
---|
101 | 'Tag','EditListFigure'); |
---|
102 | |
---|
103 | k = 1; |
---|
104 | for j = 1:col |
---|
105 | for i = 1:row |
---|
106 | |
---|
107 | if size(List,2) == 2 |
---|
108 | liststring = sprintf('%s(%d), RingData(%d)', ListName, List(k,1), List(k,2)); |
---|
109 | %liststring = sprintf('%s(%d,%d)', ListName, List(k,1), List(k,2)); |
---|
110 | else |
---|
111 | liststring = sprintf('%s(%d)', ListName, List(k,1)); |
---|
112 | end |
---|
113 | |
---|
114 | if CheckList(k) |
---|
115 | EnableFlag = 1; |
---|
116 | else |
---|
117 | EnableFlag = 0; |
---|
118 | end |
---|
119 | |
---|
120 | h(k) = uicontrol('Parent',h0, ... |
---|
121 | 'Callback','', ... |
---|
122 | 'Enable','On', ... |
---|
123 | 'FontName', 'MS Sans Serif', ... |
---|
124 | 'FontSize', [8], ... |
---|
125 | 'FontUnits', 'points', ... |
---|
126 | 'Interruptible','Off', ... |
---|
127 | 'Position',[6+(j-1)*(ButtonWidth+3) 3+(row-i+1)*ButtonHeight ButtonWidth-0*6 ButtonHeight], ... |
---|
128 | 'Style','radio', ... |
---|
129 | 'String',liststring, ... |
---|
130 | 'Value',EnableFlag, ... |
---|
131 | 'Userdata',List(k,:), ... |
---|
132 | 'Tag','Radio1'); |
---|
133 | k = k + 1; |
---|
134 | if k > n |
---|
135 | break |
---|
136 | end |
---|
137 | end |
---|
138 | end |
---|
139 | |
---|
140 | h1 = uicontrol(... |
---|
141 | 'Parent',h0, ... |
---|
142 | 'Callback',[... |
---|
143 | 'h = get(gco,''userdata'');', ... |
---|
144 | 'l=[];m=1;', ... |
---|
145 | 'for i = 1:length(h);', ... |
---|
146 | ' if get(h(i),''Value'') == 1', ... |
---|
147 | ' l(m,:) = get(h(i),''userdata'');', ... |
---|
148 | ' m=m+1;', ... |
---|
149 | ' end;', ... |
---|
150 | 'end;', ... |
---|
151 | 'set(gco,''userdata'',l);', ... |
---|
152 | 'set(gcf,''userdata'',1);' , ... |
---|
153 | 'drawnow;';], ... |
---|
154 | 'Enable','On', ... |
---|
155 | 'Interruptible','Off', ... |
---|
156 | 'Position',[3 3+0*ButtonHeight FigWidth-6 ButtonHeight], ... |
---|
157 | 'String','Change List', ... |
---|
158 | 'userdata', h, ... |
---|
159 | 'Tag','EditListClose'); |
---|
160 | |
---|
161 | |
---|
162 | waitfor(gcf,'userdata'); |
---|
163 | newList=get(gco,'userdata'); |
---|
164 | |
---|
165 | if gcf == h0 |
---|
166 | close(h0); |
---|
167 | else |
---|
168 | % If the figure is closed (not changed) return the old list |
---|
169 | i = find(CheckList); |
---|
170 | newList = List(i,:); |
---|
171 | end |
---|
172 | |
---|
173 | if RowVectorFlag |
---|
174 | newList = newList'; |
---|
175 | end |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|