/*---------------- 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.controls.Button; import nl.idgis.giclient.framework.bars.Position; import nl.idgis.giclient.framework.buttons.GIButtonEventListener; import nl.idgis.giclient.Ruler; import nl.idgis.giclient.util.URLTools; import nl.idgis.giclient.framework.GeoideTip; class nl.idgis.giclient.framework.buttons.GIButton extends MovieClip { private var name:String; // Set by init object. private var label:String; // Set by init object. private var baseURL:String; // Set by init object. private var iconURL:String; // Set by init object. private var toolTipText:String; // Set by init object. private var base:MovieClip = null; private var toolTip:GeoideTip = null; private var _giButtonLoadListener:Object; // Set by init object. private var movieClipLoader:MovieClipLoader = null; private var ruler:Ruler = null; private var giButtonWidth:Number = null; private var giButtonHeight:Number = null; private var enabled:Boolean; private var giButtonEventListeners:Array = null; private var rollTimeoutId = undefined; function GIButton() { movieClipLoader = new MovieClipLoader(); movieClipLoader.addListener(this); giButtonEventListeners = new Array(); if(baseURL == "Button") { //Set button width according to label length if (label != null) { var textFormat:TextFormat = new TextFormat(); textFormat.font = Button(base).getStyle("fontFamily"); textFormat.size = Button(base).getStyle("fontSize"); var textExtent:Object = textFormat.getTextExtent(label); giButtonWidth = textExtent.textFieldWidth + 30; } else { giButtonWidth = 20; } giButtonHeight = 20; } } function remove():Void { toolTip.removeToolTip(); this.removeMovieClip(); } function setRuler(ruler:Ruler):Void { this.ruler = ruler; } function onLoad():Void { _y = 8; var initObject:Object = null; if ((baseURL.indexOf(".swf") > -1) || (baseURL.indexOf(".jpg") > -1) || (baseURL.indexOf(".png") > -1)) { base = createEmptyMovieClip("base_mc", 1); movieClipLoader.loadClip(baseURL, base); } else if (baseURL == "Button") { initObject = {_width:giButtonWidth, _height: giButtonHeight, label:this.label, enabled:this.enabled, icon:this.iconURL}; base = attachMovie(baseURL, "base_mc", 1, initObject); } else { // The base url points to a symbol in the library and is placed within a position in a bar. _x += (_parent.width / 2); _y += (_parent.height / 2); initObject = {_width: _parent.width, _height: getHeight(), label:this.label}; base = attachMovie(baseURL, "base_mc", 1, initObject); } if ((iconURL != null) && (baseURL != "Button")) { initObject = {_width: _parent.width * 0.8, _height: getHeight() * 0.8}; URLTools.loadMovie(this, iconURL, "icon_mc", 2, initObject); } if (toolTipText != null) { initObject = {displayText:toolTipText, displayShadow:true, faceColor:"0xffffff", borderColor:"0x000000", useFade:true}; toolTip = GeoideTip(attachMovie("GeoideTip", "toolTip_mc", 3, initObject)); } _parent._parent.layout(); } function onLoadInit(target:MovieClip):Void { if (base._width > _parent.width) { base._xscale = 100 * _parent.width / base._width; } if (base._height > _parent.height) { base._yscale = 100 * _parent.height / base._height; } } function addEventListener(giButtonEventListener:GIButtonEventListener):Void { giButtonEventListeners.push(giButtonEventListener); } function removeEventListener(giButtonEventListener:GIButtonEventListener):Void{ for (var i:Number = 0; i < giButtonEventListeners.length; i++) { if (giButtonEventListener == giButtonEventListeners[i]){ giButtonEventListeners.splice(i, 1); } } } function getName():String { return name; } function getWidth():Number { if(_parent instanceof Position){ return _parent.width; } else { return giButtonWidth; } } function getHeight():Number { if(_parent instanceof Position){ return _parent.height; } else { return giButtonHeight; } } function setEnabled(enabled:Boolean):Void { if (this.enabled == enabled) { return; } this.enabled = enabled; if (baseURL == "Button") { base.enabled = enabled; } if (enabled) { _alpha = 100; } else { _alpha = 50; } } function setFocussed(focussed:Boolean):Void { if (baseURL != "Button") { if (focussed) { if (base._currentframe == 1) { base.gotoAndStop(2); } else if (base._currentframe == 3) { base.gotoAndStop(4); } } else { if (base._currentframe == 2) { base.gotoAndStop(1); } else if (base._currentframe == 4) { base.gotoAndStop(3); } } } } function setGlowing(glowing:Boolean):Void { if (baseURL != "Button") { if (glowing) { if (base._currentframe == 1) { base.gotoAndStop(3); } else if (base._currentframe == 2) { base.gotoAndStop(4); } } else { if (base._currentframe == 3) { base.gotoAndStop(1); } else if (base._currentframe == 4) { base.gotoAndStop(2); } } } } function onRollOver():Void { setFocussed(true); rollTimeoutId = _global["setTimeout"](toolTip, "displayToolTip", 300); } function onRollOut():Void { setFocussed(false); toolTip.removeToolTip(); _global["clearTimeout"](rollTimeoutId); } function onReleaseOutside() { setFocussed(false); toolTip.removeToolTip(); } }