-
Notifications
You must be signed in to change notification settings - Fork 8
/
SelectionGUI.m
371 lines (282 loc) · 11.9 KB
/
SelectionGUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
function varargout = SelectionGUI(varargin)
% SELECTIONGUI - Select from a list of strings
% -------------------------------------------------------------
% Abstract: This GUI allows you to select from a list of strings, and
% returns the result. The GUI presents a list of strings on the left pane,
% and allows the user to select them to the right pane.
%
% SelectionIndex = SelectionGUI(List,InitSelectionIndex,guiTitle);
%
% Inputs:
% List (cellstr array) - list of items that can be selected
% SelectionIndex (double array) - Indices of initially selected items
% guiTitle (char) - Title of the GUI
%
% Outputs:
% SelectionIndex (double array) - Indices of final selected items
%
% Examples:
% States = {'Alaska','Hawaii','Texas','Washington','Washington DC','Florida'}
% SelectionIndex = SelectionGUI(States,[1 2],'Pick some states')
%
% Notes: If user cancels, SelectionGUI will return zero.
% Copyright 2010 The MathWorks, Inc.
%
% Auth/Revision:
% The MathWorks Consulting Group
% Author: rjackey
% Revision: 280
% Date: 2010-07-26 17:00:35 -0700 (Mon, 26 Jul 2010)
%
% -------------------------------------------------------------------------
% Edited for use in SBEToolbox
% -------------------------------------------------------------------------
%
% Systems Biology and Evolution Toolbox (SBEToolbox).
% Authors: Kranti Konganti.
% (C) Texas A&M University.
%
% $LastChangedDate: 2013-05-30 14:53:32 -0500 (Thu, 30 May 2013) $
% $LastChangedRevision: 574 $
% $LastChangedBy: konganti $
%
% Edit the above text to modify the response to help SelectionGUI
% Last Modified by GUIDE v2.5 30-May-2013 14:37:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SelectionGUI_OpeningFcn, ...
'gui_OutputFcn', @SelectionGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
function SelectionGUI_OpeningFcn(hObject, eventdata, handles, varargin) %#ok<INUSL,INUSL>
% --- Executes just before SelectionGUI is made visible.
% Check input arguments
if length(varargin) < 1
ItemsList = {};
else
ItemsList = varargin{1};
end
if length(varargin) < 2
InitSelectionIndex = [];
else
InitSelectionIndex = reshape(varargin{2},1,[]);
end
if length(varargin) < 3
guiTitle = 'Select Node(s)';
else
guiTitle = varargin{3};
end
% Set the main list of models
setappdata(handles.MainFig, 'ItemsList', ItemsList);
% Set the output to be the initial selection
setappdata(handles.MainFig, 'OutputList', InitSelectionIndex);
% Set the title of the GUI
setappdata(handles.MainFig, 'guiTitle', guiTitle);
% Set the number of nodes available
set(handles.AvailableNodes, 'String', ['Available Node(s) ( ', ...
num2str(numel(ItemsList)), ' ) : ']);
set(handles.SelectedNodes, 'String', 'Selected Node(s) ( 0 ) : ');
%Initialize the GUI
InitGUI(handles);
% UIWAIT makes GUI wait for user response (see UIRESUME)
uiwait(handles.MainFig);
function varargout = SelectionGUI_OutputFcn(hObject, eventdata, handles) %#ok<INUSL,INUSL>
% --- Outputs from this function are returned to the command line.
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get default command line output from handles structure
varargout{1} = getappdata(hFigure, 'OutputList');
% Close down the GUI
CloseGUI(handles);
function MainFig_CloseRequestFcn(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% --- Executes when user attempts to close MainFig.
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Allow the GUI's uiwait to stop waiting
uiresume(hFigure);
%Process the figure's close request
FIGURE_CloseRequestFcn(handles)
function OkPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% --- Executes on button press in OkPB.
% Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the index of selected models
ItemsIdx_R = getappdata(hFigure, 'ItemsIdx_R');
% Copy the working variable over to the output variable
setappdata(hFigure, 'OutputList', ItemsIdx_R);
% Request the figure's close event to fire
close(hFigure);
function CancelPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% --- Executes on button press in CancelPB.
% Get the handle to the main GUI
hFigure = handles.MainFig;
% Set the output variable to zero
setappdata(hFigure, 'OutputList', -1);
% Request the figure's close event to fire
close(hFigure);
% --- Executes during object creation, after setting all properties.
function ItemsLeftLB_CreateFcn(hObject, eventdata, handles) %#ok<INUSD,DEFNU,INUSL,INUSL>
% hObject handle to ItemsLeftLB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function ItemsRightLB_CreateFcn(hObject, eventdata, handles) %#ok<INUSD,DEFNU,INUSL,INUSL>
% hObject handle to ItemsRightLB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function SearchET_CreateFcn(hObject, eventdata, handles) %#ok<INUSD,DEFNU,INUSL,INUSL>
% hObject handle to SearchET (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in SearchPB.
function SearchPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% hObject handle to SearchPB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the main list of models
ItemsList = getappdata(hFigure, 'ItemsList');
% Get the index of selected models
ItemsIdx_L = getappdata(hFigure, 'ItemsIdx_L');
% Get the list of models
ItemsList_L = ItemsList(ItemsIdx_L);
% Get the search string
SearchString = get(handles.SearchET,'String');
% Null the initial set of matches
Value_L = [];
% Find matches for the search string
for i=1:length(ItemsList_L)
if regexpi(ItemsList_L{i},['.*' SearchString '.*'],'once')
Value_L(end+1) = i; %#ok<AGROW>
end
end
% Set the selection of the left listbox
set(handles.ItemsLeftLB,'Value',Value_L);
% --- Executes on button press in ToRightAllPB.
function ToRightAllPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% hObject handle to ToRightAllPB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the main list of models
ItemsList = getappdata(hFigure, 'ItemsList');
% Set the selected models index
ItemsIdx_L = [];
ItemsIdx_R = 1:length(ItemsList);
% Set the index of selected models
setappdata(hFigure, 'ItemsIdx_L', ItemsIdx_L);
setappdata(hFigure, 'ItemsIdx_R', ItemsIdx_R);
% Set the number of selected and available nodes
set(handles.SelectedNodes, 'String', ['Selected Node(s) ( ', ...
num2str(numel(ItemsIdx_R)), ' ) : ']);
set(handles.AvailableNodes, 'String', ['Available Node(s) ( ', ...
num2str(numel(ItemsIdx_L)), ' ) : ']);
% Refresh the GUI
RefreshGUI(handles);
% --- Executes on button press in ToRightPB.
function ToRightPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% hObject handle to ToRightPB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the index of selected models
ItemsIdx_L = getappdata(hFigure, 'ItemsIdx_L');
ItemsIdx_R = getappdata(hFigure, 'ItemsIdx_R');
% Get the listbox selection indices
Value_L = get(handles.ItemsLeftLB,'Value');
% Set the selected models index
ItemsIdx_R = [ItemsIdx_R, ItemsIdx_L(Value_L)];
ItemsIdx_L(Value_L) = [];
% Set the index of selected models
setappdata(hFigure, 'ItemsIdx_L', ItemsIdx_L);
setappdata(hFigure, 'ItemsIdx_R', ItemsIdx_R);
% Set the number of selected and available nodes
set(handles.SelectedNodes, 'String', ['Selected Node(s) ( ', ...
num2str(numel(ItemsIdx_R)), ' ) : ']);
set(handles.AvailableNodes, 'String', ['Available Node(s) ( ', ...
num2str(numel(ItemsIdx_L)), ' ) : ']);
% Refresh the GUI
RefreshGUI(handles);
% --- Executes on button press in ToLeftPB.
function ToLeftPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% hObject handle to ToLeftPB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the index of selected models
ItemsIdx_L = getappdata(hFigure, 'ItemsIdx_L');
ItemsIdx_R = getappdata(hFigure, 'ItemsIdx_R');
% Get the listbox selection indices
Value_R = get(handles.ItemsRightLB,'Value');
% Set the selected models index
ItemsIdx_L = [ItemsIdx_L, ItemsIdx_R(Value_R)];
ItemsIdx_R(Value_R) = [];
% Set the index of selected models
setappdata(hFigure, 'ItemsIdx_L', ItemsIdx_L);
setappdata(hFigure, 'ItemsIdx_R', ItemsIdx_R);
% Set the number of selected and available nodes
set(handles.SelectedNodes, 'String', ['Selected Node(s) ( ', ...
num2str(numel(ItemsIdx_R)), ' ) : ']);
set(handles.AvailableNodes, 'String', ['Available Node(s) ( ', ...
num2str(numel(ItemsIdx_L)), ' ) : ']);
% Refresh the GUI
RefreshGUI(handles);
% --- Executes on button press in ToLeftAllPB.
function ToLeftAllPB_Callback(hObject, eventdata, handles) %#ok<DEFNU,INUSL,INUSL>
% hObject handle to ToLeftAllPB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Get the handle to the main GUI
hFigure = handles.MainFig;
% Get the main list of models
ItemsList = getappdata(hFigure, 'ItemsList');
% Set the selected models index
ItemsIdx_L = 1:length(ItemsList);
ItemsIdx_R = [];
% Set the index of selected models
setappdata(hFigure, 'ItemsIdx_L', ItemsIdx_L);
setappdata(hFigure, 'ItemsIdx_R', ItemsIdx_R);
% Set the number of selected and available nodes
set(handles.SelectedNodes, 'String', ['Selected Node(s) ( ', ...
num2str(numel(ItemsIdx_R)), ' ) : ']);
set(handles.AvailableNodes, 'String', ['Available Node(s) ( ', ...
num2str(numel(ItemsIdx_L)), ' ) : ']);
% Refresh the GUI
RefreshGUI(handles);