import nl.idgis.giclient.template.Dialog; import nl.idgis.giclient.framework.IDComboBox; import nl.idgis.giclient.template.Parameter; import mx.controls.CheckBox; import mx.controls.TextInput; import mx.controls.TextArea; import mx.controls.List; import nl.idgis.giclient.framework.FrameWork; import nl.idgis.giclient.gis.GIS; import nl.idgis.giclient.gis.Layer; import nl.idgis.giclient.gis.CentreScale; import nl.idgis.giclient.geoma.Envelope; import nl.idgis.giclient.print.PrintMovie; import nl.idgis.giclient.gis.ZoomListener; import nl.idgis.giclient.util.Strings; import nl.idgis.giclient.event.StateEvent; import mx.utils.Delegate; /** * @author copierrj */ class nl.idgis.giclient.template.StandardDialog extends Dialog implements ZoomListener { private var scales:Array; private var scaleBox:IDComboBox = null; private var scaleIndex:Number = -1; private var mapWidth:Number = -1; private var mapHeight:Number = -1; private var title:String = ""; private var subTitle:String = ""; private var description:String = ""; private var titleTextInput:TextInput = null; private var subTitleTextInput:TextInput = null; private var currentExtendCheckBox:CheckBox = null; private var scaleTextField:TextField; private var redliningCheckBox:CheckBox = null; private var identifyCheckBox:CheckBox = null; private var legendCheckBox:CheckBox = null; private var scaleBarCheckBox:CheckBox = null; private var northArrowCheckBox:CheckBox = null; private var overviewCheckBox:CheckBox = null; private var showTitle:Boolean = true; private var showSubTitle:Boolean = true; private var showDescription:Boolean = true; private var showScale:Boolean = true; private var showLayers:Boolean = true; private var showRedlining:Boolean = true; private var showIdentify:Boolean = true; private var showLegend:Boolean = true; private var showScaleBar:Boolean = true; private var showNorthArrow:Boolean = true; private var showOverview:Boolean = true; private var redlining:Boolean = true; private var identify:Boolean = true; private var legend:Boolean = true; private var scaleBar:Boolean = true; private var northArrow:Boolean = true; private var descriptionTextArea:TextArea = null; private var layersList:List = null; private var messageTextField:TextField = null; private var gis:GIS; private var dirty:Boolean = true; public function StandardDialog(gis:GIS) { scales = new Array(); this.gis = gis; } public function inflate(movieClip:MovieClip):Void { var format:TextFormat = new TextFormat(); format.font = "_sans"; format.size = 12; var y:Number = 10; var x:Number = 10; var printStrings:Strings = Strings.getFile("Print"); if(showTitle) { var titleTextField:TextField = movieClip.createTextField("titleTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); titleTextField.setNewTextFormat(format); titleTextField.text = printStrings.getString("SDTitle"); y += 25; titleTextInput = TextInput(movieClip.attachMovie("TextInput", "titleTextInput", movieClip.getNextHighestDepth(), {_x: x, _y: y, _width: 200})); titleTextInput.setText(title); titleTextInput.addEventListener("change", Delegate.create(this, makeDirty)); y += 35; } if(showSubTitle) { var subTitleTextField:TextField = movieClip.createTextField("subTitleTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); subTitleTextField.setNewTextFormat(format); subTitleTextField.text = printStrings.getString("SDSubtitle"); y += 25; subTitleTextInput = TextInput(movieClip.attachMovie("TextInput", "subTitleTextInput", movieClip.getNextHighestDepth(), {_x: x, _y: y, _width: 200})); subTitleTextInput.setText(subTitle); subTitleTextInput.addEventListener("change", Delegate.create(this, makeDirty)); y += 45; } if(showScale) { var scaleTextField2:TextField = movieClip.createTextField("scaleTextField2", movieClip.getNextHighestDepth(), x, y, 100, 25); scaleTextField2.setNewTextFormat(format); scaleTextField2.text = printStrings.getString("SDScale"); y += 25; currentExtendCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "currentExtendCheckBox", movieClip.getNextHighestDepth(), {_width: 150, _x: x, _y: y, label: " " + printStrings.getString("SDCurrentExtent")})); currentExtendCheckBox.setSelected(true); currentExtendCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); scaleTextField = movieClip.createTextField("scaleTextField", movieClip.getNextHighestDepth(), x + 135, y, 100, 25); scaleTextField.setNewTextFormat(format); y += 25; var scaleBoxTextField:TextField = movieClip.createTextField("scaleBoxTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); scaleBoxTextField.text = "1 :"; scaleBoxTextField.setNewTextFormat(format); scaleBox = IDComboBox(movieClip.attachMovie("IDComboBox", "scaleChooser", movieClip.getNextHighestDepth(), {_width: 200})); scaleBox._x = x + 25; scaleBox._y = y - 2; scaleBox.setEditable(false); scaleBox.setDataProvider(scales); scaleBox.setSelectedIndex(0); scaleBox.resize(); scaleBox.addEventListener("change", {dialog: this, change: function(evt) { this.dialog.scaleIndex = this.dialog.scaleBox.getSelectedIndex(); this.dialog.updateScale(); this.dialog.makeDirty(); } }); scaleBox.setEnabled(false); scaleIndex = 0; currentExtendCheckBox.addEventListener("click", {dialog: this, click : function(evt) { this.dialog.scaleBox.setEnabled(!this.dialog.currentExtendCheckBox.selected); this.dialog.updateScale(); } }); y += 35; } if(showRedlining || showIdentify || showLegend || showScaleBar || showScaleBar || showNorthArrow) { var elementsTextField:TextField = movieClip.createTextField("elementsTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); elementsTextField.setNewTextFormat(format); elementsTextField.text = printStrings.getString("SDElements"); y += 25; var elementRowCount:Number = 0; var elementColCount:Number = 0; var elementHeight:Number = 25; var elementWidth:Number = 100; if(showRedlining) { redliningCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "redliningCheckBox", movieClip.getNextHighestDepth(), {_x: x, _y: y, label: " " + printStrings.getString("SDRedlining")})); redliningCheckBox.setSelected(redlining); redliningCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); elementRowCount++; } if(showIdentify) { identifyCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "identifyCheckBox", movieClip.getNextHighestDepth(), {_x: x, _y: y + elementRowCount * elementHeight, label: " " + printStrings.getString("SDIdentify")})); identifyCheckBox.setSelected(identify); identifyCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); elementRowCount++; } if(showLegend) { legendCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "legendCheckBox", movieClip.getNextHighestDepth(), {_x: x, _y: y + elementRowCount * elementHeight, label: " " + printStrings.getString("SDLegend")})); legendCheckBox.setSelected(legend); legendCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); elementRowCount++; if(elementRowCount == 3) { elementColCount++; elementRowCount = 0; } } if(showScaleBar) { scaleBarCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "scaleBarCheckBox", movieClip.getNextHighestDepth(), { _x: x + elementColCount * elementWidth, _y: y + elementRowCount * elementHeight, label: " " + printStrings.getString("SDScalebar")})); scaleBarCheckBox.setSelected(scaleBar); scaleBarCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); elementRowCount++; if(elementRowCount == 3) { elementColCount++; elementRowCount = 0; } } if(showNorthArrow) { northArrowCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "northArrowCheckBox", movieClip.getNextHighestDepth(), { _x: x + elementColCount * elementWidth , _y: y + elementRowCount * elementHeight, label: " " + printStrings.getString("SDNortharrow")})); northArrowCheckBox.setSelected(northArrow); northArrowCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); elementRowCount++; if(elementRowCount == 3) { elementColCount++; elementRowCount = 0; } } if(showOverview) { overviewCheckBox = CheckBox(movieClip.attachMovie("CheckBox", "overviewCheckBox", movieClip.getNextHighestDepth(), { _x: x + elementColCount * elementWidth, _y: y + elementRowCount * elementHeight, label: " " + printStrings.getString("SDOverview")})); overviewCheckBox.setSelected(northArrow); overviewCheckBox.addEventListener("click", Delegate.create(this, makeDirty)); } y += (elementColCount * 3 + elementRowCount) * elementWidth; } if(y > 100) { x += 240; y = 10; } if(showDescription) { var descriptionTextField:TextField = movieClip.createTextField("descriptionTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); descriptionTextField.setNewTextFormat(format); descriptionTextField.text = printStrings.getString("SDDescription"); y += 25; descriptionTextArea = TextArea(movieClip.attachMovie("TextArea", "descriptionTextArea", movieClip.getNextHighestDepth(), {_x: x, _y: y, _width: 200, _height: 250})); descriptionTextArea.setText(description); descriptionTextArea.addEventListener("change", Delegate.create(this, makeDirty)); } if(showLayers) { x += 240; y = 10; var layersTextField:TextField = movieClip.createTextField("layersTextField", movieClip.getNextHighestDepth(), x, y, 100, 25); layersTextField.setNewTextFormat(format); layersTextField.text = printStrings.getString("SDLayers"); y += 25; layersList = List(movieClip.attachMovie("List", "layersList", movieClip.getNextHighestDepth(), {_x: x, _y: y, _height: 250, _width: 200})); layersList.labelFunction = function(layer:Layer) { var str:String = ""; for(var i:Number = layer.getSuperLayers().length - 1; i >= 0; i--) { str += " "; } str += layer.getTitle(); return str; }; layersList.multipleSelection = true; layersList.addEventListener("change", Delegate.create(this, makeDirty)); y += 100; } updateScale(); gis.gisEventDispatcher.addZoomListener(this); Stage.addListener({dialog: this, onResize: function() { this.dialog.updateScale(); } }); movieClip.lineTo(x + 200, y); messageTextField = movieClip.createTextField("messageTextField", movieClip.getNextHighestDepth(), 10, movieClip._height + 25, 200, 12); messageTextField.autoSize = "left"; var messageFormat:TextFormat = new TextFormat(format.font, format.size, 0xff0000, true); messageTextField.setNewTextFormat(messageFormat); messageTextField.text = ""; } private function updateScale() { var scale:Number = getScale(); if(currentExtendCheckBox.selected) { scaleTextField.text = "(1 : " + Math.round(scale) + ")"; } else { scaleTextField.text = ""; } fillLayersList(scale); } private function fillLayersList(scale:Number) { if(layersList != null) { var layers:Array = gis.getZoomVisibleLayersForScale(scale); layersList.removeAll(); var visible:Array = new Array(); for(var i = 0; i < layers.length; i++) { if(Layer(layers[i]).isVisible()) { visible.push(i); }; layersList.addItem(layers[i]); } layersList.setSelectedIndices(visible); } } private function getScale():Number { if(!showScale || this.currentExtendCheckBox.selected) { var centreScale:CentreScale = gis.getCurrentCentreScale(); var scale:Number = centreScale.getScale(); var dWidth:Number = Stage.width / PrintMovie.screenPrintFactor - mapWidth ; var dHeight:Number = Stage.height / PrintMovie.screenPrintFactor - mapHeight ; if(dWidth > dHeight) { scale *= 1 + dWidth / mapWidth; } else { scale *= 1 + dHeight / mapHeight; } return scale; } else { return scales[scaleIndex]; } } public function isDirty() : Boolean { return dirty; } private function makeDirty() : Void { dirty = true; eventDispatcher.dispatchEvent(new StateEvent(this, "Dialog", StateEvent.CHANGE, "dirty")); } public function getValue(parameter:Parameter) { if(dirty) { dirty = false; eventDispatcher.dispatchEvent(new StateEvent(this, "Dialog", StateEvent.CHANGE, "dirty")); } var sourceName:String = parameter.getSourceName(); if(sourceName == "scale") { parameter.setValue(this.getScale()); } else if(sourceName == "redlining") { parameter.setValue(redliningCheckBox != null ? redliningCheckBox.getSelected() : false); } else if(sourceName == "identify") { parameter.setValue(identifyCheckBox != null ? identifyCheckBox.getSelected() : false); } else if(sourceName == "legend") { parameter.setValue(legendCheckBox != null ? legendCheckBox.getSelected() : false); } else if(sourceName == "scaleBar") { parameter.setValue(scaleBarCheckBox != null ? scaleBarCheckBox.getSelected() : false); } else if(sourceName == "overview") { parameter.setValue(overviewCheckBox != null ? overviewCheckBox.getSelected() : false); } else if(sourceName == "northArrow") { parameter.setValue(northArrowCheckBox != null ? northArrowCheckBox.getSelected() : false); } else if(sourceName == "title") { parameter.setValue(Strings.escapeString(titleTextInput.getText())); } else if(sourceName == "subTitle") { parameter.setValue(Strings.escapeString(subTitleTextInput.getText())); } else if(sourceName == "description") { var lines:Array = descriptionTextArea.getText().split("\r"); var htmlString:String = ""; for(var i:Number = 0; i < lines.length; i++) { htmlString += Strings.escapeString(lines[i]) + "
\r"; } parameter.setValue(htmlString); } else if(sourceName == "layers") { var retval:Array; if(showLayers) { var selectedLayers:Array = layersList.getSelectedItems(); var layers:Array = new Array(); for(var i:Number = 0; i < selectedLayers.length; i++) { var layer:Layer = selectedLayers[i]; if(layer.getLayers().length == 0) { var superLayers:Array = layer.getSuperLayers(); var found:Number = 0; for(var j:Number = 0; j < superLayers.length; j++) { for(var k:Number = 0; k < selectedLayers.length; k++) { if(selectedLayers[k] == superLayers[j]) { found++; break; } } } if(found == superLayers.length) { layers.push(layer); } } } retval = layers; } else { retval = gis.getZoomVisibleLayersForScale(getScale()); } if(retval.length == 0) { messageTextField.text = Strings.getFile("Print").getString("EmptyMap"); } else { messageTextField.text = ""; } parameter.setValue(retval); } else { parameter.setValue(null); } } function onZoom() : Void { updateScale(); } }