// add a listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
Container content = getContentPane();
GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
content.add(gzsp);
/**
* the regular graph mouse for the normal view
*/
final DefaultModalGraphMouse<Number, Number> graphMouse =
new DefaultModalGraphMouse<Number, Number>();
vv.setGraphMouse(graphMouse);
viewSupport = new PerspectiveViewTransformSupport<String,Number>(vv);
layoutSupport = new PerspectiveLayoutTransformSupport<String,Number>(vv);
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, 0.9f, vv.getCenter());
}
});
final JSlider horizontalSlider = new JSlider(-120,120,0){
/* (non-Javadoc)
* @see javax.swing.JComponent#getPreferredSize()
*/
@Override
public Dimension getPreferredSize() {
return new Dimension(80, super.getPreferredSize().height);
}
};
final JSlider verticalSlider = new JSlider(-120,120,0) {
/* (non-Javadoc)
* @see javax.swing.JComponent#getPreferredSize()
*/
@Override
public Dimension getPreferredSize() {
return new Dimension(super.getPreferredSize().width, 80);
}
};
verticalSlider.setOrientation(JSlider.VERTICAL);
final ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int vval = -verticalSlider.getValue();
int hval = horizontalSlider.getValue();
Dimension d = vv.getSize();
PerspectiveTransform pt = null;
pt = PerspectiveTransform.getQuadToQuad(
vval, hval,
d.width-vval, -hval,
d.width+vval, d.height+hval,
-vval, d.height-hval,
0, 0,
d.width, 0,
d.width, d.height,
0, d.height);
viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
vv.repaint();
}};
horizontalSlider.addChangeListener(changeListener);
verticalSlider.addChangeListener(changeListener);
JPanel perspectivePanel = new JPanel(new BorderLayout());
JPanel perspectiveCenterPanel = new JPanel(new BorderLayout());
perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls"));
final JButton center = new JButton("Center");
center.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
horizontalSlider.setValue(0);
verticalSlider.setValue(0);
}});
ButtonGroup radio = new ButtonGroup();
JRadioButton normal = new JRadioButton("None");
normal.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
boolean selected = e.getStateChange() == ItemEvent.SELECTED;
if(selected) {
if(viewSupport != null) {
viewSupport.deactivate();
}
if(layoutSupport != null) {
layoutSupport.deactivate();
}
}
center.setEnabled(!selected);
horizontalSlider.setEnabled(!selected);
verticalSlider.setEnabled(!selected);
}
});
final JRadioButton perspectiveView = new JRadioButton("In View");
perspectiveView.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
final JRadioButton perspectiveModel = new JRadioButton("In Layout");
perspectiveModel.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
}
});
radio.add(normal);
radio.add(perspectiveModel);
radio.add(perspectiveView);
normal.setSelected(true);
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.repaint();
}
}});
JRadioButton gridButton = new JRadioButton("Grid");
gridButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
visualizationModel.setGraphLayout(gridLayout);
vv.repaint();
}
}});
graphRadio.add(graphButton);
graphRadio.add(gridButton);
JPanel modePanel = new JPanel(new GridLayout(2,1));
modePanel.setBorder(BorderFactory.createTitledBorder("Display"));
modePanel.add(graphButton);
modePanel.add(gridButton);
JMenuBar menubar = new JMenuBar();
menubar.add(graphMouse.getModeMenu());
gzsp.setCorner(menubar);
Container controls = new JPanel(new BorderLayout());
JPanel zoomControls = new JPanel(new GridLayout(2,1));
zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
JPanel perspectiveControls = new JPanel(new GridLayout(3,1));