home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch12 / geometry / Box.bak < prev    next >
Text File  |  1997-01-05  |  2KB  |  115 lines

  1. // VRML Generator
  2. // Copyright Justin Couch 1996
  3. //
  4. // Chapter 13: Late Night VRML 2.0 and Java
  5. //
  6. // Box class
  7.  
  8. package geometry;
  9.  
  10. import java.io.*;
  11. import java.awt.*;
  12. import vrml.external.*;
  13. import vrml.external.field.*;
  14. import vrml.external.exception.*;
  15. import geometry.Geometry;
  16.  
  17. public class Box extends Geometry
  18. {
  19.     private float[] size = null;
  20.  
  21.     // constructor builds a default box node
  22.     public Box()
  23.     {
  24.         System.out.println("Default called No browser");
  25.         Browser b = Browser.getBrowser();
  26.  
  27.         if(b == null)
  28.             return;
  29.  
  30.         node = b.createVrmlFromString("Box {}")[0];
  31.     }
  32.  
  33.     public Box(Browser b)
  34.     {
  35.         System.out.println("Default called with browser");
  36.         if(b == null)
  37.             return;
  38.  
  39.         node = b.createVrmlFromString("Box {}")[0];
  40.  
  41.         System.out.println("The box original is " + node );
  42.     }
  43.  
  44.     public Box(float x, float y, float z)
  45.     {
  46.         System.out.println("Long called No browser");
  47.  
  48.         Browser b = Browser.getBrowser();
  49.  
  50.         size = new float[3];
  51.  
  52.         size[0] = x;
  53.         size[1] = y;
  54.         size[2] = z;
  55.  
  56.         if(b == null)
  57.             return;
  58.  
  59.         node = b.createVrmlFromString("Box { size " +
  60.                                        x + " " +
  61.                                        y + " " +
  62.                                        z + "}")[0];
  63.         have_browser = true;
  64.     }
  65.  
  66.     public Box(Browser b, float x, float y, float z)
  67.     {
  68.         System.out.println("Long called with browser");
  69.         
  70.         size = new float[3];
  71.  
  72.         size[0] = x;
  73.         size[1] = y;
  74.         size[2] = z;
  75.  
  76.         if(b == null)
  77.             return;
  78.  
  79.         node = b.createVrmlFromString("Box { size " +
  80.                                        x + " " +
  81.                                        y + " " +
  82.                                        z + "}")[0];
  83.         have_browser = true;
  84.     }
  85.  
  86.     public void finalize()
  87.     {
  88.         node = null;
  89.         size = null;
  90.     }
  91.  
  92.     public void writeToFile(PrintStream fp, int indent)
  93.     {
  94.         int    i;
  95.         StringBuffer buffer = new StringBuffer();
  96.  
  97.         for(i = 0; i < indent; i++)
  98.             buffer.append("  ");
  99.  
  100.         fp.print(buffer.toString() + "geometry ");
  101.         if(name != null)
  102.             fp.print("DEF " + name + " ");
  103.  
  104.         fp.print("Box {");
  105.  
  106.         if(size != null)
  107.             fp.print(" size " +
  108.                      size[0] + " " +
  109.                      size[1] + " " +
  110.                      size[2]);
  111.  
  112.         fp.println("}");
  113.     }
  114. }
  115.