/*---------------- 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.gui.ContainerContent; import nl.idgis.giclient.gis.TimeZoomListener; import mx.controls.TextInput; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.gis.TimeRangeScale; import nl.idgis.giclient.StringTools; import mx.utils.Delegate; import mx.controls.Button; import nl.idgis.giclient.gis.TimeRange; import nl.idgis.giclient.util.Strings; /** * @author velsll */ class nl.idgis.giclient.timeanimation.TimeRangeScaleViewer extends ContainerContent implements TimeZoomListener{ private var displayFormat:String = ""; private var timeRangeScale:TimeRangeScale = null; private var animationDuration:Number = 100; private var displayFormatLabel:TextField; private var rangeStartLabel:TextField; private var rangeStartInput:TextInput; private var rangeEndLabel:TextField; private var rangeEndInput:TextInput; private var minSecLabel:TextField; private var animationDurationLabel:TextField; private var animationDurationInput_Min:TextInput; private var animationDurationInput_Sec:TextInput; private var timeScaleLabel:TextField; private var timeScaleField:TextField; private var textFormat:TextFormat; private var okButton:Button; private var cancelButton:Button; private var resetButton:Button; private var statusField:TextField; var ruler:Ruler = null; private function onLoad():Void { displayFormat = ruler.getGIClientConfig().getAnimationConfig().getDisplayFormat(); if ((displayFormat == null) || (displayFormat == "")) { displayFormat = "YYYY-MM-DDThh:mm:ss"; } ruler.getGIS().gisEventDispatcher.addTimeZoomListener(this); timeRangeScale = ruler.getGIS().getActiveMap().getCurrentTimeRangeScale(); //timeRangeScale = new TimeRangeScale( new Date(2007,6,15,10,30,30,20), new Date(2007,6,15,11,30,30,20),60,12); textFormat = ruler.getDefaultTextFormat(); drawAll(); } private function drawAll():Void{ createTextField("displayformatlabel_mc", this.getNextHighestDepth(), 50, 0, 150, 20); displayFormatLabel = this["displayformatlabel_mc"]; displayFormatLabel .setNewTextFormat(textFormat); displayFormatLabel .text = displayFormat; createTextField("rangestartlabel_mc", this.getNextHighestDepth(), 0, 20, 50, 20); rangeStartLabel = this["rangestartlabel_mc"]; rangeStartLabel.setNewTextFormat(textFormat); rangeStartLabel.text = "start:"; rangeStartInput = TextInput(attachMovie("TextInput", "rangestartinput_mc", this.getNextHighestDepth(), {_x:rangeStartLabel._x + 50, _y: rangeStartLabel._y, _width:150})); rangeStartInput.restrict = "0-9 : \\-"; createTextField("rangeendlabel_mc", this.getNextHighestDepth(), 0, 50, 50, 20); rangeEndLabel = this["rangeendlabel_mc"]; rangeEndLabel.setNewTextFormat(textFormat); rangeEndLabel.text = "eind:"; rangeEndInput = TextInput(attachMovie("TextInput", "rangeendinput_mc", this.getNextHighestDepth(), {_x:rangeEndLabel._x + 50, _y: rangeEndLabel._y, _width:150 })); rangeEndInput.restrict = "0-9 : \\-"; createTextField("animationdurationlabel_mc", this.getNextHighestDepth(),0 , 100, 150, 20); animationDurationLabel = this["animationdurationlabel_mc"]; animationDurationLabel.setNewTextFormat(textFormat); animationDurationLabel.text = "animatie duur:"; animationDurationInput_Min = TextInput(attachMovie("TextInput", "animationdurationinput_min_mc", this.getNextHighestDepth(), {_x:animationDurationLabel._x + 100 , _y:animationDurationLabel._y,_width:50})); animationDurationInput_Min.restrict = "0-9"; animationDurationInput_Sec = TextInput(attachMovie("TextInput", "animationdurationinput_sec_mc", this.getNextHighestDepth(), {_x:animationDurationLabel._x + 155, _y:animationDurationLabel._y, _width:30 })); animationDurationInput_Sec.restrict = "0-9"; createTextField("minseclabel_mc", this.getNextHighestDepth(),animationDurationInput_Min._x , 80, 150, 20); minSecLabel = this["minseclabel_mc"]; minSecLabel.setNewTextFormat(textFormat); minSecLabel.text = "min sec"; createTextField("timescalelabel_mc", this.getNextHighestDepth(), 0, 130, 150, 20 ); timeScaleLabel = this["timescalelabel_mc"]; timeScaleLabel.setNewTextFormat(textFormat); timeScaleLabel.text = "animatie schaal:"; createTextField("timescalefield_mc", this.getNextHighestDepth(), timeScaleLabel._x + 120, timeScaleLabel._y, 150, 20); timeScaleField = this["timescalefield_mc"]; timeScaleField.setNewTextFormat(textFormat); okButton = Button(attachMovie("Button", "okButton_mc", this.getNextHighestDepth(), {_x: 0, _y: 160, _width: 50, label: "OK"})); okButton.addEventListener("click", Delegate.create(this,onClickOKButton)); cancelButton = Button(attachMovie("Button", "cancelButton_mc",this.getNextHighestDepth(), {_x: 60, _y: 160, _width: 70, label: "Annuleren"})); cancelButton.addEventListener("click", Delegate.create(this, onClickCancelButton)); resetButton = Button(attachMovie("Button", "cancelButton_mc", this.getNextHighestDepth(), {_x: 140, _y: 160, _width: 60, label: "Reset"})); resetButton.addEventListener("click", Delegate.create(this, onClickResetButton)); createTextField("statusfield_mc", this.getNextHighestDepth(), 0, 190, this._width, 20); statusField = this["statusfield_mc"]; statusField.setNewTextFormat(textFormat); statusField.textColor = 0xffffff; setTextValues(); } private function setTextValues():Void{ rangeStartInput.text = getTimeText(timeRangeScale.getBegin()); rangeEndInput.text = getTimeText(timeRangeScale.getEnd()); timeScaleField.text = String(Math.round(timeRangeScale.getTimeScale()*10)/10); var duration:Number = timeRangeScale.calculateAnimationDuration(); if(duration != null){ var min:Number = Math.floor(duration/60); var sec:Number = Math.round(duration -(min*60)); animationDurationInput_Min.text = min.toString(); animationDurationInput_Sec.text = sec.toString(); }else { animationDurationInput_Min.text = ""; animationDurationInput_Sec.text = ""; } _parent.refreshPane(); } private function onClickOKButton(){ statusField.text = ""; var durationMin:Number; var durationSec:Number; if(animationDurationInput_Min.text != ""){ durationMin = Number(animationDurationInput_Min.text)*60; } else {durationMin = 0;} if(animationDurationInput_Sec.text != ""){ durationSec = Number(animationDurationInput_Sec.text); } else {durationSec = 0;} var newTimeScale:Number = timeRangeScale.getTimeScale(); if(durationMin != 0 || durationSec != 0) { newTimeScale = timeRangeScale.calculatetimeScale(durationMin + durationSec); } var begin:Date = getDate(rangeStartInput.text); var end:Date = getDate(rangeEndInput.text); var timeLimit:TimeRange = ruler.getGIS().getTimeLimit(); try{ if(begin==null){ throw new Error // ("geen geldige begin tijd/datum ingevoerd"); (Strings.getFile("TimeAnimation").getString("StartTimeDateInvalid")); } if(end==null){ throw new Error // ("geen geldige eind tijd/datum ingevoerd"); (Strings.getFile("TimeAnimation").getString("EndTimeDateInvalid")); } if(begin>=end){ throw new Error // ("begin tijd/datum valt later dan eind tijd/datum"); (Strings.getFile("TimeAnimation").getString("StartLaterThanEnd")); } if(begintimeLimit.getEnd()){ throw new Error // ("eind tijd/datum valt later dan limiet"); (Strings.getFile("TimeAnimation").getString("EndAfterLimit")); } var newTimeRangeScale:TimeRangeScale = new TimeRangeScale( getDate(rangeStartInput.text),getDate(rangeEndInput.text),newTimeScale,timeRangeScale.getFPS()); var maxFrames:Number = ruler.getGIS().getMaxAnimationFrames(); var numberOfFrames = newTimeRangeScale.getNumberOfAnimationFrames(); if(numberOfFrames > maxFrames){ throw new Error // ("animatie duur te lang, geen berekening"); (Strings.getFile("TimeAnimation").getString("AnimationTooLong")); } ruler.getGIS().setCurrentTimeRangeScale(newTimeRangeScale); } catch (e:Error){ statusField.text = e.message; } } private function onClickCancelButton(){ statusField.text = ""; setTextValues(); } private function onClickResetButton(){ statusField.text = ""; timeRangeScale = ruler.getGIS().getInitialTimeRangeScale(); setTextValues(); } private function getTimeText(date:Date):String { var text:String = displayFormat; if(date!=null){ text = StringTools.replace(text, "YYYY", StringTools.lpad(date.getFullYear().toString(),"0",4)); text = StringTools.replace(text, "MM", StringTools.lpad((date.getMonth() + 1).toString(),"0",2)); text = StringTools.replace(text, "DD", StringTools.lpad(date.getDate().toString(),"0",2)); text = StringTools.replace(text, "hh", StringTools.lpad(date.getHours().toString(),"0",2)); text = StringTools.replace(text, "mm", StringTools.lpad(date.getMinutes().toString(),"0",2)); text = StringTools.replace(text, "ss", StringTools.lpad(date.getSeconds().toString(),"0",2)); } return text; } private function getDate(textInput:String):Date { var year:Number = 0; var month:Number = 0; var date:Number = 0; var hour:Number = 0; var min:Number = 0; var sec:Number = 0; var ms:Number = 0; var text = displayFormat; if(text.indexOf("Y") != -1){ year = Number(textInput.substring(text.indexOf("Y"),text.lastIndexOf("Y")+1)); } if(text.indexOf("M") != -1){ month = Number(textInput.substring(text.indexOf("M"),text.lastIndexOf("M")+1)) - 1; } if(text.indexOf("D") != -1){ date = Number(textInput.substring(text.indexOf("D"),text.lastIndexOf("D")+1)); } if(text.indexOf("h") != -1){ hour = Number(textInput.substring(text.indexOf("h"),text.lastIndexOf("h")+1)); } if(text.indexOf("m") != -1){ min = Number(textInput.substring(text.indexOf("m"),text.lastIndexOf("m")+1)); } if(text.indexOf("s") != -1){ sec = Number(textInput.substring(text.indexOf("s"),text.lastIndexOf("s")+1)); } if(text.indexOf("ms") != -1){ ms = Number(textInput.substring(text.indexOf("ms"),text.lastIndexOf("ms")+1)); } try { var timeStamp:Date = new Date(year,month,date,hour,min,sec,ms); if(timeStamp.toString()== "Invalid Date"){ throw new Error("geen geldige tijd ingevoerd"); } return timeStamp; } catch (e:Error){ statusField.text = e.message; return null; } } function onTimeZoom():Void{ timeRangeScale = ruler.getGIS().getCurrentTimeRangeScale(); setTextValues(); } }