0001 function [IsOK] = vb_dlg_compare_list(name_list1, title1, name_list2, title2, figure_title)
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 
0022 if ~exist('name_list1', 'var')
0023     error('name_list1 is a required parameter.');
0024 end
0025 if ~exist('title1', 'var')
0026     error('title1 is a required parameter.');
0027 end
0028 if ~exist('name_list2', 'var')
0029     error('name_list2 is a required parameter.');
0030 end
0031 if ~exist('title2', 'var')
0032     error('title2 is a required parameter.');
0033 end
0034 if ~exist('figure_title', 'var'), figure_title = ''; end
0035 
0036 
0037 
0038 
0039 
0040 
0041 
0042 
0043 
0044 
0045 
0046 
0047 
0048 
0049 
0050 
0051 
0052 
0053 
0054 
0055 
0056 
0057 
0058 
0059 BOTTOM_MARGIN = 50;
0060 LEFT_MARGIN   = 10;
0061 WIDTH         = 200;
0062 HEIGHT        = 300;
0063 
0064 
0065 h = figure('Visible', 'off', 'WindowStyle', 'modal');
0066 set(h, 'Name', figure_title);
0067 set(h, 'NumberTitle', 'off');
0068 listbox1 = ...
0069     uicontrol(...
0070         'Parent', h, 'style', 'listbox', ...
0071         'Position', [LEFT_MARGIN, BOTTOM_MARGIN, WIDTH, HEIGHT], 'String', name_list1);
0072 listbox2 = ...
0073     uicontrol(...
0074         'Parent', h, 'style', 'listbox', ...
0075         'Position', [LEFT_MARGIN + WIDTH, BOTTOM_MARGIN, WIDTH, HEIGHT], 'String', name_list2);
0076 
0077 
0078 LABEL_HEIGHT = 20;
0079 LABEL_WIDTH  = WIDTH;
0080 uicontrol('Parent', h, 'style', 'Text', ...
0081           'String', title1,...
0082           'HorizontalAlignment', 'Left', ...
0083           'Position', [LEFT_MARGIN, BOTTOM_MARGIN + HEIGHT, LABEL_WIDTH, LABEL_HEIGHT]);
0084 uicontrol('Parent', h, 'style', 'Text', ...
0085           'String', title2, ...
0086           'HorizontalAlignment', 'Left', ...
0087           'Position', [LEFT_MARGIN+WIDTH, BOTTOM_MARGIN + HEIGHT, LABEL_WIDTH, LABEL_HEIGHT]);
0088 
0089 BUTTON_WIDTH  = WIDTH/2;
0090 BUTTON_HEIGHT = BOTTOM_MARGIN/2;
0091 
0092 
0093 ok_btn = uicontrol(...
0094     'style','pushbutton',...
0095     'string', 'OK',...
0096     'Position',[LEFT_MARGIN + WIDTH, BOTTOM_MARGIN-BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT],...
0097     'callback',{@doOK});
0098 
0099 cancel_btn = uicontrol(...
0100     'style','pushbutton',...
0101     'string','Cancel',...
0102     'Position',[LEFT_MARGIN + WIDTH+BUTTON_WIDTH, BOTTOM_MARGIN-BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT],...
0103     'callback', {@doCancel});
0104 
0105 
0106 CHECKBOX_WIDTH = WIDTH;
0107 CHECKBOX_HEIGHT = BOTTOM_MARGIN/2;
0108 
0109 uicontrol(...
0110     'style', 'checkbox', ...
0111     'string', 'Sort', ...
0112     'Position', [LEFT_MARGIN, BOTTOM_MARGIN - CHECKBOX_HEIGHT, CHECKBOX_WIDTH, CHECKBOX_HEIGHT],...
0113     'callback', {@doSort, listbox1, listbox2});
0114 
0115 
0116 fig_pos = get(h, 'Position');
0117 fig_pos(3) = WIDTH * 2 + LEFT_MARGIN * 2;
0118 fig_pos(4) = BOTTOM_MARGIN + HEIGHT + LABEL_HEIGHT + 10;
0119 set(h, 'Position', fig_pos, ...
0120     'MenuBar', 'none', 'Visible', 'on', 'Resize', 'off',...
0121     'closerequestfcn', {@doCancel});
0122 
0123 
0124 
0125 data = struct;
0126 data.IsOK = false;
0127 data.name_list1 = name_list1;
0128 data.name_list2 = name_list2;
0129 guidata(h, data);
0130 
0131 waitfor(h, 'Visible', 'off');
0132 
0133 
0134 data = guidata(h);
0135 IsOK = data.IsOK;
0136 
0137 
0138 delete(h);
0139 
0140 return;
0141 
0142 
0143 
0144 
0145 
0146 function doOK(ok_btn, evd)
0147     result = struct;
0148     result.IsOK = true;
0149     guidata(gcbf, result);
0150     set(gcbf, 'Visible', 'off');
0151 
0152 function doCancel(cancel_btn, evd)
0153     result = struct;
0154     result.IsOK = false;
0155     guidata(gcbf, result);
0156     set(gcbf, 'Visible', 'off');
0157 
0158 function doSort(checkbox, evd, listbox1, listbox2)
0159     
0160     data = guidata(gcbf);
0161     
0162     if get(checkbox, 'Value')
0163         name_list1 = sort(data.name_list1);
0164         name_list2 = sort(data.name_list2);
0165         set(listbox1, 'String', name_list1);
0166         set(listbox2, 'String', name_list2);
0167     else
0168         set(listbox1, 'String', data.name_list1);
0169         set(listbox2, 'String', data.name_list2);
0170     end
0171