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.77 diff -u -r1.77 RunDialog.java --- graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 19 Jul 2007 07:15:42 -0000 1.77 +++ graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 27 Jul 2007 19:02:43 -0000 @@ -44,6 +44,7 @@ "test.anchor.InvalidAnchorNegativeTest", "test.animator.AnimatorTest", "test.animator.ColorAnimatorTest", + "test.bird.BirdViewTest", "test.card.CardContainerWidget", "test.component.ComponentTest", "test.component.ComponentModeTest", Index: graph/examples/src/test/SceneSupport.java =================================================================== RCS file: /cvs/graph/examples/src/test/SceneSupport.java,v retrieving revision 1.9 diff -u -r1.9 SceneSupport.java --- graph/examples/src/test/SceneSupport.java 6 Dec 2006 16:37:40 -0000 1.9 +++ graph/examples/src/test/SceneSupport.java 27 Jul 2007 19:02:43 -0000 @@ -67,4 +67,12 @@ }, delay); } + public static void sleep (int delay) { + try { + Thread.sleep (delay); + } catch (InterruptedException e) { + e.printStackTrace (); + } + } + } Index: graph/examples/src/test/bird/BirdViewTest.java =================================================================== RCS file: graph/examples/src/test/bird/BirdViewTest.java diff -N graph/examples/src/test/bird/BirdViewTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/examples/src/test/bird/BirdViewTest.java 27 Jul 2007 19:02:43 -0000 @@ -0,0 +1,56 @@ +/* + * 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-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package test.bird; + +import org.netbeans.api.visual.widget.BirdViewController; +import test.SceneSupport; +import test.general.StringGraphScene; + +import java.awt.*; + +/** + * @author David Kaspar + */ +public class BirdViewTest { + + public static void main (String[] args) { + StringGraphScene scene = new StringGraphScene (); + for (int a = 0; a < 100; a ++) + scene.addNode ("node" + String.valueOf (a)).setPreferredLocation (new Point (SceneSupport.randInt (1000), SceneSupport.randInt (1000))); + + BirdViewController birdViewController = scene.createBirdView (); + + scene.createView (); // main view has to be created before showing the bird view + birdViewController.show (); + + SceneSupport.show (scene); + + SceneSupport.sleep (2000); + birdViewController.setZoomFactor (5.0); + birdViewController.setWindowSize (new Dimension (400, 400)); + + SceneSupport.sleep (2000); + birdViewController.hide (); + + SceneSupport.sleep (2000); + birdViewController.show (); + } + +} Index: graph/lib/apichanges.xml =================================================================== RCS file: /cvs/graph/lib/apichanges.xml,v retrieving revision 1.24 diff -u -r1.24 apichanges.xml --- graph/lib/apichanges.xml 18 Jul 2007 13:39:40 -0000 1.24 +++ graph/lib/apichanges.xml 27 Jul 2007 19:02:44 -0000 @@ -330,6 +330,21 @@ + + + + Bird view support added + + + + + + Bird view is a window that is always under your mouse-cursor and shows the scene with a specified zoom factor. + A bird view can be created using Scene.createBirdView method. To enable bird view you need to call the show method on returned controller instance. + + + + Index: graph/lib/manifest.mf =================================================================== RCS file: /cvs/graph/lib/manifest.mf,v retrieving revision 1.13 diff -u -r1.13 manifest.mf --- graph/lib/manifest.mf 25 Jun 2007 14:10:16 -0000 1.13 +++ graph/lib/manifest.mf 27 Jul 2007 19:02:44 -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.5 +OpenIDE-Module-Specification-Version: 2.7 Index: graph/lib/src/org/netbeans/api/visual/widget/BirdViewController.java =================================================================== RCS file: graph/lib/src/org/netbeans/api/visual/widget/BirdViewController.java diff -N graph/lib/src/org/netbeans/api/visual/widget/BirdViewController.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/api/visual/widget/BirdViewController.java 27 Jul 2007 19:02:44 -0000 @@ -0,0 +1,84 @@ +/* + * 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-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.visual.widget; + +import org.netbeans.modules.visual.widget.BirdViewWindow; + +import java.awt.*; + +/** + * This class controls a bird view created for a specific scene. The bird is tracking mouse-cursor over the main scene view. + * You can specify a separate zoom-factor and you can enable and disable it by calling show and hide methods. + *

+ * When a bird view is enabled then it consumes all events of a main scene view therefore you cannot do anything except + * watch the scene with bird view. + * + * @since 2.7 + * @author David Kaspar + */ +public final class BirdViewController { + + private BirdViewWindow birdView; + + BirdViewController (Scene scene) { + birdView = new BirdViewWindow (scene); + } + + /** + * Sets a zoom factor of the bird view. + * @param zoomFactor the zoom factor + * @since 2.7 + */ + public void setZoomFactor (double zoomFactor) { + birdView.setZoomFactor (zoomFactor); + } + + /** + * Sets a size of the bird view window. + * @param size the window size + * @since 2.7 + */ + public void setWindowSize (Dimension size) { + birdView.setWindowSize (size); + } + + /** + * Enables the bird view. It means that the bird view window will be visible while a mouse cursor is over the visible + * area of the main scene view. + *

+ * Note: Has to be invoked after Scene.createView method. + *

+ * Note: An user has to initially move cursor over the visible area of the main scene view + * to show the window up for the first time after the method call. + * @since 2.7 + */ + public void show () { + birdView.invokeShow (); + } + + /** + * Disables the bird view. It means the bird view window is hidden and the main scene view is not blocked for events. + * @since 2.7 + */ + public void hide () { + birdView.invokeHide (); + } + +} Index: graph/lib/src/org/netbeans/api/visual/widget/Scene.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/widget/Scene.java,v retrieving revision 1.46 diff -u -r1.46 Scene.java --- graph/lib/src/org/netbeans/api/visual/widget/Scene.java 8 Jun 2007 08:15:35 -0000 1.46 +++ graph/lib/src/org/netbeans/api/visual/widget/Scene.java 27 Jul 2007 19:02:44 -0000 @@ -22,8 +22,8 @@ import org.netbeans.api.visual.action.TwoStateHoverProvider; import org.netbeans.api.visual.action.WidgetAction; import org.netbeans.api.visual.animator.SceneAnimator; -import org.netbeans.api.visual.laf.LookFeel; import org.netbeans.api.visual.laf.InputBindings; +import org.netbeans.api.visual.laf.LookFeel; import org.netbeans.modules.visual.util.GeomUtil; import org.netbeans.modules.visual.widget.SatelliteComponent; @@ -126,12 +126,21 @@ return component; } - /** + /** * Creates a satellite view. * @return the satellite view */ public JComponent createSatelliteView () { return new SatelliteComponent (this); + } + + /** + * Creates a bird view with specific zoom factor. + * @return the bird view controller + * @since 2.7 + */ + public BirdViewController createBirdView () { + return new BirdViewController (this); } void setViewShowing (boolean viewShowing) { 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.20 diff -u -r1.20 documentation.html --- graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 25 Jun 2007 14:10:19 -0000 1.20 +++ graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 27 Jul 2007 19:02:47 -0000 @@ -509,6 +509,9 @@ createSatelliteView Creates a satellite view of the scene. It is showing an overview of the scene. In case the JComponent view is placed in a JScrollPane and the scene does not fit into the panel, then the satellite view paints an viewport rectangle which representing visible area. It also allows user to move with the actual viewport of the scene. +createBirdView +Creates a bird view of the scene. It is enough to create one bird view and reuse it all the time. The bird view is tracking mouse cursor and when the cursor is over visible area of the scene view, then an additional always-on-top window is shown and shows pointed part of the scene with specified zoom factor. The method returns BirdViewController which allows control over the bird view. When the bird view is enabled, then it consumes all events of the scene view. + getGraphics Returns an instance of Graphics2D used by whole scene. The instance is the one that was available during the last JComponent.addNotify or JComponent.paint method call on the JComponent view. Index: graph/lib/src/org/netbeans/modules/visual/widget/BirdViewWindow.java =================================================================== RCS file: graph/lib/src/org/netbeans/modules/visual/widget/BirdViewWindow.java diff -N graph/lib/src/org/netbeans/modules/visual/widget/BirdViewWindow.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/modules/visual/widget/BirdViewWindow.java 27 Jul 2007 19:02:48 -0000 @@ -0,0 +1,259 @@ +/* + * 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-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.visual.widget; + +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 javax.swing.border.BevelBorder; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.awt.geom.AffineTransform; + +/** + * @author David Kaspar + */ +public class BirdViewWindow extends JWindow implements MouseMotionListener { + + private Scene scene; + private BirdViewComponent birdView; + + private boolean shown = false; + private double zoomFactor = 3.0; + private Point scenePoint; + + private WidgetAction action = new SceneTrackAction (); + private ViewAncestorListener ancestorListener = new ViewAncestorListener (); + + public BirdViewWindow (final Scene scene) { + this.scene = scene; + setSize (new Dimension (256, 256)); + setLayout (new BorderLayout ()); + setAlwaysOnTop (true); + + JPanel pane = new JPanel (); + pane.setBorder (new CompoundBorder (new LineBorder (Color.BLACK, 1), new EmptyBorder (1, 1, 1, 1))); + pane.setLayout (new BorderLayout ()); + add (pane, BorderLayout.CENTER); + + birdView = new BirdViewComponent (); + birdView.setDoubleBuffered (true); + birdView.setBorder (new BevelBorder (BevelBorder.RAISED)); + pane.add (birdView, BorderLayout.CENTER); + } + + public void invokeShow () { + if (scene.getView () == null) + return; + if (shown) + return; + shown = true; + birdView.addMouseMotionListener (this); + scene.getPriorActions ().addAction (action); + scene.getView ().addAncestorListener (ancestorListener); + updateForViewPoint (null); + } + + public void invokeHide () { + if (! shown) + return; + shown = false; + birdView.removeMouseMotionListener (this); + scene.getPriorActions ().removeAction (action); + scene.getView ().removeAncestorListener (ancestorListener); + updateForViewPoint (null); + } + + public void invokeRepaint () { + birdView.repaint (); + } + + public void setZoomFactor (double zoomFactor) { + this.zoomFactor = zoomFactor; + invokeRepaint (); + } + + public void setWindowSize (Dimension size) { + Dimension previousSize = getSize (); + setSize (size); + if (isShowing ()) { + Point location = getLocation (); + setLocation (location.x + (previousSize.width - size.width) / 2, location.y + (previousSize.height - size.height) / 2); + validate (); + } + } + + private void updateForViewPoint (Point viewPoint) { + JComponent view = scene.getView (); + if (! shown || viewPoint == null || ! view.getVisibleRect ().contains (viewPoint)) { + scenePoint = null; + setVisible (false); + dispose (); + return; + } + scenePoint = scene.convertViewToScene (viewPoint); + Point viewOrigin = view.getLocationOnScreen (); + Dimension size = getSize (); + setBounds (viewOrigin.x + viewPoint.x - size.width / 2, viewOrigin.y + viewPoint.y - size.height / 2, size.width, size.height); + setVisible (true); + birdView.repaint(); + } + + private void updateForBirdViewPoint (Point birdViewPoint) { + JComponent view = scene.getView (); + if (view.isShowing () && isShowing ()) { + Point viewOrigin = view.getLocationOnScreen (); + Point birdViewOrigin = getLocationOnScreen (); + Dimension size = getSize (); + updateForViewPoint (new Point (birdViewPoint.x + birdViewOrigin.x - viewOrigin.x, birdViewPoint.y + birdViewOrigin.y - viewOrigin.y)); + } else + updateForViewPoint (null); + } + + public void mouseDragged (MouseEvent e) { + updateForBirdViewPoint (e.getPoint ()); + } + + public void mouseMoved (MouseEvent e) { + updateForBirdViewPoint (e.getPoint ()); + } + + private class SceneTrackAction implements WidgetAction { + + public State mouseClicked (Widget widget, WidgetMouseEvent event) { + return State.CONSUMED; + } + + public State mousePressed (Widget widget, WidgetMouseEvent event) { + return State.CONSUMED; + } + + public State mouseReleased (Widget widget, WidgetMouseEvent event) { + return State.CONSUMED; + } + + public State mouseEntered (Widget widget, WidgetMouseEvent event) { + return State.CONSUMED; + } + + public State mouseExited (Widget widget, WidgetMouseEvent event) { + return State.CONSUMED; + } + + public State mouseDragged (Widget widget, WidgetMouseEvent event) { + updateForViewPoint (widget.getScene ().convertSceneToView (widget.convertLocalToScene (event.getPoint ()))); + return State.CONSUMED; + } + + public State mouseMoved (Widget widget, WidgetMouseEvent event) { + updateForViewPoint (widget.getScene ().convertSceneToView (widget.convertLocalToScene (event.getPoint ()))); + return State.CONSUMED; + } + + public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) { + return State.CONSUMED; + } + + public State keyTyped (Widget widget, WidgetKeyEvent event) { + return State.CONSUMED; + } + + public State keyPressed (Widget widget, WidgetKeyEvent event) { + return State.CONSUMED; + } + + public State keyReleased (Widget widget, WidgetKeyEvent event) { + return State.CONSUMED; + } + + public State focusGained (Widget widget, WidgetFocusEvent event) { + return State.CONSUMED; + } + + public State focusLost (Widget widget, WidgetFocusEvent event) { + return State.CONSUMED; + } + + public State dragEnter (Widget widget, WidgetDropTargetDragEvent event) { + return State.CONSUMED; + } + + public State dragOver (Widget widget, WidgetDropTargetDragEvent event) { + return State.CONSUMED; + } + + public State dropActionChanged (Widget widget, WidgetDropTargetDragEvent event) { + return State.CONSUMED; + } + + public State dragExit (Widget widget, WidgetDropTargetEvent event) { + return State.CONSUMED; + } + + public State drop (Widget widget, WidgetDropTargetDropEvent event) { + return State.CONSUMED; + } + + } + + private class BirdViewComponent extends JComponent { + + public void paint (Graphics g) { + Graphics2D gr = (Graphics2D) g; + super.paint (g); + if (scenePoint == null) { + gr.setColor (Color.BLACK); + gr.fill (getBounds ()); + return; + } + Dimension size = getSize (); + AffineTransform previousTransform = gr.getTransform (); + gr.translate (size.width / 2, size.height / 2); + gr.scale (zoomFactor, zoomFactor); + gr.translate (- scenePoint.x, - scenePoint.y); + scene.paint (gr); + gr.setTransform (previousTransform); + } + + } + + private class ViewAncestorListener implements AncestorListener { + + public void ancestorAdded (AncestorEvent event) { + } + + public void ancestorRemoved (AncestorEvent event) { + invokeHide (); + } + + public void ancestorMoved (AncestorEvent event) { + } + + } + +} Index: graph/www/documentation.html =================================================================== RCS file: /cvs/graph/www/documentation.html,v retrieving revision 1.97 diff -u -r1.97 documentation.html --- graph/www/documentation.html 19 Jul 2007 07:15:43 -0000 1.97 +++ graph/www/documentation.html 27 Jul 2007 19:02:48 -0000 @@ -115,6 +115,7 @@

  • test.anchor.InvalidAnchorNegativeTest - negative test of invalid anchor (its related widget is not added into scene)
  • test.animator.AnimatorTest - how to use preferred-location animator
  • test.animator.ColorAnimatorTest - how to use background/foreground animator +
  • test.bird.BirdViewTest - how to use bird view
  • test.card.CardContainerWidget - how to use CardLayout
  • test.component.ComponentTest - shows AWT/Swing integration
  • test.component.ComponentModeTest - shows adding/removing modes of ComponentWidget Index: graph/www/index.html =================================================================== RCS file: /cvs/graph/www/index.html,v retrieving revision 1.83 diff -u -r1.83 index.html --- graph/www/index.html 8 Jun 2007 08:45:03 -0000 1.83 +++ graph/www/index.html 27 Jul 2007 19:02:48 -0000 @@ -118,10 +118,11 @@
  • Object states
  • Selection/focus model
  • Satelite view -
  • In-place editing +
  • Bird view
      +
    • In-place editing
    • ReconnectAction
    • ScrollWidget
    • Action tools