% EXAMPLE_CLASSDEF a very simple class definition that works with metaprops
%
% See also: metaprop.example

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2014 Van Oord
%       Thijs Damsma
%
%       Thijs.Damsma@VanOord.com
%
%       Schaardijk 211
%       3063 NH
%       Rotterdam
%       Netherlands
%
%   This library is free software: you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation, either version 3 of the License, or
%   (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this library.  If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://www.OpenEarth.eu">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 21 Feb 2014
% Created with Matlab version: 8.3.0.73043 (R2014a)

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $

%%
classdef example_options < oop.inspectable & oop.saveload
    %% the block with meta props is first, so the details of the properies is immediatly visible
    % All properties decripeb by metaprops must be properties of the class
    properties (Constant,Hidden,Transient)
        % Code template generated by calling metaprop.Template('metaprop.example_classdef')
        example_option_metaprops = metaprop.Construct(mfilename('class'),{
            'date',@metaprop.date,{         % the metaprop type describes the class of type data, the getter/setter methods, and the editor to use. A date implies a date picker 
                'Category','When'           % Category: only define for the graphical inspector, has no other meaning
                'Description','Date field'  % Description: this is the text that shows up when the item is selected in the graphical inspector
                }
            'time',@metaprop.time,{         % Time imples a time in the format HH:MM:SS
                'Category','When'
                'Description','Time field'
                }
            'number',@metaprop.doubleScalar,{ % Double scalar: one double precision number (not an array)
                'Category','What'
                'Description','A single double precision number greater than 1'
                'Attributes',{'>',1} % this attribute indicates that the number must be greater than one. For the syntax, see 'help validateattributes'
                }
            'position',@metaprop.doubleRow,{
                'Category','What'
                'Description','4 element row vector'
                }
            'array',@metaprop.doubleArray2D,{
                'Category','What'
                'Description','A 5x5 array of doubles. Rows can be added (but not in the gui), but the number of columns is fixed to 5'
                'Attributes',{'ncols',5}
                }
            'color',@metaprop.color,{
                'Category','How'
                'Description','A color'
                }
            });
    end
    
    methods (Hidden,Access = protected)
        function value = construct_metaprops(self)
            value = self.example_option_metaprops;
        end
    end  
    
    %% Declaration of the properties
    % Below are the properties and their default values
    % All these properties are described in the metaprops above. 
    properties
        date = datenum(2012,1,16);
        time = datenum(0,0,0,12,00,36);
        number = 2
        position = [1 2 3 4]
        array = magic(5);
        color = [1,0,0];
    end
    
    % the following properties are niot set directly, but are 
    properties (Dependent,Transient)
        datetime % date+time
        datestring
    end
    
    methods
        %% constructor
        function self = example_options(varargin)
            self = self@oop.inspectable;
            self.set_onInvalidInput    = 'warning';
            self.set_onUnknownProperty = 'warning';
            self.set(varargin{:});
        end
        
        %% setter methods
        function set.date    (self,value); self.metaprops.date    .Check(value); self.date     = value; end
        function set.time    (self,value); self.metaprops.time    .Check(value); self.time     = value; end
        function set.number  (self,value); self.metaprops.number  .Check(value); self.number   = value; end
        function set.position(self,value); self.metaprops.position.Check(value); self.position = value; end
        function set.array   (self,value); self.metaprops.array   .Check(value); self.array    = value; end
        function set.color   (self,value); self.metaprops.color   .Check(value); self.color    = value; end
        
        %% getter methods
        function value = get.datetime  (self); value = self.date+self.time;    end
        function value = get.datestring(self); value = datestr(self.datetime); end
    end
    
    methods (Static)
        function self = loadobj(s)
            self = example_options(s);
        end
    end
end