/*---------------- FILE HEADER --------------------------------------- This file is part of Geoide. Copyright (C) 2005-2006 by: IDgis B.V. http://www.idgis.nl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Herman Assink IDgis bv P.O. Box 15 7450 AA Holten The Netherlands E-Mail: herman.assink@idgis.nl * @version 1.4.0 * @author IDgis team * ------------------------------------------------------------------------*/ import nl.idgis.giclient.framework.bars.Bar; import nl.idgis.giclient.timeanimation.MovieProgressListener; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.GIClientConfig; import nl.idgis.giclient.StringTools; import mx.controls.TextInput; import nl.idgis.giclient.gis.TimeZoomListener; import nl.idgis.giclient.gis.TimeRangeScale; import nl.idgis.giclient.framework.bars.ButtonBarConfig; class nl.idgis.giclient.timeanimation.Timebar extends Bar implements TimeZoomListener, MovieProgressListener { private var ruler:Ruler = null; private var currentTimeRangeScale:TimeRangeScale = null; private var depth = 1; private var currentTimeField:TextField = null; private var currentTimeLabel:TextField = null; private var beginTimeLabel:TextField = null; private var rangeBeginField:TextField = null; private var endTimeLabel:TextField = null; private var rangeEndField:TextField = null; private var dragLine:MovieClip = null; private var dragButton:MovieClip = null; private var textformat:TextFormat; private var buttonBar:MovieClip; private var buttonx = -15; private var displayFormat:String = ""; function setRuler(ruler:Ruler):Void { this.ruler = ruler; ruler.getGIS().gisEventDispatcher.addTimeZoomListener(this); ruler.getGIS().animationEventDispatcher.addMovieProgressListener(this); currentTimeRangeScale = ruler.getGIS().getCurrentTimeRangeScale(); this.textformat = ruler.getDefaultTextFormat(); this.textformat.size = 10; } function setGIClientConfig(giClientConfig:GIClientConfig):Void { displayFormat = giClientConfig.getAnimationConfig().getDisplayFormat(); if ((displayFormat == null) || (displayFormat == "")) { displayFormat = "YYYY-MM-DDThh:mm:ss"; } drawAll(giClientConfig); } function onTimeZoom():Void { currentTimeRangeScale = ruler.getGIS().getCurrentTimeRangeScale(); resetTimeValues(); if (!dragButton.dragging) { setDragButtonX(); } } function resetTimeValues(){ rangeBeginField.text = getTimeText(currentTimeRangeScale.getBegin()); rangeEndField.text = getTimeText(currentTimeRangeScale.getEnd()); currentTimeField.text = getTimeText(ruler.getGIS().getCurrentTimeStamp()); } function onChangeCurrentTimeStamp(percentage:Number):Void { var currentTimeStamp:Date = ruler.getGIS().getCurrentTimeStamp(); currentTimeField.text = getTimeText(currentTimeStamp); if (!dragButton.dragging) { setDragButtonX(); } } function drawAll(giClientConfig:GIClientConfig):Void { buttonBar = this.createEmptyMovieClip("buttonBar",depth++); buttonBar._x = 3; buttonBar._y = 3; var timeBarConfig:ButtonBarConfig = giClientConfig.getButtonBarConfig("TimeBar"); timeBarConfig.setX(0); var initObject = {backGround:false,horiSpacing:2}; timeBarConfig.inflate(buttonBar,depth++,initObject); setWidth(510); addDragLineAndButton(); var currentTimeX:Number = 270; var timeValueWidth:Number = 105; var timeValueHeigth:Number = 15; //this.createTextField("currenttimelabel_mc", depth++,currentTimeX, 7, timeValueWidth, 20); //currentTimeLabel = this["currenttimelabel_mc"]; //textformat.align = "center"; //currentTimeLabel.setNewTextFormat(textformat); //currentTimeLabel.text = "Huidig tijdstip"; this.createTextField("currenttimefield_mc", depth++,currentTimeX , dragLine._y + 8, timeValueWidth, timeValueHeigth); currentTimeField = this["currenttimefield_mc"]; textformat.align = "left"; currentTimeField.setNewTextFormat(textformat); currentTimeField.background = true; //var currentTimeStamp:Date = ruler.getGIS().getCurrentTimeStamp(); //currentTimeField.text = getTimeText(currentTimeStamp); //this.createTextField("begintimelabel_mc", depth++,dragLine._x , 7, timeValueWidth, 20); //beginTimeLabel = this["begintimelabel_mc"]; //textformat.align = "left"; //beginTimeLabel.setNewTextFormat(textformat); //beginTimeLabel.text = "Begin tijdstip"; this.createTextField("rangebeginfield_mc", depth++,dragLine._x , dragLine._y + 8, timeValueWidth, timeValueHeigth); rangeBeginField = this["rangebeginfield_mc"]; textformat.align = "left"; rangeBeginField.setNewTextFormat(textformat); rangeBeginField.background = true; //this.createTextField("endtimelabel_mc", depth++,dragLine._x + dragLine._width - timeValueWidth, 7, timeValueWidth, 20); //endTimeLabel = this["endtimelabel_mc"]; //textformat.align = "right"; //endTimeLabel.setNewTextFormat(textformat); //endTimeLabel.text = "Eind tijdstip"; this.createTextField("rangeendfield_mc", depth++,dragLine._x + dragLine._width - timeValueWidth, dragLine._y + 8, timeValueWidth, timeValueHeigth); rangeEndField = this["rangeendfield_mc"]; rangeEndField.background = true; textformat.align = "left"; rangeEndField.setNewTextFormat(textformat); resetTimeValues(); } private function addDragLineAndButton():Void { var initObject:Object = null; initObject = new Object(); initObject["_x"] = 145; initObject["_y"] = 12; initObject["_width"] = 355; dragLine = attachMovie("PlayBar", "dragLine_mc", depth++, initObject); initObject = new Object(); initObject["_x"] = dragLine._x; initObject["_y"] = dragLine._y; initObject["_width"] = 10; initObject["_height"] = 12; initObject["dragging"] = false; dragButton = attachMovie("DragButton", "dragButton_mc", 1000, initObject); dragButton.onPress = function():Void { Mouse.addListener(this); this.startDrag(this, this._parent.dragLine._x, this._y, this._parent.dragLine._x + this._parent.dragLine._width, this._y); this.dragging = true; }; dragButton.onRelease = function():Void { this.stopDrag(); this.dragging = false; this._parent["ruler"].getGIS().setCurrentTimeStamp((this._x - this._parent.dragLine._x) / (this._parent.dragLine._width - 1)); Mouse.removeListener(this); }; dragButton.onMouseUp = function():Void { this.onRelease(); }; setDragButtonX(); } function onMouseMove():Void{ if(dragButton.dragging){ this._parent["ruler"].getGIS().setCurrentTimeStamp((this.dragButton._x - this.dragLine._x) / (this.dragLine._width - 1)); } } private function getTimeText(timeStamp:Date):String { var text:String = displayFormat; if(timeStamp != null){ text = StringTools.replace(text, "YYYY", StringTools.lpad(timeStamp.getFullYear().toString(),"0",4)); text = StringTools.replace(text, "MM", StringTools.lpad((timeStamp.getMonth() + 1).toString(),"0",2)); text = StringTools.replace(text, "DD", StringTools.lpad(timeStamp.getDate().toString(),"0",2)); text = StringTools.replace(text, "hh", StringTools.lpad(timeStamp.getHours().toString(),"0",2)); text = StringTools.replace(text, "mm", StringTools.lpad(timeStamp.getMinutes().toString(),"0",2)); text = StringTools.replace(text, "ss", StringTools.lpad(timeStamp.getSeconds().toString(),"0",2)); } return text; } private function setDragButtonX():Void { var percentage:Number = ruler.getGIS().getPlayedPercentage(); //dragButton._x = dragLine._x + Math.round((dragLine._width - 1) * percentage); if(percentage >= 0) { dragButton._x = dragLine._x + (dragLine._width - 1) * percentage; } } }