Using the mouse wheel to move the scroll bars.
By default, the yFiles viewer component's support for mouse wheels applies to zooming in and out of the view.
To use the mouse wheel for moving the scroll bars a customized MouseWheelListener has to be registered.
| Note |
|
Mouse wheel support is provided by yFiles version 2.3 and higher.
|
The following sample code shows a simple MouseWheelListener implementation that can be registered with a view's JComponent.
class WheelScroller implements MouseWheelListener
{
protected Graph2DView view;
public WheelScroller(Graph2DView view)
{
this.view = view;
}
public void mouseWheelMoved(MouseWheelEvent e)
{
Point2D p2 = view.getCenter();
Point p = view.getViewPoint();
Dimension d = view.getViewSize();
Rectangle r = view.getWorldRect();
if (e.getWheelRotation() >= 0)
{
if (r.getY() + r.getHeight() - 1 > p.getY() + d.height / view.getZoom())
p2.setLocation(p2.getX(), p2.getY() + e.getScrollAmount());
}
else
{
if (r.getY() + 1 < p.getY())
p2.setLocation(p2.getX(), p2.getY() - e.getScrollAmount());
}
if (r.contains(p2))
{
view.setCenter(p2.getX(), p2.getY());
view.updateView();
}
}
}
|