}
}
});
DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
vv.setGraphMouse(gm);
final JToggleButton groupVertices = new JToggleButton("Group Clusters");
//Create slider to adjust the number of edges to remove when clustering
final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
edgeBetweennessSlider.setBackground(Color.WHITE);
edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50));
edgeBetweennessSlider.setPaintTicks(true);
edgeBetweennessSlider.setMaximum(graph.getEdgeCount());
edgeBetweennessSlider.setMinimum(0);
edgeBetweennessSlider.setValue(0);
edgeBetweennessSlider.setMajorTickSpacing(10);
edgeBetweennessSlider.setPaintLabels(true);
edgeBetweennessSlider.setPaintTicks(true);
// edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
//TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):"));
//I also want the slider value to appear
final JPanel eastControls = new JPanel();
eastControls.setOpaque(true);
eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
eastControls.add(Box.createVerticalGlue());
eastControls.add(edgeBetweennessSlider);
final String COMMANDSTRING = "Edges removed for clusters: ";
final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();
final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
eastControls.setBorder(sliderBorder);
//eastControls.add(eastSize);
eastControls.add(Box.createVerticalGlue());
groupVertices.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
clusterAndRecolor(layout, edgeBetweennessSlider.getValue(),
similarColors, e.getStateChange() == ItemEvent.SELECTED);
vv.repaint();
}});
clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());
edgeBetweennessSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
int numEdgesToRemove = source.getValue();
clusterAndRecolor(layout, numEdgesToRemove, similarColors,
groupVertices.isSelected());
sliderBorder.setTitle(
COMMANDSTRING + edgeBetweennessSlider.getValue());
eastControls.repaint();
vv.validate();
vv.repaint();
}
}
});
Container content = getContentPane();
content.add(new GraphZoomScrollPane(vv));
JPanel south = new JPanel();
JPanel grid = new JPanel(new GridLayout(2,1));
grid.add(scramble);
grid.add(groupVertices);
south.add(grid);
south.add(eastControls);
JPanel p = new JPanel();
p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
p.add(gm.getModeComboBox());
south.add(p);
content.add(south, BorderLayout.SOUTH);
}