This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 104718
Collapse All | Expand All

(-)graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java (+2 lines)
Lines 101-107 Link Here
101
        "test.visible.VisibilityTest",
101
        "test.visible.VisibilityTest",
102
        "test.vmd.VMDCollisionTest",
102
        "test.vmd.VMDCollisionTest",
103
        "test.vmd.VMDTest",
103
        "test.vmd.VMDTest",
104
        "test.zoom.CenteredZoomTest",
104
        "test.zoom.FitToViewTest",
105
        "test.zoom.FitToViewTest",
106
        "test.zoom.MouseCenteredZoomTest",
105
    };
107
    };
106
108
107
    /** Creates new form RunDialog */
109
    /** Creates new form RunDialog */
(-)graph/examples/src/test/zoom/MouseCenteredZoomTest.java (+46 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package test.zoom;
20
21
import test.general.StringGraphScene;
22
import test.SceneSupport;
23
import org.netbeans.api.visual.action.ActionFactory;
24
import org.netbeans.api.visual.widget.Widget;
25
26
import java.awt.*;
27
28
/**
29
 * @author David Kaspar
30
 */
31
public class MouseCenteredZoomTest {
32
33
    public static void main (String[] args) {
34
        StringGraphScene scene = new StringGraphScene ();
35
        scene.getActions ().addAction (ActionFactory.createMouseCenteredZoomAction (1.1));
36
        scene.getActions ().addAction (ActionFactory.createPanAction ());
37
        for (int a = 0; a < 100; a ++) {
38
            Widget widget = scene.addNode (Integer.toString (a));
39
            int y = (int) (Math.random () * 2000);
40
            int x = (int) (Math.random () * 2000);
41
            widget.setPreferredLocation (new Point (x, y));
42
        }
43
        SceneSupport.show (scene);
44
    }
45
46
}
(-)graph/lib/apichanges.xml (+14 lines)
Lines 137-142 Link Here
137
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
137
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
138
            <issue number="98307"/>
138
            <issue number="98307"/>
139
        </change>
139
        </change>
140
141
        <change>
142
            <api name="general"/>
143
            <summary>ActionFactory.createMouseCenteredZoomAction method introduced</summary>
144
            <version major="2" minor="3"/>
145
            <date day="28" month="5" year="2007"/>
146
            <author login="dkaspar"/>
147
            <compatibility addition="yes"/>
148
            <description>
149
                ActionFactory.createMouseCenteredZoomAction method introduced.
150
            </description>
151
            <class package="org.netbeans.api.visual.action" name="ActionFactory" link="yes"/>
152
            <issue number="104718"/>
153
        </change>
140
    </changes>
154
    </changes>
141
155
142
    <htmlcontents>
156
    <htmlcontents>
(-)graph/lib/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.visual
2
OpenIDE-Module: org.netbeans.api.visual
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.1
4
OpenIDE-Module-Specification-Version: 2.3
(-)graph/lib/src/org/netbeans/api/visual/action/ActionFactory.java (+11 lines)
Lines 673-676 Link Here
673
        return new CenteredZoomAction (zoomMultiplier);
673
        return new CenteredZoomAction (zoomMultiplier);
674
    }
674
    }
675
675
676
    /**
677
     * Creates a action that controls a zoom factor of a scene where the action is assigned.
678
     * During zooming the view will be centered to the mouse cursor.
679
     * @param zoomMultiplier the zoom multiplier
680
     * @return the zoom action
681
     * @since 2.3
682
     */
683
    public static WidgetAction createMouseCenteredZoomAction (double zoomMultiplier) {
684
        return new MouseCenteredZoomAction (zoomMultiplier);
685
    }
686
676
}
687
}
(-)graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html (-2 / +2 lines)
Lines 1002-1014 Link Here
1002
<h3><a name="ZoomAction">ZoomAction</a></h3>
1002
<h3><a name="ZoomAction">ZoomAction</a></h3>
1003
1003
1004
<p>
1004
<p>
1005
Created by: <code>ActionFactory.createZoomAction (zoomFactorMultiplier, animated)</code>, <code>ActionFactory.createCenteredZoomAction (zoomFactorMultiplier)</code>
1005
Created by: <code>ActionFactory.createZoomAction (zoomFactorMultiplier, animated)</code>, <code>ActionFactory.createCenteredZoomAction (zoomFactorMultiplier)</code>, <code>ActionFactory.createMouseCenteredZoomAction (zoomFactorMultiplier)</code>
1006
1006
1007
<p>
1007
<p>
1008
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.
1008
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.
1009
1009
1010
<p>
1010
<p>
1011
While the <code>CenterZoomAction</code> is zooming, a view is still centered to the center of the view.
1011
While the <code>CenteredZoomAction</code> is zooming, a view is still centered to the center of the view. While the <code>MouseCenteredZoomAction</code> is zooming, a view is still centered to mouse cursor.
1012
1012
1013
<h3><a name="ExampleUsingActions">Example: Using Actions</a></h3>
1013
<h3><a name="ExampleUsingActions">Example: Using Actions</a></h3>
1014
1014
(-)graph/lib/src/org/netbeans/modules/visual/action/MouseCenteredZoomAction.java (+77 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.visual.action;
20
21
import org.netbeans.api.visual.action.WidgetAction;
22
import org.netbeans.api.visual.widget.Scene;
23
import org.netbeans.api.visual.widget.Widget;
24
25
import javax.swing.*;
26
import java.awt.*;
27
28
/**
29
 * @author David Kaspar
30
 */
31
public final class MouseCenteredZoomAction extends WidgetAction.Adapter {
32
33
    private double zoomMultiplier;
34
35
    public MouseCenteredZoomAction (double zoomMultiplier) {
36
        this.zoomMultiplier = zoomMultiplier;
37
    }
38
39
    public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) {
40
        Scene scene = widget.getScene ();
41
        int amount = event.getWheelRotation ();
42
43
        double scale = 1.0;
44
        while (amount > 0) {
45
            scale /= zoomMultiplier;
46
            amount --;
47
        }
48
        while (amount < 0) {
49
            scale *= zoomMultiplier;
50
            amount ++;
51
        }
52
53
        JComponent view = scene.getView ();
54
        if (view != null) {
55
            Rectangle viewBounds = view.getVisibleRect ();
56
57
            Point center = widget.convertLocalToScene (event.getPoint ());
58
            Point mouseLocation = scene.convertSceneToView (center);
59
60
            scene.setZoomFactor (scale * scene.getZoomFactor ());
61
            scene.validate (); // HINT - forcing to change preferred size of the JComponent view
62
63
            center = scene.convertSceneToView (center);
64
65
            view.scrollRectToVisible (new Rectangle (
66
                    center.x - (mouseLocation.x - viewBounds.x),
67
                    center.y - (mouseLocation.y - viewBounds.y),
68
                    viewBounds.width,
69
                    viewBounds.height
70
            ));
71
        } else
72
            scene.setZoomFactor (scale * scene.getZoomFactor ());
73
74
        return State.CONSUMED;
75
    }
76
77
}
(-)graph/www/documentation.html (+1 lines)
Lines 174-179 Link Here
174
<li><strong>test.vmd.VMDTest</strong> - how to use <strong>VMD</strong> plug-in
174
<li><strong>test.vmd.VMDTest</strong> - how to use <strong>VMD</strong> plug-in
175
<li><strong>test.zoom.CenteredZoomTest</strong> - how to use <code>CenteredZoomAction</code>
175
<li><strong>test.zoom.CenteredZoomTest</strong> - how to use <code>CenteredZoomAction</code>
176
<li><strong>test.zoom.FitToViewTest</strong> - how to implement fit-to-view feature
176
<li><strong>test.zoom.FitToViewTest</strong> - how to implement fit-to-view feature
177
<li><strong>test.zoom.MouseCenteredZoomTest</strong> - how to use <code>MouseCenteredZoomAction</code>
177
</ul>
178
</ul>
178
179
179
<p>
180
<p>

Return to bug 104718