// Copyright Neil Ramsden 2004-2006. All rights reserved.

// Presentation classes
// Neil Ramsden
// Presentation.js
// 21 Feb 06
//	Tidied dead code.
// 16 Jul 04 -> 1 Sep 04

//---------------------------------------------------------------------------

/* Presentation - manages links between views and documents

A presentation connects views to window or frame documents. The Views 
themselves know who their successors are.

Specialised presentations should implement (override) methods such as 
getPaneList().
*/

function displayView(view)
//ensure view is visible and display on screen
//  view -- view object to be displayed
//NOTE: Will need logic for finding a free document to connect to; and
// for displaying other connected documents.
{
  view.displayOn(this.getPane(view).document);
}

function getPane(view)
//get window or frame for this view
//  return -> [found] connected window or frame; [not found] null
{
  var index = null;
  var pane_list = this.getPaneList();
  var view_list = this.getViewList();
  var i_end = Math.min(pane_list.length, view_list.length);
  for (var i = 0; i < i_end; ++ i)
  {
    if (view == view_list[i])
    {
      index = i;
      break;
    }      
  }
  if (index == null)
    return null;
  else
    return pane_list[i];
}

function getView(pane)
//get view for this window or frame pane
//  pane -- name of window or frame
//  return -> [found] connected view; [not found] null
{
  var index = null;
  var pane_list = this.getPaneList();
  var view_list = this.getViewList();
  var i_end = Math.min(pane_list.length, view_list.length);
  for (var i = 0; i < i_end; ++ i)
  {
    if (pane == pane_list[i].name)
    {
      index = i;
      break;
    }      
  }
  if (index == null)
    return null;
  else
    return view_list[i];
}

function getViewList()
//get all views
//  return -> a list of current views
{
  var result = [];
  var v = this.startView;
  var i = 0;
  while (v)
  {
    result[i] = v;
    v = v.nextView;
    ++ i;
  }
  return result;
}

function Presentation()
//create a presentation object
//CODE: Implemented so that a presentation can be instantiated 
//  before all HTML windows have been created.
//NOTE: Later use specialised presentations.
{
  //start view
  this.startView = null;

  //methods
  this.displayView = displayView;
  this.getPane = getPane;
  this.getPaneList = function() { /*override*/; return []; };
  this.getView = getView;
  this.getViewList = getViewList;
  this.makeAdviceView = function(advice) { /*override*/; return null; };
  this.makeChoiceView = function(choice) { /*override*/; return null; };
}