From 1cde845f102a702eefe7dfe397cfa0d3461bf4d4 Mon Sep 17 00:00:00 2001 From: kcr Date: Mon, 12 Dec 2005 18:53:07 +0000 Subject: Partial fix for Issue 206 : Example program cleanup --- build.xml | 2 + src/Applet3D/HelloUniverse.html | 15 +++ src/Applet3D/HelloUniverse.java | 127 +++++++++++++++++++ src/Applet3D/HelloUniverse_plugin.html | 39 ++++++ src/Applet3D/build.xml | 69 +++++++++++ src/HelloUniverse/HelloUniverse.form | 36 ++++++ src/HelloUniverse/HelloUniverse.html | 15 --- src/HelloUniverse/HelloUniverse.java | 101 ++++++++++----- src/HelloUniverse/HelloUniverse_plugin.html | 39 ------ src/index.html | 183 ---------------------------- 10 files changed, 357 insertions(+), 269 deletions(-) create mode 100644 src/Applet3D/HelloUniverse.html create mode 100644 src/Applet3D/HelloUniverse.java create mode 100644 src/Applet3D/HelloUniverse_plugin.html create mode 100644 src/Applet3D/build.xml create mode 100644 src/HelloUniverse/HelloUniverse.form delete mode 100644 src/HelloUniverse/HelloUniverse.html delete mode 100644 src/HelloUniverse/HelloUniverse_plugin.html delete mode 100644 src/index.html diff --git a/build.xml b/build.xml index 346fc96..dfaa448 100644 --- a/build.xml +++ b/build.xml @@ -68,6 +68,7 @@ + @@ -95,6 +96,7 @@ + diff --git a/src/Applet3D/HelloUniverse.html b/src/Applet3D/HelloUniverse.html new file mode 100644 index 0000000..93b044c --- /dev/null +++ b/src/Applet3D/HelloUniverse.html @@ -0,0 +1,15 @@ + + +Hello, Universe! + + + +
+
+If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +
+
+
+ + diff --git a/src/Applet3D/HelloUniverse.java b/src/Applet3D/HelloUniverse.java new file mode 100644 index 0000000..7616a88 --- /dev/null +++ b/src/Applet3D/HelloUniverse.java @@ -0,0 +1,127 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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 MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS 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 THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.BorderLayout; +import java.awt.event.*; +import java.awt.GraphicsConfiguration; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.universe.*; +import javax.media.j3d.*; +import javax.vecmath.*; + +public class HelloUniverse extends Applet { + + private SimpleUniverse u = null; + + public BranchGroup createSceneGraph() { + // Create the root of the branch graph + BranchGroup objRoot = new BranchGroup(); + + // Create the TransformGroup node and initialize it to the + // identity. Enable the TRANSFORM_WRITE capability so that + // our behavior code can modify it at run time. Add it to + // the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple Shape3D node; add it to the scene graph. + objTrans.addChild(new ColorCube(0.4)); + + // Create a new Behavior object that will perform the + // desired operation on the specified transform and add + // it into the scene graph. + Transform3D yAxis = new Transform3D(); + Alpha rotationAlpha = new Alpha(-1, 4000); + + RotationInterpolator rotator = + new RotationInterpolator(rotationAlpha, objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + rotator.setSchedulingBounds(bounds); + objRoot.addChild(rotator); + + // Have Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + public HelloUniverse() { + } + + public void init() { + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + // Create a simple scene and attach it to the virtual universe + BranchGroup scene = createSceneGraph(); + u = new SimpleUniverse(c); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + u.getViewingPlatform().setNominalViewingTransform(); + + u.addBranchGraph(scene); + } + + public void destroy() { + u.cleanup(); + } + + // + // The following allows HelloUniverse to be run as an application + // as well as an applet + // + public static void main(String[] args) { + new MainFrame(new HelloUniverse(), 256, 256); + } +} diff --git a/src/Applet3D/HelloUniverse_plugin.html b/src/Applet3D/HelloUniverse_plugin.html new file mode 100644 index 0000000..947a59b --- /dev/null +++ b/src/Applet3D/HelloUniverse_plugin.html @@ -0,0 +1,39 @@ + + +Hello, Universe! + + + + + + + + + + +</COMMENT> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> + + + + + + + + diff --git a/src/Applet3D/build.xml b/src/Applet3D/build.xml new file mode 100644 index 0000000..47e5a36 --- /dev/null +++ b/src/Applet3D/build.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/HelloUniverse/HelloUniverse.form b/src/HelloUniverse/HelloUniverse.form new file mode 100644 index 0000000..48fadea --- /dev/null +++ b/src/HelloUniverse/HelloUniverse.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/HelloUniverse/HelloUniverse.html b/src/HelloUniverse/HelloUniverse.html deleted file mode 100644 index 93b044c..0000000 --- a/src/HelloUniverse/HelloUniverse.html +++ /dev/null @@ -1,15 +0,0 @@ - - -Hello, Universe! - - - -
-
-If you were using a Java-capable browser, -you would see Hello Universe! instead of this paragraph. -
-
-
- - diff --git a/src/HelloUniverse/HelloUniverse.java b/src/HelloUniverse/HelloUniverse.java index 7616a88..53faf03 100644 --- a/src/HelloUniverse/HelloUniverse.java +++ b/src/HelloUniverse/HelloUniverse.java @@ -42,20 +42,20 @@ * $State$ */ -import java.applet.Applet; -import java.awt.BorderLayout; -import java.awt.event.*; -import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class HelloUniverse extends Applet { +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class HelloUniverse extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -91,37 +91,74 @@ public class HelloUniverse extends Applet { return objRoot; } - public HelloUniverse() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration Canvas3D c = new Canvas3D(config); - add("Center", c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form HelloUniverse + */ + public HelloUniverse() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - // - // The following allows HelloUniverse to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new HelloUniverse(), 256, 256); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("HelloUniverse"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new HelloUniverse().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/HelloUniverse/HelloUniverse_plugin.html b/src/HelloUniverse/HelloUniverse_plugin.html deleted file mode 100644 index 947a59b..0000000 --- a/src/HelloUniverse/HelloUniverse_plugin.html +++ /dev/null @@ -1,39 +0,0 @@ - - -Hello, Universe! - - - - - - - - - - -</COMMENT> -<blockquote> -<hr> -If you were using a Java-capable browser, -you would see Hello Universe! instead of this paragraph. -<hr> -</blockquote> - - - - - - - - diff --git a/src/index.html b/src/index.html deleted file mode 100644 index 1d5533b..0000000 --- a/src/index.html +++ /dev/null @@ -1,183 +0,0 @@ - - - -Java 3D Example Programs - - - -

Java 3D Example Programs

- -

Run the Example Programs

- -

- -If these example programs don't work in your browser, refer to -"RUNNING JAVA 3D™ IN A BROWSER" in the Java 3D™ README file. - - -

-Click on any of the hyperlinks below to run that example program in your -browser using Java Plug-in. - -

- - - -- cgit v1.2.3