Home > rest_20090422 > rest_spm5_files > nic_spm_figure.m

nic_spm_figure

PURPOSE ^

Setup and callback functions for Graphics window

SYNOPSIS ^

function varargout=nic_spm_figure(varargin)

DESCRIPTION ^

 Setup and callback functions for Graphics window
 FORMAT varargout=spm_figure(varargin)
       - An embedded callback, multi-function function
       - For detailed programmers comments, see format specifications
         in main body of code
_______________________________________________________________________

 spm_figure creates and manages the 'Graphics' window. This window and
 these facilities may be used independently of SPM, and any number of
 Graphics windows my be used within the same MatLab session. (Though
 only one SPM 'Graphics' 'Tag'ed window is permitted.

 The Graphics window is provided with a menu bar at the top that
 facilitates editing and printing of the current graphic display,
 enabling interactive editing of graphic output prior to printing
 (e.g. selection of color maps, deleting, moving and editing graphics
 objects or adding text). (This menu is also provided as a figure
 background "ContextMenu" - right-clicking on the figure background
 should bring up the menu.)

 Print: Graphics windows with multi-page axes are printed page by page.

 Clear: Clears the Graphics window. If in SPM usage (figure 'Tag'ed as
 'Graphics') then all SPM windows are cleared and reset.

 Colormap options:
 * gray, hot, pink: Sets the colormap to its default values and loads
                 either a grayscale, 'hot metal' or color map.
 * gray-hot, etc: Creates a 'split' colormap {128 x 3 matrix}.
          The lower half is a gray scale and the upper half
          is 'hot metal' or 'pink'.  This color map is used for
        viewing 'rendered' SPMs on a PET, MRI or other background images

 Colormap effects:
 * Invert: Inverts (flips) the current color map.
 * Brighten and Darken: Brighten and Darken the current colourmap
        using the MatLab BRIGHTEN command, with  beta's of +0.2 and -0.2
        respectively.

 Editing: Right button ('alt' button) canic_els operations
 * Cut  : Deletes the graphics object next selected (if deletable)
          Select with middle mouse button to delete blocks of text,
          or to delete individual elements from a plot.
 * Move : To re-position a text, uicontrol or axis object using a
          'drag and drop' implementation (i.e. depress - move - release)
          Using the middle 'extend' mouse button on a text object moves
          the axes containing the text - i.e. blocks of text.
 * Size : Re-sizes the text, uicontrol or axis object next selected
          {left button - decrease, middle button  - inic_rease} by a factor
          of 1.24 (or inic_rease/decrease FontSize by 2 dpi)
 * Text : Creates an editable text widget that produces a text object as
          its CallBack.
          The text object is provided with a ContextMenu, obtained by
          right-clicking ('alt') on the text, allowing text attributes
          to be changed. Alternatively, the edit facilities on the window
          menu bar or ContextMenu can be used.
 * Edit : To edit text, select a text object with the circle cursor,
          and edit the text in the editable text widget that appears.
          A middle 'extend' mouse click places a context menu on the text
          object, facilitating easy modification of text atributes.

 For SPM usage, the figure should be 'Tag'ed as 'Graphics'.

 For SPM power users, and programmers, spm_figure provides utility
 routines for using the SPM graphics interface. Of particular use are
 the GetWin, FindWin and Clear functions See the embedded callback
 referenic_e in the main body of spm_figure, below the help text.

 See also: spm_print, spm_clf

_______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

nic_spm_figure.m

SOURCE CODE ^

0001 function varargout=nic_spm_figure(varargin)
0002 % Setup and callback functions for Graphics window
0003 % FORMAT varargout=spm_figure(varargin)
0004 %       - An embedded callback, multi-function function
0005 %       - For detailed programmers comments, see format specifications
0006 %         in main body of code
0007 %_______________________________________________________________________
0008 %
0009 % spm_figure creates and manages the 'Graphics' window. This window and
0010 % these facilities may be used independently of SPM, and any number of
0011 % Graphics windows my be used within the same MatLab session. (Though
0012 % only one SPM 'Graphics' 'Tag'ed window is permitted.
0013 %
0014 % The Graphics window is provided with a menu bar at the top that
0015 % facilitates editing and printing of the current graphic display,
0016 % enabling interactive editing of graphic output prior to printing
0017 % (e.g. selection of color maps, deleting, moving and editing graphics
0018 % objects or adding text). (This menu is also provided as a figure
0019 % background "ContextMenu" - right-clicking on the figure background
0020 % should bring up the menu.)
0021 %
0022 % Print: Graphics windows with multi-page axes are printed page by page.
0023 %
0024 % Clear: Clears the Graphics window. If in SPM usage (figure 'Tag'ed as
0025 % 'Graphics') then all SPM windows are cleared and reset.
0026 %
0027 % Colormap options:
0028 % * gray, hot, pink: Sets the colormap to its default values and loads
0029 %                 either a grayscale, 'hot metal' or color map.
0030 % * gray-hot, etc: Creates a 'split' colormap {128 x 3 matrix}.
0031 %          The lower half is a gray scale and the upper half
0032 %          is 'hot metal' or 'pink'.  This color map is used for
0033 %        viewing 'rendered' SPMs on a PET, MRI or other background images
0034 %
0035 % Colormap effects:
0036 % * Invert: Inverts (flips) the current color map.
0037 % * Brighten and Darken: Brighten and Darken the current colourmap
0038 %        using the MatLab BRIGHTEN command, with  beta's of +0.2 and -0.2
0039 %        respectively.
0040 %
0041 % Editing: Right button ('alt' button) canic_els operations
0042 % * Cut  : Deletes the graphics object next selected (if deletable)
0043 %          Select with middle mouse button to delete blocks of text,
0044 %          or to delete individual elements from a plot.
0045 % * Move : To re-position a text, uicontrol or axis object using a
0046 %          'drag and drop' implementation (i.e. depress - move - release)
0047 %          Using the middle 'extend' mouse button on a text object moves
0048 %          the axes containing the text - i.e. blocks of text.
0049 % * Size : Re-sizes the text, uicontrol or axis object next selected
0050 %          {left button - decrease, middle button  - inic_rease} by a factor
0051 %          of 1.24 (or inic_rease/decrease FontSize by 2 dpi)
0052 % * Text : Creates an editable text widget that produces a text object as
0053 %          its CallBack.
0054 %          The text object is provided with a ContextMenu, obtained by
0055 %          right-clicking ('alt') on the text, allowing text attributes
0056 %          to be changed. Alternatively, the edit facilities on the window
0057 %          menu bar or ContextMenu can be used.
0058 % * Edit : To edit text, select a text object with the circle cursor,
0059 %          and edit the text in the editable text widget that appears.
0060 %          A middle 'extend' mouse click places a context menu on the text
0061 %          object, facilitating easy modification of text atributes.
0062 %
0063 % For SPM usage, the figure should be 'Tag'ed as 'Graphics'.
0064 %
0065 % For SPM power users, and programmers, spm_figure provides utility
0066 % routines for using the SPM graphics interface. Of particular use are
0067 % the GetWin, FindWin and Clear functions See the embedded callback
0068 % referenic_e in the main body of spm_figure, below the help text.
0069 %
0070 % See also: spm_print, spm_clf
0071 %
0072 %_______________________________________________________________________
0073 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e
0074 
0075 % Andrew Holmes
0076 % $Id: spm_figure.m 305 2005-11-23 17:52:16Z john $
0077 
0078 
0079 %=======================================================================
0080 % - FORMAT specifications for embedded CallBack functions
0081 %=======================================================================
0082 %( This is a multi function function, the first argument is an action  )
0083 %( string, specifying the particular action function to take. Recall   )
0084 %( MatLab's command-function duality: `spm_figure Create` is           )
0085 %( equivalent to `spm_figure('Create')`.                               )
0086 %
0087 % FORMAT F = spm_figure
0088 % [ShortCut] Defaults to Action 'Create'
0089 %
0090 % FORMAT F = spm_figure(F) - numeric F
0091 % [ShortCut] Defaults to spm_figure('CreateBar',F)
0092 %
0093 % FORMAT F = spm_figure('Create',Tag,Name,Visible)
0094 % Create a full length WhiteBg figure 'Tag'ed Tag (if specified),
0095 % with a ToolBar and background context menu.
0096 % Equivalent to spm_figure('CreateWin','Tag') and spm_figure('CreateBar')
0097 % Tag      - 'Tag' string for figure.
0098 % Name    - Name for window
0099 % Visible - 'on' or 'off'
0100 % F      - Figure used
0101 %
0102 % FORMAT F = spm_figure('FindWin',F)
0103 % Finds window with 'Tag' or figure numnber F - returns empty F if not found
0104 % F    - (Input)  Figure to use [Optional] - 'Tag' string or figure number.
0105 %    - Defaults to 'Graphics'
0106 % F    - (Output) Figure number (if found) or empty (if not).
0107 %
0108 % FORMAT F = spm_figure('GetWin',Tag)
0109 % Like spm_figure('FindWin',Tag), except that if 'Tag' is 'Graphics' or
0110 % 'Interactive' and no such 'Tag'ged figure is found, one is created. Further,
0111 % the "got" window is made current.
0112 % Tag    - Figure 'Tag' to get, defaults to 'Graphics'
0113 % F    - Figure number (if found/created) or empty (if not).
0114 %
0115 % FORMAT F = spm_figure('ParentFig',h)
0116 % Finds window containing the object whose handle is specified
0117 % h    - Handle of object whose parent figure is required
0118 %    - If a vector, then first object handle is used
0119 % F    - Number or parent figure
0120 %
0121 % FORMAT spm_figure('Clear',F,Tags)
0122 % Clears figure, leaving ToolBar (& other objects with invisible handles)
0123 % Optional third argument specifies 'Tag's of objects to delete.
0124 % If figure F is 'Tag'ged 'Interactive' (SPM usage), then the window
0125 % name and pointer are reset.
0126 % F    - 'Tag' string or figure number of figure to clear, defaults to gcf
0127 % Tags  - 'Tag's (string matrix or cell array of strings) of objects to delete
0128 %         *regardless* of 'HandleVisibility'. Only these objects are deleted.
0129 %         '!all' denotes all objects
0130 %
0131 %
0132 % FORMAT spm_figure('Print',F)
0133 % F    - [Optional] Figure to print. ('Tag' or figure number)
0134 %      Defaults to figure 'Tag'ed as 'Graphics'.
0135 %      If none found, uses CurrentFigure if avaliable.
0136 % If objects 'Tag'ed 'NextPage' and 'PrevPage' are found, then the
0137 % pages are shown and printed in order. In breif, pages are held as
0138 % seperate axes, with ony one 'Visible' at any one time. The handles of
0139 % the "page" axes are stored in the 'UserData' of the 'NextPage'
0140 % object, while the 'PrevPage' object holds the current page number.
0141 % See spm_help('!Disp') for details on setting up paging axes.
0142 %
0143 % FORMAT [hNextPage, hPrevPage, hPageNo] = spm_figure('NewPage',hPage)
0144 % SPM pagination function: Makes objects with handles hPage paginated
0145 % Creates pagination buttons if necessary.
0146 % hPage                            - Handles of objects to stick to this page
0147 % hNextPage, hPrevPage, hPageNo - Handles of pagination controls
0148 %
0149 % FORMAT spm_figure('TurnPage',move,F)
0150 % SPM pagination function: Turn to specified page
0151 %
0152 % FORMAT spm_figure('DeletePageControls',F)
0153 % SPM pagination function: Deletes page controls
0154 % F    - [Optional] Figure in which to attempt to turn the page
0155 %         Defaults to 'Graphics' 'Tag'ged window
0156 %
0157 % FORMAT n = spm_figure('#page')
0158 % Returns the current page number.
0159 %
0160 % FORMAT spm_figure('WaterMark',F,str,Tag,Angle,Perm)
0161 % Adds watermark to figure windows.
0162 % F    - Figure for watermark. Defaults to gcf
0163 % str   - Watermark string. Defaults (missing or empty) to SPM
0164 % Tag   - Tag for watermark axes. Defaults to ''
0165 % Angle - Angle for watermark. Defaults to -45
0166 % Perm  - If specified, then watermark is permanent (HandleVisibility 'off')
0167 %
0168 % FORMAT F = spm_figure('CreateWin',Tag,Name,Visible)
0169 % Creates a full length WhiteBg figure 'Tag'ged Tag (if specified).
0170 % F      - Figure created
0171 % Tag      - Tag for window
0172 % Name    - Name for window
0173 % Visible - 'on' or 'off'
0174 %
0175 % FORMAT WS = spm_figure('GetWinScale')
0176 % Returns ratios of current display dimensions to that of a 1152 x 900
0177 % Sun display. WS=[Xratio,Yratio,Xratio,Yratio]. Used for scaling other
0178 % GUI elements.
0179 % (function duplicated in spm.m, repeated to reduce inter-dependenic_ies.)
0180 %
0181 % FORMAT FS = spm_figure('FontSizes',FS)
0182 % Returns fontsizes FS scaled for the current display.
0183 % FS     - (vector of) Font sizes to scale
0184 %          [default [08,09,11,13,14,6:36]]
0185 %
0186 % FORMAT spm_figure('CreateBar',F)
0187 % Creates toolbar in figure F (defaults to gcf). F can be a 'Tag'
0188 % If the figure is 'Tag'ed as 'Graphics' (SPM usage), then the Print button
0189 % callback is set to attempt to clear an 'Interactive' figure too.
0190 %
0191 % FORMAT spm_figure('ColorMap')
0192 % Callback for "ColorMap" buttons
0193 %
0194 % FORMAT h = spm_figure('GraphicsHandle',F)
0195 % GUI choose object for handle identification. LeftMouse 'normal' returns
0196 % handle, MiddleMouse 'extend' returns parents handle, RightMouse 'alt' canic_els.
0197 % F - figure to do a GUI "handle ID" in [Default gcbf]
0198 %_______________________________________________________________________
0199 
0200 
0201 %-Condition arguments
0202 %-----------------------------------------------------------------------
0203 if (nargin==0), Action = 'Create'; else Action = varargin{1}; end
0204 
0205 switch lower(Action), case 'create'
0206 %=======================================================================
0207 % F = spm_figure('Create',Tag,Name,Visible)
0208 %-Condition arguments
0209 if nargin<4, Visible='on'; else Visible=varargin{4}; end
0210 if nargin<3, Name=''; else, Name=varargin{3}; end
0211 if nargin<2, Tag=''; else Tag=varargin{2}; end
0212 
0213 F = nic_spm_figure('CreateWin',Tag,Name,Visible);
0214 nic_spm_figure('CreateBar',F);
0215 nic_spm_figure('FigContextMenu',F);
0216 varargout = {F};
0217 
0218 
0219 case 'findwin'
0220 %=======================================================================
0221 % F=spm_figure('FindWin',F)
0222 % F=spm_figure('FindWin',Tag)
0223 %-Find window: Find window with FigureNumber# / 'Tag' attribute
0224 %-Returns empty if window cannot be found - deletes multiple tagged figs.
0225 
0226 if nargin<2, F='Graphics'; else F=varargin{2}; end
0227 
0228 if isempty(F)
0229     % Leave F empty
0230 elseif ischar(F)
0231     % Finds Graphics window with 'Tag' string - delete multiples
0232     Tag=F;
0233     F = findobj(get(0,'Children'),'Flat','Tag',Tag);
0234     if length(F) > 1
0235         % Multiple Graphics windows - close all but most recent
0236         close(F(2:end))
0237         F = F(1);
0238     end
0239 else
0240     % F is supposed to be a figure number - check it
0241     if ~any(F==get(0,'Children')), F=[]; end
0242 end
0243 varargout = {F};
0244 
0245 case 'getwin'
0246 %=======================================================================
0247 % F=spm_figure('GetWin',Tag)
0248 
0249 if nargin<2, Tag='Graphics'; else Tag=varargin{2}; end
0250 F = nic_spm_figure('FindWin',Tag);
0251 
0252 if isempty(F)
0253     if ischar(Tag)
0254         switch Tag, case 'Graphics'
0255             F = nic_spm_figure('Create','Graphics','Graphics');
0256         case 'Interactive'
0257             F = nic_spm('CreateIntWin');
0258         end
0259     end
0260 else
0261     set(0,'CurrentFigure',F);
0262 end
0263 varargout = {F};
0264 
0265 case 'parentfig'
0266 %=======================================================================
0267 % F=spm_figure('ParentFig',h)
0268 if nargin<2, error('No object specified'), else h=varargin{2}; end
0269 F = get(h(1),'Parent');
0270 while ~strcmp(get(F,'Type'),'figure'), F=get(F,'Parent'); end
0271 varargout = {F};
0272 
0273 
0274 case 'clear'
0275 %=======================================================================
0276 % spm_figure('Clear',F,Tags)
0277 
0278 %-Sort out arguments
0279 %-----------------------------------------------------------------------
0280 if nargin<3, Tags=[]; else Tags=varargin{3}; end
0281 if nargin<2, F=get(0,'CurrentFigure'); else F=varargin{2}; end
0282 F = nic_spm_figure('FindWin',F);
0283 if isempty(F), return, end
0284 
0285 %-Clear figure
0286 %-----------------------------------------------------------------------
0287 if isempty(Tags)
0288     %-Clear figure of objects with 'HandleVisibility' 'on'
0289     pos = get(F,'Position');
0290     delete(findobj(get(F,'Children'),'flat','HandleVisibility','on'));
0291     drawnow
0292     set(F,'Position',pos);
0293 
0294     %-Reset figures callback functions
0295     set(F,'KeyPressFcn','',...
0296         'WindowButtonDownFcn','',...
0297         'WindowButtonMotionFcn','',...
0298         'WindowButtonUpFcn','')
0299     %-If this is the 'Interactive' window, reset name & UserData
0300     if strcmp(get(F,'Tag'),'Interactive')
0301         set(F,'Name','','UserData',[]), end
0302 else
0303     %-Clear specified objects from figure
0304     cSHH = get(0,'ShowHiddenHandles');
0305     set(0,'ShowHiddenHandles','on')
0306     if ischar(Tags); Tags=cellstr(Tags); end
0307     if any(strcmp(Tags(:),'!all'))
0308         delete(get(F,'Children'))
0309     else
0310         for tag = Tags(:)'
0311         delete(findobj(get(F,'Children'),'flat','Tag',tag{:}));
0312         end
0313     end    
0314     set(0,'ShowHiddenHandles',cSHH)
0315 end
0316 set(F,'Pointer','Arrow')
0317 movegui(F);
0318 
0319 
0320 case 'print'
0321 %=======================================================================
0322 % spm_figure('Print',F)
0323 
0324 %-Arguments & defaults
0325 if nargin<2, F='Graphics'; else F=varargin{2}; end
0326 
0327 %-Find window to print, default to gcf if specified figure not found
0328 % Return if no figures
0329 F=nic_spm_figure('FindWin',F);
0330 if isempty(F), F = get(0,'CurrentFigure'); end
0331 if isempty(F), return, end
0332 
0333 %-Note current figure, & switch to figure to print
0334 cF = get(0,'CurrentFigure');
0335 set(0,'CurrentFigure',F)
0336 
0337 %-See if window has paging controls
0338 hNextPage = findobj(F,'Tag','NextPage');
0339 hPrevPage = findobj(F,'Tag','PrevPage');
0340 hPageNo   = findobj(F,'Tag','PageNo');
0341 iPaged    = ~isempty(hNextPage);
0342 
0343 %-Construct print command
0344 %-----------------------------------------------------------------------
0345 
0346 %-Temporarily change all units to normalized prior to printing
0347 % (Fixes bizzarre problem with stuff jumping around!)
0348 %-----------------------------------------------------------------------
0349 H  = findobj(get(F,'Children'),'flat','Type','axes');
0350 if ~isempty(H),
0351     un = cellstr(get(H,'Units'));
0352     set(H,'Units','normalized')
0353 end;
0354 
0355 %-Print
0356 %-----------------------------------------------------------------------
0357 if ~iPaged
0358     nic_spm_print;
0359 else
0360     hPg       = get(hNextPage,'UserData');
0361     Cpage     = get(hPageNo,  'UserData');
0362     nPages    = size(hPg,1);
0363 
0364     set([hNextPage,hPrevPage,hPageNo],'Visible','off')
0365     if Cpage~=1
0366         set(hPg{Cpage,1},'Visible','off'), end
0367     for p = 1:nPages
0368         set(hPg{p,1},'Visible','on');
0369         nic_spm_print;
0370         set(hPg{p,1},'Visible','off')
0371     end
0372     set(hPg{Cpage,1},'Visible','on')
0373     set([hNextPage,hPrevPage,hPageNo],'Visible','on')
0374 end
0375 if ~isempty(H), set(H,{'Units'},un); end;
0376 set(0,'CurrentFigure',cF)
0377 
0378 case 'newpage'
0379 %=======================================================================
0380 % [hNextPage, hPrevPage, hPageNo] = spm_figure('NewPage',h)
0381 if nargin<2 || isempty(varargin{2}) error('No handles to paginate')
0382 else h=varargin{2}(:)'; end
0383 
0384 %-Work out which figure we're in
0385 F = nic_spm_figure('ParentFig',h(1));
0386 
0387 hNextPage = findobj(F,'Tag','NextPage');
0388 hPrevPage = findobj(F,'Tag','PrevPage');
0389 hPageNo   = findobj(F,'Tag','PageNo');
0390 
0391 %-Create pagination widgets if required
0392 %-----------------------------------------------------------------------
0393 if isempty(hNextPage)
0394     WS = nic_spm('WinScale');
0395     FS = nic_spm('FontSizes');
0396     SatFig = findobj('Tag','Satellite');
0397     if ~isempty(SatFig)
0398         SatFigPos    = get(SatFig,'Position');
0399         hNextPagePos = [SatFigPos(3)-25 15 15 15];
0400         hPrevPagePos = [SatFigPos(3)-40 15 15 15];
0401         hPageNo      = [SatFigPos(3)-40  5 30 10];
0402     else
0403         hNextPagePos = [580 022 015 015].*WS;
0404         hPrevPagePos = [565 022 015 015].*WS;
0405         hPageNo      = [550 005 060 015].*WS;
0406     end
0407     
0408     hNextPage = uicontrol(F,'Style','Pushbutton',...
0409         'HandleVisibility','on',...
0410         'String','>','FontSize',FS(10),...
0411         'ToolTipString','next page',...
0412         'Callback','nic_spm_figure(''TurnPage'',''+1'',gcbf)',...
0413         'Position',hNextPagePos,...
0414         'ForegroundColor',[0 0 0],...
0415         'Tag','NextPage','UserData',[]);
0416     hPrevPage = uicontrol(F,'Style','Pushbutton',...
0417         'HandleVisibility','on',...
0418         'String','<','FontSize',FS(10),...
0419         'ToolTipString','previous page',...
0420         'Callback','nic_spm_figure(''TurnPage'',''-1'',gcbf)',...
0421         'Position',hPrevPagePos,...
0422         'Visible','on',...
0423         'Enable','off',...
0424         'Tag','PrevPage');
0425     hPageNo = uicontrol(F,'Style','Text',...
0426         'HandleVisibility','on',...
0427         'String','1',...
0428         'FontSize',FS(6),...
0429         'HorizontalAlignment','center',...
0430         'BackgroundColor','w',...
0431         'Position',hPageNo,...
0432         'Visible','on',...
0433         'UserData',1,...
0434         'Tag','PageNo','UserData',1);
0435 end
0436 
0437 %-Add handles for this page to UserData of hNextPage
0438 %-Make handles for this page invisible if PageNo>1
0439 %-----------------------------------------------------------------------
0440 mVis    = strcmp('on',get(h,'Visible'));
0441 hPg     = get(hNextPage,'UserData');
0442 if isempty(hPg)
0443     hPg = {h(mVis), h(~mVis)};
0444 else
0445     hPg = [hPg; {h(mVis), h(~mVis)}];
0446     set(h(mVis),'Visible','off','HitTest','off')
0447 end
0448 set(hNextPage,'UserData',hPg)
0449 
0450 %-Return handles to pagination controls if requested
0451 if nargout>0, varargout = {[hNextPage, hPrevPage, hPageNo]}; end
0452 
0453 
0454 case 'turnpage'
0455 %=======================================================================
0456 % spm_figure('TurnPage',move,F)
0457 if nargin<3, F='Graphics'; else F=varargin{3}; end
0458 if nargin<2, move=1; else move=varargin{2}; end
0459 F = nic_spm_figure('FindWin',F);
0460 if isempty(F), error('No Graphics window'), end
0461 
0462 hNextPage = findobj(F,'Tag','NextPage');
0463 hPrevPage = findobj(F,'Tag','PrevPage');
0464 hPageNo   = findobj(F,'Tag','PageNo');
0465 if isempty(hNextPage), return, end
0466 hPg       = get(hNextPage,'UserData');
0467 Cpage     = get(hPageNo,  'UserData');
0468 nPages    = size(hPg,1);
0469 
0470 %-Sort out new page number
0471 if ischar(move), Npage = Cpage+eval(move); else Npage = move; end
0472 Npage = max(min(Npage,nPages),1);
0473 
0474 %-Make current page invisible, new page visible, set page number string
0475 set(hPg{Cpage,1},'Visible','off')
0476 set(hPg{Npage,1},'Visible','on')
0477 set(hPageNo,'UserData',Npage,'String',sprintf('%d / %d',Npage,nPages))
0478 
0479 for k = 1:length(hPg{Npage,1}) % VG
0480     if strcmp(get(hPg{Npage,1}(k),'Type'),'axes')
0481         axes(hPg{Npage,1}(k))
0482     end;
0483 end;
0484 
0485 %-Disable appropriate page turning control if on first/last page (for neatness)
0486 if Npage==1, set(hPrevPage,'Enable','off')
0487 else set(hPrevPage,'Enable','on'), end
0488 if Npage==nPages, set(hNextPage,'Enable','off')
0489 else set(hNextPage,'Enable','on'), end
0490 
0491 
0492 
0493 case 'deletepagecontrols'
0494 %=======================================================================
0495 % spm_figure('DeletePageControls',F)
0496 if nargin<2, F='Graphics'; else F=varargin{2}; end
0497 F = nic_spm_figure('FindWin',F);
0498 if isempty(F), error('No Graphics window'), end
0499 
0500 hNextPage = findobj(F,'Tag','NextPage');
0501 hPrevPage = findobj(F,'Tag','PrevPage');
0502 hPageNo   = findobj(F,'Tag','PageNo');
0503 
0504 delete([hNextPage hPrevPage hPageNo])
0505 
0506 
0507 case '#page'
0508 %=======================================================================
0509 % n = spm_figure('#Page',F)
0510 if nargin<2, F='Graphics'; else F=varargin{2}; end
0511 F = nic_spm_figure('FindWin',F);
0512 if isempty(F), error('No Graphics window'), end
0513 
0514 hNextPage = findobj(F,'Tag','NextPage');
0515 if isempty(hNextPage)
0516     n = 1;
0517 else
0518     n = size(get(hNextPage,'UserData'),1)+1;
0519 end
0520 varargout = {n};
0521 
0522 
0523 case 'watermark'
0524 %=======================================================================
0525 % spm_figure('WaterMark',F,str,Tag,Angle,Perm)
0526 if nargin<6, HVis='on'; else HVis='off'; end
0527 if nargin<5, Angle=-45; else Angle=varargin{5}; end
0528 if nargin<4 || isempty(varargin{4}), Tag = 'WaterMark'; else Tag=varargin{4}; end
0529 if nargin<3 || isempty(varargin{3}), str = 'SPM';       else str=varargin{3}; end
0530 if nargin<2, if any(get(0,'Children')), F=gcf; else F=''; end
0531 else F=varargin{2}; end
0532 F = nic_spm_figure('FindWin',F);
0533 if isempty(F), return, end
0534 
0535 %-Specify watermark color from background colour
0536 %-----------------------------------------------------------------------
0537 Colour = get(F,'Color');
0538 %-Only mess with grayscale backgrounds
0539 if ~all(Colour==Colour(1)), return, end
0540 %-Work out colour - lighter unless grey value > 0.9
0541 Colour = Colour+(2*(Colour(1)<0.9)-1)*0.02;
0542 
0543 cF = get(0,'CurrentFigure');
0544 set(0,'CurrentFigure',F)
0545 Units=get(F,'Units');
0546 set(F,'Units','normalized');
0547 h = axes('Position',[0.45,0.5,0.1,0.1],...
0548     'Units','normalized',...
0549     'Visible','off',...
0550     'Tag',Tag);
0551 set(F,'Units',Units)
0552 text(0.5,0.5,str,...
0553     'FontSize',nic_spm('FontSize',80),...
0554     'FontWeight','Bold',...
0555     'FontName',nic_spm_platform('Font','times'),...
0556     'Rotation',Angle,...
0557     'HorizontalAlignment','Center',...
0558     'VerticalAlignment','middle',...
0559     'EraseMode','normal',...
0560     'Color',Colour,...
0561     'ButtonDownFcn',[...
0562         'if strcmp(get(gcbf,''SelectionType''),''open''),',...
0563             'delete(get(gcbo,''Parent'')),',...
0564         'end'])
0565 set(h,'HandleVisibility',HVis)
0566 set(0,'CurrentFigure',cF)
0567 
0568 
0569 case 'createwin'
0570 %=======================================================================
0571 % F=spm_figure('CreateWin',Tag,Name,Visible)
0572 
0573 %-Condition arguments
0574 %-----------------------------------------------------------------------
0575 if nargin<4 || isempty(varargin{4}), Visible='on'; else Visible=varargin{4}; end
0576 if nargin<3, Name=''; else Name = varargin{3}; end
0577 if nargin<2, Tag='';  else Tag  = varargin{2}; end
0578 
0579 WS   = nic_spm('WinScale');                %-Window scaling factors
0580 FS   = nic_spm('FontSizes');            %-Scaled font sizes
0581 PF   = nic_spm_platform('fonts');            %-Font names (for this platform)
0582 Rect = nic_spm('WinSize','Graphics','raw').*WS;    %-Graphics window rectangle
0583 
0584 F    = figure(...
0585     'Tag',Tag,...
0586     'Position',Rect,...
0587     'Resize','off',...
0588     'Color','w',...
0589     'ColorMap',gray(64),...
0590     'DefaultTextColor','k',...
0591     'DefaultTextInterpreter','none',...
0592     'DefaultTextFontName',PF.helvetica,...
0593     'DefaultTextFontSize',FS(10),...
0594     'DefaultAxesColor','w',...
0595     'DefaultAxesXColor','k',...
0596     'DefaultAxesYColor','k',...
0597     'DefaultAxesZColor','k',...
0598     'DefaultAxesFontName',PF.helvetica,...
0599     'DefaultPatchFaceColor','k',...
0600     'DefaultPatchEdgeColor','k',...
0601     'DefaultSurfaceEdgeColor','k',...
0602     'DefaultLineColor','k',...
0603     'DefaultUicontrolFontName',PF.helvetica,...
0604     'DefaultUicontrolFontSize',FS(10),...
0605     'DefaultUicontrolInterruptible','on',...
0606     'PaperType','A4',...
0607     'PaperUnits','normalized',...
0608     'PaperPosition',[.0726 .0644 .854 .870],...
0609     'InvertHardcopy','off',...
0610     'Renderer','painters',...
0611     'Visible','off',...
0612     'Toolbar','none');
0613 if ~isempty(Name)
0614     set(F,'Name',sprintf('%s%s: %s',nic_spm('ver'),...
0615         nic_spm('GetUser',' (%s)'),Name),'NumberTitle','off')
0616 end
0617 set(F,'Visible',Visible)
0618 varargout = {F};
0619 
0620 
0621 case 'getwinscale'
0622 %=======================================================================
0623 % WS = spm_figure('GetWinScale')
0624 warning('nic_spm_figure(''GetWinScale''... is Grandfathered: use spm(''WinScale''')
0625 varargout = {nic_spm('WinScale')};
0626 
0627 
0628 case 'fontsizes'
0629 %=======================================================================
0630 % FS = spm_figure('FontSizes',FS)
0631 warning('nic_spm_figure(''FontSizes''... is Grandfathered: use nic_spm(''FontSizes''')
0632 if nargin<2, FS=[08,09,11,13,14,6:36]; else FS=varargin{2}; end
0633 varargout = {round(FS*min(nic_spm('WinScale')))};
0634 
0635 
0636 %=======================================================================
0637  case 'createbar'
0638 %=======================================================================
0639 % spm_figure('CreateBar',F)
0640 if nargin<2, if any(get(0,'Children')), F=gcf; else F=''; end
0641 else F=varargin{2}; end
0642 F = nic_spm_figure('FindWin',F);
0643 if isempty(F), return, end
0644 
0645 cSHH = get(0,'ShowHiddenHandles');
0646 set(0,'ShowHiddenHandles','on')
0647 
0648 t0 = findobj(get(F,'Children'),'Flat','Label','&Help');
0649 if isempty(t0), t0 = uimenu( F,'Label','&Help'); end;
0650 
0651 set(findobj(t0,'Position',1),'Separator','on');
0652 uimenu(t0,'Position',1,...
0653     'Label','SPM web',...
0654     'CallBack','web(''http://www.fil.ion.ucl.ac.uk/spm/'');');
0655 uimenu(t0,'Position',1,...
0656     'Label','SPM help','ForegroundColor',[0 1 0],...
0657     'CallBack','spm_help');
0658 
0659 t0=uimenu( F,'Label','Colours','HandleVisibility','off');
0660 t1=uimenu(t0,'Label','ColorMap');
0661 uimenu(t1,'Label','Gray',     'CallBack','nic_spm_figure(''ColorMap'',''gray'')');
0662 uimenu(t1,'Label','Hot',      'CallBack','nic_spm_figure(''ColorMap'',''hot'')');
0663 uimenu(t1,'Label','Pink',     'CallBack','nic_spm_figure(''ColorMap'',''pink'')');
0664 uimenu(t1,'Label','Jet','CallBack','nic_spm_figure(''ColorMap'',''jet'')');
0665 uimenu(t1,'Label','Gray-Hot', 'CallBack','nic_spm_figure(''ColorMap'',''gray-hot'')');
0666 uimenu(t1,'Label','Gray-Cool','CallBack','nic_spm_figure(''ColorMap'',''gray-cool'')');
0667 uimenu(t1,'Label','Gray-Pink','CallBack','nic_spm_figure(''ColorMap'',''gray-pink'')');
0668 uimenu(t1,'Label','Gray-Jet', 'CallBack','nic_spm_figure(''ColorMap'',''gray-jet'')');
0669 t1=uimenu(t0,'Label','Effects');
0670 uimenu(t1,'Label','Invert','CallBack','nic_spm_figure(''ColorMap'',''invert'')');
0671 uimenu(t1,'Label','Brighten','CallBack','nic_spm_figure(''ColorMap'',''brighten'')');
0672 uimenu(t1,'Label','Darken','CallBack','nic_spm_figure(''ColorMap'',''darken'')');
0673 uimenu( F,'Label','Clear','HandleVisibility','off','CallBack','nic_spm_figure(''Clear'',gcbf)');
0674 %t0=uimenu( F,'Label','SPM-Print','HandleVisibility','off');
0675 uimenu( F,'Label','SPM-Print','HandleVisibility','off','CallBack','nic_spm_figure(''Print'',gcbf)');
0676 
0677 % ### CODE FOR SATELLITE FIGURE ###
0678 % Code checks if there is a satellite window and if results are currently displayed
0679 % It assumes that if hReg is invalid then there are no results currently displayed
0680 % Modified by DRG to display a satellite figure 02/14/01.
0681 cb = ['global SatWindow,',...
0682         'try,',...
0683         'tmp = get(hReg);,',...
0684         'ResFlag = 1;',...
0685         'catch,',...
0686         'ResFlag = 0;',...
0687         'end,',...
0688         'if SatWindow,',...
0689         'figure(SatWindow),',...
0690         'else,',...
0691         'if ResFlag,',...
0692         'spm_setup_satfig,',...
0693         'end,',...
0694         'end'];
0695 uimenu( F,'Label','Results-Fig','HandleVisibility','off','Callback',cb);
0696 % ### END NEW CODE ###
0697 
0698 
0699 set(0,'ShowHiddenHandles',cSHH)
0700 spm_jobman('pulldown');
0701 %=======================================================================
0702 
0703 
0704 case 'figcontextmenu'
0705 %=======================================================================
0706 % h = spm_figure('FigContextMenu',F)
0707 if nargin<2
0708     F = get(0,'CurrentFigure');
0709     if isempty(F), error('no figure'), end
0710 else
0711     F = spm_figure('FindWin',varargin{2});
0712     if isempty(F), error('no such figure'), end
0713 end
0714 h       = uicontextmenu('Parent',F,'HandleVisibility','CallBack');
0715 cSHH = get(0,'ShowHiddenHandles');
0716 set(0,'ShowHiddenHandles','on')
0717 copy_menu(F,h);
0718 set(0,'ShowHiddenHandles',cSHH)
0719 set(F,'UIContextMenu',h)
0720 varargout = {h};
0721 
0722 
0723 case 'colormap'
0724 %=======================================================================
0725 % spm_figure('ColorMap',ColAction,h)
0726 if nargin<3, h=[]; else h=varargin{3}; end
0727 if nargin<2, ColAction='gray'; else ColAction=varargin{2}; end
0728 
0729 switch lower(ColAction), case 'gray'
0730     colormap(gray(64))
0731 case 'hot'
0732     colormap(hot(64))
0733 case 'pink'
0734     colormap(pink(64))
0735 case 'jet'
0736     colormap(jet(64))
0737 case 'gray-hot'
0738     tmp = hot(64 + 16);  tmp = tmp((1:64) + 16,:);
0739     colormap([gray(64); tmp]);
0740 case 'gray-cool'
0741     cool = [zeros(10,1) zeros(10,1) linspace(0.5,1,10)';
0742             zeros(31,1) linspace(0,1,31)' ones(31,1);
0743             linspace(0,1,23)' ones(23,1) ones(23,1) ];
0744     colormap([gray(64); cool]);
0745 case 'gray-pink'
0746     tmp = pink(64 + 16); tmp = tmp((1:64) + 16,:);
0747     colormap([gray(64); tmp]);
0748 case 'gray-jet'
0749     colormap([gray(64); jet(64)]);
0750 case 'invert'
0751     colormap(flipud(colormap));
0752 case 'brighten'
0753     colormap(brighten(colormap, 0.2));
0754 case 'darken'
0755     colormap(brighten(colormap, -0.2));
0756 otherwise
0757     error('Illegal ColAction specification');
0758 end
0759 
0760 case 'graphicshandle'
0761 %=======================================================================
0762 % h = spm_figure('GraphicsHandle',F)
0763 if nargin<2, F=gcbf; else F=nic_spm_figure('FindWin',varargin{2}); end
0764 if isempty(F), return, end
0765 
0766 tmp = get(F,'Name');
0767 set(F,'Name',...
0768     'Handle: Select item to identify, MiddleMouse=parent, RightMouse=canic_el...');
0769 set(F,'Pointer','CrossHair')
0770 waitforbuttonpress;
0771 h        = gco(F);
0772 hType    = get(h,'Type');
0773 SelnType = get(gcf,'SelectionType');
0774 set(F,'Pointer','Arrow','Name',tmp)
0775 
0776 if ~strcmp(SelnType,'alt') && ~isempty(h) && gcf==F
0777     str = sprintf('Selected (%s) object',get(h,'Type'));
0778     if strcmp(SelnType,'normal')
0779         str = sprintf('%s: handle',str);
0780     else
0781         h = get(h,'Parent');
0782         str = sprintf('%s: handle of parent (%s) object',str,get(h,'Type'));
0783     end
0784     if nargout==0
0785         assignin('base','ans',h)
0786         fprintf('\n%s: \n',str)
0787         ans = h
0788     else
0789         varargout={h};
0790     end
0791 else
0792     varargout={[]};
0793 end
0794 
0795 
0796 
0797 otherwise
0798 %=======================================================================
0799 warning(['Illegal Action string: ',Action])
0800 end
0801 return;
0802 %=======================================================================
0803 
0804 
0805 %=======================================================================
0806 function copy_menu(F,G)
0807 %=======================================================================
0808 handles = findobj(get(F,'Children'),'Flat','Type','uimenu','Visible','on');
0809 if isempty(handles), return; end;
0810 for F1=handles',
0811     if ~strcmp(get(F1,'Label'),'&Window'),
0812         G1 = uimenu(G,'Label',get(F1,'Label'),...
0813             'CallBack',get(F1,'CallBack'),...
0814             'Position',get(F1,'Position'),...
0815             'Separator',get(F1,'Separator'));
0816         copy_menu(F1,G1);
0817     end;
0818 end;
0819 return;
0820 %=======================================================================

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005