? graph/lib/test/lib ? graph/lib/test/results ? graph/lib/test/work Index: graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java =================================================================== RCS file: /cvs/graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java,v retrieving revision 1.64 diff -u -r1.64 RunDialog.java --- graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 2 May 2007 04:34:21 -0000 1.64 +++ graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 29 May 2007 07:54:07 -0000 @@ -101,7 +101,9 @@ "test.visible.VisibilityTest", "test.vmd.VMDCollisionTest", "test.vmd.VMDTest", + "test.zoom.CenteredZoomTest", "test.zoom.FitToViewTest", + "test.zoom.MouseCenteredZoomTest", }; /** Creates new form RunDialog */ Index: graph/examples/src/test/zoom/MouseCenteredZoomTest.java =================================================================== RCS file: graph/examples/src/test/zoom/MouseCenteredZoomTest.java diff -N graph/examples/src/test/zoom/MouseCenteredZoomTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/examples/src/test/zoom/MouseCenteredZoomTest.java 29 May 2007 07:54:07 -0000 @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package test.zoom; + +import test.general.StringGraphScene; +import test.SceneSupport; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.widget.Widget; + +import java.awt.*; + +/** + * @author David Kaspar + */ +public class MouseCenteredZoomTest { + + public static void main (String[] args) { + StringGraphScene scene = new StringGraphScene (); + scene.getActions ().addAction (ActionFactory.createMouseCenteredZoomAction (1.1)); + scene.getActions ().addAction (ActionFactory.createPanAction ()); + for (int a = 0; a < 100; a ++) { + Widget widget = scene.addNode (Integer.toString (a)); + int y = (int) (Math.random () * 2000); + int x = (int) (Math.random () * 2000); + widget.setPreferredLocation (new Point (x, y)); + } + SceneSupport.show (scene); + } + +} Index: graph/lib/apichanges.xml =================================================================== RCS file: /cvs/graph/lib/apichanges.xml,v retrieving revision 1.8 diff -u -r1.8 apichanges.xml --- graph/lib/apichanges.xml 3 Apr 2007 16:59:58 -0000 1.8 +++ graph/lib/apichanges.xml 29 May 2007 07:54:08 -0000 @@ -137,6 +137,20 @@ + + + + ActionFactory.createMouseCenteredZoomAction method introduced + + + + + + ActionFactory.createMouseCenteredZoomAction method introduced. + + + + Index: graph/lib/manifest.mf =================================================================== RCS file: /cvs/graph/lib/manifest.mf,v retrieving revision 1.9 diff -u -r1.9 manifest.mf --- graph/lib/manifest.mf 6 Apr 2007 06:43:33 -0000 1.9 +++ graph/lib/manifest.mf 29 May 2007 07:54:08 -0000 @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.visual OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 2.1 +OpenIDE-Module-Specification-Version: 2.3 Index: graph/lib/src/org/netbeans/api/visual/action/ActionFactory.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/action/ActionFactory.java,v retrieving revision 1.22 diff -u -r1.22 ActionFactory.java --- graph/lib/src/org/netbeans/api/visual/action/ActionFactory.java 13 Mar 2007 16:57:38 -0000 1.22 +++ graph/lib/src/org/netbeans/api/visual/action/ActionFactory.java 29 May 2007 07:54:08 -0000 @@ -673,4 +673,15 @@ return new CenteredZoomAction (zoomMultiplier); } + /** + * Creates a action that controls a zoom factor of a scene where the action is assigned. + * During zooming the view will be centered to the mouse cursor. + * @param zoomMultiplier the zoom multiplier + * @return the zoom action + * @since 2.3 + */ + public static WidgetAction createMouseCenteredZoomAction (double zoomMultiplier) { + return new MouseCenteredZoomAction (zoomMultiplier); + } + } Index: graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html,v retrieving revision 1.9 diff -u -r1.9 documentation.html --- graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 23 Apr 2007 15:24:52 -0000 1.9 +++ graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 29 May 2007 07:54:08 -0000 @@ -1002,13 +1002,13 @@

ZoomAction

-Created by: ActionFactory.createZoomAction (zoomFactorMultiplier, animated), ActionFactory.createCenteredZoomAction (zoomFactorMultiplier) +Created by: ActionFactory.createZoomAction (zoomFactorMultiplier, animated), ActionFactory.createCenteredZoomAction (zoomFactorMultiplier), ActionFactory.createMouseCenteredZoomAction (zoomFactorMultiplier)

The action allows to zoom the view using scrolling mouse-middle-button. The action is usually assigned to a Scene only. For correct functionality of the action, the JComponent has to be put into scrollable panel like JScrollPane.

-While the CenterZoomAction is zooming, a view is still centered to the center of the view. +While the CenteredZoomAction is zooming, a view is still centered to the center of the view. While the MouseCenteredZoomAction is zooming, a view is still centered to mouse cursor.

Example: Using Actions

Index: graph/lib/src/org/netbeans/modules/visual/action/MouseCenteredZoomAction.java =================================================================== RCS file: graph/lib/src/org/netbeans/modules/visual/action/MouseCenteredZoomAction.java diff -N graph/lib/src/org/netbeans/modules/visual/action/MouseCenteredZoomAction.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/modules/visual/action/MouseCenteredZoomAction.java 29 May 2007 07:54:08 -0000 @@ -0,0 +1,77 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.visual.action; + +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +import javax.swing.*; +import java.awt.*; + +/** + * @author David Kaspar + */ +public final class MouseCenteredZoomAction extends WidgetAction.Adapter { + + private double zoomMultiplier; + + public MouseCenteredZoomAction (double zoomMultiplier) { + this.zoomMultiplier = zoomMultiplier; + } + + public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { + Scene scene = widget.getScene (); + 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; + } + +} Index: graph/www/documentation.html =================================================================== RCS file: /cvs/graph/www/documentation.html,v retrieving revision 1.83 diff -u -r1.83 documentation.html --- graph/www/documentation.html 2 May 2007 04:34:21 -0000 1.83 +++ graph/www/documentation.html 29 May 2007 07:54:08 -0000 @@ -174,6 +174,7 @@
  • test.vmd.VMDTest - how to use VMD plug-in
  • test.zoom.CenteredZoomTest - how to use CenteredZoomAction
  • test.zoom.FitToViewTest - how to implement fit-to-view feature +
  • test.zoom.MouseCenteredZoomTest - how to use MouseCenteredZoomAction