SourceForge.net Logo
Creating Behaviors
Drag.java


	

/*
 *	@(#)Drag.java 1.14 98/04/13 13:07:16
 *
 * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import com.sun.j3d.utils.behaviors.mouse.MouseRotate;

import com.sun.j3d.utils.behaviors.mouse.MouseZoom;

import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;

import java.applet.*;

import java.awt.*;

import java.io.*;

import java.net.*;

import java.awt.BorderLayout;

import java.awt.event.*;

import javax.media.j3d.*;

import javax.vecmath.*;

import com.sun.j3d.utils.universe.*;


/**
 * Class Drag
 *
 * Author Jim Argabright
 * Date   11/24/97
 */
public class Drag extends Applet {

   boolean appletFlag = true;

   /**
    * Sets the "applet" flag which is used to determine 
    * whether or not this program is running as an applet.
    */
   public void setAppletFlag(boolean flag) {
      appletFlag = flag;
   }

   /**
    *  Create the scenegraph for this program.
    */
   public BranchGroup createSceneGraph() {

        // Define colors

        Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f red   = new Color3f(0.80f, 0.20f, 0.2f);
        Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f);
        Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f);
        Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f);
        Color3f specular = new Color3f(0.7f, 0.7f, 0.7f);
	Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

        // Create the branch group

	BranchGroup branchGroup = new BranchGroup();

        // Create a Transformgroup to scale all objects so they

        // appear in the scene.

        TransformGroup objScale = new TransformGroup();
        Transform3D t3d = new Transform3D();
        t3d.setScale(0.4);
        objScale.setTransform(t3d);
        branchGroup.addChild(objScale);

        // Create the bounding leaf node

	BoundingSphere bounds = 
           new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
        objScale.addChild(boundingLeaf);

	// Set up the background

	Background bg = new Background(bgColor);
	bg.setApplicationBounds(bounds);
	objScale.addChild(bg);

        // Create the ambient light

        AmbientLight ambLight = new AmbientLight(white);
        ambLight.setInfluencingBounds(bounds);
        objScale.addChild(ambLight);

        // Create the directional light

        Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
        DirectionalLight dirLight = new DirectionalLight(white, dir);
        dirLight.setInfluencingBounds(bounds);
        objScale.addChild(dirLight);
     
        // Create the red appearance node

        Material redMaterial = 
           new Material(ambientRed, black, red, specular, 75.0f);
        redMaterial.setLightingEnable(true);
        Appearance redAppearance = new Appearance();
        redAppearance.setMaterial(redMaterial);

        // Create the white appearance node

        Material whiteMaterial = 
           new Material(ambient, black, diffuse, specular, 75.0f);
        whiteMaterial.setLightingEnable(true);
        Appearance whiteAppearance = new Appearance();
        whiteAppearance.setMaterial(whiteMaterial);

        // Create the transform node

	TransformGroup transformGroup = new TransformGroup();
	transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
	transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
	transformGroup.addChild(new Cube(redAppearance).getChild());
	transformGroup.addChild(new Corners(whiteAppearance).getChild());
	objScale.addChild(transformGroup);
	
	// Create the drag behavior node

	MouseRotate behavior = new MouseRotate();
	behavior.setTransformGroup(transformGroup);
	transformGroup.addChild(behavior);
	behavior.setSchedulingBounds(bounds);
	
	// Create the zoom behavior node

	MouseZoom behavior2 = new MouseZoom();
	behavior2.setTransformGroup(transformGroup);
	transformGroup.addChild(behavior2);
	behavior2.setSchedulingBounds(bounds);
	
	// Create the zoom behavior node

	MouseTranslate behavior3 = new MouseTranslate();
	behavior3.setTransformGroup(transformGroup);
	transformGroup.addChild(behavior3);
	behavior3.setSchedulingBounds(bounds);

        // Let Java 3D perform optimizations on this scene graph.

        branchGroup.compile();

	return branchGroup;
    }

    /**
     * Calls the various methods necessary to initialize the 
     * program.
     */
    public void init() {

        // Set the layout manager

	setLayout(new BorderLayout());

        // Create the 3D canvas

	Canvas3D canvas = new Canvas3D(null);
	add("Center", canvas);

	// Create the scene branch graph

	BranchGroup scene = createSceneGraph();

	// Create the Universe, the Locale, and the view branch graph

	SimpleUniverse u = new SimpleUniverse(canvas);

        // This will move the ViewPlatform back a bit so the

        // objects in the scene can be viewed.

        u.getViewingPlatform().setNominalViewingTransform();

	u.addBranchGraph(scene);
   }

    /**
     *  Inner class used to "kill" the window when running as
     *  an application.
     */
    static class killAdapter extends WindowAdapter {
       public void windowClosing(WindowEvent event) {
          System.exit(0);
       }
    }

    /**
     *  Used when running as an application.
     */
    public static void main(String[] args) {
       Drag drag = new Drag();
       drag.setAppletFlag(false);
       drag.init();

       Frame frame = new Frame("Drag the mouse in the window");
       frame.setSize(640, 480);
       frame.add("Center", drag);
       frame.addWindowListener(new killAdapter());
       frame.setVisible(true);
    }
}




Tutorials

Linux System Admin Tips: There are over 200 Linux tips and tricks in this article. That is over 100 pages covering everything from NTP, setting up 2 IP address on one NIC, sharing directories among several users, putting running jobs in the background, find out who is doing what on your system by examining open sockets and the ps command, how to watch a file, how to prevent even root from deleting a file, tape commands, setting up cron jobs, using rsync, using screen conveniently with emacs, how to kill every process for a user, security tips and a lot more. These tip grow weekly. The above link will download the text version for easy grep searching. There is also an html version here.

Breaking Firewalls with OpenSSH and PuTTY: If the system administrator deliberately filters out all traffic except port 22 (ssh), to a single server, it is very likely that you can still gain access other computers behind the firewall. This article shows how remote Linux and Windows users can gain access to firewalled samba, mail, and http servers. In essence, it shows how openSSH and Putty can be used as a VPN solution for your home or workplace.

MySQL Tips and Tricks: Find out who is doing what in MySQL and how to kill the process, create binary log files, connect, create and select with Perl and Java, remove duplicates in a table with the index command, rollback and how to apply, merging several tables into one, updating foreign keys, monitor port 3306 with the tcpdump command, creating a C API, complex selects, and much more.

Create a Live Linux CD - BusyBox and OpenSSH Included: These steps will show you how to create a functioning Linux system, with the latest 2.6 kernel compiled from source, and how to integrate the BusyBox utilities including the installation of DHCP. Plus, how to compile in the OpenSSH package on this CD based system. On system boot-up a filesystem will be created and the contents from the CD will be uncompressed and completely loaded into RAM -- the CD could be removed at this point for boot-up on a second computer. The remaining functioning system will have full ssh capabilities. You can take over any PC assuming, of course, you have configured the kernel with the appropriate drivers and the PC can boot from a CD. This tutorial steps you through the whole processes.

SQLite Tutorial : This article explores the power and simplicity of sqlite3, first by starting with common commands and triggers, then the attach statement with the union operation is introduced in a way that allows multiple tables, in separate databases, to be combined as one virtual table, without the overhead of copying or moving data. Next, the simple sign function and the amazingly powerful trick of using this function in SQL select statements to solve complex queries with a single pass through the data is demonstrated, after making a brief mathematical case for how the sign function defines the absolute value and IF conditions.

The Lemon Parser Tutorial: This article explains how to build grammars and programs using the lemon parser, which is faster than yacc. And, unlike yacc, it is thread safe.

How to Compile the 2.6 kernel for Red Hat 9 and 8.0 and get Fedora Updates: This is a step by step tutorial on how to compile the 2.6 kernel from source.

Virtual Filesystem: Building A Linux Filesystem From An Ordinary File. You can take a disk file, format it as ext2, ext3, or reiser filesystem and then mount it, just like a physical drive. Yes, it then possible to read and write files to this newly mounted device. You can also copy the complete filesystem, since it is just a file, to another computer. If security is an issue, read on. This article will show you how to encrypt the filesystem, and mount it with ACL (Access Control Lists), which give you rights beyond the traditional read (r) write (w) and execute (x) for the 3 user groups file, owner and other.

Working With Time: What? There are 61 seconds in a minute? We can go back in time? We still tell time by the sun?



Chirico img Mike Chirico, a father of triplets (all girls) lives outside of Philadelphia, PA, USA. He has worked with Linux since 1996, has a Masters in Computer Science and Mathematics from Villanova University, and has worked in computer-related jobs from Wall Street to the University of Pennsylvania. His hero is Paul Erdos, a brilliant number theorist who was known for his open collaboration with others.


Mike's notes page is souptonuts. For open source consulting needs, please send an email to mchirico@gmail.com. All consulting work must include a donation to SourceForge.net.

SourceForge.net Logo


SourceForge.net Logo