function disp(opaque_array)
%DISP DISP for an OPAQUE object.

%   Chip Nylander, August 1999
%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.14 $  $Date: 2000/06/16 19:04:56 $

%
% For opaque types other than those programmed here, just run the default
% builtin display function.
%
if ~isjava(opaque_array),
    builtin('disp', opaque_array);
    return;
end

%
% Check that there is a toString Java method for Java objects.
%
ts_error = 0;
eval('javaMethod(''toString'', opaque_array);', 'ts_error = 1;');

if (ts_error ~= 0)
  builtin('disp', opaque_array);
  return;
end;

cls = class(opaque_array);

if cls(end) ~= ']'
  desc = char(javaMethod('toString', opaque_array));
else
  disp([cls ':']);
  desc = cell(opaque_array);
end;

if ~ischar(desc) & ~iscell(desc)
  builtin('disp', opaque_array);
else
  if  isempty(findstr(cls, '[][][]')) &...
      strncmp('java.lang.String[]',cls,length('java.lang.String[]')),
    disp(' ');
  end;
  if (iscell(desc) & ~isempty(findstr(evalc('disp(desc)'), '{[]}'))),
    desc = '    []';
  end;
  name = evalin('caller','inputname(1);','[]');
  if ~isempty(name),
    eval([name '= desc;']);
  else,
    name = 'ans';
    ans = desc;
  end;
  eval(['builtin(''disp'',' name ')'])
end;


