use of org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry 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 org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry in project titan.EclipsePlug-ins by eclipse.
the class ModuleGraphEditor method initWindow.
@Override
protected void initWindow() {
super.initWindow();
isom.addActionListener(layoutListener);
layoutGroup.add(isom);
layoutMenu.add(isom);
kk.addActionListener(layoutListener);
layoutGroup.add(kk);
layoutMenu.add(kk);
fr.addActionListener(layoutListener);
layoutGroup.add(fr);
layoutMenu.add(fr);
spring.addActionListener(layoutListener);
layoutMenu.add(spring);
layoutGroup.add(spring);
circle.addActionListener(layoutListener);
layoutMenu.add(circle);
layoutGroup.add(circle);
final JMenu dagMenu = new JMenu("Directed layouts");
layoutMenu.add(dagMenu);
tdag.setSelected(true);
tdag.addActionListener(layoutListener);
dagMenu.add(tdag);
layoutGroup.add(tdag);
rtdag.addActionListener(layoutListener);
dagMenu.add(rtdag);
layoutGroup.add(rtdag);
layoutMenu.add(metricLayoutMenu);
final ActionListener changeMetrics = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
MetricsEntry metric = (MetricsEntry) e.getSource();
chosenMetric = metric;
for (NodeDescriptor node : graph.getVertices()) {
((MeasureableGraphHandler) handler).calculateColour(node, chosenMetric.getMetric());
}
drawArea.repaint();
if (satView != null) {
satView.repaint();
}
}
};
boolean isFirst = true;
// Creating the metric-selection menu:
JMenu actMenu = new JMenu(ModuleMetric.GROUP_NAME);
JMenu actLayoutMenu = new JMenu(ModuleMetric.GROUP_NAME);
metricsMenu.add(actMenu);
metricLayoutMenu.add(actLayoutMenu);
for (final ModuleMetric metric : ModuleMetric.values()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
if (isFirst) {
item.setSelected(true);
chosenMetric = item;
isFirst = false;
}
item.addActionListener(changeMetrics);
metricsGroup.add(item);
actMenu.add(item);
final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
layoutItem.addActionListener(layoutListener);
layoutGroup.add(layoutItem);
actLayoutMenu.add(layoutItem);
}
actMenu = new JMenu(AltstepMetric.GROUP_NAME);
actLayoutMenu = new JMenu(AltstepMetric.GROUP_NAME);
metricsMenu.add(actMenu);
metricLayoutMenu.add(actLayoutMenu);
for (final AltstepMetric metric : AltstepMetric.values()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
item.addActionListener(changeMetrics);
metricsGroup.add(item);
actMenu.add(item);
final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
layoutItem.addActionListener(layoutListener);
layoutGroup.add(layoutItem);
actLayoutMenu.add(layoutItem);
}
actMenu = new JMenu(FunctionMetric.GROUP_NAME);
actLayoutMenu = new JMenu(FunctionMetric.GROUP_NAME);
metricLayoutMenu.add(actLayoutMenu);
metricsMenu.add(actMenu);
for (final FunctionMetric metric : FunctionMetric.values()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
item.addActionListener(changeMetrics);
metricsGroup.add(item);
actMenu.add(item);
final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
layoutItem.addActionListener(layoutListener);
layoutGroup.add(layoutItem);
actLayoutMenu.add(layoutItem);
}
actMenu = new JMenu(TestcaseMetric.GROUP_NAME);
actLayoutMenu = new JMenu(TestcaseMetric.GROUP_NAME);
metricLayoutMenu.add(actLayoutMenu);
metricsMenu.add(actMenu);
for (final TestcaseMetric metric : TestcaseMetric.values()) {
if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
continue;
}
final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
item.addActionListener(changeMetrics);
metricsGroup.add(item);
actMenu.add(item);
final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
layoutItem.addActionListener(layoutListener);
layoutGroup.add(layoutItem);
actLayoutMenu.add(layoutItem);
}
final JMenuItem recalcItem = new JMenuItem("Recalculate metrics");
recalcItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
WrapperStore.clearStore();
GlobalParser.reAnalyzeSemantically();
recolour(graph.getVertices());
if (chosenLayout instanceof MetricsLayoutEntry) {
chosenLayout.doClick();
}
}
});
metricsMenu.add(recalcItem);
folderKnotCluster.addActionListener(new ClusteringAction("foldername", true));
knotClusteringMenu.add(folderKnotCluster);
folderGraphCluster.addActionListener(new ClusteringAction("foldername", false));
graphClusteringMenu.add(folderGraphCluster);
linkedKnotCluster.addActionListener(new ClusteringAction("linkedlocation", true));
knotClusteringMenu.add(linkedKnotCluster);
linkedGraphCluster.addActionListener(new ClusteringAction("linkedlocation", false));
graphClusteringMenu.add(linkedGraphCluster);
locationKnotCluster.addActionListener(new ClusteringAction("modulelocation", true));
knotClusteringMenu.add(locationKnotCluster);
locationGraphCluster.addActionListener(new ClusteringAction("modulelocation", false));
graphClusteringMenu.add(locationGraphCluster);
regKnotCluster.addActionListener(new ClusteringAction("regularexpression", true));
knotClusteringMenu.add(regKnotCluster);
regGraphCluster.addActionListener(new ClusteringAction("regularexpression", false));
graphClusteringMenu.add(regGraphCluster);
nameKnotCluster.addActionListener(new ClusteringAction("modulename", true));
knotClusteringMenu.add(nameKnotCluster);
nameGraphCluster.addActionListener(new ClusteringAction("modulename", false));
nameClusteringMenu.add(nameGraphCluster);
fullNameGraphCluster.addActionListener(new ClusteringAction("fullmodulenametree", false, (LayoutEntry) tdag));
nameClusteringMenu.add(fullNameGraphCluster);
sparseNameGraphCluster.addActionListener(new ClusteringAction("sparsemodulenametree", false, (LayoutEntry) tdag));
nameClusteringMenu.add(sparseNameGraphCluster);
autoKnotCluster.addActionListener(new ClusteringAction("automatic", true));
knotClusteringMenu.add(autoKnotCluster);
closeGraphClusters.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
chosenLayout.setSelected(false);
tdag.setSelected(true);
chosenLayout = (LayoutEntry) tdag;
enableModuleMenus(true);
setGraph(originalGraph);
}
});
closeGraphClusters.setEnabled(false);
menuBar.add(metricsMenu);
clusteringMenu.add(knotClusteringMenu);
graphClusteringMenu.add(nameClusteringMenu);
clusteringMenu.add(graphClusteringMenu);
clusteringMenu.add(closeGraphClusters);
menuBar.add(clusteringMenu);
}
Aggregations