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 28 May 2007 14:06:33 -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 28 May 2007 14:06:33 -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 28 May 2007 14:06:33 -0000
@@ -1002,13 +1002,13 @@
-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.
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 28 May 2007 14:06:33 -0000
@@ -0,0 +1,76 @@
+/*
+ * 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 ());
+
+ 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;
+ }
+
+}
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 28 May 2007 14:06:34 -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