source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/+uiextras/ButtonBox.m @ 17

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

To have a stable version on the server.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1classdef ButtonBox < uiextras.Container
2    %ButtonBox  Abstract parent for button box classes
3   
4    %   Copyright 2009-2010 The MathWorks, Inc.
5    %   1.1
6    %   2012/05/08 08:02:58
7   
8    properties( SetObservable = true )
9        ButtonSize = [100 25]          % Desired size for all buttons [width height]
10        HorizontalAlignment = 'center' % Horizonral alignment of buttons [left|center|right]
11        VerticalAlignment = 'middle'   % Vertical alignment of buttons [top|middle|bottom]
12        Spacing = 5                    % spacing between contents (pixels)
13        Padding = 0                    % spacing around all contents
14    end % public properties
15   
16    methods
17       
18        function obj = ButtonBox( varargin )
19            %ButtonBox  Container with contents in a single row or column
20           
21           
22            % First step is to create the parent class. We pass the
23            % arguments (if any) just incase the parent needs setting
24            obj@uiextras.Container( varargin{:} );
25                       
26            % Set some defaults
27            obj.setPropertyFromDefault( 'ButtonSize' );
28            obj.setPropertyFromDefault( 'HorizontalAlignment' );
29            obj.setPropertyFromDefault( 'VerticalAlignment' );
30            obj.setPropertyFromDefault( 'Spacing' );
31            obj.setPropertyFromDefault( 'Padding' );
32
33        end % constructor
34       
35        function set.ButtonSize( obj, value )
36            % Check
37            if ~isnumeric( value ) || numel( value )~= 2 ...
38                    || any( ~isreal( value ) ) || any( isnan( value ) ) ...
39                    || any( ~isfinite( value ) ) || any( value <= 0 )
40                error( 'GUILayout:InvalidPropertyValue', ...
41                    'Property ''ButtonSize'' must consist of two positive integers.' )
42            end
43           
44            % Set & redraw
45            obj.ButtonSize = value;
46            obj.redraw();
47        end % set.Sizes
48       
49        function set.Padding( obj, value )
50            % Check
51            if ~isnumeric( value ) || ~isscalar( value ) || ...
52                    ~isreal( value ) || isnan( value ) || ~isfinite( value ) || ...
53                    value < 0 || rem( value, 1 ) ~= 0
54                error( 'GUILayout:InvalidPropertyValue', ...
55                    'Property ''Padding'' must be a nonnegative integer.' )
56            end
57           
58            % Set and redraw
59            obj.Padding = value;
60            obj.redraw();
61        end % set.Padding
62       
63        function set.Spacing( obj, value )
64            % Check
65            if ~isnumeric( value ) || ~isscalar( value ) || ...
66                    ~isreal( value ) || isnan( value ) || ~isfinite( value ) || ...
67                    value < 0 || rem( value, 1 ) ~= 0
68                error( 'GUILayout:InvalidPropertyValue', ...
69                    'Property ''Spacing'' must be a nonnegative integer.' )
70            end
71           
72            % Set and redraw
73            obj.Spacing = value;
74            obj.redraw();
75        end % set.Spacing
76       
77        function set.HorizontalAlignment( obj, value )
78            if ~ischar( value ) || ~any( strcmpi( value, {'left','center','right'} ) )
79                error( 'GUILayout:InvalidPropertyValue', ...
80                    'Property ''HorizontalAlignment'' must be a one of ''left'',''center'',''right''.' );
81            end
82            obj.HorizontalAlignment = value;
83            obj.redraw();
84        end % set.HorizontalAlignment
85       
86        function set.VerticalAlignment( obj, value )
87            if ~ischar( value ) || ~any( strcmpi( value, {'top','middle','bottom'} ) )
88                error( 'GUILayout:InvalidPropertyValue', ...
89                    'Property ''HorizontalAlignment'' must be a one of ''top'',''middle'',''bottom''.' );
90            end
91            obj.VerticalAlignment = value;
92            obj.redraw();
93        end % set.VerticalAlignment
94       
95    end % public methods
96   
97end % classdef
Note: See TracBrowser for help on using the repository browser.