
com.mxgraph.costfunction.mxDoubleValCostFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgraphx Show documentation
Show all versions of jgraphx Show documentation
JGraphX Swing Component - Java Graph Visualization Library
This is a binary & source redistribution of the original, unmodified
JGraphX library originating from:
"https://github.com/jgraph/jgraphx/archive/v3.3.1.1.tar.gz".
The purpose of this redistribution is to make the library available
to other Maven projects.
The newest version!
/**
* Copyright (c) 2012, JGraph Ltd
* Returns the value of a cell, which is assumed a Double
*/
package com.mxgraph.costfunction;
import com.mxgraph.view.mxCellState;
import com.mxgraph.view.mxGraph;
/**
* A cost function that assumes that edge value is of type "double" or "String" and returns that value. Default edge weight is 1.0 (if no double value can be retrieved)
*/
public class mxDoubleValCostFunction extends mxCostFunction
{
public double getCost(mxCellState state)
{
//assumed future parameters
if (state == null || state.getView() == null || state.getView().getGraph() == null)
{
return 1.0;
}
mxGraph graph = state.getView().getGraph();
Object cell = state.getCell();
Double edgeWeight = null;
if(graph.getModel().getValue(cell) == null || graph.getModel().getValue(cell) == "")
{
return 1.0;
}
else if (graph.getModel().getValue(cell) instanceof String)
{
edgeWeight = Double.parseDouble((String) graph.getModel().getValue(cell));
}
else
{
edgeWeight = (Double) graph.getModel().getValue(cell);
}
return edgeWeight;
};
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy