Home > functions > common > utility > @file_dialog > private > create_gui.m

create_gui

PURPOSE ^

dialog windowを作成する。

SYNOPSIS ^

function [gui_handles] = create_gui(this)

DESCRIPTION ^

 dialog windowを作成する。

 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:

SOURCE CODE ^

0001 function [gui_handles] = create_gui(this)
0002 % dialog windowを作成する。
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 S = get(0,'ScreenSize');
0008 
0009 
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 % Dialog windowの大きさ
0012 Width = 380;
0013 Height = 440;
0014 
0015 
0016 BorderH = 10;
0017 BorderV = 5;
0018 
0019 
0020 % 'Current directory' static text labelの大きさと位置
0021 CurrentDirTextWidth = Width - 2*BorderH;
0022 CurrentDirTextHeight = 20;
0023 CurrentDirTextLeft = BorderH;
0024 CurrentDirTextBottom = Height - CurrentDirTextHeight;
0025 
0026 % current directoryを選択するpop-up menuの大きさと位置
0027 CurrentDirPopupWidth = Width - 2*BorderH;
0028 CurrentDirPopupHeight = 20;
0029 CurrentDirPopupLeft = BorderH;
0030 CurrentDirPopupBottom = CurrentDirTextBottom - CurrentDirPopupHeight;
0031 
0032 
0033 % 'Extension' static text labelの大きさと位置
0034 ExtensionTextWidth = 0.6*(CurrentDirPopupWidth/2);
0035 ExtensionTextHeight = 20;
0036 ExtensionTextLeft = BorderH;
0037 ExtensionTextBottom = CurrentDirPopupBottom - (ExtensionTextHeight+BorderV);
0038 
0039 % 拡張子を選択するpop-up menuの大きさと位置
0040 ExtensionPopupWidth = CurrentDirPopupWidth/2 - ExtensionTextWidth;
0041 ExtensionPopupHeight = ExtensionTextHeight;
0042 ExtensionPopupLeft = ExtensionTextLeft + ExtensionTextWidth;
0043 ExtensionPopupBottom = ExtensionTextBottom;
0044 
0045 
0046 % 'Drive' static text labelの大きさと位置
0047 DriveTextWidth = ExtensionTextWidth;
0048 DriveTextHeight = ExtensionPopupHeight;
0049 DriveTextLeft = ExtensionPopupLeft + ExtensionPopupWidth;
0050 DriveTextBottom = ExtensionPopupBottom;
0051 
0052 % Driveを選択するpop-up menuの大きさと位置
0053 DrivePopupWidth = ExtensionPopupWidth;
0054 DrivePopupHeight = DriveTextHeight;
0055 DrivePopupLeft = DriveTextLeft + DriveTextWidth;
0056 DrivePopupBottom = DriveTextBottom;
0057 
0058 
0059 % panelの大きさと位置
0060 PanelWidth = CurrentDirPopupWidth;
0061 PanelHeighth = 320;
0062 PanelLeft = BorderH;
0063 PanelBottom = ExtensionTextBottom - (PanelHeighth+BorderV);
0064 
0065 
0066 % MATLAB R14 SP2以降ならpanelを作成し、各GUIはpanelを親として作成する。
0067 % panelを親として作成したcontrolの表示位置は、親panelの相対位置で指定する。
0068 % また、親panelの'visible'を'off'にすると、子GUIも非表示化される。
0069 % MATLAB R14より前のバージョンでは、panelがサポートされていない。
0070 % またMATLABR14 SP1ではpanelの動作が不安定なので、frameを作成し各control
0071 % はdialogを親として作成する。
0072 % この場合、GUIが重なり合う領域は、後から作成したGUIが優先して表示される。
0073 
0074 % R14 SP1 = 7.0.1, SP2 = 7.0.4
0075 [major, minor, rev] = vb_matlab_version;
0076 version_value = 100*major + 10*minor + rev * 1;
0077 if version_value < 704
0078   TmpLeft = PanelLeft;    TmpBottom = PanelBottom;
0079 else
0080   TmpLeft = 0;    TmpBottom = 0;
0081 end
0082     
0083 
0084 
0085 % 'Directories' static text labelの大きさと位置
0086 DirTextWidth = PanelWidth*2/5 - BorderH;
0087 DirTextHeight = 20;
0088 DirTextLeft = TmpLeft + BorderH;
0089 DirTextBottom = TmpBottom + PanelHeighth - (DirTextHeight+BorderV);
0090 
0091 % ディレクトリ一覧を表示するlist boxの大きさと位置
0092 DirListWidth = DirTextWidth;
0093 DirListHeight = 180;
0094 DirListLeft = DirTextLeft;
0095 DirListBottom = DirTextBottom - DirListHeight;
0096 
0097 
0098 % 'Files' static text labelの大きさと位置
0099 FnameTextWidth = PanelWidth - DirTextWidth - 2*BorderH;
0100 FnameTextHeight = DirTextHeight;
0101 FnameTextLeft = DirTextLeft + DirTextWidth;
0102 FnameTextBottom = DirTextBottom;
0103 
0104 % ファイル名一覧を表示するlist boxの大きさと位置
0105 FnameListWidth = FnameTextWidth;
0106 FnameListHeight = DirListHeight;
0107 FnameListLeft = FnameTextLeft;
0108 FnameListBottom = DirListBottom;
0109 
0110 
0111 % 'Filter' static text label
0112 FilterFnameTextWidth = PanelWidth - 2*BorderH;
0113 FilterFnameTextHeight= 20;
0114 FilterFnameTextLeft  = TmpLeft + BorderH;
0115 FilterFnameTextBottom= DirListBottom - (FilterFnameTextHeight+BorderV);
0116 
0117 % 'Filter' edit text
0118 FilterFnameEditWidth = FilterFnameTextWidth;
0119 FilterFnameEditHeight= 22;
0120 FilterFnameEditLeft  = FilterFnameTextLeft;
0121 FilterFnameEditBottom= FilterFnameTextBottom - FilterFnameEditHeight;
0122 
0123 % 'Select file' static text labelの大きさと位置
0124 SelFnameTextWidth = PanelWidth - 2*BorderH;
0125 SelFnameTextHeight = 20;
0126 SelFnameTextLeft = TmpLeft + BorderH;
0127 SelFnameTextBottom = FilterFnameEditBottom - (SelFnameTextHeight+BorderV);
0128 
0129 % 選択ファイル名を表示するedit textの大きさと位置
0130 SelFnameEditWidth = SelFnameTextWidth;
0131 SelFnameEditHeight = 22;
0132 SelFnameEditLeft = SelFnameTextLeft;
0133 SelFnameEditBottom = SelFnameTextBottom - SelFnameEditHeight;
0134 
0135 
0136 % 'Cancel' push buttonの大きさと位置
0137 CancelWidth = CurrentDirPopupWidth/2;
0138 CancelHeight = 35;
0139 CancelLeft = BorderH;
0140 CancelBottom = PanelBottom - (CancelHeight+BorderV);
0141 
0142 % 'Done' push buttonの大きさと位置
0143 DoneWidth = CancelWidth;
0144 DoneHeight = CancelHeight;
0145 DoneLeft = CancelLeft + CancelWidth;
0146 DoneBottom = CancelBottom;
0147 
0148 
0149 % GUIの色を求める。
0150 dialog_color   = this.public.dialog_color;    % dialogのcolor
0151 dialog_title   = this.public.dialog_title;    % dialogのtitle
0152 bgcol_panel = this.public.bgcol_panel;    % panelのbackground color
0153 fgcol_panel = this.public.fgcol_panel;    % panelのforeground color
0154 fgcol_text  = this.public.fgcol_text;    % static text labelのforeground color
0155 bgcol_popup = this.public.bgcol_popup;    % pop-up menuのbackground color
0156 fgcol_popup = this.public.fgcol_popup;    % pop-up menuのforeground color
0157 bgcol_listbox = this.public.bgcol_listbox;    % list boxのbackground color
0158 fgcol_listbox = this.public.fgcol_listbox;    % list boxのforeground color
0159 bgcol_edit  = this.public.bgcol_edit;    % edit textのbackground color
0160 fgcol_edit  = this.public.fgcol_edit;    % edit textのforeground color
0161 bgcol_push  = this.public.bgcol_push;    % push buttonのbackground color
0162 fgcol_push  = this.public.fgcol_push;    % push buttonのforeground color
0163 
0164 
0165 % Save/Load file選択用Dialog windowを作成する。
0166 dialog_handle = figure('Name', dialog_title, 'Tag', 'SelFileWin',...
0167     'MenuBar', 'none',...
0168     'NumberTitle', 'off',...
0169     'Color', dialog_color,...
0170     'Resize', 'off',...
0171     'Visible', 'off',...
0172     'Units', 'Pixels',...
0173     'Position',...
0174     [S(3)/2-Width/2, S(4)/2-Height/2, Width, Height]);
0175 
0176 % 'Current directory' static text labelを作成する。
0177 uicontrol('Parent', dialog_handle, 'Style', 'text',...
0178     'String', 'current directory',...
0179     'BackgroundColor', dialog_color, 'ForegroundColor', fgcol_text,...
0180     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0181     'Position',...
0182     [CurrentDirTextLeft, CurrentDirTextBottom,...
0183       CurrentDirTextWidth, CurrentDirTextHeight]);
0184 
0185 % current directoryを選択するpop-up menuを作成する。
0186 current_dir_popup_handle = uicontrol('Parent',dialog_handle,...
0187     'Style', 'popup', 'String', ' ', 'Value', 1,...
0188     'BackgroundColor', bgcol_popup, 'ForegroundColor', fgcol_popup,...
0189     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0190     'CallBack', {@current_dir_popup, dialog_handle},...
0191     'Position',...
0192     [CurrentDirPopupLeft, CurrentDirPopupBottom,...
0193       CurrentDirPopupWidth, CurrentDirPopupHeight]);
0194 
0195 
0196 % 'Extension' static text labelを作成する。
0197 uicontrol('Parent', dialog_handle, 'Style', 'text',...
0198     'String', 'Extension',...
0199     'BackgroundColor', dialog_color, 'ForegroundColor', fgcol_text,...
0200     'FontSize', 12,...
0201     'Position',...
0202     [ExtensionTextLeft, ExtensionTextBottom,...
0203       ExtensionTextWidth, ExtensionTextHeight]);
0204 
0205 % ファイルの拡張子を選択するpop-up menuを作成する。
0206 str = sprintf('|%s', this.public.file_extensions{:});    str(1) = [];
0207 extension_popup_handle = uicontrol('Parent', dialog_handle,...
0208     'Style', 'popup', 'String', str, 'Value', 1,...
0209     'BackgroundColor', bgcol_popup, 'ForegroundColor', fgcol_popup,...
0210     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0211     'CallBack', {@extension_popup, dialog_handle},...
0212     'Position',...
0213     [ExtensionPopupLeft, ExtensionPopupBottom,...
0214       ExtensionPopupWidth, ExtensionPopupHeight]);
0215 
0216 
0217 % 'Drive' static text labelを作成する。
0218 drive_text = uicontrol('Parent', dialog_handle, 'Style', 'text',...
0219     'String', 'Drive',...
0220     'BackgroundColor', dialog_color, 'ForegroundColor', fgcol_text,...
0221     'FontSize', 12,...
0222     'Position',...
0223     [DriveTextLeft, DriveTextBottom, DriveTextWidth, DriveTextHeight]);
0224 
0225 % Driveを選択するpop-up menuを作成する。
0226 drive_popup_handle = uicontrol('Parent',dialog_handle, 'Style', 'popup',...
0227     'String', ' ',...
0228     'BackgroundColor', bgcol_popup, 'ForegroundColor', fgcol_popup,...
0229     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0230     'CallBack', {@drive_popup, dialog_handle},...
0231     'Position',...
0232     [DrivePopupLeft DrivePopupBottom DrivePopupWidth DrivePopupHeight]);
0233 
0234 
0235 
0236 % panelを作成する。
0237 if version_value < 704    % MATLAB R14 SP2以前のバージョン
0238   tmp = uicontrol('Parent', dialog_handle, 'Style', 'Frame',...
0239       'Position', [PanelLeft PanelBottom PanelWidth PanelHeighth],...
0240       'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel);
0241   panel = [];
0242   parent = dialog_handle;
0243   bgcol = get(tmp, 'BackgroundColor');
0244 else    % MATLAB R14以降のバージョン
0245   panel = uipanel('Parent', dialog_handle, 'Title', '', 'FontSize', 12,...
0246       'Units', 'pixels',...
0247       'Position', [PanelLeft PanelBottom PanelWidth PanelHeighth],...
0248       'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel);
0249   parent = panel;
0250   bgcol = get(panel, 'BackgroundColor');
0251 end
0252 
0253 
0254 % 'Directories' static text labelを作成する。
0255 uicontrol('Parent', parent, 'Style', 'Text', 'String', 'Directories',...
0256     'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel,...
0257     'HorizontalAlignment', 'Center', 'FontSize', 12,...
0258     'Position',[DirTextLeft DirTextBottom DirTextWidth DirTextHeight]);
0259 
0260 % ディレクトリ一覧を表示するlist boxを作成する。
0261 dir_listbox_handle = uicontrol('Parent', parent,  'Style', 'listbox',...
0262     'String', '',...
0263     'BackgroundColor', bgcol_listbox, 'ForegroundColor', fgcol_listbox,...
0264     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0265     'CallBack', {@dir_listbox, dialog_handle},...
0266     'Position', [DirListLeft DirListBottom DirListWidth DirListHeight]);
0267 
0268 
0269 % 'Files' static text labelを作成する。
0270 uicontrol('Parent', parent, 'Style', 'Text', 'String', 'Files',...
0271     'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel,...
0272     'HorizontalAlignment', 'Center', 'FontSize', 12,...
0273     'Position',...
0274     [FnameTextLeft FnameTextBottom FnameTextWidth FnameTextHeight]);
0275 
0276 % ファイル名一覧を表示するlist boxを作成する。
0277 fname_listbox_handle = uicontrol('Parent', parent,  'Style', 'listbox',...
0278     'String', '',...
0279     'BackgroundColor', bgcol_listbox, 'ForegroundColor', fgcol_listbox,...
0280     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0281     'CallBack', {@fname_listbox, dialog_handle},...
0282     'Position',...
0283     [FnameListLeft FnameListBottom FnameListWidth FnameListHeight]);
0284 
0285 
0286 % 'Filter' static text labelを作成する。
0287 uicontrol('Parent', parent, 'Style', 'text', 'String', 'Filter',...
0288     'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel,...
0289     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0290     'Position',...
0291     [FilterFnameTextLeft, FilterFnameTextBottom,...
0292       FilterFnameTextWidth, FilterFnameTextHeight]);
0293 
0294 % 'Filter' edit textを作成する。
0295 filter_str_edit = uicontrol('Parent', parent, 'Style', 'edit', 'String', '',...
0296     'BackgroundColor', bgcol_edit, 'ForegroundColor', fgcol_edit,...
0297     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0298     'CallBack', {@fname_edit, dialog_handle},...
0299     'String', '*',...
0300     'Position',...
0301     [FilterFnameEditLeft,FilterFnameEditBottom,...
0302       FilterFnameEditWidth, FilterFnameEditHeight]);
0303 
0304 % 'Select file' static text labelを作成する。
0305 uicontrol('Parent', parent, 'Style', 'text', 'String', 'selected file(s)',...
0306     'BackgroundColor', bgcol_panel, 'ForegroundColor', fgcol_panel,...
0307     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0308     'Position',...
0309     [SelFnameTextLeft, SelFnameTextBottom,...
0310       SelFnameTextWidth, SelFnameTextHeight]);
0311 
0312 % 選択ファイル名を表示するedit textを作成する。
0313 sel_fname_edit = uicontrol('Parent', parent, 'Style', 'edit', 'String', '',...
0314     'BackgroundColor', bgcol_edit, 'ForegroundColor', fgcol_edit,...
0315     'HorizontalAlignment', 'Left', 'FontSize', 12,...
0316     'CallBack', {@fname_edit, dialog_handle},...
0317     'Position',...
0318     [SelFnameEditLeft,SelFnameEditBottom,...
0319       SelFnameEditWidth, SelFnameEditHeight]);
0320 
0321 
0322 % 'Cancel' push buttonを作成する。
0323 uicontrol('Parent', dialog_handle, 'Style', 'push', 'String', 'Cancel',...
0324     'FontSize', 12, ...
0325     'BackgroundColor', bgcol_push, 'ForegroundColor', fgcol_push,...
0326     'CallBack', {@close_gui, dialog_handle, 'cancel'},...
0327     'Position', [CancelLeft CancelBottom CancelWidth CancelHeight]);
0328 
0329 
0330 % 'Done' push buttonを作成する。
0331 done_push = uicontrol('Parent', dialog_handle, 'Style', 'push',...
0332     'String', 'OK', 'FontSize', 12,...
0333     'BackgroundColor', bgcol_push, 'ForegroundColor', fgcol_push,...
0334     'CallBack', {@close_gui, dialog_handle, 'done'},...
0335     'Position', [DoneLeft DoneBottom DoneWidth DoneHeight]);
0336 
0337 
0338 % Save/Load file選択用Dialog windowを管理する構造体を設定する。
0339 gui_handles = struct(...
0340     'dialog', dialog_handle,...
0341     'current_dir_popup', current_dir_popup_handle,...
0342     'panel', panel,...
0343     'extension_popup', extension_popup_handle,...
0344     'drive_text', drive_text,...
0345     'drive_popup', drive_popup_handle,...
0346     'dir_listbox', dir_listbox_handle,...
0347     'fname_listbox', fname_listbox_handle,...
0348     'filter_str_edit', filter_str_edit,...
0349     'sel_fname_edit', sel_fname_edit,...
0350     'done_push', done_push);
0351 
0352 % enable resizing
0353 set(dialog_handle, 'Units', 'normalized', 'Resize', 'on');
0354 h_all = [get(parent, 'children'); get(dialog_handle, 'children')];
0355 for k=1:length(h_all)
0356     try
0357         set(h_all(k), 'Units', 'normalized');
0358     catch
0359     end
0360     try
0361         set(h_all(k), 'FontUnit', 'normalized');
0362     catch
0363     end
0364 end
0365 pos = get(dialog_handle, 'Position');
0366 pos(3) = pos(3)*1.2; % width * 1.2
0367 set(dialog_handle, 'Position', pos);

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