<?php
/*
 * $RCSfile: PanoramaDerivativeImage.class,v $
 *
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2005 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
/**
 * @version $Revision: 1.9 $ $Date: 2005/08/23 03:49:48 $
 * @package Panorama
 * @author Alan Harder <alan.harder@sun.com>
 */

/**
 * Load the parent class
 */
GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryDerivativeImage.class');

/**
 * An extension of GalleryDerivativeImage to render in panorama mode
 *
 * @g2 <class-name>PanoramaDerivativeImage</class-name>
 * @g2 <parent-class-name>GalleryDerivativeImage</parent-class-name>
 * @g2 <schema>
 * @g2   <schema-major>1</schema-major>
 * @g2   <schema-minor>0</schema-minor>
 * @g2 </schema>
 * @g2 <requires-id/>
 *
 * @package Panorama
 * @subpackage Classes
 */
class PanoramaDerivativeImage_core extends GalleryDerivativeImage {

    /**
     * @see GalleryDerivative::render
     */
    function render($format, $item, $params) {
	global $gallery;

	list ($ret, $viewWidth) = GalleryCoreApi::getPluginParameter('module', 'panorama', 'width');
	if ($ret->isError() || $this->getWidth() < $viewWidth) {
	    return parent::render($format, $item, $params);
	}

	switch($format) {
	case 'HTML':
	    $urlGenerator =& $gallery->getUrlGenerator();
	    $src = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
						    'itemId' => $this->getId(),
						    'serialNumber' => $this->getSerialNumber()));

	    list ($width, $height) = array($this->getWidth(), $this->getHeight());
	    $baseUrl = GalleryUtilities::convertPathToUrl(dirname(dirname(__FILE__)));

	    return sprintf(
		'<applet archive="%s/java/Metamorphose.jar" code="Metamorphose" width="%d" height="%d">' .
		'<param name=BackgroundColor value="#666666"><param name=PanoramaRect value="0,0,%d,%d">' .
		'<param name=ScrollerRect value="0,%d,%d,17"><param name=ScrollerThumb value="%s/images/slider.png">' .
		'<param name="PanoramaTile" value="%s"><param name=PanoramaSize value="%d,%d"></applet>',
			   $baseUrl,
			   $viewWidth, $height + 17,
			   $viewWidth, $height,
			   $height, $viewWidth,
			   $baseUrl,
			   $src, $width, $height);

	default:
	    return null;
	}
    }
}

GalleryCoreApi::relativeRequireOnce(
    'modules/panorama/classes/interfaces/PanoramaDerivativeImage.inc');
?>
