Container content = getContentPane();
GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
content.add(gzsp);
/**
* the regular graph mouse for the normal view
*/
final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
vv.setGraphMouse(graphMouse);
vv.addKeyListener(graphMouse.getModeKeyListener());
hyperbolicViewSupport =
new ViewLensSupport<String,Number>(vv, new HyperbolicShapeTransformer(vv,
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
new ModalLensGraphMouse());
hyperbolicLayoutSupport =
new LayoutLensSupport<String,Number>(vv, new HyperbolicTransformer(vv,
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
new ModalLensGraphMouse());
magnifyViewSupport =
new ViewLensSupport<String,Number>(vv, new MagnifyShapeTransformer(vv,
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
magnifyLayoutSupport =
new LayoutLensSupport<String,Number>(vv, new MagnifyTransformer(vv,
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
hyperbolicLayoutSupport.getLensTransformer().setLensShape(hyperbolicViewSupport.getLensTransformer().getLensShape());
magnifyViewSupport.getLensTransformer().setLensShape(hyperbolicLayoutSupport.getLensTransformer().getLensShape());
magnifyLayoutSupport.getLensTransformer().setLensShape(magnifyViewSupport.getLensTransformer().getLensShape());
final ScalingControl scaler = new CrossoverScalingControl();
JButton plus = new JButton("+");
plus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1.1f, vv.getCenter());
}
});
JButton minus = new JButton("-");
minus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1/1.1f, vv.getCenter());
}
});
ButtonGroup radio = new ButtonGroup();
JRadioButton normal = new JRadioButton("None");
normal.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
if(hyperbolicViewSupport != null) {
hyperbolicViewSupport.deactivate();
}
if(hyperbolicLayoutSupport != null) {
hyperbolicLayoutSupport.deactivate();
}
if(magnifyViewSupport != null) {
magnifyViewSupport.deactivate();
}
if(magnifyLayoutSupport != null) {
magnifyLayoutSupport.deactivate();
}
}
}
});
final JRadioButton hyperView = new JRadioButton("Hyperbolic View");
hyperView.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout");
hyperModel.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
final JRadioButton magnifyView = new JRadioButton("Magnified View");
magnifyView.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
magnifyViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
final JRadioButton magnifyModel = new JRadioButton("Magnified Layout");
magnifyModel.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
magnifyLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
JLabel modeLabel = new JLabel(" Mode Menu >>");
modeLabel.setUI(new VerticalLabelUI(false));
radio.add(normal);
radio.add(hyperModel);
radio.add(hyperView);
radio.add(magnifyModel);
radio.add(magnifyView);
normal.setSelected(true);
graphMouse.addItemListener(hyperbolicLayoutSupport.getGraphMouse().getModeListener());
graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener());
graphMouse.addItemListener(magnifyLayoutSupport.getGraphMouse().getModeListener());
graphMouse.addItemListener(magnifyViewSupport.getGraphMouse().getModeListener());
ButtonGroup graphRadio = new ButtonGroup();
JRadioButton graphButton = new JRadioButton("Graph");
graphButton.setSelected(true);
graphButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
visualizationModel.setGraphLayout(graphLayout);
vv.getRenderContext().setVertexShapeTransformer(ovals);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.repaint();
}
}});
JRadioButton gridButton = new JRadioButton("Grid");
gridButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
visualizationModel.setGraphLayout(gridLayout);
vv.getRenderContext().setVertexShapeTransformer(squares);
vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null));
vv.repaint();
}
}});
graphRadio.add(graphButton);
graphRadio.add(gridButton);
JPanel modePanel = new JPanel(new GridLayout(3,1));
modePanel.setBorder(BorderFactory.createTitledBorder("Display"));
modePanel.add(graphButton);
modePanel.add(gridButton);
JMenuBar menubar = new JMenuBar();
menubar.add(graphMouse.getModeMenu());
gzsp.setCorner(menubar);
Box controls = Box.createHorizontalBox();
JPanel zoomControls = new JPanel(new GridLayout(2,1));