Search in sources :

Example 1 with MetricLayout

use of org.eclipse.titanium.graph.gui.layouts.MetricLayout 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;
}
Also used : KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) ClusterTransformer(org.eclipse.titanium.graph.clustering.gui.ClusterTransformer) MetricsLayoutEntry(org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) StaticLayout(edu.uci.ics.jung.algorithms.layout.StaticLayout) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) ReverseDAGLayout(org.eclipse.titanium.graph.gui.layouts.ReverseDAGLayout) MetricLayout(org.eclipse.titanium.graph.gui.layouts.MetricLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) TitaniumISOMLayout(org.eclipse.titanium.graph.gui.layouts.TitaniumISOMLayout)

Aggregations

FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)1 StaticLayout (edu.uci.ics.jung.algorithms.layout.StaticLayout)1 ClusterTransformer (org.eclipse.titanium.graph.clustering.gui.ClusterTransformer)1 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)1 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)1 MetricLayout (org.eclipse.titanium.graph.gui.layouts.MetricLayout)1 ReverseDAGLayout (org.eclipse.titanium.graph.gui.layouts.ReverseDAGLayout)1 TitaniumISOMLayout (org.eclipse.titanium.graph.gui.layouts.TitaniumISOMLayout)1 MetricsLayoutEntry (org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry)1