function FigureCallback(event)
% FigureCallback - Callback called by a MatlabServer object for generating a
% Matlab figure as response
%
% CALL:
%     FigureCallback(event)
%
% INPUT:
%     event: <modelit.webserver.HttpExchange>
%         with the request data and methods to generate a response.
%
% OUTPUT:
%     No output
%
% EXAMPLE:
%  server = modelit.web.server.Server(8081, @FigureCallback).start()
%
%  % Open a webbrowser and type: http://localhost:8081 in the address bar
%  % Now a figure with the Matlab logo appears in the browser.

%   Copyright 2006-2015 Modelit, www.modelit.nl

HWIN = figure('tag',mfilename);
peaks;
shading interp;

% Generate the response
response = fig2html(HWIN);

delete(HWIN);

% Set the MIME type
% See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
event.addResponseHeader('Content-Type', 'text/html');

% Send the response back to the client, with statuscode 200 (OK)
% See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
event.send(200, response);