Search in sources :

Example 1 with IMouseWheelEventHandler

use of org.freeplane.core.ui.IMouseWheelEventHandler in project freeplane by freeplane.

the class DefaultMouseWheelListener method mouseWheelMoved.

/*
	 * (non-Javadoc)
	 * @see
	 * freeplane.modes.ModeController.MouseWheelEventHandler#handleMouseWheelEvent
	 * (java.awt.event.MouseWheelEvent)
	 */
public void mouseWheelMoved(final MouseWheelEvent e) {
    final MapView mapView = (MapView) e.getSource();
    final ModeController mController = mapView.getModeController();
    if (mController.isBlocked()) {
        return;
    }
    final Set<IMouseWheelEventHandler> registeredMouseWheelEventHandler = mController.getUserInputListenerFactory().getMouseWheelEventHandlers();
    for (final IMouseWheelEventHandler handler : registeredMouseWheelEventHandler) {
        final boolean result = handler.handleMouseWheelEvent(e);
        if (result) {
            return;
        }
    }
    if ((e.getModifiers() & DefaultMouseWheelListener.ZOOM_MASK) != 0) {
        float newZoomFactor = 1f + Math.abs((float) e.getWheelRotation()) / 10f;
        if (e.getWheelRotation() < 0) {
            newZoomFactor = 1 / newZoomFactor;
        }
        final float oldZoom = ((MapView) e.getComponent()).getZoom();
        float newZoom = oldZoom / newZoomFactor;
        newZoom = (float) Math.rint(newZoom * 1000f) / 1000f;
        newZoom = Math.max(1f / 32f, newZoom);
        newZoom = Math.min(32f, newZoom);
        if (newZoom != oldZoom) {
            Controller.getCurrentController().getMapViewManager().setZoom(newZoom);
        }
    } else if ((e.getModifiers() & DefaultMouseWheelListener.HORIZONTAL_SCROLL_MASK) != 0) {
        ((MapView) e.getComponent()).scrollBy(DefaultMouseWheelListener.SCROLL_SKIPS * e.getWheelRotation(), 0);
    } else {
        ((MapView) e.getComponent()).scrollBy(0, DefaultMouseWheelListener.SCROLL_SKIPS * e.getWheelRotation());
    }
}
Also used : IMouseWheelEventHandler(org.freeplane.core.ui.IMouseWheelEventHandler) MapView(org.freeplane.view.swing.map.MapView) ModeController(org.freeplane.features.mode.ModeController)

Aggregations

IMouseWheelEventHandler (org.freeplane.core.ui.IMouseWheelEventHandler)1 ModeController (org.freeplane.features.mode.ModeController)1 MapView (org.freeplane.view.swing.map.MapView)1