hackedteam/rcs-console

View on GitHub
src/org/un/cava/birdeye/ravis/components/ui/controls/vgraphControls/ScaleLabels.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * The MIT License
 *
 * Copyright (c) 2008
 * United Nations Office at Geneva
 * Center for Advanced Visual Analytics
 * http://cava.unog.ch
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
-->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
    
    <mx:Label
        toolTip="Use this control to increase/decrease text/icon size."
        text="Scaling"
        fontSize="9" 
        textAlign="center"
        />
        
    <mx:HBox width="95%">
        <mx:Button
            id="minusScale"
            icon="{EmbeddedIcons.zoomoutIcon}"
            cornerRadius="5"
            width="25"
            height="25"
            click="scaleSlider.value=scaleSlider.value-.1; updateScale();"
            />        
        <mx:HSlider
            tickInterval=".25"
            width="95%"
            id="scaleSlider"
            value="1"
            minimum=".5"
            maximum="2.0"
            snapInterval=".1"
            liveDragging="true"
            change="updateScale()"
            />
        <mx:Button
            id="plusScale"
            icon="{EmbeddedIcons.zoominIcon}"
            cornerRadius="5"
            width="25"
            height="25"
            click="scaleSlider.value=scaleSlider.value+.1; updateScale();"
            />    
    </mx:HBox>

    <mx:Script>
        <![CDATA[
            import mx.core.Container;
            import mx.core.UIComponent;
            
            import org.un.cava.birdeye.ravis.assets.icons.EmbeddedIcons;
            import org.un.cava.birdeye.ravis.graphLayout.data.INode;
            import org.un.cava.birdeye.ravis.graphLayout.visual.VisualGraph;
            import org.un.cava.birdeye.ravis.utils.LogUtil;
            import org.un.cava.birdeye.ravis.utils.events.VGraphEvent;
            
            private static const _LOG:String = "vgraphControls.ScaleLabels";
            private var _vgraph:VisualGraph;

            /**
             * Provides access to the registered vgraph object.
             * */
            public function set vgraph(v:VisualGraph):void {
                _vgraph = v;
                registerListeners();
            }


            /**
             * @private
             * */
            public function get vgraph():VisualGraph {
                return _vgraph;
            }
            
            /**
             * this updates the scale factor in all children of the vgraph
             * */    
            public function updateScale():void {
                
                if(_vgraph == null) {
                    LogUtil.info(_LOG,"Cannot update Scale of VGraph, no valid vgraph!");
                    return;
                }

                for each(var node:INode in _vgraph.graph.nodes)
                {
                    node.vnode.view.scaleX = scaleSlider.value;
                    node.vnode.view.scaleY = scaleSlider.value;    
                }

                /* check if we have a layouter at all */
                if(_vgraph.layouter != null) {
                    _vgraph.layouter.layoutChanged = true;
                } else {
                    LogUtil.info(_LOG,"Cannot notify null layouter of layout change due to scaling.");
                }
                _vgraph.draw();
            }
            
            /**
             * refreshes the slider from the current scale value
             * of the first child object of VGraph
             * */
            public function refreshSlider(e:VGraphEvent = null):void {
                
                if(_vgraph == null ||
                   _vgraph.graph == null ||
                   _vgraph.graph.nodes == null) {
                    LogUtil.info(_LOG,"Cannot refresh ScaleSlider of VGraph, no valid vgraph!");
                    return;
                }    
                                    
                if(_vgraph.graph.nodes.length == 0 ||
                    _vgraph.graph.nodes[0].vnode == null ||
                    _vgraph.graph.nodes[0].vnode.view == null)
                    return;
                
                scaleSlider.value = _vgraph.graph.nodes[0].vnode.view.scaleX;
            }
            
            /**
             * register that we are complete
             * */
            private function registerListeners():void {
                _vgraph.addEventListener(VGraphEvent.VGRAPH_CHANGED,refreshSlider);
            }
        ]]>
    </mx:Script>
</mx:VBox>