View Javadoc

    1   /*
    2    * @(#) PickObjectMouseBehavior.java 16-mei-2004
    3    *
    4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
    5    * Delft, the Netherlands. All rights reserved.
    6    *
    7    * This software is proprietary information of Delft University of Technology
    8    * The code is published under the Lesser General Public License
    9    */
    10  package nl.tudelft.simulation.dsol.gui.animation3D.mouse;
    11
    12  import javax.media.j3d.Bounds;
    13  import javax.media.j3d.BranchGroup;
    14  import javax.media.j3d.Canvas3D;
    15
    16  import nl.tudelft.simulation.dsol.animation.D3.Renderable3D;
    17  import nl.tudelft.simulation.introspection.gui.IntroSpectionDialog;
    18
    19  import com.sun.j3d.utils.picking.PickResult;
    20  import com.sun.j3d.utils.picking.PickTool;
    21  import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;
    22
    23  /***
    24   * PickObjectMouseBehavior.java <br>
    25   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
    26   * University of Technology </a>, the Netherlands. <br>
    27   * See for project information <a
    28   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
    29   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
    30   * General Public License (LGPL) </a>, no warranty.
    31   *
    32   * @version $Revision$ $Date$
    33   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
    34   *         </a>
    35   */
    36  public class PickObjectMouseBehavior extends PickMouseBehavior
    37  {
    38
    39  	/***
    40  	 * Construct a new behavior
    41  	 *
    42  	 * @param canvas3D A canvas3D
    43  	 * @param root The root branch group
    44  	 * @param bounds Bounds for this behavior
    45  	 */
    46  	public PickObjectMouseBehavior(final Canvas3D canvas3D,
    47  			final BranchGroup root, final Bounds bounds)
    48  	{
    49  		super(canvas3D, root, bounds);
    50  		this.setSchedulingBounds(bounds);
    51  		this.pickCanvas.setMode(PickTool.BOUNDS);
    52  		root.addChild(this);
    53  	}
    54
    55  	/***
    56  	 * @see com.sun.j3d.utils.picking.behaviors.PickMouseBehavior#updateScene(int,
    57  	 *      int)
    58  	 */
    59  	public void updateScene(final int xpos, final int ypos)
    60  	{
    61  		PickResult pickResult = null;
    62  		// Shape3D shape = null;
    63  		BranchGroup group = null;
    64
    65  		this.pickCanvas.setShapeLocation(xpos, ypos);
    66
    67  		pickResult = this.pickCanvas.pickClosest();
    68  		if (pickResult != null)
    69  		{
    70  			// shape = (Shape3D) pickResult.getNode(PickResult.SHAPE3D);
    71  			group = (BranchGroup) pickResult.getNode(PickResult.BRANCH_GROUP);
    72  			if (group != null)
    73  			{
    74  				new IntroSpectionDialog(((Renderable3D) group).getSource(),
    75  						((Renderable3D) group).getSource().toString());
    76
    77  			}
    78  		}
    79  	}
    80  }