classdef viewer < matlab.mixin.SetGet & matlab.mixin.Copyable
%viewgui.viewer class
%    viewgui.viewer properties:
%       AvailableViews - All available view types with the recipe for creating them. 
%       EventManager - Event coordinator (@framemgr object) 
%       Figure - Property is of type 'MATLAB array'  
%       Preferences - Viewer preferences. 
%       StyleManager - Style manager. 
%       Views - Vector of all @plot handles. 
%       HG - Property is of type 'MATLAB array'  (read only) 
%       PlotCells - Property is of type 'MATLAB array'  
%
%    viewgui.viewer methods:
%       addview -   Adds one or several views to @viewer instance.
%       draw - does a layout of all the visible views and updates the responses of
%       generic_listeners -  Installs generic listeners for @viewer class.
%       getCurrentViews -  Get type of currently active views.
%       layout - PLOTPOS  Determines new locations for response plots in the viewer
%       layoutstatus -  positions the status bar and text in the figure window.
%       printsetup - sets the visibility specified in 'value' to the HG objects in
%       setCurrentViews -  Brings up the specified view types.
%       toolbar -  Creates the tool bar.


properties (Access=protected, SetObservable)
    %LISTENERS Property is of type 'MATLAB array' 
    Listeners = [];
end

properties (Access=protected, Transient, SetObservable)
    %LISTENERSDATA Property is of type 'MATLAB array' 
    ListenersData = [];
end

properties (SetAccess=protected, SetObservable)
    %HG Property is of type 'MATLAB array'  (read only)
    HG = [];
end

properties (SetObservable)
    %AVAILABLEVIEWS All available view types with the recipe for creating them.
    AvailableViews = struct( 'Name', cell( 0, 1 ), 'Alias', [  ], 'CreateFcn', [  ] );
    %EVENTMANAGER Event coordinator (@framemgr object)
    EventManager = [];
    %FIGURE Property is of type 'MATLAB array' 
    Figure = [];
    %PREFERENCES Viewer preferences.
    Preferences = [];
    %STYLEMANAGER Style manager.
    StyleManager = [];
    %VIEWS Vector of all @plot handles. MaxNumberViews = 6
    Views = repmat( handle( NaN ), 6, 1 );
    OldViews = repmat( handle(NaN),6,1);
    %PLOTCELLS Property is of type 'MATLAB array' 
    PlotCells = repmat( { handle( zeros( 0, 1 ) ) }, 6, 1 );
end


events 
    ConfigurationChanged
end  % events

    methods 
        function set.EventManager(obj,value)
            % DataType = 'handle'
        validateattributes(value,{'handle'}, {'scalar'},'','EventManager')
        obj.EventManager = value;
        end

        function set.Figure(obj,value)
        obj.Figure = LocalConvertToHandle(obj,value);
        end

        function set.Preferences(obj,value)
            % DataType = 'handle'
        validateattributes(value,{'handle'}, {'scalar'},'','Preferences')
        obj.Preferences = value;
        end

        function set.StyleManager(obj,value)
            % DataType = 'handle'
        validateattributes(value,{'handle'}, {'scalar'},'','StyleManager')
        obj.StyleManager = value;
        end

        function set.Views(obj,value)
        obj.Views = LocalSetViews(obj,value);
        end

        function value = get.Listeners(obj)
        value = LocalGetListenersValue(obj,obj.Listeners);
        end

    end   % set and get functions 

    methods  % public methods
    Views = addview(this,plottypes)
    draw(this)
    generic_listeners(this)
    CurrentViews = getCurrentViews(this,Request)
    layout(this,varargin)
    layoutstatus(this,varargin)
    printsetup(this,prop,value)
    setCurrentViews(this,NewViewList,SilentFlag)
    toolbar(this)
end  % public methods 

end  % classdef

function NewViews = LocalSetViews(this, NewViews)
% Sets the Current Views based on the visibility of the Views in the Viewer
if ~isempty(this.Views) && length(NewViews)~=length(this.Views)
   ctrlMsgUtils.error('Control:viewer:ViewsProperty', length(this.Views))
end
end  % LocalSetViews



function StoredValue = LocalGetListenersValue(this,StoredValue)
if isempty(this.ListenersData)
    this.ListenersData = controllibutils.ListenerManager;
end
StoredValue = this.ListenersData;
end  % LocalGetListenersValue


function Value = LocalConvertToHandle(this,Value)
% Converts to handle
Value = handle(Value);
end  % LocalConvertToHandle
