source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/layoutHelp/Examples/dockexample.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.8 KB
Line 
1function dockexample()
2%DOCKEXAMPLE: An example of using the panelbox dock/undock functionality
3
4%   Copyright 2009 The MathWorks Ltd.
5%   1.1    2012/05/08 08:03:00
6
7% Create the window and main layout
8fig = figure( 'Name', 'Dockable GUI example', ...'
9    'NumberTitle', 'off', ...
10    'Toolbar', 'none', ...
11    'MenuBar', 'none', ...
12    'CloseRequestFcn', @nCloseAll );
13box = uiextras.HBox( 'Parent', fig );
14
15% Add three panels to the box
16panel{1} = uiextras.BoxPanel( 'Title', 'Panel 1', ...
17    'DockFcn', {@nDock, 1}, ...
18    'Parent', box );
19panel{2} = uiextras.BoxPanel( 'Title', 'Panel 2', ...
20    'DockFcn', {@nDock, 2}, ...
21    'Parent', box );
22panel{3} = uiextras.BoxPanel( 'Title', 'Panel 3', ...
23    'DockFcn', {@nDock, 3}, ...
24    'Parent', box );
25
26% Add some contents
27uicontrol( 'Style', 'PushButton', 'String', 'Button 1', 'Parent', panel{1} );
28uicontrol( 'Style', 'PushButton', 'String', 'Button 2', 'Parent', panel{2} );
29uicontrol( 'Style', 'PushButton', 'String', 'Button 3', 'Parent', panel{3} );
30
31% Set the dock/undock callback
32set( panel{1}, 'DockFcn', {@nDock, 1} );
33set( panel{2}, 'DockFcn', {@nDock, 2} );
34set( panel{3}, 'DockFcn', {@nDock, 3} );
35
36%-------------------------------------------------------------------------%
37    function nDock( eventSource, eventData, whichpanel ) %#ok<INUSL>
38        % Set the flag
39        panel{whichpanel}.IsDocked = ~panel{whichpanel}.IsDocked;
40        if panel{whichpanel}.IsDocked
41            % Put it back into the layout
42            newfig = get( panel{whichpanel}, 'Parent' );
43            set( panel{whichpanel}, 'Parent', box );
44            delete( newfig );
45        else
46            % Take it out of the layout
47            pos = getpixelposition( panel{whichpanel} );
48            newfig = figure( ...
49                'Name', get( panel{whichpanel}, 'Title' ), ...
50                'NumberTitle', 'off', ...
51                'MenuBar', 'none', ...
52                'Toolbar', 'none', ...
53                'CloseRequestFcn', {@nDock, whichpanel} );
54            figpos = get( newfig, 'Position' );
55            set( newfig, 'Position', [figpos(1,1:2), pos(1,3:4)] );
56            set( panel{whichpanel}, 'Parent', newfig, ...
57                'Units', 'Normalized', ...
58                'Position', [0 0 1 1] );
59        end
60    end % nDock
61
62%-------------------------------------------------------------------------%
63    function nCloseAll( ~, ~ )
64        % User wished to close the application, so we need to tidy up
65       
66        % Delete all windows, including undocked ones. We can do this by
67        % getting the window for each panel in turn and deleting it.
68        for ii=1:numel( panel )
69            if isvalid( panel{ii} ) && ~strcmpi( panel{ii}.BeingDeleted, 'on' )
70                figh = ancestor( panel{ii}, 'figure' );
71                delete( figh );
72            end
73        end
74       
75    end % nCloseAll
76
77end % Main function
Note: See TracBrowser for help on using the repository browser.