diff options
author | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-14 19:26:20 +0000 |
---|---|---|
committer | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-14 19:26:20 +0000 |
commit | db51908057c333598179879522a230fc4929aeb3 (patch) | |
tree | f17cfb6d4fe7445280ff49f57e4b2337dc9a6a09 /src/classes/org | |
parent | 39d071c598f993a69999ec06cdff6e38cb5448c0 (diff) |
Modified programs to access data files via Resources class
Diffstat (limited to 'src/classes/org')
9 files changed, 126 insertions, 98 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java index 578401e..bed5d0b 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java @@ -46,14 +46,13 @@ package org.jdesktop.j3d.examples.appearance; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class AppearanceMixed extends Applet { @@ -443,28 +442,23 @@ public class AppearanceMixed extends Applet { public void init() { 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); + } + } + if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - setLayout(new BorderLayout()); + // the path to the image for an applet + texImage = Resources.getResource("resources/images/apimage.jpg"); + if (texImage == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + } + + setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); @@ -495,14 +489,17 @@ public class AppearanceMixed extends Applet { // the path to the image file for an application java.net.URL bgurl = null; java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceMixed(bgurl, texurl), 700, 700); + bgurl = Resources.getResource("resources/images/bg.jpg"); + if (bgurl == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + texurl = Resources.getResource("resources/images/apimage.jpg"); + if (texurl == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + + new MainFrame(new AppearanceMixed(bgurl, texurl), 700, 700); } } diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java index 8d57c48..03f25d8 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java @@ -46,12 +46,12 @@ package org.jdesktop.j3d.examples.appearance; 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 com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class AppearanceTest extends Applet { @@ -316,28 +316,23 @@ public class AppearanceTest extends Applet { public void init() { 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); - } - } - + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + // the path to the image for an applet + texImage = Resources.getResource("resources/images/apimage.jpg"); + if (texImage == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + } + setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); @@ -369,14 +364,18 @@ public class AppearanceTest extends Applet { // the path to the image file for an application java.net.URL bgurl = null; java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceTest(bgurl, texurl), 700, 700); + + bgurl = Resources.getResource("resources/images/bg.jpg"); + if (bgurl == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + texurl = Resources.getResource("resources/images/apimage.jpg"); + if (texurl == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + + new MainFrame(new AppearanceTest(bgurl, texurl), 700, 700); } } 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 838c7a2..93c89a2 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java @@ -119,8 +119,8 @@ public class ObjLoadCg extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully(Resources.getResource("resources/cg_shader/simple_vp.cg")); - fragmentProgram = StringIO.readFully(Resources.getResource("resources/cg_shader/simple_fp.cg")); + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_vp.cg")); + fragmentProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_fp.cg")); } catch (IOException e) { e.printStackTrace(); 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 2e436d7..9106c0f 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java @@ -117,8 +117,8 @@ public class ObjLoadGLSL extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/" + shaderName + ".vert")); - fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/" + shaderName + ".frag")); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/" + shaderName + ".vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/" + shaderName + ".frag")); } catch (IOException e) { throw new RuntimeException(e); 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 171fa63..50b68fc 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java @@ -127,8 +127,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { String[] attrNames = { "numLights" }; try { - vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/gouraud.vert")); - fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/gouraud.frag")); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/gouraud.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/gouraud.frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -143,8 +143,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { gouraudSP.setShaders(shaders); try { - vertexProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/phong.vert")); - fragmentProgram = StringIO.readFully(Resources.getResource("resources/glsl_shader/phong.frag")); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/phong.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/phong.frag")); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java index ba4e0f6..c7e2809 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.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; public class ShaderTestGLSL extends javax.swing.JFrame { @@ -114,20 +115,20 @@ public class ShaderTestGLSL extends javax.swing.JFrame { try { switch (index) { case DIMPLE_SHADER: - vertexProgram = StringIO.readFully("./dimple.vert"); - fragmentProgram = StringIO.readFully("./dimple.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/dimple.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/dimple.frag")); break; case BRICK_SHADER: - vertexProgram = StringIO.readFully("./aabrick.vert"); - fragmentProgram = StringIO.readFully("./aabrick.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/aabrick.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/aabrick.frag")); break; case WOOD_SHADER: - vertexProgram = StringIO.readFully("./wood.vert"); - fragmentProgram = StringIO.readFully("./wood.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/wood.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/wood.frag")); break; case POLKADOT3D_SHADER: - vertexProgram = StringIO.readFully("./polkadot3d.vert"); - fragmentProgram = StringIO.readFully("./polkadot3d.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/polkadot3d.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/polkadot3d.frag")); break; default: } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java index 0865f93..d1ac99e 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java @@ -53,9 +53,7 @@ import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.util.Enumeration; -import java.net.URL; -import java.net.MalformedURLException; +import org.jdesktop.j3d.examples.Resources; /** * Simple GLSL Shader test program @@ -112,8 +110,8 @@ public class SphereGLSL extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple.vert"); - fragmentProgram = StringIO.readFully("./simple.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/simple.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/simple.frag")); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java index cbca643..5366738 100644 --- a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java @@ -46,7 +46,6 @@ package org.jdesktop.j3d.examples.morphing; 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.*; @@ -56,6 +55,7 @@ import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; +import org.jdesktop.j3d.examples.Resources; public class Morphing extends Applet { @@ -210,6 +210,14 @@ public class Morphing extends Applet { public void init() { if (objFiles == null) { objFiles = new java.net.URL[3]; + for(int i=0; i<3; i++) { + objFiles[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); + if (objFiles[i] == null) { + System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); + System.exit(1); + } + } + /* // the path to the image for an applet String path = getCodeBase().toString(); try { @@ -221,6 +229,7 @@ public class Morphing extends Applet { System.out.println(ex.getMessage()); System.exit(1); } + */ } setLayout(new BorderLayout()); @@ -248,6 +257,14 @@ public class Morphing extends Applet { public static void main(String[] args) { java.net.URL[] urls = new java.net.URL[3]; // the path to the image file for an application + for(int i=0; i<3; i++) { + urls[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); + if (urls[i] == null) { + System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); + System.exit(1); + } + } + /* try { urls[0] = new java.net.URL("file:./hand1.obj"); urls[1] = new java.net.URL("file:./hand2.obj"); @@ -257,6 +274,7 @@ public class Morphing extends Applet { System.out.println(ex.getMessage()); System.exit(1); } + **/ new MainFrame(new Morphing(urls), 700, 700); } } diff --git a/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java b/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java index 1faad7e..e12204c 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java +++ b/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java @@ -52,10 +52,10 @@ import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.image.*; -import java.awt.color.ColorSpace; import com.sun.j3d.utils.image.TextureLoader; import javax.swing.*; import javax.swing.event.*; +import org.jdesktop.j3d.examples.Resources; public class TextureByReference extends Applet @@ -88,16 +88,16 @@ implements ItemListener, ActionListener, ChangeListener { // image files used for the Texture animation for the applet, // or if no parameters are passed in for the application public static final String[] defaultFiles = { - "../images/animation1.gif", - "../images/animation2.gif", - "../images/animation3.gif", - "../images/animation4.gif", - "../images/animation5.gif", - "../images/animation6.gif", - "../images/animation7.gif", - "../images/animation8.gif", - "../images/animation9.gif", - "../images/animation10.gif"}; + "resources/images/animation1.gif", + "resources/images/animation2.gif", + "resources/images/animation3.gif", + "resources/images/animation4.gif", + "resources/images/animation5.gif", + "resources/images/animation6.gif", + "resources/images/animation7.gif", + "resources/images/animation8.gif", + "resources/images/animation9.gif", + "resources/images/animation10.gif"}; private java.net.URL[] urls = null; @@ -113,7 +113,13 @@ implements ItemListener, ActionListener, ChangeListener { if (urls == null) { urls = new java.net.URL[defaultFiles.length]; for (int i = 0; i < defaultFiles.length; i++) { - try { + urls[i] = Resources.getResource(defaultFiles[i]); + if (urls[i] == null) { + System.err.println(defaultFiles[i] + " not found"); + System.exit(1); + } + /* + try { urls[i] = new java.net.URL(getCodeBase().toString() + defaultFiles[i]); } @@ -121,6 +127,7 @@ implements ItemListener, ActionListener, ChangeListener { System.out.println(ex.getMessage()); System.exit(1); } + */ } } setLayout(new BorderLayout()); @@ -511,7 +518,14 @@ implements ItemListener, ActionListener, ChangeListener { else { fnames = new java.net.URL[TextureByReference.defaultFiles.length]; for (int i = 0; i < TextureByReference.defaultFiles.length; i++) { - try { + fnames[i] = Resources.getResource(defaultFiles[i]); + if (fnames[i] == null) { + System.err.println(TextureByReference.defaultFiles[i] + " not found"); + System.exit(1); + } + +/* + try { fnames[i] = new java.net.URL("file:" + TextureByReference.defaultFiles[i]); } @@ -519,6 +533,7 @@ implements ItemListener, ActionListener, ChangeListener { System.out.println(ex.getMessage()); System.exit(1); } + */ } } new MainFrame((new TextureByReference(fnames)), 650, 750); |