This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
IntrinsicImaging/WidgetExport.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
271 lines (204 sloc)
8.62 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classdef WidgetExport < handle | |
%WIDGETEXPORT user defined export folder and file name | |
properties | |
folder | |
name | |
end | |
properties (Access = private) | |
ui_parent | |
ui_panel | |
ui_grid | |
ui_edit_folder | |
ui_edit_name | |
ui_pushbutton_folder | |
ui_checkbox_auto | |
end | |
properties (Constant = true, Access = private) | |
UIWINDOW_SIZE = [1, 1, 256, 125]; | |
GRID_VGAP = [10, 2, 5]; | |
GRID_HGAP = [5, 2, 5]; | |
BACKGROUND_COLOR = [1, 1, 1]; | |
FOREGROUND_COLOR = [0.5, 0.5, 0.5]; | |
PUSHBUTTON_SIZE = [1, 1, 50, 26]; | |
EDITBOX_SIZE = [1, 1, 180, 20]; | |
CHECKBOX_SIZE = [1, 1, 50, 20]; | |
end | |
%% --- constructor / destructor --- %% | |
methods | |
function obj = WidgetExport(varargin) | |
%WIDGETAUDIOSTIMULI class constructor | |
parserObj = inputParser; | |
addParameter(parserObj, 'Parent', [], @isgraphics); | |
parse(parserObj, varargin{:}); | |
if isempty(parserObj.Results.Parent) | |
obj.ui_parent = figure(... | |
'Visible', 'on',... | |
'Tag', 'hAudioStimuli',... | |
'Name', 'Audio Stimuli',... | |
'MenuBar', 'none',... | |
'ToolBar', 'none',... | |
'NumberTitle', 'off',... | |
'Color', obj.BACKGROUND_COLOR,... | |
'Resize', 'off',... | |
'Units', 'pixels',... | |
'Position', obj.UIWINDOW_SIZE,... | |
'CloseRequestFcn', @obj.fcnCallback_close); | |
movegui(obj.ui_parent, 'northwest'); | |
else | |
obj.ui_parent = parserObj.Results.Parent; | |
end | |
% set default properties | |
obj.folder = pwd; | |
obj.name = sprintf('%s_IntrinsicImaging', datestr(now,'yyyymmdd')); | |
% render user interface | |
obj.render(); | |
end | |
function obj = dispose(obj) | |
%DISPOSE class destructor | |
if isa(obj.ui_grid, 'uiGridLayout') | |
delete(obj.ui_grid); | |
end | |
if isgraphics(obj.ui_parent, 'figure') | |
delete(obj.ui_parent); | |
end | |
delete(obj); | |
end | |
function obj = render(obj) | |
%RENDER creates user interface | |
%%% --- create widget panel --- %%% | |
obj.ui_panel = uipanel(... | |
'Parent', obj.ui_parent,... | |
'Title', 'Export',... | |
'TitlePosition', 'lefttop',... | |
'BorderType', 'line',... | |
'HighlightColor', obj.FOREGROUND_COLOR,... | |
'ForegroundColor', obj.FOREGROUND_COLOR,... | |
'BackgroundColor', obj.BACKGROUND_COLOR,... | |
'Units', 'normalized',... | |
'Position', [0, 0, 1, 1],... | |
'Units', 'pixels'); | |
%%% --- create grid object --- %%% | |
obj.ui_grid = uiGridLayout(... | |
'Parent', obj.ui_panel,... | |
'VGrid', 4,... | |
'HGrid', 4,... | |
'VGap', obj.GRID_VGAP,... | |
'HGap', obj.GRID_HGAP); | |
ui_text = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'text',... | |
'String', 'Folder',... | |
'BackgroundColor', obj.BACKGROUND_COLOR,... | |
'Units', 'pixels',... | |
'Position', obj.ui_grid.getGrid('VIndex', 1, 'HIndex', 1:2)); | |
obj.ui_grid.align(ui_text,... | |
'VIndex', 1,... | |
'HIndex', 1:2,... | |
'Anchor', 'southwest'); | |
obj.ui_edit_folder = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'edit',... | |
'String', obj.folder,... | |
'HorizontalAlignment', 'left',... | |
'Callback', @obj.fcnCallback_parse,... | |
'Units', 'pixels',... | |
'Position', obj.EDITBOX_SIZE); | |
obj.ui_grid.align(obj.ui_edit_folder,... | |
'VIndex', 2,... | |
'HIndex', 1:3,... | |
'Anchor', 'west'); | |
obj.ui_pushbutton_folder = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'pushbutton',... | |
'String', '...',... | |
'Callback',@obj.fcnCallback_folder,... | |
'Units', 'pixels',... | |
'Position', obj.PUSHBUTTON_SIZE); | |
obj.ui_grid.align(obj.ui_pushbutton_folder,... | |
'VIndex', 2,... | |
'HIndex', 4,... | |
'Anchor', 'center'); | |
ui_text = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'text',... | |
'String', 'Name',... | |
'BackgroundColor', obj.BACKGROUND_COLOR,... | |
'Units', 'pixels',... | |
'Position', obj.ui_grid.getGrid('VIndex', 3, 'HIndex', 1:2)); | |
obj.ui_grid.align(ui_text,... | |
'VIndex', 3,... | |
'HIndex', 1:2,... | |
'Anchor', 'southwest'); | |
obj.ui_edit_name = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'edit',... | |
'String', obj.name,... | |
'HorizontalAlignment', 'left',... | |
'Callback', @obj.fcnCallback_parse,... | |
'Enable', 'off',... | |
'Units', 'pixels',... | |
'Position', obj.EDITBOX_SIZE); | |
obj.ui_grid.align(obj.ui_edit_name,... | |
'VIndex', 4,... | |
'HIndex', 1:3,... | |
'Anchor', 'west'); | |
obj.ui_checkbox_auto = uicontrol(... | |
'Parent', obj.ui_panel,... | |
'Style', 'checkbox',... | |
'String', 'auto',... | |
'Value', 1,... | |
'BackgroundColor', obj.BACKGROUND_COLOR,... | |
'Callback', @obj.fcnCallback_checkAuto,... | |
'Units', 'pixels',... | |
'Position', obj.CHECKBOX_SIZE); | |
obj.ui_grid.align(obj.ui_checkbox_auto,... | |
'VIndex', 4,... | |
'HIndex', 4,... | |
'Anchor', 'center'); | |
end | |
end | |
%% --- callback methods --- %% | |
methods | |
function obj = fcnCallback_close(obj, ~, ~) | |
%FCNCALLBACK_CLOSE close class destructor | |
obj.dispose(); | |
end | |
function obj = fcnCallback_parse(obj, hSrc, ~) | |
%FCNCALLBACK_parse parse user input | |
% current input | |
varchar = get(hSrc, 'String'); | |
% replace empty space with underscore | |
varchar = regexprep(varchar, '[\ ]+','_'); | |
% remove filename reserved chars | |
varchar = regexprep(varchar, '[\?\%\*\:\;\|\"\<\>\.]+',''); | |
% assing properties | |
switch hSrc | |
case obj.ui_edit_folder | |
if exist(varchar, 'dir') ~= 7 | |
varchar = pwd; | |
end | |
set(obj.ui_edit_folder, 'String', varchar); | |
obj.folder = varchar; | |
case obj.ui_edit_name | |
set(obj.ui_edit_name, 'String', varchar); | |
obj.name = varchar; | |
end | |
end | |
function obj = fcnCallback_folder(obj, ~, ~) | |
%FCNCALLBACK_FOLDER choose folder | |
vardir = uigetdir(pwd); | |
set(obj.ui_edit_folder, 'String', vardir); | |
obj.folder = vardir; | |
end | |
function obj = fcnCallback_checkAuto(obj, ~, ~) | |
%FCNCALLBACK_CHECKAUTO toggle check box auto file name | |
if get(obj.ui_checkbox_auto, 'Value') == 1 | |
set(obj.ui_edit_name, 'Enable', 'off'); | |
obj.name = sprintf('%s_IntrinsicImaging', datestr(now,'yyyymmdd')); | |
set(obj.ui_edit_name, 'String', obj.name); | |
else | |
set(obj.ui_edit_name, 'Enable', 'on'); | |
end | |
end | |
end | |
end | |