diff options
Diffstat (limited to 'src')
6 files changed, 107 insertions, 44 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/Resources.java b/src/classes/org/jdesktop/j3d/examples/Resources.java new file mode 100644 index 0000000..13012d3 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/Resources.java @@ -0,0 +1,70 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 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$ + */ + +package org.jdesktop.j3d.examples; + +import java.net.URL; + +/** + * + */ +public class Resources { + + /** + * Do not construct an instance of this class. + */ + private Resources() { + + } + + /** + * Return the URL of the filename under the resources directory + */ + public static URL getResource(String filename) { + URL url = Resources.class.getResource(filename); + return url; + } + + +} diff --git a/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java index e6ea23c..86c380a 100644 --- a/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java +++ b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java @@ -48,12 +48,12 @@ import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.behaviors.mouse.*; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class BackgroundGeometry extends Applet { @@ -169,14 +169,12 @@ public class BackgroundGeometry extends Applet { if (bgImage == null) { // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } setLayout(new BorderLayout()); GraphicsConfiguration config = @@ -225,11 +223,10 @@ public class BackgroundGeometry extends Applet { System.out.println(" Note that the background geometry only changes with rotation"); // the path to the image file for an application java.net.URL bgurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + + bgurl = Resources.getResource("resources/images/bg.jpg"); + if (bgurl == null) { + System.err.println("resources/images/bg.jpg not found"); System.exit(1); } new MainFrame(new BackgroundGeometry(bgurl), 750, 750); diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java index 02d02a1..838c7a2 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java @@ -51,7 +51,6 @@ import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; @@ -61,6 +60,7 @@ import java.io.*; import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; import java.net.MalformedURLException; +import org.jdesktop.j3d.examples.Resources; public class ObjLoadCg extends Applet { @@ -119,8 +119,8 @@ public class ObjLoadCg extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple_vp.cg"); - fragmentProgram = StringIO.readFully("./simple_fp.cg"); + vertexProgram = StringIO.readFully(Resources.getResource("resources/cg_shader/simple_vp.cg")); + fragmentProgram = StringIO.readFully(Resources.getResource("resources/cg_shader/simple_fp.cg")); } catch (IOException e) { e.printStackTrace(); @@ -183,12 +183,9 @@ public class ObjLoadCg extends Applet { public void init() { if (filename == null) { // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - System.err.println(e); + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); System.exit(1); } } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java index 9841a52..2e436d7 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java @@ -51,7 +51,6 @@ import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; @@ -61,6 +60,7 @@ import java.io.*; import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; import java.net.MalformedURLException; +import org.jdesktop.j3d.examples.Resources; public class ObjLoadGLSL extends Applet { @@ -117,8 +117,8 @@ public class ObjLoadGLSL extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully(shaderName + ".vert"); - fragmentProgram = StringIO.readFully(shaderName + ".frag"); + vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/" + shaderName + ".vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/" + shaderName + ".frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -181,12 +181,10 @@ public class ObjLoadGLSL extends Applet { public void init() { if (filename == null) { // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - throw new RuntimeException(e); + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); } } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java index 4f93a77..171fa63 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java @@ -51,6 +51,7 @@ import javax.media.j3d.*; import javax.vecmath.*; import java.awt.GraphicsConfiguration; import java.io.IOException; +import org.jdesktop.j3d.examples.Resources; /** * @@ -126,8 +127,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { String[] attrNames = { "numLights" }; try { - vertexProgram = StringIO.readFully("./gouraud.vert"); - fragmentProgram = StringIO.readFully("./gouraud.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/gouraud.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/gouraud.frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -142,8 +143,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { gouraudSP.setShaders(shaders); try { - vertexProgram = StringIO.readFully("./phong.vert"); - fragmentProgram = StringIO.readFully("./phong.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/phong.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/phong.frag")); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java index dd57983..dfe6c13 100644 --- a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java +++ b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java @@ -49,8 +49,6 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; @@ -60,6 +58,11 @@ import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; import java.net.MalformedURLException; + + +import java.awt.*; +import org.jdesktop.j3d.examples.Resources; + public class ObjLoad extends Applet { private boolean spin = false; @@ -159,12 +162,9 @@ public class ObjLoad extends Applet { public void init() { if (filename == null) { // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - System.err.println(e); + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); System.exit(1); } } |