function varargout = arrayviewfunc(whichcall, varargin)
% ARRAYVIEWFUNC  Support function for array view component

%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.4 $  $Date: 2000/08/30 15:15:18 $

  switch whichcall
    case 'getdata',
      varargout{1} = getData(varargin{1}, varargin{2});
    case 'setdata',
      varargout{1} = setData(varargin{1}, varargin{2}, varargin{3});
    case 'setvarwidth',
      varargout{1} = setVarWidth(varargin{1}, varargin{2});
    case 'setvarheight',
      varargout{1} = setVarHeight(varargin{1}, varargin{2});
  end

%********************************************************************
function result = getData(x, format)
  if (ischar(x))
	% First, make sure that there aren't a newline in the string.
	% If there are, we can't display it properly.
	if ~isempty(findstr(x, char(10))) | ~isempty(findstr(x, char(13)))
	  result = [];
	  return;
	end
    result = sprintf('%s', x);
  elseif iscellstr(x)
	% First, make sure that there are no newlines in the strings.
	% If there are, we can't display them properly.
	for i = 1:length(x)
	  if ~isempty(findstr(x{i}, char(10))) | ~isempty(findstr(x{i}, char(13)))
		result = [];
		return;
	  end
    end
    % have to pad with a space so java tokenizer will function
    % properly when a cell contains an empty string.
    result = sprintf('%s \n', x{:});
  elseif iscell(x)
    result = [];
  else
    oldFormat = get(0, 'format');
    oldSpacing = get(0, 'formatspacing');

    set(0, 'format', format);
    set(0, 'formatspacing', 'compact');

    result = evalc('disp(x(:))');

    set(0, 'format', oldFormat);
    set(0, 'formatspacing', oldSpacing);
  end;

%********************************************************************
function newRef = setData(var, coord, expr)
  try,
    if ischar(var),
      var = expr;
    elseif iscellstr(var),
      var{coord{:}} = expr;
    else,
      var(coord{:}) = eval(expr);
    end;

    newRef = system_dependent(45, var);
  catch,
    newRef = lasterr;
  end;

%********************************************************************
function newRef = setVarWidth(var, width)
  try,
    sz = size(var);
    oldWidth = sz(2);

    if iscellstr(var),
      repl = {''};
    else
      repl = 0;
    end;

    if width > oldWidth,
      var(:,end+1:width) = repl;
    elseif width < oldWidth,
      var(:,width+1:end) = [];
    end;

	newRef = system_dependent(45, var);
  catch,
    newRef = lasterr;
  end;

%********************************************************************
function newRef = setVarHeight(var, height)
  try,
    sz = size(var);
    oldHeight = sz(1);

    if iscellstr(var),
      repl = {''};
    else
      repl = 0;
    end;

    if height > oldHeight,
      var(end+1:height,:) = repl;
    elseif height < oldHeight,
      var(height+1:end,:) = [];
    end;

	newRef = system_dependent(45, var);
  catch,
    newRef = lasterr;
  end;
