Home > functions > common > utility > vb_dlg_compare_list.m

vb_dlg_compare_list

PURPOSE ^

dialog for compare list.

SYNOPSIS ^

function [IsOK] = vb_dlg_compare_list(name_list1, title1, name_list2, title2, figure_title)

DESCRIPTION ^

 dialog for compare list.
 [USAGE]
    [IsOK] = vb_dlg_compare_list(<name_list1>, <title1>,...
                              <name_list2>, <title2> [,figure_title]);
 [IN]
      name_list1 : name list1                       {Nx1}
          title1 : explanation string of name_list1 [string]
      name_list2 : name list2                       {Mx1}
          title2 : explanation string of name_list2 [string]
    figure_title : figure title bar string          [string]
 [OUT]
    IsOK : = true  : user pushed OK
           = false : user pushed Cancel

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [IsOK] = vb_dlg_compare_list(name_list1, title1, name_list2, title2, figure_title)
0002 % dialog for compare list.
0003 % [USAGE]
0004 %    [IsOK] = vb_dlg_compare_list(<name_list1>, <title1>,...
0005 %                              <name_list2>, <title2> [,figure_title]);
0006 % [IN]
0007 %      name_list1 : name list1                       {Nx1}
0008 %          title1 : explanation string of name_list1 [string]
0009 %      name_list2 : name list2                       {Mx1}
0010 %          title2 : explanation string of name_list2 [string]
0011 %    figure_title : figure title bar string          [string]
0012 % [OUT]
0013 %    IsOK : = true  : user pushed OK
0014 %           = false : user pushed Cancel
0015 %
0016 % Copyright (C) 2011, ATR All Rights Reserved.
0017 % License : New BSD License(see VBMEG_LICENSE.txt)
0018 
0019 %
0020 % --- Previous check
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 % --- Main Procedure
0038 %
0039 
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 % figure_title
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 %<--->
0044 % LEFT_MARGIN
0045 %
0046 %        title1        title2
0047 %         WIDTH         WIDTH
0048 %    H|------------||------------|
0049 %    E| name_list1 || name_list2 |
0050 %    I|            ||            |
0051 %    G|            ||            |
0052 %    H|            ||            |
0053 %    T|------------||------------|
0054 % =
0055 % | BOTTOM_MARGIN
0056 % =
0057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0058 
0059 BOTTOM_MARGIN = 50;
0060 LEFT_MARGIN   = 10;
0061 WIDTH         = 200;
0062 HEIGHT        = 300;
0063 
0064 % Create figure and two Listboxes
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 % Create title1, title2 text
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 % Create OK, CANCEL button
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 % Sort button
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 % Set figure size
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 % make initial data
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 % get result
0134 data = guidata(h);
0135 IsOK = data.IsOK;
0136 
0137 % delete figure
0138 delete(h);
0139 
0140 return;
0141 %-------------------------------------------------end of function
0142 
0143 %
0144 % --- Callback functions(Flag ON/OFF)
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     % load original data
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

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005