/*
 * author liduena
 * version $Id: simple_toolBar-2_1.js,v 1.4 2002/10/18 15:48:30 liduena Exp $
 */

//


 function Simple_ToolBar( viewer,
                          enableDragEvents,
                          enableToolTips,
                          enableLogs ) {
  this._viewer = viewer; {
    this._viewer._toolBar = this;
  }
  
  this._enableToolTips = enableToolTips;
  this._enableLogs     = enableLogs;

  if ( this._enableLogs )
    DynAPI.console.write( 'Simple_ToolBar.Simple_ToolBar( . )' );

  this.DynLayer = DynLayer;
  this.DynLayer();

  if ( enableDragEvents )
    DragEvent.enableDragEvents( this );

  this.setSize( 440, 22, true );

  if ( this._enableToolTips )
    ToolTip.setBgColor( '#99CCFF' );
  /*********************************************************************
  _zoomBar
  *********************************************************************/
  this._zoomBar = new DynLayer(); {
    //this._zoomBar.moveTo( 5, 5 );
    this._zoomBar.setSize( 90, 20 );
	
   this._zoomBar._zoomInButton = new DynImage(); {
	//   this._zoomBar._zoomInButton.setBgColor("#FFFFFF");
	  	 this._zoomBar._zoomInButton._viewer = this._viewer;
		this._zoomBar._zoomInButton.setImageSrc( rootImage+'zoomIn_2.gif' );
       //this._zoomBar._zoomInButton.moveTo( 0, 0 );

      if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._zoomBar._zoomInButton, 'Zoom avant' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._zoomBar._zoomInButton ); {
        listener.onmousedown = function( e ) {
          var button = e.getTarget();
          button._viewer.zoomIn();
        };

        this._zoomBar._zoomInButton.addEventListener( listener );
      }

      this._zoomBar.addChild( this._zoomBar._zoomInButton );
    }
	//
	

	this._zoomBar._text = new DynLayer(); {
	  this._zoomBar._text.setBgColor( '#99CCFF' );
	  this._zoomBar._text.moveTo( 25, 3);
	  this._zoomBar._text.setSize( 40, 14 );
	  
	  // this._zoomBar._text.setHTML( '<center><small>' + this._viewer._currentLevel + '-1 / ' + Math.pow( 2, this._viewer._currentLevel ) + '</small></center>' );
	  this.setCurrentLevel( this._viewer._currentLevel );
	  //alert(this._viewer._currentLevel)
	  
	  this._zoomBar.addChild( this._zoomBar._text );
	}

    this._zoomBar._zoomOutButton = new DynImage(); {
	  this._zoomBar._zoomOutButton._viewer = this._viewer;
     // this._zoomBar._zoomOutButton.setImage( DynAPI.librarypath + 'dynapi/images/viewer/ZoomOut24.gif' );
	 this._zoomBar._zoomOutButton.setImageSrc(rootImage+ 'ZoomOut_2.gif' );
	  //this._zoomBar._zoomOutButton.setSize( 28, 28 );
     this._zoomBar._zoomOutButton.moveTo( 70, 0 );
	  
	  if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._zoomBar._zoomOutButton, 'Zoom arrière' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._zoomBar._zoomOutButton ); {
        listener.onmousedown = function( e ) {
          var button = e.getTarget();

          button._viewer.zoomOut();
        };

        this._zoomBar._zoomOutButton.addEventListener( listener );
      }

      this._zoomBar.addChild( this._zoomBar._zoomOutButton );
    }

    this.addChild( this._zoomBar );
  }
/*****************************************************
_navigationBar
*****************************************************/
  this._navigationBar = new DynLayer(); {
    this._navigationBar.moveTo( 100, 0 );
    this._navigationBar.setSize( 95, 20 );
	/***************_navigationBar._leftButton******************/
    this._navigationBar._leftButton = new DynImage(); {
	  	 this._navigationBar._leftButton.setImageSrc( rootImage+'leftButton.gif' );
		this._navigationBar._leftButton.moveTo( 0, 0 );
      if ( this._enableToolTips ) {
        // ToolTip
        var tt = new ToolTip( this._navigationBar._leftButton, 'Déplace vers la gauche' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._viewer ); {
        listener.onmousedown = function( e ) {
		  // var source = e.getSource();
          var viewer = e.getTarget();		  
		  viewer.moveLeft( 0.1 );
        };

        this._navigationBar._leftButton.addEventListener( listener );
      }

      this._navigationBar.addChild( this._navigationBar._leftButton );
    }
		/***************_navigationBar._upButton******************/
    this._navigationBar._upButton = new DynImage(); {
	   this._navigationBar._upButton.setImageSrc( rootImage+'upButton.gif' );
      this._navigationBar._upButton.moveTo( 25, 0 );

      if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._navigationBar._upButton, 'Déplace vers le haut' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._navigationBar._upButton ); {
        listener.onmousedown = function( e ) {
          var button = e.getTarget();

		  viewer.moveUp( 0.1 );
        };

        this._navigationBar._upButton.addEventListener( listener );
      }
      
      this._navigationBar.addChild( this._navigationBar._upButton );
    }
	
/***************_navigationBar._downButton******************/

    this._navigationBar._downButton = new DynImage(); {
	 this._navigationBar._downButton.setImageSrc( rootImage+'downButton.gif' );
      this._navigationBar._downButton.moveTo( 50, 0 );

      if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._navigationBar._downButton, 'Déplace vers le bas' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._navigationBar._downButton ); {
        listener.onmousedown = function( e ) {
          var button = e.getTarget();

		  viewer.moveDown( 0.1 );
        };

        this._navigationBar._downButton.addEventListener( listener );
      }
      
      this._navigationBar.addChild( this._navigationBar._downButton );
    }
/***************_navigationBar._rightButton******************/
    this._navigationBar._rightButton = new DynImage(); {
	  // this._navigationBar._rightButton.setEnabled( false );
	  	 this._navigationBar._rightButton.setImageSrc( rootImage+'rightButton_2.gif' );
     // this._navigationBar._rightButton.setImage( DynAPI.librarypath + 'dynapi/images/viewer/Forward24.gif' );
	  //this._navigationBar._rightButton.setSize( 28, 28 );
      this._navigationBar._rightButton.moveTo( 75, 0 );

      if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._navigationBar._rightButton, 'Déplace vers la droite' ); {
	      tt.setBorder( true );
	    }
	  }

      var listener = new EventListener( this._navigationBar._rightButton ); {
        listener.onmousedown = function( e ) {
          var button = e.getTarget();
		  viewer.moveRight( 0.1 );
        };

        this._navigationBar._rightButton.addEventListener( listener );
      }
      
      this._navigationBar.addChild( this._navigationBar._rightButton );
    }

    this.addChild( this._navigationBar );
  }	
  /*********************************************************************
  barre de qualite
  ********************************************************************
  this._qualityBar = new DynLayer(); {
    this._qualityBar.moveTo( 205, 0 );
	this._qualityBar.setSize( 200, 20 );*/
		/*********************************_qualityBar._label*********************
	this._qualityBar._label = new DynLayer(); {
	  //this._qualityBar._label.setBgColor( '#99CCFF' );
	  this._qualityBar._label.moveTo( 0, 3 );
	  this._qualityBar._label.setSize( 45, 14 );
	  this._qualityBar._label.setHTML( 'Qualité: '  );
	  this._qualityBar.addChild( this._qualityBar._label );
	}*/
	/*********************************_qualityBar._text *********************
	this._qualityBar._text = new DynLayer(); {
	  this._qualityBar._text.setBgColor( '#99CCFF' );
	  this._qualityBar._text.moveTo( 46, 3 );
	  this._qualityBar._text.setSize( 50, 14 );
	  
	  this._qualityBar._text.setHTML( '<center>' + Math.round( this._viewer._quality * 100 ) + '.0 %</center>' );
	  
	  this._qualityBar.addChild( this._qualityBar._text );
	}
	
    if ( this._viewer._width_0 * this._viewer._height_0 < 5000 * 5000 ) {*/
		/*********************************_qualityBar._scrollBar *********************
	  this._qualityBar._scrollBar = new ScrollBar( ScrollBar.HORIZONTAL ); {
	    this._qualityBar._scrollBar._text = this._qualityBar._text;
		
		 this._qualityBar._scrollBar.setTheme(BleuScrollBar());
	    if ( this._enableToolTips ) {
	    // ToolTip
        var tt = new ToolTip( this._qualityBar._scrollBar, 'Sélecteur de qualité' ); {
	      tt.setBorder( true );
	    }
	  }
	  
	    this._qualityBar._scrollBar.moveTo( 100, 2 );
	    this._qualityBar._scrollBar.setWidth( 100 );
	    this._qualityBar._scrollBar.setRatioX( this._viewer._quality );

        var hListener = new EventListener( viewer ); {
          hListener.onscroll = function( e ) {
            var src = e.getSource();
		    var viewer = e.getTarget();
            var quality = 100 * src.getRatioX();

            var qT = Math.round( quality / 5 ) * 5;
		    src._text.setHTML( '<center><small>' + Math.round( qT ) + '.0 %</small></center>' );
		  
	        viewer.setQuality( qT / 100 );
          };

          this._qualityBar._scrollBar.addEventListener( hListener );
	    }
	  
	  
 	    this._qualityBar.addChild( this._qualityBar._scrollBar );
	  }
	}
	else
	  this.setWidth( this.getWidth() - 100 );
	
    this.addChild( this._qualityBar );
  }
  */
  
   /*********************************************************************
  _HelpBar
  *********************************************************************/
  this._helpBar = new DynLayer(); {
    //this._helpBar.moveTo(415, 0 );
	this._helpBar.moveTo(270, 0 );
    this._helpBar.setSize( 20, 20 );
	
   this._helpBar._helpButton = new DynImage(); {
	//   this._zoomBar._zoomInButton.setBgColor("#FFFFFF");
	  	 this._helpBar._helpButton._viewer = this._viewer;
		this._helpBar._helpButton.setImageSrc(rootImage+ 'helpButton.gif' );
       //this._zoomBar._zoomInButton.moveTo( 0, 0 );

      	if ( this._enableToolTips ) {
	    	// ToolTip
        	var tt = new ToolTip( this._helpBar._helpButton, 'Aide' ); {
	      		tt.setBorder( true );
	    	}
	 	}

      	var listener = new EventListener( this._helpBar._helpButton ); {
			listener.onmousedown = function( e ) {
          		var button = e.getTarget();
				//MakeHelpWindow();
         	};
       		this._helpBar._helpButton.addEventListener( listener );
		}

      	this._helpBar.addChild( this._helpBar._helpButton );
    }
	 this.addChild( this._helpBar );
	 }
  /*
  this._statusBar = new DynLayer(); {
    this._statusBar.moveTo( 318, 5 );
    this._statusBar.setSize( 100, 28 );
	
	var status = new riStatus( 0, 0, 100, 28, '#c0c0c0', 'orange', 100,' completed' ); {
	  this._statusBar.addChild( status );
	}
	
	this.addChild( this._statusBar );
  }
  */
};

Simple_ToolBar.prototype = new DynLayer;

Simple_ToolBar.prototype.setCurrentLevel = function( currentLevel ) {
 	this._zoomBar._text.setHTML( '<center><small>1 : ' + Math.pow( 2, this._viewer._currentLevel ) + '</small></center>' );
};


Simple_ToolBar.prototype.setQuality = function( quality ) {
  this._qualityBar._scrollBar.setRatioX( quality );
  this._qualityBar._text.setHTML( '<center>' + Math.round( quality * 100 ) + '.0 %</center>' );
};

function BleuScrollBar () {
	//if (!DynAPI.librarypath) return null;
	return {
		vtrough : DynImage.getImage(DynAPI.librarypath+'dynapi/images/scrollpane/scrollbar-vbg.gif',16,16),
		vknob : DynImage.getImage(DynAPI.librarypath+'dynapi/images/scrollpane/scrollbar-vknob.gif',16,37),
		htrough : DynImage.getImage('http://columbia/docimsol/produits/vlsimage/toolbar/hbg-2.gif',100,16),
		hknob : DynImage.getImage('http://columbia/docimsol/produits/vlsimage/toolbar/hknob-2.gif',6,16)
	}
}
/*
 * $Log: simple_toolBar-2_1.js,v $
 * Revision 1.4  2002/10/18 15:48:30  liduena
 * _ Ajout de l'argument de création enableDragEvents.
 *
 * Revision 1.3  2002/10/04 14:30:08  liduena
 * _ Correction de la rédaction javaScript pour compression / JSCruncher
 *
 * Revision 1.1  2002/10/03 22:26:16  liduena
 * _ Fichier de base *.2.1.js, puis modifications :
 *   _ désactivation du drag event ;
 *   _ activation des boutons de déplacement de la barre d'outils & rédaction des méthodes de Viewer correspondantes ;
 *   _ activation de la scrollBar / qualité & prise en compte dynamique.
 *
 */
