/*---------------- 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 mx.utils.Delegate; import nl.idgis.giclient.gui.ContainerContent; import nl.idgis.giclient.gis.ActiveMapListener; import nl.idgis.giclient.gis.Layer; import nl.idgis.giclient.gis.LayerLoadedFeaturesListener; import nl.idgis.giclient.gis.Map; import nl.idgis.giclient.framework.IDComboBox; import nl.idgis.giclient.query.QueryAspect; import nl.idgis.giclient.query.QueryAspectViewer; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.gis.SelectableLayer; import nl.idgis.giclient.util.Strings; import mx.controls.ComboBase; import mx.controls.ComboBox; class nl.idgis.giclient.query.QueryBuilderViewer extends ContainerContent implements ActiveMapListener, LayerLoadedFeaturesListener { var map : Map; var selectedQueryAspect : QueryAspect; var queryAspectPicker : IDComboBox = null; var queryAspectViewer : QueryAspectViewer = null; var textFormat : TextFormat = null; var ruler : Ruler = null; var initialTitle : String = null; function onLoad() { ruler.getGIS().gisEventDispatcher.addActiveMapListener(this); map = ruler.getGIS().getActiveMap(); textFormat = new TextFormat(); textFormat.font = "_sans"; initialTitle = frame.getPaneTitle(); paint(); } function onUnload() { //map.setCurrentQueryAspect(null); } function beforeChangeActiveMap() : Void { } function afterChangeActiveMap() : Void { map = ruler.getGIS().getActiveMap(); paint(); } function onChangeLayerLoadedFeatures(layer : Layer) : Void { var features : Array = SelectableLayer(layer).getLoadedFeatures(); if(features.length == 0) { state(Strings.getFile("Query").getString("NoObjectsFound")); } else { state(Strings.getFile("Query").getString("NumberOfObjectsFound", {number: features.length})); } } private function paint() : Void { var queryAspects : Array = map.getQueryAspects(); //trace("queryAspects.length = " + queryAspects.length ); this.clearAll(); if(queryAspects.length > 1) { frame.setPaneTitle(initialTitle); paintQueryAspectPicker(queryAspects); } else { paintQueryAspectTitle(QueryAspect(queryAspects[0])); map.setCurrentQueryAspect(queryAspects[0]); addQueryAspectViewer(queryAspects[0]); } paintStatusText(); } /* window title */ private function paintQueryAspectTitle(queryAspect : QueryAspect) : Void { if (queryAspect == null) { frame.setPaneTitle(initialTitle); } else { frame.setPaneTitle(Strings.getFile("Query").getString("SearchingFor", {label: queryAspect.getLabel() })); } } private function paintQueryAspectPicker(queryAspects : Array) : Void { contentHeight = frame.height; createTextField("queryAspectLabel", 1, 0, 0, 100, 20, {enabled:false}); this["queryAspectLabel"].setNewTextFormat(textFormat); this["queryAspectLabel"].text = Strings.getFile("Query").getString("SearchEntry"); var queryAspectPickerName:String = "queryAspectPicker_" + map.getName(); queryAspectPicker = IDComboBox(attachMovie("IDComboBox", queryAspectPickerName, 2, {_x: 100, _y: 0, _width:200})); queryAspectPicker.textField.setNewTextFormat(textFormat); queryAspectPicker.addEventListener("select", Delegate.create(this, onSelectQueryAspect)); var aspectProvider : Array = new Array(); aspectProvider.push({label: Strings.getFile("Query").getString("Select"), queryAspect:null}); for (var i : Number = 0;i < queryAspects.length; i++) { aspectProvider.push({label: (queryAspects[i].getLayer() != null ? (queryAspects[i].getLayer().getTitle() + ": ") : "") + queryAspects[i].getLabel(), queryAspect:queryAspects[i]}); } queryAspectPicker.dataProvider = aspectProvider; queryAspectPicker.resize(); queryAspectPicker.selectedIndex = 0; state(Strings.getFile("Query").getString("SelectSearchEntry")); frame.setSize(getContentWidth(), contentHeight); _parent.refreshPane(); } private function paintStatusText() : Void { createTextField("statusTextField", 4, 0, (contentHeight - 30), 200, 20); this["statusTextField"].setNewTextFormat(textFormat); } private function onSelectQueryAspect(eventObject : Object) : Void { //if(selectedQueryAspect!=null){ // selectedQueryAspect.getLayer().layerEventDispatcher.removeLayerLoadedFeaturesListener(this); //} selectedQueryAspect = this.queryAspectPicker.selectedItem.queryAspect; //selectedQueryAspect.getLayer().layerEventDispatcher.addLayerLoadedFeaturesListener(this); state(""); paintQueryAspectTitle(QueryAspect(selectedQueryAspect)); map.setCurrentQueryAspect(selectedQueryAspect); addQueryAspectViewer(selectedQueryAspect); } private function checkQueryAspectLayerVisibility(queryAspect : QueryAspect) : Void { if(ruler.getGIS().isVisibleLayer(queryAspect.getLayer()) == false) { state(Strings.getFile("Query").getString("LayerNotVisible")); } } private function addQueryAspectViewer(currentQueryAspect : QueryAspect) : Void { var queryAspectViewerName : String = currentQueryAspect.getName() + "QueryAspectViewer"; queryAspectViewer = QueryAspectViewer(this.attachMovie("QueryAspectViewer", queryAspectViewerName, 3, {_x:0, _y:30, queryAspect:currentQueryAspect, queryBuilderViewer:this, textFormat:textFormat, ruler:this.ruler})); contentHeight = queryAspectViewer.getViewerHeight() + 60; frame.setSize(getContentWidth(), contentHeight); _parent.refreshPane(); checkQueryAspectLayerVisibility(currentQueryAspect); } function onResizeQueryAspectViewer(queryAspectViewer : QueryAspectViewer) : Void { contentHeight = queryAspectViewer.getViewerHeight() + 60; this["statusTextField"]._y = (contentHeight - 30); frame.setSize(getContentWidth(), contentHeight); _parent.refreshPane(); } private function getContentWidth() : Number { if (queryAspectPicker == null) { contentWidth = frame.getPaneTitleWidth(); } else { contentWidth = queryAspectPicker.getWidth() + 120; } if (queryAspectViewer.getViewerWidth() + 20 > contentWidth) { contentWidth = queryAspectViewer.getViewerWidth() + 20; } if (TextField(this["statusTextField"])._width > contentWidth) { contentWidth = TextField(this["statusTextField"])._width; } return contentWidth; } function state(message : String) : Void { this["statusTextField"].text = message; } }