use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project titan.EclipsePlug-ins by eclipse.
the class LayoutBuilder method build.
/**
* This method implements the building of the chosen layout with chosen parameters
* @return The built layout
* @throws BadLayoutException If the chosen layout doesn't exist (invalid code was provided)
*/
public Layout<NodeDescriptor, EdgeDescriptor> build() throws BadLayoutException {
Layout<NodeDescriptor, EdgeDescriptor> layout;
final String layoutCode = layoutEntry.getCode();
if (layoutCode.equals(Layouts.LAYOUT_ISOM.getCode())) {
layout = new TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>(g);
((TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
} else if (layoutCode.equals(Layouts.LAYOUT_KK.getCode())) {
layout = new KKLayout<NodeDescriptor, EdgeDescriptor>(g);
((KKLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
} else if (layoutCode.equals(Layouts.LAYOUT_FR.getCode())) {
layout = new FRLayout<NodeDescriptor, EdgeDescriptor>(g);
((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setAttractionMultiplier(0.6);
((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setRepulsionMultiplier(0.8);
((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
} else if (layoutCode.equals(Layouts.LAYOUT_SPRING.getCode())) {
layout = new SpringLayout<NodeDescriptor, EdgeDescriptor>(g);
} else if (layoutCode.equals(Layouts.LAYOUT_CIRCLE.getCode())) {
layout = new CircleLayout<NodeDescriptor, EdgeDescriptor>(g);
} else if (layoutCode.equals(Layouts.LAYOUT_RTDAG.getCode())) {
layout = new ReverseDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
} else if (layoutCode.equals(Layouts.LAYOUT_TDAG.getCode())) {
layout = new TitaniumDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
} else if (layoutCode.equals(Layouts.METRIC_LAYOUT_CODE)) {
if (!(layoutEntry instanceof MetricsLayoutEntry)) {
throw new IllegalStateException("A metric must be chosen before using metric layout!");
}
layout = new MetricLayout<EdgeDescriptor>(g, size, ((MetricsLayoutEntry) layoutEntry).getMetric());
} else if (layoutCode.equals(Layouts.S_LAYOUT_CLUSTER)) {
if (clusters == null) {
throw new IllegalStateException("A clustering must be set before using cluster layout!");
}
final ClusterTransformer trf = new ClusterTransformer(new FRLayout<NodeDescriptor, EdgeDescriptor>(g), clusters, size);
layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, trf);
} else if ("STATIC".equals(layoutCode)) {
if (pointTransformer == null) {
throw new IllegalStateException("A point transformer must be set before using static layout!");
}
layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, pointTransformer);
} else {
throw new BadLayoutException("There is no such layout! (Layout=" + layoutCode + ")", ErrorType.NOT_EXISITING_LAYOUT);
}
layout.setSize(size);
return layout;
}
use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project opennms by OpenNMS.
the class RealUltimateLayoutAlgorithm method doSpringLayout.
private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) {
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
layout.setRepulsionRange(repulsion);
layout.setInitializer(initializer(graphLayout));
layout.setSize(size);
int count = 0;
while (!layout.done() && count < 700) {
layout.step();
count++;
}
for (VertexRef v : jungGraph.getVertices()) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project opennms by OpenNMS.
the class SpringLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
Collection<? extends Vertex> vertices = graph.getDisplayVertices();
for (VertexRef v : vertices) {
jungGraph.addVertex(v);
}
Collection<? extends Edge> edges = graph.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
layout.setInitializer(initializer(graphLayout));
layout.setSize(selectLayoutSize(graph));
int count = 0;
while (!layout.done() && count < 700) {
layout.step();
count++;
}
for (VertexRef v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
Aggregations