collapse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
if(picked.size() > 1) {
Graph inGraph = layout.getGraph();
Graph clusterGraph = collapser.getClusterGraph(inGraph, picked);
Graph g = collapser.collapse(layout.getGraph(), clusterGraph);
collapsedGraph = g;
double sumx = 0;
double sumy = 0;
for(Object v : picked) {
Point2D p = (Point2D)layout.transform(v);
sumx += p.getX();
sumy += p.getY();
}
Point2D cp = new Point2D.Double(sumx/picked.size(), sumy/picked.size());
vv.getRenderContext().getParallelEdgeIndexFunction().reset();
layout.setGraph(g);
layout.setLocation(clusterGraph, cp);
vv.getPickedVertexState().clear();
vv.repaint();
}
}});
JButton compressEdges = new JButton("Compress Edges");
compressEdges.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Collection picked = vv.getPickedVertexState().getPicked();
if(picked.size() == 2) {
Pair pair = new Pair(picked);
Graph graph = layout.getGraph();
Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
exclusions.addAll(edges);
vv.repaint();
}
}});
JButton expandEdges = new JButton("Expand Edges");
expandEdges.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Collection picked = vv.getPickedVertexState().getPicked();
if(picked.size() == 2) {
Pair pair = new Pair(picked);
Graph graph = layout.getGraph();
Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
exclusions.removeAll(edges);
vv.repaint();
}
}});
JButton expand = new JButton("Expand");
expand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
for(Object v : picked) {
if(v instanceof Graph) {
Graph g = collapser.expand(layout.getGraph(), (Graph)v);
vv.getRenderContext().getParallelEdgeIndexFunction().reset();
layout.setGraph(g);
}
vv.getPickedVertexState().clear();
vv.repaint();