1 /**
  2  * Creates a new ZoomController. Object that controls the zoom setting.
  3  * 
  4  * @constructor
  5  * @param {mindmaps.EventBus} eventBus
  6  */
  7 mindmaps.ZoomController = function(eventBus, commandRegistry) {
  8 	var self = this;
  9 
 10 	/**
 11 	 * @constant
 12 	 */
 13 	this.ZOOM_STEP = 0.25;
 14 
 15 	/**
 16 	 * @constant
 17 	 */
 18 	this.MAX_ZOOM = 3;
 19 
 20 	/**
 21 	 * @constant
 22 	 */
 23 	this.MIN_ZOOM = 0.25;
 24 
 25 	/**
 26 	 * @constant
 27 	 */
 28 	this.DEFAULT_ZOOM = 1;
 29 
 30 	/**
 31 	 * @private
 32 	 */
 33 	this.zoomFactor = this.DEFAULT_ZOOM;
 34 
 35 	/**
 36 	 * Sets the zoom factor if param is within MIN_ZOOM and MAX_ZOOM bounds.
 37 	 * 
 38 	 * @param {Number} factor
 39 	 */
 40 	this.zoomTo = function(factor) {
 41 		if (factor <= this.MAX_ZOOM && factor >= this.MIN_ZOOM) {
 42 			this.zoomFactor = factor;
 43 			eventBus.publish(mindmaps.Event.ZOOM_CHANGED, factor);
 44 		}
 45 	};
 46 
 47 	/**
 48 	 * Zooms in by ZOOM_STEP.
 49 	 * 
 50 	 * @returns {Number} the new zoomFactor.
 51 	 */
 52 	this.zoomIn = function() {
 53 		this.zoomFactor += this.ZOOM_STEP;
 54 		if (this.zoomFactor > this.MAX_ZOOM) {
 55 			this.zoomFactor -= this.ZOOM_STEP;
 56 		} else {
 57 			eventBus.publish(mindmaps.Event.ZOOM_CHANGED, this.zoomFactor);
 58 		}
 59 
 60 		return this.zoomFactor;
 61 	};
 62 
 63 	/**
 64 	 * Zooms out by ZOOM_STEP,
 65 	 * 
 66 	 * @returns {Number} the new zoomFactor.
 67 	 */
 68 	this.zoomOut = function() {
 69 		this.zoomFactor -= this.ZOOM_STEP;
 70 		if (this.zoomFactor < this.MIN_ZOOM) {
 71 			this.zoomFactor += this.ZOOM_STEP;
 72 		} else {
 73 			eventBus.publish(mindmaps.Event.ZOOM_CHANGED, this.zoomFactor);
 74 		}
 75 
 76 		return this.zoomFactor;
 77 	};
 78 
 79 	/**
 80 	 * Reset zoom factor when document was closed.
 81 	 * 
 82 	 * @ignore
 83 	 */
 84 	eventBus.subscribe(mindmaps.Event.DOCUMENT_CLOSED, function(doc) {
 85 		self.zoomTo(self.DEFAULT_ZOOM);
 86 	});
 87 };