classdef(Hidden, Sealed) PlainTextRepresentation < matlab.display.internal.CompactDisplayRepresentation
    % PlainTextRepresentation Plain-text representation
    % of data for displaying objects within a container or under space 
    % constraints.
    %
    % Use this class when you want to display objects of your class by
    % showing its full or partial data.
    % 
    
    % Copyright 2020 The MathWorks, Inc.
    
    properties(SetAccess = immutable)
        % String representation of the object data.
        Representation (1,1) string;
    end
    
    methods
        function obj = PlainTextRepresentation(dataRepresentation, displayConfiguration, optionalParams)
        % PlainTextRepresentation constructor.
        % 
        % PlainTextRepresentation(dataRepresentation)
        % Constructs a PlainTextRepresentation object with its Representation
        % property set to dataRepresentation and its Annotation value
        % set to empty
        %
        % PlainTextRepresentation(dataRepresentation, 'Annotation', annotation)
        % Constructs a PlainTextRepresentation object with its Representation
        % property set to dataRepresentation and the Annotation value set
        % to the annotation text.
            arguments
                dataRepresentation (1,1) string
                displayConfiguration (1,1) matlab.display.internal.DisplayConfiguration
                optionalParams.Annotation (1,1) string = ""
            end
            % Append data delimiters
            paddedDisplayOutput = displayConfiguration.DataOpenDelimiter + dataRepresentation + displayConfiguration.DataCloseDelimiter;
            annotation = "";
            if (~isempty(optionalParams.Annotation) && optionalParams.Annotation ~= "")
                % Append annotation if it is not set to empty
                annotation = displayConfiguration.AnnotationOpenDelimiter + optionalParams.Annotation + displayConfiguration.AnnotationCloseDelimiter;
                paddedDisplayOutput = paddedDisplayOutput + displayConfiguration.AnnotationPadding + ...
                                       annotation;
            end
            % Compute the character width for display string
            characterWidth = columnCount(displayConfiguration, paddedDisplayOutput);
            obj@matlab.display.internal.CompactDisplayRepresentation(annotation, characterWidth, paddedDisplayOutput);
            obj.Representation = dataRepresentation;
        end
    end
end

