Java Code Examples for org.netbeans.api.visual.widget.Scene#setZoomFactor()
The following examples show how to use
org.netbeans.api.visual.widget.Scene#setZoomFactor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MouseCenteredZoomAction.java From netbeans with Apache License 2.0 | 4 votes |
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { Scene scene = widget.getScene (); int modifiers = scene.getInputBindings ().getZoomActionModifiers (); if ((event.getModifiers () & modifiers) != modifiers) return State.REJECTED; int amount = event.getWheelRotation (); double scale = 1.0; while (amount > 0) { scale /= zoomMultiplier; amount --; } while (amount < 0) { scale *= zoomMultiplier; amount ++; } JComponent view = scene.getView (); if (view != null) { Rectangle viewBounds = view.getVisibleRect (); Point center = widget.convertLocalToScene (event.getPoint ()); Point mouseLocation = scene.convertSceneToView (center); scene.setZoomFactor (scale * scene.getZoomFactor ()); scene.validate (); // HINT - forcing to change preferred size of the JComponent view center = scene.convertSceneToView (center); view.scrollRectToVisible (new Rectangle ( center.x - (mouseLocation.x - viewBounds.x), center.y - (mouseLocation.y - viewBounds.y), viewBounds.width, viewBounds.height )); } else scene.setZoomFactor (scale * scene.getZoomFactor ()); return State.CONSUMED; }
Example 2
Source File: CenteredZoomAction.java From netbeans with Apache License 2.0 | 4 votes |
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { Scene scene = widget.getScene (); int modifiers = scene.getInputBindings ().getZoomActionModifiers (); if ((event.getModifiers () & modifiers) != modifiers) return State.REJECTED; int amount = event.getWheelRotation (); double scale = 1.0; while (amount > 0) { scale /= zoomMultiplier; amount --; } while (amount < 0) { scale *= zoomMultiplier; amount ++; } JComponent view = scene.getView (); if (view != null) { Rectangle viewBounds = view.getVisibleRect (); Point center = GeomUtil.center (viewBounds); center = scene.convertViewToScene (center); scene.setZoomFactor (scale * scene.getZoomFactor ()); scene.validate (); // HINT - forcing to change preferred size of the JComponent view center = scene.convertSceneToView (center); view.scrollRectToVisible (new Rectangle ( center.x - viewBounds.width / 2, center.y - viewBounds.height / 2, viewBounds.width, viewBounds.height )); } else scene.setZoomFactor (scale * scene.getZoomFactor ()); return State.CONSUMED; }