📄 bvqxfigure.m
字号:
function [varargout] = BVQXfigure(varargin)
% BVQXfigure (Object class)
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Version: v0.7b
% Build: 7083122
% Date: Aug-31 2007, 10:57 PM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL / Info: http://wiki.brainvoyager.com/BVQXtools
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This class handles MATLAB's UI related stuff with an OO interface. Returned
% objects can have a subtype of either
%
% -> ROOT (the factory itself, corresponds to MATLAB handle 0)
% -> Figure (MATLAB figure objects)
% -> UIControl (MATLAB uicontrols objects)
% -> UIMenu (MATLAB uimenu objects)
% -> UIContextMenu (MATLAB uicontextmenu objects)
%
% The following constructors are available:
%
% BVQXfigure
% BVQXfigure(matlabhandle [, 'delete'])
% BVQXfigure(objecttype, bvqxfighandle)
% BVQXfigure(filename [, options])
% BVQXfigure(objecttag)
%
% For better object access, the struct notation
%
% uiobject.Property
%
% is implemented for both reading/writing.
%
% Note: due to a MATLAB restriction of a maximum length for variable
% names (31 characters), Tags longer than 27 won't work.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTERNAL INTERFACE SPEC %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% internal object representation
%
% obj.ihnd internal object handle for find(...) [s.b.]
% obj.mhnd MATLAB object handle value for fast access
% obj.type 1x1 double value:
% 0 -> ROOT object
% 1 -> figure subtype object
% 2 -> UIControl subtype object
% 3 -> UIMenu subtype object
% 4 -> UIContextMenu subtype object
% persistent storage variables
persistent ...
bvqxfigure_factory ... % 1x1 struct array, factory settings and storage
bvqxfigures ... % 1xN struct array, BVQXfigure objects
bvqxfig_ilup ... % 1xN double array, handle lookup array
bvqxfig_mlup ... % 1xN double array, MATLAB handle lookup array
bvqxfig_type; % 1xN double array, BVQXfigure object type array
% bvqxfigure_factory 1x1 struct array
% .I_ROOT = handle of ROOT object for fast access
% .dblclickint = interval needed to be undermined for DblClick's
% .figbgcolor = standard background color for figures
% .is_init = set to 1 after initialization complete
% .linkhandler = how to deal with XLinks
% .objtypes = onetime fixed struct with valid BVQXfigure subtypes
% .oouictype = UIControls with on/off feature
% .progbarface = minumum number of "rounded" bars' grades
% .rp_init = MATLAB root object properties at init time
% .slideswidth = fixed width in pixels for special slidebars
% .tags = lookup struct for tags (max 27 chars!)
% .uictypes = onetime fixed struct with valid type names
% .units = onetime fixed struct with valid units names
%
% bvqxfigures 1xN struct array
% .callbacks = cell array for objects callbacks
% {1} Callback / CallbackClick
% {2} CallbackClReq
% {3} CallbackDblClick
% {4} CallbackDelete
% {5} CallbackKey
% {6} CallbackMDown
% {7} CallbackMMove
% {8} CallbackMUp
% {9} CallbackResize
% .deletefcn = original CallbackDelete value (replaced!)
% .figprops = struct with sub fields
% .cpage = currently shown page for figures [set to -2]
% .egroups = SetGroupEnabled groups (with lookup pointers
% UIControls: positive/UIMenus: negative doubles)
% .lgroups = groups of linked fields for load and update
% .lilookup = struct for lookups (max 31 chars!)
% .linkcont = FieldLinkCont BVQXIniFile object handles struct
% .linkspec = FieldLinkSpec BVQXIniFile object handles array
% .llookup = 1x1 struct array for lookups (max 31 chars!)
% .pages = list of available pages
% .rgroups = RadioGroupSetOne groups (with lookup pointers)
% .rszuics = cell array with affected UICs for CallbackResize
% .sgroups = SlideGroupXY groups (with lookup pointers)
% .vgroups = SetGroupVisible groups (with lookup pointers
% UIControls: positive/UIMenus: negative doubles)
% .loadprops = struct with input fields at creation time
% .prevprops = props stored after executing of last callback
% .timeclick = time index of last OnClick event (for DblClick)
% .uicprops = struct with extended properties
% internal methods
%
% [handle, type] = findmlparent(handle, type)
% newhandle = handlenew(type, given)
% i_loadfield()
% updateok = i_updatefield(hObj, flnk, flt)
% object = makeobj(ihnd, hnd, type)
% mydelete(MLhandle)
% redrawfig(MLhandle)
% check for class initialization -> do if necessary
if isempty(bvqxfigure_factory) || ...
~bvqxfigure_factory.is_init
% set init state, time and version number
bvqxfigure_factory.is_init = false;
% double click internval
bvqxfigure_factory.dblclickint = 0.8 / 86400;
% figure background color
defbgcol = [0.8, 0.8, 0.8];
try
bvqxfigure_factory.figbgcolor = get(0, 'DefaultFigureColor');
if ~isnumeric(bvqxfigure_factory.figbgcolor) || ...
isempty(bvqxfigure_factory.figbgcolor)
bvqxfigure_factory.figbgcolor = defbgcol;
end
catch
bvqxfigure_factory.figbgcolor = defbgcol;
end
% font sizes
bvqxfigure_factory.fntsizes = struct( ...
'xsmall', 8, ...
'small', 9, ...
'normal', 10, ...
'large', 12, ...
'xlarge', 16 ...
);
% number of progress bar color shades
bvqxfigure_factory.progbarface = 32;
% default slider width
bvqxfigure_factory.slideswidth = 20;
% support "silent mode"
bvqxfigure_factory.suppsilent = true;
% initialise "silent mode" flag
bvqxfigure_factory.issilent = false;
% determine runtime features
try
% turn off property hiding
hud = get(0, 'HideUndocumented');
ghud = true;
set(0, 'HideUndocumented', 'off');
catch
ghud = false;
end
% get all properties !
rootprops = get(0);
bvqxfigure_factory.rp_init = rootprops;
% if necessary, turn on hiding again
if ghud
set(0, 'HideUndocumented', hud);
end
% test objects to see if everything works
try
tfig = figure('Visible', 'off');
catch
tfig = [];
end
% if we even can't open a figure
if isempty(tfig)
eval('bvqxfigure_factory(:)=[];', '');
clear bvqxfigure_factory BVQXfigure;
error( ...
'BVQXfigure:FiguresUnavailable', ...
'Can''t create any figures with this setup.' ...
);
end
% get valid papertype options and clean up object
bvqxfigure_factory.figptypes = set(tfig, 'PaperType');
delete(tfig);
% property aliases
bvqxfigure_factory.objtypel = { ...
'root', ...
'figure', ...
'uicontrol', ...
'uimenu', ...
'uicontextmenu' ...
};
bvqxfigure_factory.aliases = { ...
struct, ...
struct( ...
'callbackclreq', 'CloseRequestFcn', ...
'callbackdelete', 'DeleteFcn', ...
'callbackresize', 'ResizeFcn', ...
'contextmenu', 'uicontextmenu', ...
'resizeable', 'Resize', ...
'title', 'Name' ...
), struct( ...
'caption', 'String', ...
'color', 'BackgroundColor', ...
'contextmenu', 'uicontextmenu', ...
'enabled', 'Enable', ...
'halign', 'HorizontalAlignment', ...
'textcolor', 'ForegroundColor', ...
'tooltip', 'TooltipString', ...
'top', 'ListboxTop' ...
), struct( ...
'caption', 'Label', ...
'enabled', 'Enable', ...
'string', 'Label' ...
), struct( ...
'caption', 'Label', ...
'enabled', 'Enable', ...
'string', 'Label' ...
) ...
};
% type lookup
bvqxfigure_factory.objtypes = struct( ...
'r', 0, 'root', 0, ...
'f', 1, 'fig', 1, 'figure', 1, ...
'c', 2, 'uic', 2, 'uicontrol', 2, ...
'm', 3, 'uim', 3, 'uimenu', 3, ...
'x', 4, 'uix', 4, 'uicontextmenu', 4 ...
);
% type tag prepends and lookup order
bvqxfigure_factory.objtypet = {'FIG_', 'UIC_', 'UIM_', 'UIX_'};
bvqxfigure_factory.objtlup = {'UIC_', 'FIG_', 'UIM_', 'UIX_'};
% supported BVQXfigure:UIControl types
bvqxfigure_factory.uictypes = struct( ...
'blabel', 'BUILTIN', ...
'button', 'pushbutton', ...
'checkbox', 'checkbox', ...
'dropdown', 'popupmenu', ...
'edit', 'edit', ...
'frame', 'frame', ...
'label', 'text', ...
'listbox', 'listbox', ...
'multiedit', 'edit', ...
'popupmenu', 'popupmenu', ...
'pushbutton', 'pushbutton', ...
'radiobutton', 'radiobutton', ...
'slider', 'slider', ...
'text', 'text', ...
'toggle', 'togglebutton', ...
'togglebutton','togglebutton', ...
'xaxes', 'BUILTIN', ...
'ximage', 'BUILTIN', ...
'xlabel', 'BUILTIN', ...
'xlink', 'BUILTIN', ...
'xprogress', 'BUILTIN' ...
);
% those with callbacks
bvqxfigure_factory.oouictypes = struct( ...
'checkbox', 0, ...
'edit', 0, ...
'listbox', 0, ...
'popupmenu', 0, ...
'radiobutton', 1, ...
'toggle', 0 ...
); % maybe add 'text' for blabels later ...
% set valid types for context menu objects
bvqxfigure_factory.uixtypes = struct ( ...
'figure', bvqxfigure_factory.objtypes.figure, ...
'uicontrol', bvqxfigure_factory.objtypes.uicontrol, ...
'axes', bvqxfigure_factory.objtypes.uicontrol, ...
'image', bvqxfigure_factory.objtypes.uicontrol, ...
'line', bvqxfigure_factory.objtypes.uicontrol, ...
'patch', bvqxfigure_factory.objtypes.uicontrol, ...
'rectangle', bvqxfigure_factory.objtypes.uicontrol, ...
'text', bvqxfigure_factory.objtypes.uicontrol ...
);
% set types for extended handle lookup
bvqxfigure_factory.xobjtypes = struct ( ...
'axes', bvqxfigure_factory.objtypes.uicontrol, ...
'image', bvqxfigure_factory.objtypes.uicontrol, ...
'line', bvqxfigure_factory.objtypes.uicontrol, ...
'patch', bvqxfigure_factory.objtypes.uicontrol, ...
'rectangle', bvqxfigure_factory.objtypes.uicontrol, ...
'text', bvqxfigure_factory.objtypes.uicontrol ...
);
% valid font unit names and option
bvqxfigure_factory.funits = struct( ...
'centimeters', 0, ...
'inches', 0, ...
'normalized', -1, ...
'pixels', 1, ...
'points', 0 ...
);
% valid paper unit names and option
bvqxfigure_factory.punits = struct( ...
'centimeters', 0, ...
'inches', 1, ...
'normalized', -1, ...
'points', 0 ...
);
% valid unit names and option
bvqxfigure_factory.units = struct( ...
'centimeters', 0, ...
'characters', 0, ...
'inches', 0, ...
'normalized', -1, ...
'pixels', 1, ...
'points', 0 ...
);
% valid and default options for figures (for checkstruct)
bvqxfigure_factory.optfig = { ...
'BackingStore', 'char', {'on', 'off'}, 'off'; ...
'CallbackClReq', 'char', 'expression', 'closereq;'; ...
'CallbackClick', 'char', 'expression', ''; ...
'CallbackDelete', 'char', 'expression', ''; ...
'CallbackKey', 'char', 'expression', ''; ...
'CallbackMDown', 'char', 'expression', ''; ...
'CallbackMMove', 'char', 'expression', ''; ...
'CallbackMUp', 'char', 'expression', ''; ...
'CallbackResize', 'char', 'expression', ''; ...
'Color', 'double', 'noinfnan', bvqxfigure_factory.figbgcolor; ...
'ContextMenu', 'char', 'label', ''; ...
'DoubleBuffer', 'char', {'on', 'off'}, 'on'; ...
'FieldLinkCont', '', '', []; ...
'FieldLinkSpec', '', '', []; ...
'Interrupts', 'char', {'on', 'off'}, 'on'; ...
'IntegerHandle', 'char', {'on', 'off'}, 'off'; ...
'MenuBar', 'char', {'none', 'figure'}, 'none'; ...
'MinSize', 'double', 'nonempty', []; ...
'Modal', 'char', {'on', 'off'}, 'off'; ...
'Page', 'double', 'noinfnan', []; ...
'PaperUnits', 'char', fieldnames(bvqxfigure_factory.punits), 'inches'; ...
'PaperOrientation','char', {'portrait', 'landscape', 'rotated'}, 'portrait'; ...
'PaperPosition', 'double', 'noinfnan', [0.25, 2.5, 8, 6]; ...
'PaperSize', 'double', 'noinfnan', [8.5, 11]; ...
'PaperType', 'char', bvqxfigure_factory.figptypes, 'usletter'; ...
'Position', 'double', 'nonempty', [0, 0, 300, 200]; ...
'PrintBW', 'char', {'on', 'off'}, 'on'; ...
'Resizeable', 'char', {'on', 'off'}, 'off'; ...
'Tag', 'char', 'label', ''; ...
'Title', 'char', 'deblank', ''; ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -