001/*
002 *  @(#)CBLayout.java         1.0       2007/04/11
003 *
004 *
005 *  Institut d'Investigaci� en Intel.lig?ncia Artificial (IIIA)
006 *
007 */
008
009/*
010 *-----------------------------------------------------------------------------
011 *
012 * Copyright 2007 by the
013 * Institut d'Investigaci� en Intel.lig?ncia Artificial, CSIC, Catalonia, EU
014 * http://www.iiia.csic.es
015 *
016 *  This file is part of InfoVisual Toolkit
017 *
018 *  InfoVisual Toolkit is free software; you can redistribute it and/or modify
019 *  it under the terms of the GNU General Public License as published by
020 *  the Free Software Foundation; either version 2 of the License, or
021 *  (at your option) any later version.
022 *
023 *  InfoVisual Toolkit is distributed in the hope that it will be useful,
024 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
025 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
026 *  GNU General Public License for more details.
027 *
028 *  You should have received a copy of the GNU General Public License
029 *  along with iForecast; if not, write to the Free Software
030 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031 *
032 *-----------------------------------------------------------------------------
033 */
034
035package es.ucm.fdi.gaia.jcolibri.extensions.visualization.infovisual;
036
037
038//-------------------------------------------------------------------
039//  External Classes or Libraries needed in the Class.
040//-------------------------------------------------------------------
041
042/*
043 * From prefuse ( http://prefuse.org/ ).
044 */
045import prefuse.action.layout.graph.ForceDirectedLayout;
046import prefuse.util.force.Force;
047import prefuse.util.force.ForceSimulator;
048import prefuse.util.force.SpringForce;
049import prefuse.visual.EdgeItem;
050
051/*
052 * The CB ForceLayout controls the spring length of the 
053 * edges by using the distance parameter in edges.
054 */
055public class CBForceLayout extends ForceDirectedLayout {
056
057    public CBForceLayout(String graph)
058    {
059        super(graph);
060    }
061
062    /*
063         * Returns the distance value associated to the edge.
064         */
065    protected float getSpringLength(EdgeItem e) {
066          float defaultLength = getDefaultSpringLength();
067          String dist = e.getString("distance");
068          if (dist.equals("")) {
069        return defaultLength;
070          }else{
071                return Float.parseFloat(dist) * (defaultLength * 25.f); //285.7f;
072      }
073    }
074        
075        protected float getDefaultSpringLength() {
076          ForceSimulator fsim = this.getForceSimulator();
077      Force force = fsim.getForces()[2];
078          return (float) force.getParameter(SpringForce.SPRING_LENGTH);
079        }
080
081}